Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » Annotations and com.sun.mirror API
Annotations and com.sun.mirror API [message #636866] Wed, 03 November 2010 08:06 Go to next message
Fabien Giquel is currently offline Fabien GiquelFriend
Messages: 147
Registered: July 2009
Senior Member
Given two classes with some inheritance and annotations :

public class A {
@MyAnnotation
public String myField;
}

public class B {
@MyOtherAnnotation
public String myOtherField;
}


-> Writing an AnnotationProcessor impl, i encounter this little problem, and i do not know if it is a bug or a normal limitation :

I get a com.sun.mirror.declaration.TypeDeclaration instance for B
- I can retrieve a FieldDeclaration, and the AnnotationMirror isntance, and then the SourcePosition associated to the annotation "MyOtherAnnotation"
- I can retrieve a TypeDeclaration for A from B (using .getSuperclass()), and then the FieldDeclaration for "myField"', and then AnnotationMirror instance for "MyAnnotation" but then there is no SourcePosition associated to this last one. Meanwhile there is one SourcePosition associated for the FieldDeclaration.


Thanks in advance for anyone who has an explanation about this.


----------------------------------------------------
Fabien GIQUEL
R&D Engineer
Mia-Software
rue Nina Simone
44000 NANTES
----------------------------------------------------
Re: Annotations and com.sun.mirror API [message #636988 is a reply to message #636866] Wed, 03 November 2010 16:36 Go to previous messageGo to next message
Walter Harley is currently offline Walter HarleyFriend
Messages: 847
Registered: July 2009
Senior Member
On 11/3/10 1:06 AM, Fabien Giquel wrote:
> Given two classes with some inheritance and annotations :
>
> public class A {
> @MyAnnotation
> public String myField;
> }
>
> public class B {
> @MyOtherAnnotation
> public String myOtherField;
> }
>
>
> -> Writing an AnnotationProcessor impl, i encounter this little problem,
> and i do not know if it is a bug or a normal limitation :
>
> I get a com.sun.mirror.declaration.TypeDeclaration instance for B
> - I can retrieve a FieldDeclaration, and the AnnotationMirror isntance,
> and then the SourcePosition associated to the annotation
> "MyOtherAnnotation"
> - I can retrieve a TypeDeclaration for A from B (using
> .getSuperclass()), and then the FieldDeclaration for "myField"', and
> then AnnotationMirror instance for "MyAnnotation" but then there is no
> SourcePosition associated to this last one. Meanwhile there is one
> SourcePosition associated for the FieldDeclaration.
>
>
> Thanks in advance for anyone who has an explanation about this.

I assume you mean B extends A? Your code example doesn't say so.

If A has already been compiled, then it might be read from the .class
instead of from source. In that case there is no SourcePosition. Are
both classes in the same project? Do you get these results on a full
build (after a clean) or only on incremental builds?

Generally the best way to think about annotation processing is that you
are looking at a typesystem - not at source code - but that you get a
little bit of extra information for the particular file whose
annotations are being processed. So if you're writing a processor for
@MyOtherAnnotation, you will get source positions for files containing
that annotation, and you will get typesystem information only for the
other files. Sometimes you get a bit extra but that is not guaranteed.
Re: Annotations and com.sun.mirror API [message #637139 is a reply to message #636988] Thu, 04 November 2010 10:45 Go to previous messageGo to next message
Fabien Giquel is currently offline Fabien GiquelFriend
Messages: 147
Registered: July 2009
Senior Member
Yes, i forget the "extends A".

Thanks for your explanation. In my case, both A and B .java files are in
the same project. I use incremental build and did not try some clean.
Never mind. I understand your explanation about typesystem information,
and finally the provided information will fit my needs.

Thanks again.
Fabien.


----------------------------------------------------
Fabien GIQUEL
R&D Engineer
Mia-Software
rue Nina Simone
44000 NANTES
----------------------------------------------------
Re: Annotations and com.sun.mirror API [message #637234 is a reply to message #637139] Thu, 04 November 2010 16:40 Go to previous message
Walter Harley is currently offline Walter HarleyFriend
Messages: 847
Registered: July 2009
Senior Member
On 11/4/10 3:45 AM, Fabien wrote:
> Yes, i forget the "extends A".
>
> Thanks for your explanation. In my case, both A and B .java files are in
> the same project. I use incremental build and did not try some clean.
> Never mind. I understand your explanation about typesystem information,
> and finally the provided information will fit my needs.

The com.sun.mirror.apt (Java 5) APT API was designed for command-line
compilation with the apt tool, and did not take incremental compilation
(as in an IDE) into account. When the javax.annotation.processing API
was standardized in Java 6, with JSR269, we were able to get them to
make some changes to make it a little better for incremental compilation
- it is still not ideal but it is a little more predictable and usable.
Previous Topic:workspace preferences vs. project preferences
Next Topic:Howto replace pattern in all (open/project) files ?
Goto Forum:
  


Current Time: Tue Apr 23 08:03:45 GMT 2024

Powered by FUDForum. Page generated in 0.03904 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top