Skip to main content



      Home
Home » Language IDEs » Java Development Tools (JDT) » Annotation processing (Java 1.6) Eclipse Galileo
Annotation processing (Java 1.6) Eclipse Galileo [message #532066] Thu, 06 May 2010 22:41 Go to next message
Eclipse UserFriend
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 Go to previous messageGo to next message
Eclipse UserFriend
<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.
Re: Annotation processing (Java 1.6) Eclipse Galileo [message #533332 is a reply to message #532323] Thu, 13 May 2010 08:30 Go to previous message
Eclipse UserFriend
Sorry for the late reply.

Walter thank you for the response, I will enter an enhancement request in Bugzilla.
You were right on specifying the target I was successfully able to show the error message where I wanted.

Previous Topic:How can the VM notify JDT that a class has been unloaded?
Next Topic:I am very frustrated and I need help
Goto Forum:
  


Current Time: Tue Apr 15 01:47:44 EDT 2025

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

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

Back to the top