Bug 172743 - [jsr269] APT needs to convert IFile into internal ICompilationUnit
Summary: [jsr269] APT needs to convert IFile into internal ICompilationUnit
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.3   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.3 M6   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-02-02 19:46 EST by Walter Harley CLA
Modified: 2007-03-20 10:59 EDT (History)
0 users

See Also:


Attachments
Patch for jdt.core (1.41 KB, patch)
2007-02-02 19:47 EST, Walter Harley CLA
no flags Details | Diff
patch for compiler.apt (589 bytes, patch)
2007-02-02 19:47 EST, Walter Harley CLA
no flags Details | Diff
Patch for jdt.core (4.58 KB, patch)
2007-02-05 12:37 EST, Walter Harley CLA
no flags Details | Diff
Patch for compiler.apt (1.17 KB, patch)
2007-02-05 12:38 EST, Walter Harley CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Walter Harley CLA 2007-02-02 19:46:09 EST
(per discussion with Olivier)

The AbstractAnnotationProcessorManager interface tells the Compiler about new units via the method 
  ICompilationUnit[] getNewUnits()

The ICompilationUnit type here is in org.eclipse.jdt.internal.compiler.env; it is not the same as the Java Model type of the same name.  In order to implement this method, the AnnotationProcessorManager needs to be able to create objects that implement this interface.

In batch mode, it simply constructs an org.eclipse.jdt.internal.compiler.batch.CompilationUnit.

In IDE mode, the necessary implementation of ICompilationUnit seems to be org.eclipse.jdt.internal.core.builder.SourceFile.  (When I tried passing in a CompilationUnit, I got ClassCastException from something casting it to a SourceFile.)  But it seems that the only way to get a SourceFile is to call AbstractImageBuilder.findSourceFile().  The constructor of SourceFile requires a ClasspathMultiDirectory, which is a package-access object, so I can't directly construct one from within APT.

If I am right about that, the least fragile way I can see for APT to create an ICompilationUnit in IDE mode is to add an interface in jdt.core like the following, have AbstractImageBuilder implement it, and pass it in as a parameter to
AbstractAnnotationProcessorManager.configureFromPlatform():


  public interface ICompilationUnitLocator {
    public ICompilationUnit fromIFile(IFile file);
  }

  // Method in AbstractAnnotationProcessorManager:
  public abstract void configureFromPlatform(
      Compiler compiler, 
      Object compilationUnitLocator, 
      Object javaProject);


Are there any other approaches that might be cleaner or simpler?  I considered just passing the AbstractImageBuilder itself, rather than an interface, but that seemed very fragile.  I also considered changing the
AbstractAnnotationProcessorManager.getNewUnits() call to return something more generic than ICompilationUnit[], but then the Compiler itself would have to figure out how to do the conversion so it wouldn't solve the problem.

I'll attach these suggestions in the form of a patch to jdt.core and a corresponding patch to jdt.compiler.apt.
Comment 1 Walter Harley CLA 2007-02-02 19:47:06 EST
Created attachment 58171 [details]
Patch for jdt.core
Comment 2 Walter Harley CLA 2007-02-02 19:47:33 EST
Created attachment 58172 [details]
patch for compiler.apt
Comment 3 Philipe Mulet CLA 2007-02-05 03:48:32 EST
I can't read any of the attached patches (doesn't look like text).
One thing to check is that it didn't introduce a dependency on non Foundation1.0 code in the compiler land.
Comment 4 Walter Harley CLA 2007-02-05 12:37:30 EST
Created attachment 58263 [details]
Patch for jdt.core

Sorry, had attached the patches as .zip files instead of .txt.
Comment 5 Walter Harley CLA 2007-02-05 12:38:06 EST
Created attachment 58264 [details]
Patch for compiler.apt
Comment 6 Walter Harley CLA 2007-02-05 12:41:15 EST
I've replaced the patches with the same thing in plain text instead of .zip.  I think there are no new dependencies introduced.
Comment 7 Olivier Thomann CLA 2007-02-08 20:44:10 EST
Released for 3.3M6.
Comment 8 Eric Jodet CLA 2007-03-20 10:24:29 EDT
Verified for 3.3 M6 using build I20070320-0010
Comment 9 Olivier Thomann CLA 2007-03-20 10:59:24 EDT
Verified for 3.3 M6 using build I20070320-0010