moosetechnology / Moose

MOOSE - Platform for software and data analysis.
https://moosetechnology.github.io/moose-wiki
MIT License
135 stars 34 forks source link

VerveineJ does not produce correct values for classes in annotation instances #714

Closed seandenigris closed 9 years ago

seandenigris commented 9 years ago

Originally reported on Google Code with ID 714

Take a look at the example below:

    @XmlElement(name = "Time", required = true, type = String.class)
    protected Date time;

The value of the third attribute of the annotation instance is the actual source code
of the String class. Instead, it should be just the string 'String.class'.

Ideally, we would get an actual reference, but the string would do for now.

Reported by tudor.girba on 2011-09-27 09:47:15

seandenigris commented 9 years ago
fixed and tested

Reported by anquetil.nicolas on 2012-03-23 17:33:29

seandenigris commented 9 years ago

Reported by tudor@tudorgirba.com on 2013-03-03 12:55:47

seandenigris commented 9 years ago
The problem seems to be back again. I just checked with the latest VerveineJ and for
a code that looks like (taken from Jenkins):

    @Restricted(NoExternalUse.class)
    public transient final NodeProvisioner overallNodeProvisioner = unlabeledNodeProvisioner;

I get an annotation instance that looks like

(FAMIX.AnnotationInstanceAttribute (id: 126)
        (annotationTypeAttribute (ref: 138875))
        (parentAnnotationInstance (ref: 8858))
        (value 'public class org.kohsuke.accmod.restrictions.NoExternalUse
    extends org.kohsuke.accmod.restrictions.DoNotUse
/*   methods   */
[unresolved] public void <init>() 
[unresolved] public void error(Unresolved type org.kohsuke.accmod.impl.Location, Unresolved
type org.kohsuke.accmod.impl.RestrictedElement, Unresolved type org.kohsuke.accmod.impl.ErrorListener)

'))

It would be so great if someone could take a look at this.

Reported by tudor@tudorgirba.com on 2013-08-09 20:59:04

seandenigris commented 9 years ago
Flagging as Invalid because I was enabled to reproduce the error.
tried (not all combinations):
- library annotation, project local annotation
- library class as parameter, project local class as parameter
- annotation on attribute, on method, on class

Reported by anquetil.nicolas on 2013-08-14 15:38:28

seandenigris commented 9 years ago
I am reopening it again, but this time I have an example project that shows the problem
in the attachment.

If you parse that one with the latest VerveineJ, you get the following AnnotationInstanceAttribute:

(FAMIX.AnnotationInstanceAttribute (id: 5)
        (annotationTypeAttribute (ref: 14))
        (parentAnnotationInstance (ref: 16))
        (value '(id=NoId)
public class annotationTest.InterceptorClass
    extends java.lang.Object
/*   methods   */
[unresolved] public void <init>() 

'))

Reported by tudor@tudorgirba.com on 2013-08-20 09:55:39


seandenigris commented 9 years ago
OK
thanks for the example
I believe it fixed now

Reported by anquetil.nicolas on 2013-08-23 13:41:31

seandenigris commented 9 years ago
Great. I will test it right away

Reported by tudor@tudorgirba.com on 2013-08-23 14:14:26

seandenigris commented 9 years ago
I tested it and it works in the previous case, but I found another one for which it
does not work properly.

Namely:

@Interceptors({InterceptorClass.class, AnotherInterceptorClass.class})
public class AnotherAnnotatedClass {
}

produces:

    (FAMIX.AnnotationInstanceAttribute (id: 26)
        (annotationTypeAttribute (ref: 9))
        (parentAnnotationInstance (ref: 3))
        (value 'InterceptorClass.class'))

The value should be '{InterceptorClass.class, AnotherInterceptorClass.class}'. Or we
can make it such that value accepts a collection, and then value can be 
        (value 'InterceptorClass.class' 'AnotherInterceptorClass.class')

Reported by tudor@tudorgirba.com on 2013-08-23 14:40:33


seandenigris commented 9 years ago
I forgot to mention that I attached a test project.

Reported by tudor@tudorgirba.com on 2013-08-23 14:41:04

seandenigris commented 9 years ago
This is becoming more difficult.

First I choose the solution of "{InterceptorClass.class, AnotherInterceptorClass.class}"
to avoid changing FAMIX and make it unnecessarily complex

second, the problem with the previous  pb was that the annotationInstanceAttribute
"InterceptorClass.class" was treated as an array of one element by JDT

I corrected it by taking the first element of the array.

Now, {InterceptorClass.class, AnotherInterceptorClass.class} is also an array and it
did not show correctly because verveinej took only the first element.
This is easy to solve when the array has more than one element.
But when it has only one element, I have no way to tell the difference between
"InterceptorClass.class" and "{InterceptorClass.class}".

I choose to always consider it is the first solution (so I don't put {} around an array
of one)
Hope it will be acceptable to all

Reported by anquetil.nicolas on 2013-08-23 21:29:35