diff options
14 files changed, 377 insertions, 95 deletions
diff --git a/org.eclipse.jdt.compiler.apt/.settings/org.eclipse.jdt.core.prefs b/org.eclipse.jdt.compiler.apt/.settings/org.eclipse.jdt.core.prefs index 7c29f14073..0319a075b1 100644 --- a/org.eclipse.jdt.compiler.apt/.settings/org.eclipse.jdt.core.prefs +++ b/org.eclipse.jdt.compiler.apt/.settings/org.eclipse.jdt.core.prefs @@ -1,12 +1,21 @@ -#Tue Dec 12 11:15:15 EST 2006 +#Wed Dec 13 14:02:09 EST 2006 eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error org.eclipse.jdt.core.compiler.problem.autoboxing=ignore org.eclipse.jdt.core.compiler.problem.deprecation=warning org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=disabled org.eclipse.jdt.core.compiler.problem.discouragedReference=ignore org.eclipse.jdt.core.compiler.problem.emptyStatement=warning +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error org.eclipse.jdt.core.compiler.problem.fallthroughCase=ignore org.eclipse.jdt.core.compiler.problem.fieldHiding=ignore org.eclipse.jdt.core.compiler.problem.finalParameterBound=warning @@ -50,3 +59,4 @@ org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=di org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning +org.eclipse.jdt.core.compiler.source=1.6 diff --git a/org.eclipse.jdt.compiler.apt/batch/org/eclipse/jdt/internal/compiler/apt/dispatch/AnnotationDiscoveryVisitor.java b/org.eclipse.jdt.compiler.apt/batch/org/eclipse/jdt/internal/compiler/apt/dispatch/AnnotationDiscoveryVisitor.java index e32fbd598c..ae68190a3d 100644 --- a/org.eclipse.jdt.compiler.apt/batch/org/eclipse/jdt/internal/compiler/apt/dispatch/AnnotationDiscoveryVisitor.java +++ b/org.eclipse.jdt.compiler.apt/batch/org/eclipse/jdt/internal/compiler/apt/dispatch/AnnotationDiscoveryVisitor.java @@ -14,6 +14,7 @@ import org.eclipse.jdt.internal.compiler.ast.MethodDeclaration; import org.eclipse.jdt.internal.compiler.ast.NormalAnnotation; import org.eclipse.jdt.internal.compiler.ast.SingleMemberAnnotation; import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration; +import org.eclipse.jdt.internal.compiler.lookup.AnnotationBinding; import org.eclipse.jdt.internal.compiler.lookup.Binding; import org.eclipse.jdt.internal.compiler.lookup.BlockScope; import org.eclipse.jdt.internal.compiler.lookup.ClassScope; @@ -23,9 +24,9 @@ import org.eclipse.jdt.internal.compiler.lookup.MethodScope; public class AnnotationDiscoveryVisitor extends ASTVisitor { Binding currentBinding; -List collector; +List<AnnotationBinding> collector; public AnnotationDiscoveryVisitor() { - this.collector = new ArrayList(); + this.collector = new ArrayList<AnnotationBinding>(); } public boolean visit(Argument argument, BlockScope scope) { this.currentBinding = argument.binding; diff --git a/org.eclipse.jdt.compiler.apt/batch/org/eclipse/jdt/internal/compiler/apt/dispatch/AnnotationProcessorManager.java b/org.eclipse.jdt.compiler.apt/batch/org/eclipse/jdt/internal/compiler/apt/dispatch/AnnotationProcessorManager.java index 805e853ea5..31266f5757 100644 --- a/org.eclipse.jdt.compiler.apt/batch/org/eclipse/jdt/internal/compiler/apt/dispatch/AnnotationProcessorManager.java +++ b/org.eclipse.jdt.compiler.apt/batch/org/eclipse/jdt/internal/compiler/apt/dispatch/AnnotationProcessorManager.java @@ -1,22 +1,45 @@ package org.eclipse.jdt.internal.compiler.apt.dispatch; import java.io.PrintWriter; +import java.nio.charset.Charset; import java.util.ArrayList; +import java.util.Iterator; import java.util.List; +import javax.tools.JavaFileManager; + import org.eclipse.jdt.internal.compiler.AbstractAnnotationProcessorManager; import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration; +import org.eclipse.jdt.internal.compiler.batch.Main; import org.eclipse.jdt.internal.compiler.env.ICompilationUnit; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; +import org.eclipse.jdt.internal.compiler.tool.EclipseCompiler; +import org.eclipse.jdt.internal.compiler.tool.EclipseFileManager; public class AnnotationProcessorManager extends AbstractAnnotationProcessorManager { - List addedUnits; + List<ICompilationUnit> addedUnits; + JavaFileManager fileManager; - public void configure(org.eclipse.jdt.internal.compiler.Compiler compiler, String[] commandLineArguments) { - // do nothing + public void configure(Main batchCompiler, String[] commandLineArguments) { + if (batchCompiler instanceof EclipseCompiler) { + this.fileManager = ((EclipseCompiler) batchCompiler).fileManager; + } else { + String encoding = (String) batchCompiler.options.get(CompilerOptions.OPTION_Encoding); + Charset charset = encoding != null ? Charset.forName(encoding) : null; + JavaFileManager manager = new EclipseFileManager(batchCompiler, batchCompiler.compilerLocale, charset); + ArrayList<String> options = new ArrayList<String>(); + for (String argument : commandLineArguments) { + options.add(argument); + } + for (Iterator<String> iterator = options.iterator(); iterator.hasNext(); ) { + manager.handleOption(iterator.next(), iterator); + } + this.fileManager = manager; + } } private AnnotationProcessorManager() { - this.addedUnits = new ArrayList(); + this.addedUnits = new ArrayList<ICompilationUnit>(); } public void processAnnotations(CompilationUnitDeclaration[] units, boolean isLastRound) { @@ -27,7 +50,7 @@ public class AnnotationProcessorManager extends AbstractAnnotationProcessorManag this.addedUnits.add(unit); } - public List getNewUnits() { + public List<ICompilationUnit> getNewUnits() { return this.addedUnits; } @@ -39,6 +62,10 @@ public class AnnotationProcessorManager extends AbstractAnnotationProcessorManag // do nothing } + public void setProcessors(Object[] processors) { + // do nothing + } + public void setOut(PrintWriter out) { // do nothing } diff --git a/org.eclipse.jdt.compiler.tool.tests/src/org/eclipse/jdt/compiler/tool/tests/CompilerToolTests.java b/org.eclipse.jdt.compiler.tool.tests/src/org/eclipse/jdt/compiler/tool/tests/CompilerToolTests.java index 0c9929ff2d..76f4c2a595 100644 --- a/org.eclipse.jdt.compiler.tool.tests/src/org/eclipse/jdt/compiler/tool/tests/CompilerToolTests.java +++ b/org.eclipse.jdt.compiler.tool.tests/src/org/eclipse/jdt/compiler/tool/tests/CompilerToolTests.java @@ -70,7 +70,10 @@ public class CompilerToolTests extends TestCase { "-target", "-maxProblems", "-log", - "-repeat" + "-repeat", + "-processorpath", + "-s", + "-processor", }; private static String[] ZERO_ARG_OPTIONS = { "-1.3", @@ -107,7 +110,11 @@ public class CompilerToolTests extends TestCase { "-help", "-v", "-version", - "-showversion" + "-showversion", + "-XprintRounds", + "-XprintProcessorInfo", + "-proc:none", + "-proc:only", }; private void displayLocation(StandardJavaFileManager manager, StandardLocation standardLocation) { @@ -144,6 +151,7 @@ public class CompilerToolTests extends TestCase { } assertEquals("-Jignore requires no argument", 0, Compiler.isSupportedOption("-Jignore")); assertEquals("-Xignore requires no argument", 0, Compiler.isSupportedOption("-Xignore")); + assertEquals("-Akey=value requires no argument", 0, Compiler.isSupportedOption("-Akey=value")); } public void testCompilerOneClassWithSystemCompiler() { diff --git a/org.eclipse.jdt.compiler.tool/src/org/eclipse/jdt/internal/compiler/tool/EclipseCompiler.java b/org.eclipse.jdt.compiler.tool/src/org/eclipse/jdt/internal/compiler/tool/EclipseCompiler.java index 14fc466a43..33175c4c50 100644 --- a/org.eclipse.jdt.compiler.tool/src/org/eclipse/jdt/internal/compiler/tool/EclipseCompiler.java +++ b/org.eclipse.jdt.compiler.tool/src/org/eclipse/jdt/internal/compiler/tool/EclipseCompiler.java @@ -74,6 +74,7 @@ public class EclipseCompiler extends Main implements JavaCompiler { Iterable<? extends JavaFileObject> compilationUnits; public DiagnosticListener<? super JavaFileObject> diagnosticListener; public JavaFileManager fileManager; + protected Processor[] processors; public EclipseCompiler(PrintWriter out, PrintWriter err, boolean systemExitWhenFinished) { super(out, err, systemExitWhenFinished); @@ -307,7 +308,7 @@ public class EclipseCompiler extends Main implements JavaCompiler { } } - String[] optionsToProcess = new String[allOptions.size()]; + final String[] optionsToProcess = new String[allOptions.size()]; allOptions.toArray(optionsToProcess); try { this.configure(optionsToProcess); @@ -339,7 +340,13 @@ public class EclipseCompiler extends Main implements JavaCompiler { EclipseCompiler.this.setLocale(locale); } public void setProcessors(Iterable<? extends Processor> processors) { - throw new UnsupportedOperationException(); + ArrayList<Processor> temp = new ArrayList<Processor>(); + for (Processor processor : processors) { + temp.add(processor); + } + Processor[] processors2 = new Processor[temp.size()]; + temp.toArray(processors2); + EclipseCompiler.this.processors = processors2; } }; } @@ -351,6 +358,16 @@ public class EclipseCompiler extends Main implements JavaCompiler { this.javaFileObjectMap = new HashMap<CompilationUnit, JavaFileObject>(); } + @Override + protected void initializeAnnotationProcessorManager() { + super.initializeAnnotationProcessorManager(); + if (this.batchCompiler.annotationProcessorManager != null) { + this.batchCompiler.annotationProcessorManager.setProcessors(this.processors); + } else if (this.processors != null) { + throw new UnsupportedOperationException("Cannot handle annotation processing"); //$NON-NLS-1$ + } + } + /* * (non-Javadoc) * diff --git a/org.eclipse.jdt.compiler.tool/src/org/eclipse/jdt/internal/compiler/tool/EclipseFileManager.java b/org.eclipse.jdt.compiler.tool/src/org/eclipse/jdt/internal/compiler/tool/EclipseFileManager.java index 97e8a26d9a..08466d1891 100644 --- a/org.eclipse.jdt.compiler.tool/src/org/eclipse/jdt/internal/compiler/tool/EclipseFileManager.java +++ b/org.eclipse.jdt.compiler.tool/src/org/eclipse/jdt/internal/compiler/tool/EclipseFileManager.java @@ -65,7 +65,9 @@ public class EclipseFileManager implements StandardJavaFileManager { } try { this.setLocation(StandardLocation.PLATFORM_CLASS_PATH, getDefaultBootclasspath()); - this.setLocation(StandardLocation.CLASS_PATH, getDefaultClasspath()); + Iterable<? extends File> defaultClasspath = getDefaultClasspath(); + this.setLocation(StandardLocation.CLASS_PATH, defaultClasspath); + this.setLocation(StandardLocation.ANNOTATION_PROCESSOR_PATH, defaultClasspath); } catch (IOException e) { // ignore } @@ -193,6 +195,7 @@ public class EclipseFileManager implements StandardJavaFileManager { private Iterable<? extends File> concatFiles(Iterable<? extends File> iterable, Iterable<? extends File> iterable2) { ArrayList<File> list = new ArrayList<File>(); + if (iterable2 == null) return iterable; for (Iterator<? extends File> iterator = iterable.iterator(); iterator.hasNext(); ) { list.add(iterator.next()); } @@ -236,20 +239,6 @@ public class EclipseFileManager implements StandardJavaFileManager { return archive; } - private Iterable<? extends File> getBootclasspathFrom(String path) { - ArrayList<FileSystem.Classpath> paths = new ArrayList<FileSystem.Classpath>(); - ArrayList<File> files = new ArrayList<File>(); - try { - this.compiler.processPathEntries(Main.DEFAULT_SIZE_CLASSPATH, paths, path, this.charset.toString(), false, false); - } catch (InvalidInputException e) { - return null; - } - for (FileSystem.Classpath classpath : paths) { - files.add(new File(classpath.getPath())); - } - return files; - } - /* (non-Javadoc) * @see javax.tools.JavaFileManager#getClassLoader(javax.tools.JavaFileManager.Location) */ @@ -272,7 +261,7 @@ public class EclipseFileManager implements StandardJavaFileManager { return new URLClassLoader(allURLs.toArray(result), getClass().getClassLoader()); } - private Iterable<? extends File> getClasspathFrom(String path) { + private Iterable<? extends File> getPathsFrom(String path) { ArrayList<FileSystem.Classpath> paths = new ArrayList<FileSystem.Classpath>(); ArrayList<File> files = new ArrayList<File>(); try { @@ -471,7 +460,8 @@ public class EclipseFileManager implements StandardJavaFileManager { } Iterable<? extends File> files = getLocation(location); if (files == null) { - if (!location.equals(StandardLocation.CLASS_OUTPUT)) + if (!location.equals(StandardLocation.CLASS_OUTPUT) + && !location.equals(StandardLocation.SOURCE_OUTPUT)) throw new IllegalArgumentException("Unknown location : " + location);//$NON-NLS-1$ // we will use either the sibling or user.dir if (sibling != null) { @@ -590,20 +580,6 @@ public class EclipseFileManager implements StandardJavaFileManager { return list; } - private Iterable<? extends File> getSourcepathFrom(String path) { - ArrayList<FileSystem.Classpath> paths = new ArrayList<FileSystem.Classpath>(); - ArrayList<File> files = new ArrayList<File>(); - try { - this.compiler.processPathEntries(Main.DEFAULT_SIZE_CLASSPATH, paths, path, this.charset.toString(), false, false); - } catch (InvalidInputException e) { - return null; - } - for (FileSystem.Classpath classpath : paths) { - files.add(new File(classpath.getPath())); - } - return files; - } - /* (non-Javadoc) * @see javax.tools.JavaFileManager#handleOption(java.lang.String, java.util.Iterator) */ @@ -612,7 +588,7 @@ public class EclipseFileManager implements StandardJavaFileManager { if ("-bootclasspath".equals(current)) {//$NON-NLS-1$ remaining.remove(); // remove the current option if (remaining.hasNext()) { - final Iterable<? extends File> bootclasspaths = getBootclasspathFrom(remaining.next()); + final Iterable<? extends File> bootclasspaths = getPathsFrom(remaining.next()); if (bootclasspaths != null) { Iterable<? extends File> iterable = getLocation(StandardLocation.PLATFORM_CLASS_PATH); if ((this.flags & HAS_ENDORSED_DIRS) == 0 @@ -639,7 +615,7 @@ public class EclipseFileManager implements StandardJavaFileManager { if ("-classpath".equals(current) || "-cp".equals(current)) {//$NON-NLS-1$//$NON-NLS-2$ remaining.remove(); // remove the current option if (remaining.hasNext()) { - final Iterable<? extends File> classpaths = getClasspathFrom(remaining.next()); + final Iterable<? extends File> classpaths = getPathsFrom(remaining.next()); if (classpaths != null) setLocation(StandardLocation.CLASS_PATH, classpaths); remaining.remove(); return true; @@ -660,7 +636,7 @@ public class EclipseFileManager implements StandardJavaFileManager { if ("-sourcepath".equals(current)) {//$NON-NLS-1$ remaining.remove(); // remove the current option if (remaining.hasNext()) { - final Iterable<? extends File> sourcepaths = getSourcepathFrom(remaining.next()); + final Iterable<? extends File> sourcepaths = getPathsFrom(remaining.next()); if (sourcepaths != null) setLocation(StandardLocation.SOURCE_PATH, sourcepaths); remaining.remove(); return true; @@ -694,7 +670,7 @@ public class EclipseFileManager implements StandardJavaFileManager { throw new IllegalArgumentException(); } } - if ("-d".equals(current)) {//$NON-NLS-1$ + if ("-d".equals(current)) { //$NON-NLS-1$ remaining.remove(); // remove the current option if (remaining.hasNext()) { final Iterable<? extends File> outputDir = getOutputDir(remaining.next()); @@ -707,6 +683,34 @@ public class EclipseFileManager implements StandardJavaFileManager { throw new IllegalArgumentException(); } } + if ("-s".equals(current)) { //$NON-NLS-1$ + remaining.remove(); // remove the current option + if (remaining.hasNext()) { + final Iterable<? extends File> outputDir = getOutputDir(remaining.next()); + if (outputDir != null) { + setLocation(StandardLocation.SOURCE_OUTPUT, outputDir); + } + remaining.remove(); + return true; + } else { + throw new IllegalArgumentException(); + } + } + if ("-processorpath".equals(current) || "-cp".equals(current)) {//$NON-NLS-1$//$NON-NLS-2$ + remaining.remove(); // remove the current option + if (remaining.hasNext()) { + final Iterable<? extends File> processorpaths = getPathsFrom(remaining.next()); + if (processorpaths != null) { + Iterable<? extends File> iterable = getLocation(StandardLocation.ANNOTATION_PROCESSOR_PATH); + setLocation(StandardLocation.ANNOTATION_PROCESSOR_PATH, + prependFiles(iterable, processorpaths)); + } + remaining.remove(); + return true; + } else { + throw new IllegalArgumentException(); + } + } } catch (IOException e) { // ignore } @@ -797,6 +801,7 @@ public class EclipseFileManager implements StandardJavaFileManager { private Iterable<? extends File> prependFiles(Iterable<? extends File> iterable, Iterable<? extends File> iterable2) { + if (iterable2 == null) return iterable; ArrayList<File> list = new ArrayList<File>(); for (Iterator<? extends File> iterator = iterable2.iterator(); iterator.hasNext(); ) { list.add(iterator.next()); diff --git a/org.eclipse.jdt.compiler.tool/src/org/eclipse/jdt/internal/compiler/tool/Options.java b/org.eclipse.jdt.compiler.tool/src/org/eclipse/jdt/internal/compiler/tool/Options.java index 3e32d4ff9f..a605305a81 100644 --- a/org.eclipse.jdt.compiler.tool/src/org/eclipse/jdt/internal/compiler/tool/Options.java +++ b/org.eclipse.jdt.compiler.tool/src/org/eclipse/jdt/internal/compiler/tool/Options.java @@ -55,6 +55,10 @@ public final class Options { ZERO_ARGUMENT_OPTIONS.add("-1.6");//$NON-NLS-1$ ZERO_ARGUMENT_OPTIONS.add("-6");//$NON-NLS-1$ ZERO_ARGUMENT_OPTIONS.add("-6.0");//$NON-NLS-1$ + ZERO_ARGUMENT_OPTIONS.add("-proc:only");//$NON-NLS-1$ + ZERO_ARGUMENT_OPTIONS.add("-proc:none");//$NON-NLS-1$ + ZERO_ARGUMENT_OPTIONS.add("-XprintProcessorInfo");//$NON-NLS-1$ + ZERO_ARGUMENT_OPTIONS.add("-XprintRounds");//$NON-NLS-1$ FILE_MANAGER_OPTIONS = new HashSet<String>(); FILE_MANAGER_OPTIONS.add("-bootclasspath");//$NON-NLS-1$ @@ -65,6 +69,8 @@ public final class Options { FILE_MANAGER_OPTIONS.add("-sourcepath");//$NON-NLS-1$ FILE_MANAGER_OPTIONS.add("-extdirs");//$NON-NLS-1$ FILE_MANAGER_OPTIONS.add("-endorseddirs");//$NON-NLS-1$ + FILE_MANAGER_OPTIONS.add("-s");//$NON-NLS-1$ + FILE_MANAGER_OPTIONS.add("-processorpath");//$NON-NLS-1$ ONE_ARGUMENT_OPTIONS = new HashSet<String>(); ONE_ARGUMENT_OPTIONS.addAll(FILE_MANAGER_OPTIONS); @@ -73,6 +79,7 @@ public final class Options { ONE_ARGUMENT_OPTIONS.add("-maxProblems");//$NON-NLS-1$ ONE_ARGUMENT_OPTIONS.add("-source");//$NON-NLS-1$ ONE_ARGUMENT_OPTIONS.add("-target");//$NON-NLS-1$ + ONE_ARGUMENT_OPTIONS.add("-processor");//$NON-NLS-1$ } public static int processOptionsFileManager(String option) { @@ -218,7 +225,9 @@ public final class Options { return 0; } } - if (option.startsWith("-J") || option.startsWith("-X")) {//$NON-NLS-1$//$NON-NLS-2$ + if (option.startsWith("-J")//$NON-NLS-1$ + || option.startsWith("-X")//$NON-NLS-1$ + || option.startsWith("-A")) {//$NON-NLS-1$ return 0; } return -1; diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java index 72a014a5b8..34fcaff3c7 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java @@ -940,12 +940,26 @@ public void test012(){ " -g:none no debug info\n" + " -preserveAllLocals preserve unused local vars for debug purpose\n" + " \n" + - " Ignored options:\n" + - " -J<option> pass option to virtual machine (ignored)\n" + - " -X<option> specify non-standard option (ignored\n" + - " except for -Xemacs)\n" + - " -X print non-standard options and exit (ignored)\n" + - " -O optimize for execution time (ignored)\n" + + " Annotation processing options:\n" + + " These options are meaningful only in a 1.6 environment.\n" + + " -Akey[=value] annotation processors options that are made to\n" + + " annotation processors. key are identifiers separated\n" + + " by ..\n" + + " -processorpath <directories and zip/jar files separated by ;>\n" + + " specify locations where to find annotation processors\n" + + " If this option is not used, the classpath will be\n" + + " searched for processors.\n" + + " -processor <class1[,class2,...]>\n" + + " Qualified names of the annotation processors to run.\n" + + " This bypasses the default annotation discovery process\n" + + " -proc:only run annotation processors, but do not compile\n" + + " -proc:none perform compilation but do not run annotation\n" + + " processors\n" + + " -s <dir> specify a directory where to put the generated source\n" + + " files\n" + + " -XprintProcessorInfo print information about which annotations and which\n" + + " elements a processor is asked to process\n" + + " -XprintRounds print information about annotation processing rounds.\n" + " \n" + " Advanced options:\n" + " @<file> read command line arguments from file\n" + @@ -970,6 +984,13 @@ public void test012(){ " -? -help print this help message\n" + " -v -version print compiler version\n" + " -showversion print compiler version and continue\n" + + " \n" + + " Ignored options:\n" + + " -J<option> pass option to virtual machine (ignored)\n" + + " -X<option> specify non-standard option (ignored\n" + + " except for listed -X options)\n" + + " -X print non-standard options and exit (ignored)\n" + + " -O optimize for execution time (ignored)\n" + "\n"; String expandedExpectedOutput = MessageFormat.format(expectedOutput, new String[] { @@ -1137,6 +1158,7 @@ public void test012b(){ " <option key=\"org.eclipse.jdt.core.compiler.debug.localVariable\" value=\"do not generate\"/>\n" + " <option key=\"org.eclipse.jdt.core.compiler.debug.sourceFile\" value=\"generate\"/>\n" + " <option key=\"org.eclipse.jdt.core.compiler.doc.comment.support\" value=\"disabled\"/>\n" + + " <option key=\"org.eclipse.jdt.core.compiler.generateClassFiles\" value=\"enabled\"/>\n" + " <option key=\"org.eclipse.jdt.core.compiler.maxProblemPerUnit\" value=\"100\"/>\n" + " <option key=\"org.eclipse.jdt.core.compiler.problem.annotationSuperInterface\" value=\"warning\"/>\n" + " <option key=\"org.eclipse.jdt.core.compiler.problem.assertIdentifier\" value=\"warning\"/>\n" + @@ -1203,6 +1225,7 @@ public void test012b(){ " <option key=\"org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete\" value=\"disabled\"/>\n" + " <option key=\"org.eclipse.jdt.core.compiler.problem.unusedPrivateMember\" value=\"warning\"/>\n" + " <option key=\"org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast\" value=\"warning\"/>\n" + + " <option key=\"org.eclipse.jdt.core.compiler.processAnnotations\" value=\"enabled\"/>\n" + " <option key=\"org.eclipse.jdt.core.compiler.source\" value=\"1.5\"/>\n" + " <option key=\"org.eclipse.jdt.core.compiler.taskCaseSensitive\" value=\"enabled\"/>\n" + " <option key=\"org.eclipse.jdt.core.compiler.taskPriorities\" value=\"\"/>\n" + diff --git a/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/Main.java b/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/Main.java index e349275c40..4391ab8e68 100644 --- a/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/Main.java +++ b/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/Main.java @@ -44,6 +44,7 @@ import org.eclipse.jdt.core.compiler.CategorizedProblem; import org.eclipse.jdt.core.compiler.CharOperation; import org.eclipse.jdt.core.compiler.InvalidInputException; import org.eclipse.jdt.core.compiler.IProblem; +import org.eclipse.jdt.internal.compiler.AbstractAnnotationProcessorManager; import org.eclipse.jdt.internal.compiler.ClassFile; import org.eclipse.jdt.internal.compiler.CompilationResult; import org.eclipse.jdt.internal.compiler.Compiler; @@ -940,7 +941,7 @@ public class Main implements ProblemSeverities, SuffixConstants { this.log.println("# " + dateFormat.format(date));//$NON-NLS-1$ } } catch (FileNotFoundException e) { - throw new InvalidInputException(this.main.bind("configure.cannotOpenLog")); //$NON-NLS-1$ + throw new InvalidInputException(this.main.bind("configure.cannotOpenLog", logFileName)); //$NON-NLS-1$ } } @@ -1151,6 +1152,10 @@ public boolean timing = false; public boolean verbose = false; +private String[] expandedCommandLine; + +private PrintWriter err; + public Main(PrintWriter outWriter, PrintWriter errWriter, boolean systemExitWhenFinished) { this(outWriter, errWriter, systemExitWhenFinished, null); } @@ -1918,6 +1923,9 @@ public void configure(String[] argv) throws InvalidInputException { final int INSIDE_SOURCE_PATH_start = 13; final int INSIDE_ENDORSED_DIRS = 15; final int INSIDE_SOURCE_DIRECTORY_DESTINATION_PATH = 16; + final int INSIDE_PROCESSOR_PATH_start = 17; + final int INSIDE_PROCESSOR_start = 18; + final int INSIDE_S_start = 19; final int DEFAULT = 0; ArrayList bootclasspaths = new ArrayList(DEFAULT_SIZE_CLASSPATH); @@ -1996,6 +2004,7 @@ public void configure(String[] argv) throws InvalidInputException { } } argCount = newCommandLineArgs.length; + this.expandedCommandLine = newCommandLineArgs; while (++index < argCount) { if (customEncoding != null) { @@ -2422,6 +2431,42 @@ public void configure(String[] argv) throws InvalidInputException { this.logger.setEmacs(); continue; } + // annotation processing + if (currentArg.startsWith("-A")) { //$NON-NLS-1$ + mode = DEFAULT; + continue; + } + if (currentArg.equals("-processorpath")) { //$NON-NLS-1$ + mode = INSIDE_PROCESSOR_PATH_start; + continue; + } + if (currentArg.equals("-processor")) { //$NON-NLS-1$ + mode = INSIDE_PROCESSOR_start; + continue; + } + if (currentArg.equals("-proc:only")) { //$NON-NLS-1$ + this.options.put( + CompilerOptions.OPTION_GenerateClassFiles, + CompilerOptions.DISABLED); + mode = DEFAULT; + continue; + } + if (currentArg.equals("-proc:none")) { //$NON-NLS-1$ + this.options.put( + CompilerOptions.OPTION_Process_Annotations, + CompilerOptions.DISABLED); + mode = DEFAULT; + continue; + } + if (currentArg.equals("-s")) { //$NON-NLS-1$ + mode = INSIDE_S_start; + continue; + } + if (currentArg.equals("-XprintProcessorInfo") //$NON-NLS-1$ + || currentArg.equals("-XprintRounds")) { //$NON-NLS-1$ + mode = DEFAULT; + continue; + } // tolerated javac options - quietly filtered out if (currentArg.startsWith("-X")) { //$NON-NLS-1$ mode = DEFAULT; @@ -2576,7 +2621,19 @@ public void configure(String[] argv) throws InvalidInputException { this.bind("configure.incorrectDestinationPathEntry", //$NON-NLS-1$ "[-d " + currentArg)); //$NON-NLS-1$ } - // continue; fall through on purpose + break; + case INSIDE_PROCESSOR_PATH_start : + // nothing to do here. This is consumed again by the AnnotationProcessorManager + mode = DEFAULT; + continue; + case INSIDE_PROCESSOR_start : + // nothing to do here. This is consumed again by the AnnotationProcessorManager + mode = DEFAULT; + continue; + case INSIDE_S_start : + // nothing to do here. This is consumed again by the AnnotationProcessorManager + mode = DEFAULT; + continue; } // default is input directory, if no custom destination path exists @@ -2678,13 +2735,14 @@ public void configure(String[] argv) throws InvalidInputException { this.timesCounter = 0; } - if (filesCount != 0) + if (filesCount != 0) { System.arraycopy( this.filenames, 0, (this.filenames = new String[filesCount]), 0, filesCount); + } setPaths(bootclasspaths, sourcepathClasspathArg, @@ -2857,6 +2915,7 @@ protected void initialize(PrintWriter outWriter, Map customDefaultOptions) { this.logger = new Logger(this, outWriter, errWriter); this.out = outWriter; + this.err = errWriter; this.systemExitWhenFinished = systemExit; this.options = new CompilerOptions().getMap(); if (customDefaultOptions != null) { @@ -2952,6 +3011,11 @@ public void performCompilation() throws InvalidInputException { getProblemFactory(), this.out); + if (this.compilerOptions.complianceLevel >= ClassFileConstants.JDK1_6 + && this.compilerOptions.processAnnotations) { + initializeAnnotationProcessorManager(); + } + // set the non-externally configurable options. this.compilerOptions.verbose = this.verbose; this.compilerOptions.produceReferenceInfo = this.produceRefInfo; @@ -2967,7 +3031,24 @@ public void performCompilation() throws InvalidInputException { // cleanup environment.cleanup(); } - +protected void initializeAnnotationProcessorManager() { + try { + Class c = Class.forName("org.eclipse.jdt.internal.compiler.apt.dispatch.AnnotationProcessorManager"); //$NON-NLS-1$ + AbstractAnnotationProcessorManager annotationManager = (AbstractAnnotationProcessorManager) c.newInstance(); + annotationManager.configure(this, this.expandedCommandLine); + annotationManager.setErr(this.err); + annotationManager.setOut(this.out); + this.batchCompiler.annotationProcessorManager = annotationManager; + } catch (ClassNotFoundException e) { + // ignore + } catch (InstantiationException e) { + // should not happen + throw new org.eclipse.jdt.internal.compiler.problem.AbortCompilation(); + } catch (IllegalAccessException e) { + // should not happen + throw new org.eclipse.jdt.internal.compiler.problem.AbortCompilation(); + } +} public void printUsage() { printUsage("misc.usage"); //$NON-NLS-1$ } diff --git a/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/messages.properties b/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/messages.properties index 8f8e8c5f78..358445d601 100644 --- a/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/messages.properties +++ b/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/messages.properties @@ -63,7 +63,7 @@ configure.directoryNotExist = directory does not exist: {0} configure.noClasspath = no classpath defined, using default directory instead configure.incorrectClasspath = incorrect classpath: {0} configure.invalidexpansionargumentname = expansion argument file {0} does not exist or cannot be read -configure.cannotOpenLog = cannot open .log file +configure.cannotOpenLog = cannot open .log file: {0} configure.unexpectedCustomEncoding = unexpected custom encoding specification: {0}[{1}] configure.unsupportedEncoding = unsupported encoding format: {0} configure.duplicateDefaultEncoding = duplicate default encoding format specification: {0} @@ -160,12 +160,26 @@ misc.usage = {1} {2}\n\ \ -g:none no debug info\n\ \ -preserveAllLocals preserve unused local vars for debug purpose\n\ \ \n\ -\ Ignored options:\n\ -\ -J<option> pass option to virtual machine (ignored)\n\ -\ -X<option> specify non-standard option (ignored\n\ -\ except for -Xemacs)\n\ -\ -X print non-standard options and exit (ignored)\n\ -\ -O optimize for execution time (ignored)\n\ +\ Annotation processing options:\n\ +\ These options are meaningful only in a 1.6 environment.\n\ +\ -Akey[=value] annotation processors options that are made to\n\ +\ annotation processors. key are identifiers separated\n\ +\ by '.'.\n\ +\ -processorpath <directories and zip/jar files separated by {0}>\n\ +\ specify locations where to find annotation processors\n\ +\ If this option is not used, the classpath will be\n\ +\ searched for processors.\n\ +\ -processor <class1[,class2,...]>\n\ +\ Qualified names of the annotation processors to run.\n\ +\ This bypasses the default annotation discovery process\n\ +\ -proc:only run annotation processors, but do not compile\n\ +\ -proc:none perform compilation but do not run annotation\n\ +\ processors\n\ +\ -s <dir> specify a directory where to put the generated source\n\ +\ files\n\ +\ -XprintProcessorInfo print information about which annotations and which\n\ +\ elements a processor is asked to process\n\ +\ -XprintRounds print information about annotation processing rounds.\n\ \ \n\ \ Advanced options:\n\ \ @<file> read command line arguments from file\n\ @@ -189,7 +203,14 @@ misc.usage = {1} {2}\n\ \ \n\ \ -? -help print this help message\n\ \ -v -version print compiler version\n\ -\ -showversion print compiler version and continue\n +\ -showversion print compiler version and continue\n\ +\ \n\ +\ Ignored options:\n\ +\ -J<option> pass option to virtual machine (ignored)\n\ +\ -X<option> specify non-standard option (ignored\n\ +\ except for listed -X options)\n\ +\ -X print non-standard options and exit (ignored)\n\ +\ -O optimize for execution time (ignored)\n misc.usage.warn = {1} {2}\n\ {3}\n\ \ \n\ diff --git a/org.eclipse.jdt.core/buildnotes_jdt-core.html b/org.eclipse.jdt.core/buildnotes_jdt-core.html index f84b16d426..83e4b16db1 100644 --- a/org.eclipse.jdt.core/buildnotes_jdt-core.html +++ b/org.eclipse.jdt.core/buildnotes_jdt-core.html @@ -53,6 +53,8 @@ Eclipse SDK 3.3M5 - ??th Decembre 2006 <h2>What's new in this drop</h2> <h3>Problem Reports Fixed</h3> +<a href="http://bugs.eclipse.org/bugs/show_bug.cgi?id=160773">160773</a> +[jsr269] Need interfaces between jdt compiler and jsr269 impl <a name="v_727"></a> diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/AbstractAnnotationProcessorManager.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/AbstractAnnotationProcessorManager.java new file mode 100644 index 0000000000..c9fdb1f459 --- /dev/null +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/AbstractAnnotationProcessorManager.java @@ -0,0 +1,23 @@ +package org.eclipse.jdt.internal.compiler; + +import java.io.PrintWriter; +import java.util.List; + +import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration; +import org.eclipse.jdt.internal.compiler.batch.Main; + +public abstract class AbstractAnnotationProcessorManager { + public abstract void configure(Main batchCompiler, String[] options); + + public abstract void setOut(PrintWriter out); + + public abstract void setErr(PrintWriter err); + + public abstract List getNewUnits(); + + public abstract void reset(); + + public abstract void processAnnotations(CompilationUnitDeclaration[] units, boolean isLastRound); + + public abstract void setProcessors(Object[] processors); +} diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/Compiler.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/Compiler.java index 46fe48b419..f8ccc7ab14 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/Compiler.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/Compiler.java @@ -40,6 +40,9 @@ public class Compiler implements ITypeRequestor, ProblemSeverities { // ONCE STABILIZED, THESE SHOULD RETURN TO A FINAL FIELD public static boolean DEBUG = false; public int parseThreshold = -1; + + public AbstractAnnotationProcessorManager annotationProcessorManager; + // number of initial units parsed at once (-1: none) /* @@ -354,34 +357,30 @@ public class Compiler implements ITypeRequestor, ProblemSeverities { CompilationUnitDeclaration parsedUnit; CompilationResult unitResult = new CompilationResult(sourceUnits[i], i, maxUnits, this.options.maxProblemsPerUnit); - try { - if (options.verbose) { - this.out.println( - Messages.bind(Messages.compilation_request, - new String[] { - String.valueOf(i + 1), - String.valueOf(maxUnits), - new String(sourceUnits[i].getFileName()) - })); - } - // diet parsing for large collection of units - if (totalUnits < parseThreshold) { - parsedUnit = parser.parse(sourceUnits[i], unitResult); - } else { - parsedUnit = parser.dietParse(sourceUnits[i], unitResult); - } - // initial type binding creation - lookupEnvironment.buildTypeBindings(parsedUnit, null /*no access restriction*/); - this.addCompilationUnit(sourceUnits[i], parsedUnit); - ImportReference currentPackage = parsedUnit.currentPackage; - if (currentPackage != null) { - unitResult.recordPackageName(currentPackage.tokens); - } - //} catch (AbortCompilationUnit e) { - // requestor.acceptResult(unitResult.tagAsAccepted()); - } finally { - sourceUnits[i] = null; // no longer hold onto the unit + if (options.verbose) { + this.out.println( + Messages.bind(Messages.compilation_request, + new String[] { + String.valueOf(i + 1), + String.valueOf(maxUnits), + new String(sourceUnits[i].getFileName()) + })); + } + // diet parsing for large collection of units + if (totalUnits < parseThreshold) { + parsedUnit = parser.parse(sourceUnits[i], unitResult); + } else { + parsedUnit = parser.dietParse(sourceUnits[i], unitResult); + } + ImportReference currentPackage = parsedUnit.currentPackage; + if (currentPackage != null) { + unitResult.recordPackageName(currentPackage.tokens); } + // initial type binding creation + lookupEnvironment.buildTypeBindings(parsedUnit, null /*no access restriction*/); + this.addCompilationUnit(sourceUnits[i], parsedUnit); + //} catch (AbortCompilationUnit e) { + // requestor.acceptResult(unitResult.tagAsAccepted()); } // binding resolution lookupEnvironment.completeTypeBindings(); @@ -394,14 +393,19 @@ public class Compiler implements ITypeRequestor, ProblemSeverities { */ public void compile(ICompilationUnit[] sourceUnits) { CompilationUnitDeclaration unit = null; - int i = 0; try { // build and record parsed units beginToCompile(sourceUnits); + if (this.annotationProcessorManager != null) { + processAnnotations(sourceUnits); + if (!options.generateClassFiles) { + return; + } + } // process all units (some more could be injected in the loop by the lookup environment) - for (; i < this.totalUnits; i++) { + for (int i = 0; i < this.totalUnits; i++) { unit = unitsToProcess[i]; try { if (options.verbose) @@ -450,6 +454,33 @@ public class Compiler implements ITypeRequestor, ProblemSeverities { } } + protected void processAnnotations(ICompilationUnit[] sourceUnits) { + int newUnitSize = 0; + do { + this.annotationProcessorManager.processAnnotations(unitsToProcess, false); + List newUnits = this.annotationProcessorManager.getNewUnits(); + newUnitSize = newUnits.size(); + ICompilationUnit[] newSourceUnits = sourceUnits; + if (newUnitSize != 0) { + // we reset the compiler in order to restart with the new units + this.reset(); + int sourceUnitsLength = sourceUnits.length; + newSourceUnits = new ICompilationUnit[sourceUnitsLength + newUnitSize]; + newUnits.toArray(newSourceUnits); + System.arraycopy(sourceUnits, 0, newSourceUnits, newUnitSize, sourceUnitsLength); + beginToCompile(newSourceUnits); + this.annotationProcessorManager.reset(); + } + } while (newUnitSize != 0); + // one more loop to create possible resources + // this loop cannot create any java source files + this.annotationProcessorManager.processAnnotations(unitsToProcess, true); + List newUnits = this.annotationProcessorManager.getNewUnits(); + if (newUnits.size() != 0) { + // TODO report error + } + } + /* * Compiler crash recovery in case of unexpected runtime exceptions */ diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/impl/CompilerOptions.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/impl/CompilerOptions.java index 3b7e5a4a2a..6b1d270ba4 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/impl/CompilerOptions.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/impl/CompilerOptions.java @@ -108,6 +108,8 @@ public class CompilerOptions { public static final String OPTION_ReportParameterAssignment = "org.eclipse.jdt.core.compiler.problem.parameterAssignment"; //$NON-NLS-1$ public static final String OPTION_ReportFallthroughCase = "org.eclipse.jdt.core.compiler.problem.fallthroughCase"; //$NON-NLS-1$ public static final String OPTION_ReportOverridingMethodWithoutSuperInvocation = "org.eclipse.jdt.core.compiler.problem.overridingMethodWithoutSuperInvocation"; //$NON-NLS-1$ + public static final String OPTION_GenerateClassFiles = "org.eclipse.jdt.core.compiler.generateClassFiles"; //$NON-NLS-1$ + public static final String OPTION_Process_Annotations = "org.eclipse.jdt.core.compiler.processAnnotations"; //$NON-NLS-1$ // Backward compatibility public static final String OPTION_ReportInvalidAnnotation = "org.eclipse.jdt.core.compiler.problem.invalidAnnotation"; //$NON-NLS-1$ @@ -303,6 +305,10 @@ public class CompilerOptions { // store annotations public boolean storeAnnotations = false; + // annotation processing + public boolean generateClassFiles = true; + public boolean processAnnotations = true; + /** * Initializing the compiler options with defaults */ @@ -412,6 +418,8 @@ public class CompilerOptions { optionsMap.put(OPTION_ReportParameterAssignment, getSeverityString(ParameterAssignment)); optionsMap.put(OPTION_ReportFallthroughCase, getSeverityString(FallthroughCase)); optionsMap.put(OPTION_ReportOverridingMethodWithoutSuperInvocation, getSeverityString(OverridingMethodWithoutSuperInvocation)); + optionsMap.put(OPTION_GenerateClassFiles, this.generateClassFiles ? ENABLED : DISABLED); + optionsMap.put(OPTION_Process_Annotations, this.processAnnotations ? ENABLED : DISABLED); return optionsMap; } @@ -740,6 +748,20 @@ public class CompilerOptions { this.reportMissingJavadocCommentsOverriding = false; } } + if ((optionValue = optionsMap.get(OPTION_GenerateClassFiles)) != null) { + if (ENABLED.equals(optionValue)) { + this.generateClassFiles = true; + } else if (DISABLED.equals(optionValue)) { + this.generateClassFiles = false; + } + } + if ((optionValue = optionsMap.get(OPTION_Process_Annotations)) != null) { + if (ENABLED.equals(optionValue)) { + this.processAnnotations = true; + } else if (DISABLED.equals(optionValue)) { + this.processAnnotations = false; + } + } } public String toString() { @@ -819,6 +841,8 @@ public class CompilerOptions { buf.append("\n\t- unused label: ").append(getSeverityString(UnusedLabel)); //$NON-NLS-1$ buf.append("\n\t- treat optional error as fatal: ").append(this.treatOptionalErrorAsFatal ? ENABLED : DISABLED); //$NON-NLS-1$ buf.append("\n\t- parameter assignment: ").append(getSeverityString(ParameterAssignment)); //$NON-NLS-1$ + buf.append("\n\t- generate class files: ").append(this.generateClassFiles ? ENABLED : DISABLED); //$NON-NLS-1$ + buf.append("\n\t- process annotations: ").append(this.processAnnotations ? ENABLED : DISABLED); //$NON-NLS-1$ return buf.toString(); } |