Annotation processing (in Java 1.6 flavour) [message #259338] |
Sun, 05 April 2009 11:18  |
Eclipse User |
|
|
|
I wrote a simple annotation processor catching some annotations on methods
and constructors. Apparently I can not access parameters because the
method getParameters() of ExecutableElement always return a void list.
It is because this functionality is not yet implemented or it is an error?
Federico
|
|
|
|
Re: Annotation processing (in Java 1.6 flavour) [message #259421 is a reply to message #259342] |
Tue, 07 April 2009 14:32   |
Eclipse User |
|
|
|
Walter Harley wrote:
> "Federico Tomassetti" <f.tomassetti@gmail.com> wrote in message
> news:0ffbd510f9569b38f76e0fe44a3a7ded$1@www.eclipse.org...
>>I wrote a simple annotation processor catching some annotations on methods
>>and constructors. Apparently I can not access parameters because the method
>>getParameters() of ExecutableElement always return a void list.
>>
>> It is because this functionality is not yet implemented or it is an error?
> There have been some bugs fixed recently regarding annotations on
> parameters. What version of Eclipse are you using? Can you try Eclipse
> 3.4.2, and/or Eclipse 3.5 M5, and see if the problem still exists?
First of all thank you for you reply.
Under Eclipse 3.4.0 I used this code:
@SupportedAnnotationTypes("it.tomassetti.NotNullParams") // Process all
annotations
@SupportedSourceVersion(RELEASE_6)
public class CommonAnnoProcessor extends AbstractProcessor {
@Override
public boolean process(Set<? extends TypeElement> annotations,
RoundEnvironment roundEnv) {
for (Element e :
roundEnv.getElementsAnnotatedWith(NotNullParams.class)){
if (e instanceof ExecutableElement){
ExecutableElement ee = (ExecutableElement)e;
String s =
"name="+ee.getSimpleName()+",n_params="+ee.getParameters().size();
this.processingEnv.getMessager().printMessage(Kind.OTHER, "Annotated
"+s, e);
} else {
this.processingEnv.getMessager().printMessage(Kind.ERROR, "Not
executable element", e);
}
}
return true;
}
}
---
package it.tomassetti;
import it.tomassetti.NotNullParams;
public class TestA {
@NotNullParams("")
public void a(){
}
@NotNullParams("")
public void b(){
}
@NotNullParams("")
public void c(int a){
}
@NotNullParams("")
public void d(String a, String b){
}
}
---
In the editor I can see a note on all of my methods (a,b,c,d) and all of
theese notes reports that the number of parameters is zero.
I am going to test it under Eclipse 3.4.2 and look if it behaves
differently.
Federico Tomassetti
|
|
|
Re: Annotation processing (in Java 1.6 flavour) [message #259425 is a reply to message #259421] |
Tue, 07 April 2009 14:48   |
Eclipse User |
|
|
|
Federico Tomassetti wrote:
> Walter Harley wrote:
>> "Federico Tomassetti" <f.tomassetti@gmail.com> wrote in message
>> news:0ffbd510f9569b38f76e0fe44a3a7ded$1@www.eclipse.org...
>>>I wrote a simple annotation processor catching some annotations on methods
>>>and constructors. Apparently I can not access parameters because the method
>>>getParameters() of ExecutableElement always return a void list.
>>>
>>> It is because this functionality is not yet implemented or it is an error?
>> There have been some bugs fixed recently regarding annotations on
>> parameters. What version of Eclipse are you using? Can you try Eclipse
>> 3.4.2, and/or Eclipse 3.5 M5, and see if the problem still exists?
> First of all thank you for you reply.
> Under Eclipse 3.4.0 I used this code:
> @SupportedAnnotationTypes("it.tomassetti.NotNullParams") // Process all
> annotations
> @SupportedSourceVersion(RELEASE_6)
> public class CommonAnnoProcessor extends AbstractProcessor {
> @Override
> public boolean process(Set<? extends TypeElement> annotations,
> RoundEnvironment roundEnv) {
> for (Element e :
> roundEnv.getElementsAnnotatedWith(NotNullParams.class)){
> if (e instanceof ExecutableElement){
> ExecutableElement ee = (ExecutableElement)e;
> String s =
> "name="+ee.getSimpleName()+",n_params="+ee.getParameters().size();
> this.processingEnv.getMessager().printMessage(Kind.OTHER, "Annotated
> "+s, e);
> } else {
> this.processingEnv.getMessager().printMessage(Kind.ERROR, "Not
> executable element", e);
> }
> }
> return true;
> }
> }
> ---
> package it.tomassetti;
> import it.tomassetti.NotNullParams;
> public class TestA {
> @NotNullParams("")
> public void a(){
> }
> @NotNullParams("")
> public void b(){
> }
> @NotNullParams("")
> public void c(int a){
> }
> @NotNullParams("")
> public void d(String a, String b){
> }
> }
> ---
> In the editor I can see a note on all of my methods (a,b,c,d) and all of
> theese notes reports that the number of parameters is zero.
> I am going to test it under Eclipse 3.4.2 and look if it behaves
> differently.
> Federico Tomassetti
Under Eclipse 3.4.2 the correct number of params is recognized.
Federico Tomassetti
|
|
|
|
Powered by
FUDForum. Page generated in 0.03779 seconds