Home » Language IDEs » Java Development Tools (JDT) » pluggable annotation processin doesn't work
pluggable annotation processin doesn't work [message #253742] |
Tue, 03 June 2008 15:54  |
Eclipse User |
|
|
|
Hello,
I've written a simple annotation processor (JSR-269) that works with the
normal javac.
But neither inside the IDE nor using ecj standalone I'm capable of getting
it to work.
Following the output in standalone mode:
/usr/lib/jvm/java-6-sun/bin/java -jar /opt/eclipse-34/plugins/org.eclipse.jdt.core_3.4.0.v_871.jar -6
-XprintRounds -XprintProcessorInfo -verbose -cp ../SwingAnnotations/bin:tstProc.jar
src/dk/example/AnnotatedClass.java src/dk/example/AnnotatedClassB.java
[parsing src/dk/example/AnnotatedClass.java - #1/2]
[parsing src/dk/example/AnnotatedClassB.java - #2/2]
[reading java/lang/Object.class]
[analyzing src/dk/example/AnnotatedClass.java - #1/2]
[reading dk/DataObject.class]
[reading java/lang/String.class]
[reading java/lang/System.class]
[reading java/io/PrintStream.class]
[analyzing src/dk/example/AnnotatedClassB.java - #2/2]
[writing dk/example/AnnotatedClass.class - #1]
[completed src/dk/example/AnnotatedClass.java - #1/2]
[writing dk/example/AnnotatedClassB.class - #2]
[completed src/dk/example/AnnotatedClassB.java - #2/2]
[2 units compiled]
[2 .class files generated]
AnnotatedClass and AnnotatedClassB are two classes annotated with the
annotation DataObject.
As you can see there's not even the attempt to run the annotation processor.
Of course there is a corresponding META-INF-entry...
Hope you can help,
Daniel
|
|
| |
Re: pluggable annotation processin doesn't work [message #253836 is a reply to message #253742] |
Tue, 10 June 2008 13:02   |
Eclipse User |
|
|
|
"Daniel Koebbing" <Daniel.Koebbing@westfleisch.de> wrote in message
news:g247ho$rro$1@build.eclipse.org...
> Hello,
>
> I've written a simple annotation processor (JSR-269) that works with the
> normal javac.
> But neither inside the IDE nor using ecj standalone I'm capable of getting
> it to work.
> Following the output in standalone mode:
>
> /usr/lib/jvm/java-6-sun/bin/java -jar
> /opt/eclipse-34/plugins/org.eclipse.jdt.core_3.4.0.v_871.jar -6
> -XprintRounds -XprintProcessorInfo -verbose -cp
> ../SwingAnnotations/bin:tstProc.jar
> src/dk/example/AnnotatedClass.java src/dk/example/AnnotatedClassB.java
>
> [parsing src/dk/example/AnnotatedClass.java - #1/2]
> [parsing src/dk/example/AnnotatedClassB.java - #2/2]
> [reading java/lang/Object.class]
> [analyzing src/dk/example/AnnotatedClass.java - #1/2]
> [reading dk/DataObject.class]
> [reading java/lang/String.class]
> [reading java/lang/System.class]
> [reading java/io/PrintStream.class]
> [analyzing src/dk/example/AnnotatedClassB.java - #2/2]
> [writing dk/example/AnnotatedClass.class - #1]
> [completed src/dk/example/AnnotatedClass.java - #1/2]
> [writing dk/example/AnnotatedClassB.class - #2]
> [completed src/dk/example/AnnotatedClassB.java - #2/2]
> [2 units compiled]
> [2 .class files generated]
>
> AnnotatedClass and AnnotatedClassB are two classes annotated with the
> annotation DataObject.
> As you can see there's not even the attempt to run the annotation
> processor.
> Of course there is a corresponding META-INF-entry...
Oh, in addition to my other response regarding ecj.jar, I see you've tried
to get it to work in the IDE. Did you have the same problem there (ie, no
sign of any annotation processing at all)? Did you enable annotation
processing in the project preferences, and add the processor jar to the
factory path in the annotation processing factory path preferences?
If that stuff all seems right and it's still not working, please file a bug
in Bugzilla (JDT/APT component) and include your processor, and I'll try to
take a look at it. Annotation processing does work :-) so I think this is
just a configuration problem, but there are a lot of pieces that all need to
be in just the right place for it to happen.
Thanks,
-Walter Harley
JDT APT lead
|
|
| |
Re: pluggable annotation processin doesn't work [message #253849 is a reply to message #253836] |
Wed, 11 June 2008 04:43   |
Eclipse User |
|
|
|
Hello Walter,
as I mentioned in my answer to your former reply I got annotation processing
working with eclipse.
But now I have the following problem: I want to use velocity for my
processor. Running the processor with javac or ecj.jar everything works
fine. But using the processor inside eclipse I get the following exception:
!ENTRY org.eclipse.jdt.apt.pluggable.core 1 1 2008-06-11 10:33:21.478
!MESSAGE init: java.lang.Exception: The specified class for ResourceManager
(org.apache.velocity.runtime.resource.ResourceManagerImpl) does not
implement org.apache.velocity.runtime.resource.ResourceManager; Velocity is
not initialized correctly.
at
org.apache.velocity.runtime.RuntimeInstance.initializeResour ceManager(RuntimeInstance.java:589)
at
org.apache.velocity.runtime.RuntimeInstance.init(RuntimeInst ance.java:241)
at
org.apache.velocity.runtime.RuntimeSingleton.init(RuntimeSin gleton.java:113)
at org.apache.velocity.app.Velocity.init(Velocity.java:83)
at dk.TestProcessor.init(TestProcessor.java:39)
at
org.eclipse.jdt.internal.apt.pluggable.core.dispatch.IdeAnno tationProcessorManager.discoverNextProcessor(IdeAnnotationPr ocessorManager.java:93)
.......
I checked the velocity source, they use
"o = ClassUtils.getNewInstance( rm );"
which uses either Thread.currentThread().getContextClassLoader() or the
system class loader.
Now I'm stuck...
Regards,
Daniel
Walter Harley wrote:
> "Daniel Koebbing" <Daniel.Koebbing@westfleisch.de> wrote in message
> news:g247ho$rro$1@build.eclipse.org...
>> Hello,
>>
>> I've written a simple annotation processor (JSR-269) that works with the
>> normal javac.
>> But neither inside the IDE nor using ecj standalone I'm capable of
>> getting it to work.
>> Following the output in standalone mode:
>>
>> /usr/lib/jvm/java-6-sun/bin/java -jar
>> /opt/eclipse-34/plugins/org.eclipse.jdt.core_3.4.0.v_871.jar -6
>> -XprintRounds -XprintProcessorInfo -verbose -cp
>> ../SwingAnnotations/bin:tstProc.jar
>> src/dk/example/AnnotatedClass.java src/dk/example/AnnotatedClassB.java
>>
>> [parsing src/dk/example/AnnotatedClass.java - #1/2]
>> [parsing src/dk/example/AnnotatedClassB.java - #2/2]
>> [reading java/lang/Object.class]
>> [analyzing src/dk/example/AnnotatedClass.java - #1/2]
>> [reading dk/DataObject.class]
>> [reading java/lang/String.class]
>> [reading java/lang/System.class]
>> [reading java/io/PrintStream.class]
>> [analyzing src/dk/example/AnnotatedClassB.java - #2/2]
>> [writing dk/example/AnnotatedClass.class - #1]
>> [completed src/dk/example/AnnotatedClass.java - #1/2]
>> [writing dk/example/AnnotatedClassB.class - #2]
>> [completed src/dk/example/AnnotatedClassB.java - #2/2]
>> [2 units compiled]
>> [2 .class files generated]
>>
>> AnnotatedClass and AnnotatedClassB are two classes annotated with the
>> annotation DataObject.
>> As you can see there's not even the attempt to run the annotation
>> processor.
>> Of course there is a corresponding META-INF-entry...
>
>
> Oh, in addition to my other response regarding ecj.jar, I see you've tried
> to get it to work in the IDE. Did you have the same problem there (ie, no
> sign of any annotation processing at all)? Did you enable annotation
> processing in the project preferences, and add the processor jar to the
> factory path in the annotation processing factory path preferences?
>
> If that stuff all seems right and it's still not working, please file a
> bug in Bugzilla (JDT/APT component) and include your processor, and I'll
> try to
> take a look at it. Annotation processing does work :-) so I think this is
> just a configuration problem, but there are a lot of pieces that all need
> to be in just the right place for it to happen.
>
> Thanks,
> -Walter Harley
> JDT APT lead
|
|
| | | |
Re: pluggable annotation processin doesn't work [message #253916 is a reply to message #253912] |
Fri, 13 June 2008 08:48   |
Eclipse User |
|
|
|
Hello Florin,
Unfortunately I can't really say where the problem has been, but I'll try to
describe what I've done to get it working:
First of all I created different projects for the annotation, the processor
and my test case (you don't have to, but it makes things easier).
Then I use the current release candidate (RC4)...
Following my current test processor:
package dk;
import java.util.Set;
import javax.annotation.processing.AbstractProcessor;
import javax.annotation.processing.ProcessingEnvironment;
import javax.annotation.processing.RoundEnvironment;
import javax.annotation.processing.SupportedAnnotationTypes;
import javax.annotation.processing.SupportedSourceVersion;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.element.Element;
import javax.lang.model.element.TypeElement;
import javax.tools.Diagnostic.Kind;
@SupportedAnnotationTypes("dk.*")
@SupportedSourceVersion(SourceVersion.RELEASE_6)
public class TestProcessorB extends AbstractProcessor {
@Override
public synchronized void init(ProcessingEnvironment arg) {
super.init(arg);
processingEnv.getMessager().printMessage(Kind.NOTE, "init called");
}
@Override
public boolean process(Set<? extends TypeElement> elements,
RoundEnvironment roundEnv) {
for (TypeElement e : elements) {
System.err.println("Type-Element: " + e);
}
if (!roundEnv.processingOver()) {
for (Element re : roundEnv.getRootElements()) {
showElementInfo(re, "");
}
}
return false;
}
private void showElementInfo(Element re, String einr) {
System.err.print(einr + "Element(" + re.getKind().name() + "): " + re
+ " - ");
for (AnnotationMirror am : re.getAnnotationMirrors()) {
System.err.print(" " + am.getAnnotationType().toString());
}
System.err.println();
for (Element el : re.getEnclosedElements())
showElementInfo(el, einr + " ");
}
}
Most important is the services entry in the META-INF directory of the jar
(META-INF/services/javax.annotation.processing.Processor) containing the
classname of the processor ("dk.TestProcessorB" in my case).
After building the jar I just selected it as annotation processor in my test
case (enable processing in editor, no batch mode). Ensure that you can see
your processor when you click the advanced-button.
As soon as I try to use a more sophisticated processor that uses velocity I
encounter new problems. But for my project at hand I can do without
velocity for some time...
I'll keep you informed if I find a solution.
Good luck,
Daniel
Florin Bratu wrote:
> I am encountering the same problem - in the IDE the annotation processor
> does not get called. Daniel, can you please share the cause of the problem
> in your case and your solution? Maybe it is the same for me...
>
> I wrote an annotation processor according using apt & the Mirror API, and
> I managed to get it working within Eclipse, but with jsr269 I can't get it
> configured properly.
|
|
|
Re: pluggable annotation processin doesn't work [message #253925 is a reply to message #253916] |
Fri, 13 June 2008 09:52   |
Eclipse User |
|
|
|
Originally posted by: Florin-Alexandru.Bratu.sophia.inria.fr
Hello again,
About the META-INF/services file, I knew I had to created it for the
MirrorAPI in order to specify the ProcessFactory, but I didn't know it
was necessary for jsr269. I've added it , and now my processor appears
in the list when clicking on the advanced button. However, the process
does not execute!
I've created an ant build.xml in which I call javac using the options:
-proc:only -processorpath ${AnnotDir} -processor ${AnnotProc}
and it works, but of course it shows me the errors in the console view,
and I want them to show up in the error view and also in the source
editor, with the red underline thing.
So, my question would be: how can I pass options to the Java compiler
that Eclipse invokes when compiling the Java sources?
Daniel Koebbing wrote:
> Hello Florin,
>
> Unfortunately I can't really say where the problem has been, but I'll try to
> describe what I've done to get it working:
>
> First of all I created different projects for the annotation, the processor
> and my test case (you don't have to, but it makes things easier).
> Then I use the current release candidate (RC4)...
> Following my current test processor:
>
> package dk;
>
> import java.util.Set;
>
> import javax.annotation.processing.AbstractProcessor;
> import javax.annotation.processing.ProcessingEnvironment;
> import javax.annotation.processing.RoundEnvironment;
> import javax.annotation.processing.SupportedAnnotationTypes;
> import javax.annotation.processing.SupportedSourceVersion;
> import javax.lang.model.SourceVersion;
> import javax.lang.model.element.AnnotationMirror;
> import javax.lang.model.element.Element;
> import javax.lang.model.element.TypeElement;
> import javax.tools.Diagnostic.Kind;
>
>
> @SupportedAnnotationTypes("dk.*")
> @SupportedSourceVersion(SourceVersion.RELEASE_6)
> public class TestProcessorB extends AbstractProcessor {
>
> @Override
> public synchronized void init(ProcessingEnvironment arg) {
> super.init(arg);
> processingEnv.getMessager().printMessage(Kind.NOTE, "init called");
> }
>
>
> @Override
> public boolean process(Set<? extends TypeElement> elements,
> RoundEnvironment roundEnv) {
> for (TypeElement e : elements) {
> System.err.println("Type-Element: " + e);
> }
>
> if (!roundEnv.processingOver()) {
> for (Element re : roundEnv.getRootElements()) {
> showElementInfo(re, "");
> }
>
> }
>
> return false;
> }
>
>
> private void showElementInfo(Element re, String einr) {
> System.err.print(einr + "Element(" + re.getKind().name() + "): " + re
> + " - ");
> for (AnnotationMirror am : re.getAnnotationMirrors()) {
> System.err.print(" " + am.getAnnotationType().toString());
> }
> System.err.println();
>
> for (Element el : re.getEnclosedElements())
> showElementInfo(el, einr + " ");
> }
> }
>
>
> Most important is the services entry in the META-INF directory of the jar
> (META-INF/services/javax.annotation.processing.Processor) containing the
> classname of the processor ("dk.TestProcessorB" in my case).
>
> After building the jar I just selected it as annotation processor in my test
> case (enable processing in editor, no batch mode). Ensure that you can see
> your processor when you click the advanced-button.
>
> As soon as I try to use a more sophisticated processor that uses velocity I
> encounter new problems. But for my project at hand I can do without
> velocity for some time...
> I'll keep you informed if I find a solution.
>
> Good luck,
> Daniel
>
>
>
> Florin Bratu wrote:
>
>> I am encountering the same problem - in the IDE the annotation processor
>> does not get called. Daniel, can you please share the cause of the problem
>> in your case and your solution? Maybe it is the same for me...
>>
>> I wrote an annotation processor according using apt & the Mirror API, and
>> I managed to get it working within Eclipse, but with jsr269 I can't get it
>> configured properly.
>
>
|
|
|
Re: pluggable annotation processin doesn't work [message #253945 is a reply to message #253925] |
Sun, 15 June 2008 13:58   |
Eclipse User |
|
|
|
"Florin-Alexandru Bratu" <Florin-Alexandru.Bratu@sophia.inria.fr> wrote in
message news:g2tu2e$kh3$1@build.eclipse.org...
> Hello again,
>
> About the META-INF/services file, I knew I had to created it for the
> MirrorAPI in order to specify the ProcessFactory, but I didn't know it was
> necessary for jsr269. I've added it , and now my processor appears in the
> list when clicking on the advanced button. However, the process does not
> execute!
If it does not appear to execute, it is possibly getting an exception during
the process() method. Make sure to take a look at the error log, as the
exception may have been logged there even if it was not reported in the
problems view.
By the way, please realize that the JSR269 annotation processing in the IDE
currently runs only during a build, not during reconcile (i.e., not as you
type in the editor).
> I've created an ant build.xml in which I call javac using the options:
> -proc:only -processorpath ${AnnotDir} -processor ${AnnotProc}
> and it works, but of course it shows me the errors in the console view,
> and I want them to show up in the error view and also in the source
> editor, with the red underline thing.
>
> So, my question would be: how can I pass options to the Java compiler that
> Eclipse invokes when compiling the Java sources?
The -A options (which you didn't mention, but which are for communicating
options to the annotation processor) get set in the Annotation Processing
preferences page.
The processor path and processor are set in the Factory Path preferences
page.
There is no equivalent of -proc:only when using annotation processing from
the IDE.
Thanks,
-Walter Harley
JDT APT lead
|
|
| | |
Re: pluggable annotation processin doesn't work [message #253973 is a reply to message #253945] |
Mon, 16 June 2008 13:08   |
Eclipse User |
|
|
|
Originally posted by: Florin-Alexandru.Bratu.sophia.inria.fr
Hello again!
Walter Harley wrote:
> "Florin-Alexandru Bratu" <Florin-Alexandru.Bratu@sophia.inria.fr> wrote in
> message news:g2tu2e$kh3$1@build.eclipse.org...
>> Hello again,
>>
>> About the META-INF/services file, I knew I had to created it for the
>> MirrorAPI in order to specify the ProcessFactory, but I didn't know it was
>> necessary for jsr269. I've added it , and now my processor appears in the
>> list when clicking on the advanced button. However, the process does not
>> execute!
>
> If it does not appear to execute, it is possibly getting an exception during
> the process() method. Make sure to take a look at the error log, as the
> exception may have been logged there even if it was not reported in the
> problems view.
This is not the case, as I can run the annotation processor using javac
at the command-line, and it runs with no problems.
>
> By the way, please realize that the JSR269 annotation processing in the IDE
> currently runs only during a build, not during reconcile (i.e., not as you
> type in the editor).
>
>
>> I've created an ant build.xml in which I call javac using the options:
>> -proc:only -processorpath ${AnnotDir} -processor ${AnnotProc}
>> and it works, but of course it shows me the errors in the console view,
>> and I want them to show up in the error view and also in the source
>> editor, with the red underline thing.
>>
>> So, my question would be: how can I pass options to the Java compiler that
>> Eclipse invokes when compiling the Java sources?
>
> The -A options (which you didn't mention, but which are for communicating
> options to the annotation processor) get set in the Annotation Processing
> preferences page.
I thought the -A options are only used for the apt tool. But then again,
this is not what I want to do - I want to simply to know whether one can
pass arguments to the Java compiler in Eclipse, and if so, how to do it.
>
> The processor path and processor are set in the Factory Path preferences
> page.
>
> There is no equivalent of -proc:only when using annotation processing from
> the IDE.
>
> Thanks,
> -Walter Harley
> JDT APT lead
>
>
|
|
|
Re: pluggable annotation processin doesn't work [message #253992 is a reply to message #253973] |
Mon, 16 June 2008 20:33   |
Eclipse User |
|
|
|
"Florin-Alexandru Bratu" <Florin-Alexandru.Bratu@sophia.inria.fr> wrote in
message news:g366m6$ack$1@build.eclipse.org...
>> If it does not appear to execute, it is possibly getting an exception
>> during the process() method. Make sure to take a look at the error log,
>> as the exception may have been logged there even if it was not reported
>> in the problems view.
>
> This is not the case, as I can run the annotation processor using javac at
> the command-line, and it runs with no problems.
There may be exceptions happening when you run inside the IDE. You could be
hitting a bug in our code; or you could be inadvertently relying on a bug in
Sun's code; or you could be getting different behavior in one of the many
cases where the APT API spec is ambiguous. You don't know unless you try
stepping through the code in the debugger.
> I thought the -A options are only used for the apt tool. But then again,
> this is not what I want to do - I want to simply to know whether one can
> pass arguments to the Java compiler in Eclipse, and if so, how to do it.
The -A options don't actually affect the apt tool at all, they are passed
through so that processors can access them via the APT API. There are some
differences in how they are processed between the Mirror API and the JSR269
API, but the same basic principle applies.
I'm still not sure what you mean by "pass arguments to the Java compiler in
Eclipse". When you are running in the IDE, the settings for the Eclipse
Java compiler are made on the various Java preference pages. For instance,
your Java Build Path replaces the -classpath command line option, and the
Annotation Processing Factory Path replaces the -factorypath option. There
is not a 1:1 mapping, however, because the functionality and set of
supported options is different between the IDE and the command line. Which
setting are you looking for?
|
|
|
Re: pluggable annotation processin doesn't work [message #253997 is a reply to message #253965] |
Mon, 16 June 2008 20:37   |
Eclipse User |
|
|
|
"Daniel Koebbing" <Daniel.Koebbing@westfleisch.de> wrote in message
news:g35s09$r73$1@build.eclipse.org...
> I added the velocity jar with dependencies (velocity-dep.jar) but without
> success. I still get the following exception:
>
> !ENTRY org.eclipse.jdt.apt.pluggable.core 1 1 2008-06-16 15:55:03.761
> !MESSAGE process exception: java.lang.NullPointerException
> at
> org.apache.velocity.runtime.RuntimeInstance.getTemplate(Runt imeInstance.java:1102)
> at
> org.apache.velocity.runtime.RuntimeInstance.getTemplate(Runt imeInstance.java:1077)
> at
> org.apache.velocity.runtime.RuntimeSingleton.getTemplate(Run timeSingleton.java:303)
> at org.apache.velocity.app.Velocity.getTemplate(Velocity.java:5 03)
> at dk.TestProcessor.process(TestProcessor.java:59)
>
> Adding velocity-dep.jar to the projects classpath doesn't help neither.
>
> It seems to me that velocity's class loading doesn't work properly when
> used
> with jsr-269 inside eclipse, but that's onyl a guess...
>
> When I extract the velocity-dep.jar and include the corresponding class
> files in my processor jar the result is the same, so there has to be an
> issue with the class loading mechanism, has it not?
You mean, you put the Velocity classes directly into your jar and they still
wouldn't load? That would seem to rule *out* any classloader issue, at
least for the classes themselves; rather, it suggests that there is
something preventing the classes from successfully loading, e.g., maybe
something in the class's constructor or static initializers is failing?
Are you able to load the Velocity classes from an ordinary Eclipse plugin,
e.g., starting with the Hello World plugin template?
Does velocity-dep.jar have a manifest classpath (that is, in its
manifest.mf, is it adding other jars to the classpath)? The Eclipse
classloader won't follow manifest classpaths, although I dimly recollect
that in APT we actually added support for that so maybe it's irrelevant.
|
|
|
Re: pluggable annotation processin doesn't work [message #254013 is a reply to message #253997] |
Tue, 17 June 2008 04:25   |
Eclipse User |
|
|
|
Walter Harley wrote:
> You mean, you put the Velocity classes directly into your jar and they
> still
> wouldn't load? That would seem to rule *out* any classloader issue, at
> least for the classes themselves; rather, it suggests that there is
> something preventing the classes from successfully loading, e.g., maybe
> something in the class's constructor or static initializers is failing?
>
Yes, I put the velocity classes and their dependencies (as classes) into my
jar. Perhaps it has something to do with static initializers, but I don't
know.
> Are you able to load the Velocity classes from an ordinary Eclipse plugin,
> e.g., starting with the Hello World plugin template?
>
I just tried to use velocity with the Hello World plugin template and it
works (generated some output based on a velocity template).
> Does velocity-dep.jar have a manifest classpath (that is, in its
> manifest.mf, is it adding other jars to the classpath)? The Eclipse
> classloader won't follow manifest classpaths, although I dimly recollect
> that in APT we actually added support for that so maybe it's irrelevant.
Velocity-dep.jar has a manifest without a classpath as the dependencies are
inside the jar.
So at the moment I'm somewhat lost. I think I'll have a closer look at the
velocity source.
Daniel
|
|
| |
Re: pluggable annotation processin doesn't work [message #254021 is a reply to message #253992] |
Tue, 17 June 2008 07:48   |
Eclipse User |
|
|
|
Originally posted by: Florin-Alexandru.Bratu.sophia.inria.fr
Walter Harley wrote:
> I'm still not sure what you mean by "pass arguments to the Java
compiler in
> Eclipse". When you are running in the IDE, the settings for the Eclipse
> Java compiler are made on the various Java preference pages. For instance,
> your Java Build Path replaces the -classpath command line option, and the
> Annotation Processing Factory Path replaces the -factorypath option. There
> is not a 1:1 mapping, however, because the functionality and set of
> supported options is different between the IDE and the command line. Which
> setting are you looking for?
>
>
It is not a specific setting I am searching, I was just wondering if it
can be done in general. I mean, I wanted to know how to pass the
-processorpath and -processor options, but you already told me how to
do it using the preference pages. I just want to know whether it is
possible also to do it manually, it gives me the feeling of having more
control over the compilation process :)
|
|
|
Re: pluggable annotation processin doesn't work [message #254025 is a reply to message #253945] |
Tue, 17 June 2008 08:55   |
Eclipse User |
|
|
|
Originally posted by: Florin-Alexandru.Bratu.sophia.inria.fr
Hello again,
Walter Harley wrote:
> "Florin-Alexandru Bratu" <Florin-Alexandru.Bratu@sophia.inria.fr> wrote in
> message news:g2tu2e$kh3$1@build.eclipse.org...
>> Hello again,
>>
>> About the META-INF/services file, I knew I had to created it for the
>> MirrorAPI in order to specify the ProcessFactory, but I didn't know it was
>> necessary for jsr269. I've added it , and now my processor appears in the
>> list when clicking on the advanced button. However, the process does not
>> execute!
>
> If it does not appear to execute, it is possibly getting an exception during
> the process() method. Make sure to take a look at the error log, as the
> exception may have been logged there even if it was not reported in the
> problems view.
You were right, there are exceptions when the process() method is called.
My processor uses the Compiler Tree API. When trying to do a build, I
get the following exception:
java.lang.IllegalArgumentException
at com.sun.source.util.Trees.instance(Trees.java:52)
at
org.objectweb.proactive.annotation.jsr269.ProActiveProcessor .processActiveObjectAnnotation(ProActiveProcessor.java:131)
at
org.objectweb.proactive.annotation.jsr269.ProActiveProcessor .process(ProActiveProcessor.java:88)
at
org.eclipse.jdt.internal.compiler.apt.dispatch.RoundDispatch er.handleProcessor(RoundDispatcher.java:139)
at
org.eclipse.jdt.internal.compiler.apt.dispatch.RoundDispatch er.round(RoundDispatcher.java:121)
at
org.eclipse.jdt.internal.compiler.apt.dispatch.BaseAnnotatio nProcessorManager.processAnnotations(BaseAnnotationProcessor Manager.java:159)
at
org.eclipse.jdt.internal.apt.pluggable.core.dispatch.IdeAnno tationProcessorManager.processAnnotations(IdeAnnotationProce ssorManager.java:134)
at
org.eclipse.jdt.internal.compiler.Compiler.processAnnotation s(Compiler.java:794)
at org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler. java:423)
at
org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.c ompile(AbstractImageBuilder.java:363)
at
org.eclipse.jdt.internal.core.builder.BatchImageBuilder.comp ile(BatchImageBuilder.java:178)
at
org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.c ompile(AbstractImageBuilder.java:300)
at
org.eclipse.jdt.internal.core.builder.BatchImageBuilder.buil d(BatchImageBuilder.java:60)
at
org.eclipse.jdt.internal.core.builder.JavaBuilder.buildAll(J avaBuilder.java:254)
at
org.eclipse.jdt.internal.core.builder.JavaBuilder.build(Java Builder.java:178)
at
org.eclipse.core.internal.events.BuildManager$2.run(BuildMan ager.java:633)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:37)
at
org.eclipse.core.internal.events.BuildManager.basicBuild(Bui ldManager.java:170)
at
org.eclipse.core.internal.events.BuildManager.basicBuild(Bui ldManager.java:201)
at
org.eclipse.core.internal.events.BuildManager$1.run(BuildMan ager.java:253)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:37)
at
org.eclipse.core.internal.events.BuildManager.basicBuild(Bui ldManager.java:256)
at
org.eclipse.core.internal.events.BuildManager.basicBuild(Bui ldManager.java:218)
at
org.eclipse.core.internal.events.BuildManager.build(BuildMan ager.java:360)
at
org.eclipse.core.internal.resources.Project.internalBuild(Pr oject.java:516)
at org.eclipse.core.internal.resources.Project.build(Project.ja va:94)
at org.eclipse.ui.actions.BuildAction.invokeOperation(BuildActi on.java:221)
at org.eclipse.ui.actions.WorkspaceAction.execute(WorkspaceActi on.java:162)
at
org.eclipse.ui.actions.WorkspaceAction$2.runInWorkspace(Work spaceAction.java:483)
at
org.eclipse.core.internal.resources.InternalWorkspaceJob.run (InternalWorkspaceJob.java:38)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)
Looking at the instance(ProcessingEnvironment) method of the Trees class
javadoc, I see that the IllegalArgumentException is thrown when the
ProcessingEnvironment argument "does not support the Trees API". The
ProcessingEnvironment argument I am passing to the instance() method
call is the protected processEnv field of the abstract class
AbstractProcessor. More precisely, the code that produces the exception is:
public class ProActiveProcessor extends AbstractProcessor {
// ...
private void processActiveObjectAnnotation( RoundEnvironment
roundEnv, TypeElement proActiveAnotElement) {
// initialization stuff
Trees trees = Trees.instance(this.processingEnv);
// ...
}
}
Does this mean that I cannot use the Compiler Tree API if I want to use
the processor from within Eclipse?
thanks,
Florin.
|
|
| |
Re: pluggable annotation processin doesn't work [message #254063 is a reply to message #254021] |
Wed, 18 June 2008 11:30   |
Eclipse User |
|
|
|
"Florin-Alexandru Bratu" <Florin-Alexandru.Bratu@sophia.inria.fr> wrote in
message news:g388b1$qvh$1@build.eclipse.org...
>
> It is not a specific setting I am searching, I was just wondering if it
> can be done in general. I mean, I wanted to know how to pass
> the -processorpath and -processor options, but you already told me how to
> do it using the preference pages. I just want to know whether it is
> possible also to do it manually, it gives me the feeling of having more
> control over the compilation process :)
Hmm, I wonder if there is a confusion here.
Eclipse does not shell out to javac, or to any other separate compiler
process. The compiler is a built-in, integral part of the JDT code. It
does have a command-line wrapper (in ecj.jar) that lets it be accessed from
the command line or Ant outside of the context of an Eclipse instance, and
it also exposes the JSR199 Tool interface, but all these (IDE, command line,
JSR199) are just entry points to the same underlying Compiler object.
So, the settings that you make in the "Java Compiler" page under
Project->Properties, and the other pref pages nested underneath that, those
*are* the compiler settings. They're not getting mapped to javac-like
command-line settings under the covers, they're simply used directly.
That's how you pass preferences to the compiler, when running in the IDE:
you set project properties.
If you look in an Eclipse project, you'll find a .settings directory, and
under it a number of *.prefs files. Those are the persisted form of the
project settings; they're human-readable, if you want to look inside.
Programmatically, these files are accessed (read and written) via the
org.eclipse.core.runtime.preferences package.
|
|
| | | | |
Re: pluggable annotation processin doesn't work [message #254194 is a reply to message #254172] |
Mon, 23 June 2008 22:12   |
Eclipse User |
|
|
|
"Florin-Alexandru Bratu" <Florin-Alexandru.Bratu@sophia.inria.fr> wrote in
message news:g3o6dt$9j7$1@build.eclipse.org...
>
> OK, so I can only use the Mirror API to access the AST? The problem with
> Mirror API is that it exposes the AST only up to the method declarations,
> unlike the Tree API, which exposes all the AST.
That is exactly correct. This is, indeed, one of the big weaknesses in APT.
It gives access to the typesystem, not to the source code.
> Do you know, what API can I use in order to access all the AST and also be
> able to use it within an annotation processor supported by Eclipse? Is it
> possible to do this?
There is unfortunately no standardized AST API. If you're running your
processor in Sun's javac, you need to use the Tree API; if you are running
it in Eclipse you could use the DOM AST API (org.eclipse.jdt.core.dom); I
don't know whether other APT implementations exist, but if so they would
probably have their own AST interfaces.
|
|
|
Re: pluggable annotation processin doesn't work [message #257858 is a reply to message #254172] |
Fri, 19 December 2008 07:28   |
Eclipse User |
|
|
|
Originally posted by: Florin-Alexandru.Bratu.sophia.inria.fr
Florin-Alexandru Bratu wrote:
> Walter Harley wrote:
>> "Florin-Alexandru Bratu" <Florin-Alexandru.Bratu@sophia.inria.fr>
>> wrote in message news:g38c7i$r4a$1@build.eclipse.org...
>>> You were right, there are exceptions when the process() method is
>>> called.
>>> My processor uses the Compiler Tree API. [...]
>>> Does this mean that I cannot use the Compiler Tree API if I want to
>>> use the processor from within Eclipse?
>>
>> That's correct. The Tree API is a proprietary Sun API, not a Java
>> standard. It is not supported by the Eclipse Java compiler. If you
>> call it from your processor, your processor will only work when run
>> under javac, not under the Eclipse compiler.
>>
>>
>
> OK, so I can only use the Mirror API to access the AST? The problem with
> Mirror API is that it exposes the AST only up to the method
> declarations, unlike the Tree API, which exposes all the AST. Do you
> know, what API can I use in order to access all the AST and also be able
> to use it within an annotation processor supported by Eclipse? Is it
> possible to do this?
This is again on annotation processing within Eclipse.
I have developed two annotation processors, one using the API from JDK
1.5 - the Mirror API - and another one using the API provided in JDK 1.6
- Compiler Tree API. I have packaged them into a jar file, together with
a META-INF/services/ directory which contains the specification of the
annotation processors as services provided by the jar. I've done this so
that both annotation processors can be used from the console.
Now, as you said, the Compiler Tree API is not yet supported by Eclipse.
I would like to be able to "disable" the Compiler Tree annotation
processor from within Eclipse. Unfortunately, when I go to
Properties->Java Compiler->Annotation Processors->Factory Path, and add
my jar, and then click on advanced, I get the list of processors, but
there is no way to disable any of them.
Is there any other way to disable a processor from that list? ( Besides
the obvious option of recreating the jar file without the processor
inside...)
|
|
|
Re: pluggable annotation processin doesn't work [message #257868 is a reply to message #257858] |
Sat, 20 December 2008 02:36  |
Eclipse User |
|
|
|
"Florin-Alexandru Bratu" <Florin-Alexandru.Bratu@sophia.inria.fr> wrote in
message news:gig41v$ait$1@build.eclipse.org...
> I would like to be able to "disable" the Compiler Tree annotation
> processor from within Eclipse. Unfortunately, when I go to
> Properties->Java Compiler->Annotation Processors->Factory Path, and add my
> jar, and then click on advanced, I get the list of processors, but there
> is no way to disable any of them.
> Is there any other way to disable a processor from that list? ( Besides
> the obvious option of recreating the jar file without the processor
> inside...)
Put them in separate jars, or separate plug-ins.
There is no way to disable a single processor within a jar file containing
multiple processors (not in javac, apt, nor Eclipse).
It's roughly the same as saying that you have a jar file containing classes
A and B, and you want the compiler to see class A but not B.
|
|
|
Goto Forum:
Current Time: Thu Apr 17 21:48:54 EDT 2025
Powered by FUDForum. Page generated in 0.06380 seconds
|