View | Details | Raw Unified | Return to bug 329156 | Differences between
and this patch

Collapse All | Expand All

(-)META-INF/services/javax.annotation.processing.Processor (+1 lines)
Lines 2-5 Link Here
2
org.eclipse.jdt.apt.pluggable.tests.processors.message6.Message6Proc
2
org.eclipse.jdt.apt.pluggable.tests.processors.message6.Message6Proc
3
org.eclipse.jdt.apt.pluggable.tests.processors.filertester.FilerTesterProc
3
org.eclipse.jdt.apt.pluggable.tests.processors.filertester.FilerTesterProc
4
org.eclipse.jdt.apt.pluggable.tests.processors.buildertester.InheritedAnnoProc
4
org.eclipse.jdt.apt.pluggable.tests.processors.buildertester.InheritedAnnoProc
5
org.eclipse.jdt.apt.pluggable.tests.processors.buildertester.TestFinalRoundProc
5
org.eclipse.jdt.apt.pluggable.tests.processors.modeltester.ModelTesterProc
6
org.eclipse.jdt.apt.pluggable.tests.processors.modeltester.ModelTesterProc
(-)plugin.xml (+3 lines)
Lines 29-34 Link Here
29
               class="org.eclipse.jdt.apt.pluggable.tests.processors.buildertester.InheritedAnnoProc">
29
               class="org.eclipse.jdt.apt.pluggable.tests.processors.buildertester.InheritedAnnoProc">
30
         </java6processor>
30
         </java6processor>
31
         <java6processor
31
         <java6processor
32
               class="org.eclipse.jdt.apt.pluggable.tests.processors.buildertester.TestFinalRoundProc">
33
         </java6processor>
34
         <java6processor
32
               class="org.eclipse.jdt.apt.pluggable.tests.processors.modeltester.ModelTesterProc">
35
               class="org.eclipse.jdt.apt.pluggable.tests.processors.modeltester.ModelTesterProc">
33
         </java6processor>
36
         </java6processor>
34
      </java6processors>
37
      </java6processors>
(-)src/org/eclipse/jdt/apt/pluggable/tests/BuilderTests.java (-3 / +40 lines)
Lines 20-25 Link Here
20
import org.eclipse.core.runtime.IPath;
20
import org.eclipse.core.runtime.IPath;
21
import org.eclipse.jdt.apt.core.util.AptConfig;
21
import org.eclipse.jdt.apt.core.util.AptConfig;
22
import org.eclipse.jdt.apt.pluggable.tests.processors.buildertester.InheritedAnnoProc;
22
import org.eclipse.jdt.apt.pluggable.tests.processors.buildertester.InheritedAnnoProc;
23
import org.eclipse.jdt.apt.pluggable.tests.processors.buildertester.TestFinalRoundProc;
23
import org.eclipse.jdt.core.IJavaProject;
24
import org.eclipse.jdt.core.IJavaProject;
24
25
25
/**
26
/**
Lines 36-44 Link Here
36
		return new TestSuite(BuilderTests.class);
37
		return new TestSuite(BuilderTests.class);
37
	}
38
	}
38
	
39
	
39
	// Need this to avoid JUnit complaining that there are no tests in this suite
40
	/**
40
	public void testDummy() {
41
	 * Verify that a new type generated in the final round does not get
41
		assertTrue(true);
42
	 * annotations processed, but does get compiled. The JSR269 spec is somewhat
43
	 * vague about whether it should be possible to generate a new type during
44
	 * the final round (since the final round does not happen until after a
45
	 * round in which no new types are generated); but apparently javac behaves
46
	 * this way.
47
	 * <p>
48
	 * See <a href="http://bugs.eclipse.org/329156">Bug 329156</a> and <a
49
	 * href="http://bugs.sun.com/view_bug.do?bug_id=6634138">the corresponding
50
	 * bug in javac</a>, which Sun fixed.
51
	 */
52
	public void testFinalRound() throws Throwable {
53
		ProcessorTestStatus.reset();
54
		TestFinalRoundProc.resetNumRounds();
55
		IJavaProject jproj = createJavaProject(_projectName);
56
		disableJava5Factories(jproj);
57
		IProject proj = jproj.getProject();
58
		IPath projPath = proj.getFullPath();
59
		IPath root = projPath.append("src");
60
		
61
		// The @FinalRoundTestTrigger processor does not generate any files when it
62
		// first runs; but on its final round it then generates a new Java type
63
		// that is annotated with @FinalRoundTestTrigger.
64
		env.addClass(root, "t", "Foo",
65
				"package t;\n" +
66
				"import org.eclipse.jdt.apt.pluggable.tests.annotations.FinalRoundTestTrigger;\n" +
67
				"@FinalRoundTestTrigger\n" +
68
				"public class Foo {}"
69
		);
70
		AptConfig.setEnabled(jproj, true);
71
		
72
		fullBuild();
73
		expectingNoProblems();
74
		
75
		// Processor should have run total of two rounds; compiled classes
76
		// should include Foo and FinalRoundGen.
77
		assertEquals(2, TestFinalRoundProc.getNumRounds());
78
		expectingUniqueCompiledClasses(new String[] {"t.Foo", "g.FinalRoundGen"});
42
	}
79
	}
43
	
80
	
44
	/**
81
	/**
(-)src/org/eclipse/jdt/apt/pluggable/tests/annotations/FinalRoundTestTrigger.java (+24 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 Walter Harley and others
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *    eclipse@cafewalter.com - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.jdt.apt.pluggable.tests.annotations;
12
13
/**
14
 * Marker interface to trigger the TestFinalRoundProc, which does nothing
15
 * normally but on the final round of processing generates a new Java type
16
 * that is annotated with this annotation.
17
 * <p>
18
 * See <a href="http://bugs.eclipse.org/329156">Bug 329156</a> and
19
 * <a href="http://bugs.sun.com/view_bug.do?bug_id=6634138">the
20
 * corresponding bug in javac</a>, which Sun fixed.
21
 * @since 3.7
22
 */
23
public @interface FinalRoundTestTrigger {
24
}
(-)src/org/eclipse/jdt/apt/pluggable/tests/processors/buildertester/InheritedAnnoProc.java (-1 / +1 lines)
Lines 43-49 Link Here
43
@SupportedOptions( {})
43
@SupportedOptions( {})
44
public class InheritedAnnoProc extends AbstractProcessor {
44
public class InheritedAnnoProc extends AbstractProcessor {
45
	
45
	
46
	private static List<String> processedElements = new ArrayList<String>();
46
	private static final List<String> processedElements = new ArrayList<String>();
47
47
48
	public static List<String> getProcessedElements() {
48
	public static List<String> getProcessedElements() {
49
		return Collections.unmodifiableList(processedElements);
49
		return Collections.unmodifiableList(processedElements);
(-)src/org/eclipse/jdt/apt/pluggable/tests/processors/buildertester/TestFinalRoundProc.java (+87 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 Walter Harley and others
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *    eclipse@cafewalter.com - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.jdt.apt.pluggable.tests.processors.buildertester;
13
14
import java.io.IOException;
15
import java.io.PrintWriter;
16
import java.util.Set;
17
18
import javax.annotation.processing.AbstractProcessor;
19
import javax.annotation.processing.RoundEnvironment;
20
import javax.annotation.processing.SupportedAnnotationTypes;
21
import javax.annotation.processing.SupportedOptions;
22
import javax.annotation.processing.SupportedSourceVersion;
23
import javax.lang.model.SourceVersion;
24
import javax.lang.model.element.TypeElement;
25
import javax.tools.Diagnostic.Kind;
26
import javax.tools.JavaFileObject;
27
28
import org.eclipse.jdt.apt.pluggable.tests.annotations.FinalRoundTestTrigger;
29
30
/**
31
 * Do nothing when first triggered; then, in the final round, generate a
32
 * new type that is annotated with {@link FinalRoundTestTrigger}.
33
 * Used to verify that a new type generated in the final round does not get
34
 * annotations processed, but does get compiled. The JSR269 spec is somewhat
35
 * vague about whether it should be possible to generate a new type during
36
 * the final round (since the final round does not happen until after a
37
 * round in which no new types are generated); but apparently javac behaves
38
 * this way.
39
 * <p>
40
 * See <a href="http://bugs.eclipse.org/329156">Bug 329156</a> and <a
41
 * href="http://bugs.sun.com/view_bug.do?bug_id=6634138">the corresponding
42
 * bug in javac</a>, which Sun fixed.
43
 */
44
@SupportedAnnotationTypes( { "org.eclipse.jdt.apt.pluggable.tests.annotations.FinalRoundTestTrigger" })
45
@SupportedSourceVersion(SourceVersion.RELEASE_6)
46
@SupportedOptions( {})
47
public class TestFinalRoundProc extends AbstractProcessor {
48
	private static int _numRounds;
49
	
50
	public static int getNumRounds() {
51
		return _numRounds;
52
	}
53
	
54
	public static void resetNumRounds() {
55
		_numRounds = 0;
56
	}
57
58
	@Override
59
	public boolean process(Set<? extends TypeElement> annotations,
60
			RoundEnvironment roundEnv) {
61
		if (roundEnv.processingOver()) {
62
			createFile();
63
		}
64
		_numRounds++;
65
		return true;
66
	}
67
68
	private void createFile() {
69
		PrintWriter pw = null;
70
		try {
71
			JavaFileObject jfo = processingEnv.getFiler().createSourceFile("g.FinalRoundGen");
72
			pw = new PrintWriter(jfo.openWriter());
73
			pw.println("package g;");
74
			pw.println("import org.eclipse.jdt.apt.pluggable.tests.annotations.FinalRoundTestTrigger;");
75
			pw.println("@FinalRoundTestTrigger");
76
			pw.println("public class FinalRoundGen {}");
77
		} catch (IOException e) {
78
			e.printStackTrace();
79
			processingEnv.getMessager().printMessage(Kind.ERROR, "Unable to create source file! Exception message was: " + e.getMessage());
80
		} finally {
81
			if (pw != null) {
82
				pw.close();
83
			}
84
		}
85
	}
86
87
}
(-)compiler/org/eclipse/jdt/internal/compiler/Compiler.java (-4 / +20 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
2
 * Copyright (c) 2000, 2010 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 831-840 Link Here
831
				this.annotationProcessorManager.reset();
831
				this.annotationProcessorManager.reset();
832
			}
832
			}
833
		} while (newUnitSize != 0 || newClassFilesSize != 0);
833
		} while (newUnitSize != 0 || newClassFilesSize != 0);
834
		// one more loop to create possible resources
834
		
835
		// this loop cannot create any java source files
836
		this.annotationProcessorManager.processAnnotations(null, null, true);
835
		this.annotationProcessorManager.processAnnotations(null, null, true);
837
		// TODO we might want to check if this loop created new units
836
		// process potential units added in the final round see 329156 
837
		ICompilationUnit[] newUnits = this.annotationProcessorManager.getNewUnits();
838
		newUnitSize = newUnits.length;
839
		if (newUnitSize != 0) {
840
			ICompilationUnit[] newProcessedUnits = (ICompilationUnit[]) newUnits.clone(); // remember new units in case a source type collision occurs
841
			try {
842
				this.lookupEnvironment.isProcessingAnnotations = true;
843
				internalBeginToCompile(newUnits, newUnitSize);
844
			} catch (SourceTypeCollisionException e) {
845
				e.newAnnotationProcessorUnits = newProcessedUnits;
846
				throw e;
847
			} finally {
848
				this.lookupEnvironment.isProcessingAnnotations = false;
849
				this.annotationProcessorManager.reset();
850
			}
851
		} else {
852
			this.annotationProcessorManager.reset();
853
		}
838
	}
854
	}
839
855
840
	public void reset() {
856
	public void reset() {

Return to bug 329156