Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 344159 - Not able to use Java 6 APT
Summary: Not able to use Java 6 APT
Status: RESOLVED FIXED
Alias: None
Product: AJDT
Classification: Tools
Component: Core (show other bugs)
Version: 2.1.2   Edit
Hardware: Macintosh Mac OS X
: P3 normal with 6 votes (vote)
Target Milestone: 2.2.4   Edit
Assignee: AJDT-inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-04-28 12:06 EDT by Andrew Eisenberg CLA
Modified: 2014-08-20 14:36 EDT (History)
8 users (show)

See Also:


Attachments
A sample project with an annotation processor (10.90 KB, application/octet-stream)
2011-04-28 12:07 EDT, Andrew Eisenberg CLA
no flags Details
An ant build script generated by eclipse and edited to use AJC instead of Javac (3.44 KB, application/xml)
2011-04-28 12:11 EDT, Andrew Eisenberg CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Andrew Eisenberg CLA 2011-04-28 12:06:08 EDT
Java6 annotation processing is not working from inside AJDT.  Originally, I had thought that this would be covered under bug 16985.  This bug covers the CompilationParticipant API.  However, Java6 annotation processing does not use that API.  Rather, it uses something internal to the compiler to process the annotations.

When ajc is run in batch mode, then APT is run properly, but not when run in the ide.
Comment 1 Andrew Eisenberg CLA 2011-04-28 12:07:27 EDT
Created attachment 194279 [details]
A sample project with an annotation processor

These two projects were sent to me by email and show a simple example of where AJDT does not run APT.
Comment 2 Andrew Eisenberg CLA 2011-04-28 12:11:38 EDT
Created attachment 194281 [details]
An ant build script generated by eclipse and edited to use AJC instead of Javac

This ant script will compile the test project using ajc in batch mode.  You can see in the results that APT is called correctly.  To run this script, place this script in the root of the HelloWorld-Test project.  You must also edit the hard coded paths to match your filesystem.
Comment 3 Andrew Eisenberg CLA 2011-04-28 12:12:56 EDT
It seems that currently, AJDT is not set up to work with the Java6 APT, but AJC is.  There might be a way that AJDT can initialize AJC's version of APT before a build starts.
Comment 4 Andrew Eisenberg CLA 2011-06-28 13:46:23 EDT
Consider for the 2.2.0 release.
Comment 5 Alan Egerton CLA 2012-04-01 12:10:58 EDT
I think this issue may be the root of that described at http://code.google.com/p/google-web-toolkit/issues/detail?id=7083 - pretty catastrophic for Spring Roo + GWT 2.4 !

I don't suppose there is a workaround at present?
Comment 6 Andrew Eisenberg CLA 2012-07-08 18:09:54 EDT
Consider for the 2.2.1 release.
Comment 7 Andrew Eisenberg CLA 2012-09-21 14:00:08 EDT
Consider for 2.2.2.
Comment 8 raym - CLA 2012-09-24 05:18:21 EDT
For roo+gwt there might be a 'workaround':
- Ensure the eclipse project config matches description of http://code.google.com/p/google-web-toolkit/wiki/RequestFactoryInterfaceValidation
- Remove any '.apt_generated' directory from the project.
- On the command-line run 'mvn gwt:run' - this should generate anew the '.apt_generated' directory
- Now run the application from eclipse.

This should make it possible to run roo+gwt generated projects from eclipse, but it's still cumbersome.
Comment 9 Mario Jauvin CLA 2013-11-09 17:59:46 EST
(In reply to Andrew Eisenberg from comment #7)
> Consider for 2.2.2.

Has this been fixed?  How do I tell from the bugzilla?
Comment 10 Mario Jauvin CLA 2013-11-21 22:18:10 EST
I asked for an update on this bug 12 days ago.  Is there no one looking at this bug?
Comment 11 Andrew Eisenberg CLA 2013-11-21 23:09:02 EST
This bug is not on our plan for the next release.
Comment 12 Mario Jauvin CLA 2014-04-16 20:49:20 EDT
This bug is catastrophic for Spring Roo+GWT.  Is there some plan to resolve this.  AJDT and AJC should not work differently.  Even if it were not for Spring Roo+GWT having a catastrophic effect, this AJDT should support Java6 annotations.  When is this going to be fixed in AJDT?
Comment 13 Andrew Clement CLA 2014-04-17 12:26:47 EDT
I'm afraid supporting this has still not bubbled up to the top of the priority list. When will it? I'm honestly not sure.
Comment 14 Mario Jauvin CLA 2014-07-31 21:22:03 EDT
We are now at java 8 and AJDT still does not support java 6 annotation.  Any chances this can be fixed soon?
Comment 15 Mario Jauvin CLA 2014-07-31 21:26:38 EDT
If anyone who is watching this bug is interested in getting it fix can you please:

1. Vote for the bug
2. Get anyone in your organization interested to vote for it.

Currently there are only 5 votes.
Comment 16 Andrew Clement CLA 2014-08-01 12:04:21 EDT
Some annotation processing work is currently being done for bug 252199 - I am processing a couple of pull requests in relation to that issue.
Comment 17 Mario Jauvin CLA 2014-08-01 21:12:42 EDT
I don't understand because bug 252199 is in AspectJ.  The comments indicate that the batch AJC works but when run in the IDE it does not.  This seems to imply that the support is already in AspectJ and I do not understand how fixing bug 252199 will help this bug.  Could you also elaborate on what your last comment means in term of fixing this bug.  Thanks.
Comment 18 SERGEY STUPIN CLA 2014-08-06 07:12:44 EDT
Ok, this is indeed strange bug so let me clarify some things.

I don't know how ajc could handle APT properly to the moment when this bug was created (who knows, it was 3 years ago) but I can assure you that in last release version 1.8.1 ajc definitely skips annotation processing in whatever mode: batch or incremental. So I will try to explain why:

1. ajc uses patched version of jdt compiler. Here is a repo: https://github.com/eclipse/org.aspectj.shadows
2. If you look at line https://github.com/eclipse/org.aspectj.shadows/blob/aj_BETA_JAVA8_LUNA_c0f9341/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/Compiler.java#L431
you see, that ATP is running only if annotationProcessingManager was initialized.
3. annotationProcessingManager could be initialized in ajc project inside method org.aspectj.org.eclipse.jdt.internal.compiler.batch.Main#initializeAnnotationProcessorManager
4. At the beginning this method tries to load class org.eclipse.jdt.internal.compiler.apt.dispatch.BatchAnnotationProcessorManager
5. That class BatchAnnotationProcessorManager was added to that patched version of jdt compiler by me 1 month ago.

So if anybody could create a small project with working annotation processing which could be compiled only by ajc 1.8.1 (without any precompilation javac steps which could potentially process APT) I will really appreciate that.

BTW, APT should work in ajc 1.8.2 but not in ide yet.
Comment 19 Andrew Clement CLA 2014-08-20 11:48:55 EDT
Let me write up my findings. Mostly it is behaving as Andrew originally wrote.

The Java5 annotation processing uses a compilation participant to do the annotation processing ahead of the compiler doing its work (compiling the original sources plus any generated sources).

The Java6 annotation processing is done as part of the real compiler, and really the difference between running it command line vs running it in AJDT is being able to get that processorpath supplied to the compiler.  Outside of the workbench it is a simple -processorpath XXX but inside AJDT we need some machinery to pass across the factory path (as defined in the project properties annotation processing section).

So I have implemented that (effectively what Andrew describes in comment 3) and it does work. Generating aspects is a little more hairy than generating regular java source code but they do seem to behave.  The only failure I've seen so far is that the gutter markers that show where advice in effect will break if you try to use them for navigation and the code they point to was actually generated.

I will tidy this up and commit it very soon, then it would be great to get some of you to kick the tyres on it. The markers thing can be fixed up later.
Comment 20 Andrew Clement CLA 2014-08-20 14:36:47 EDT
Dev builds are through. I'm closing this as fixed !

I've written up how to use it:

http://andrewclement.blogspot.ca/2014/08/annotation-processing-in-ajdt.html

The update site is here (for Eclipse 4.4):

http://download.eclipse.org/tools/ajdt/44/dev/update

I don't plan on back porting this to Eclipse 4.3 unless there is enough feedback that justifies it.