Annotation processing (Java 1.6) Eclipse Galileo [message #532066] |
Thu, 06 May 2010 22:41  |
Eclipse User |
|
|
|
I am trying to use a pluggable annotation processing in eclipse. I have created a custom annotation and a annotation processor:-
@SupportedAnnotationTypes("*")
@SupportedSourceVersion(SourceVersion.RELEASE_6)
public class TestAnnoPro extends AbstractProcessor {
@Override
public boolean process(Set<?extends TypeElement> annotations, RoundEnvironment roundEnv){
Messager mes = processingEnv.getMessager();
for (TypeElement element : annotations){
System.out.println(element.getQualifiedName() + "---" + element.getSimpleName());
mes.printMessage(Kind.ERROR, "test error");
}
mes.printMessage(Kind.ERROR, "2222222222");
return true;
}
Now I clean my project and do a build, I see that the error messages are printed in the error log window (so the annotation processor is being called) and the class files (for the java class that i have annotated with my custom annotation) are generated. But since i am throwing an error the class files should not get generated right?
If I run the processor using javac, it is working fine (the class files is not generated).
Also if i get an error I want eclipse to show the error as red on the editor similar to the other compile time errors that are shown in the editor. For doing this should I have to create a eclipse plugin, if yes could someone guide me as to how I should proceed in order to accomplish this task
|
|
|
Re: Annotation processing (Java 1.6) Eclipse Galileo [message #532323 is a reply to message #532066] |
Sat, 08 May 2010 02:21   |
Eclipse User |
|
|
|
<anuj0416@gmail.com> wrote in message news:hrvult$6ho$1@build.eclipse.org...
>I am trying to use a pluggable annotation processing in eclipse. I have
>created a custom annotation and a annotation processor:-
>
> @SupportedAnnotationTypes("*")
> @SupportedSourceVersion(SourceVersion.RELEASE_6)
> public class TestAnnoPro extends AbstractProcessor {
> @Override
> public boolean process(Set<?extends TypeElement> annotations,
> RoundEnvironment roundEnv){
> Messager mes = processingEnv.getMessager();
> for (TypeElement element : annotations){
> System.out.println(element.getQualifiedName() + "---" +
> element.getSimpleName()); mes.printMessage(Kind.ERROR, "test
> r"); } mes.printMessage(Kind.ERROR, "2222222222"); return
> }
>
>
> Now I clean my project and do a build, I see that the error messages are
> printed in the error log window (so the annotation processor is being
> called) and the class files (for the java class that i have annotated with
> my custom annotation) are generated. But since i am throwing an error the
> class files should not get generated right?
> If I run the processor using javac, it is working fine (the class files is
> not generated).
That is an interesting question. I don't think the JSR269 spec (the
annotation processing spec) says anything about whether the compiler is
allowed to generate class files if an annotation processor reports errors.
I can certainly see why you would expect it not to. I think that would be a
very reasonable enhancement request. More generally, if a
compilationParticipant (that's the API that annotation processing in Eclipse
uses) reports an error, perhaps the compiler should not generate class
files.
Could you enter an enhancement request for that, in Bugzilla?
>
> Also if i get an error I want eclipse to show the error as red on the
> editor similar to the other compile time errors that are shown in the
> editor. For doing this should I have to create a eclipse plugin, if yes
> could someone guide me as to how I should proceed in order to accomplish
> this task
You probably need to specify the target of the message. Note that the
printMessage() method takes some optional parameters to specify the element
that the error should be reported against. Without that, we have no way of
knowing where to put the red marking.
|
|
|
|
Powered by
FUDForum. Page generated in 0.04396 seconds