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

Collapse All | Expand All

(-)src/org/eclipse/jdt/internal/compiler/apt/dispatch/RoundEnvImpl.java (-3 / +11 lines)
Lines 29-34 Link Here
29
import org.eclipse.jdt.internal.compiler.lookup.Binding;
29
import org.eclipse.jdt.internal.compiler.lookup.Binding;
30
import org.eclipse.jdt.internal.compiler.lookup.FieldBinding;
30
import org.eclipse.jdt.internal.compiler.lookup.FieldBinding;
31
import org.eclipse.jdt.internal.compiler.lookup.MethodBinding;
31
import org.eclipse.jdt.internal.compiler.lookup.MethodBinding;
32
import org.eclipse.jdt.internal.compiler.lookup.ParameterizedTypeBinding;
32
import org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding;
33
import org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding;
33
import org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding;
34
import org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding;
34
import org.eclipse.jdt.internal.compiler.lookup.TagBits;
35
import org.eclipse.jdt.internal.compiler.lookup.TagBits;
Lines 64-69 Link Here
64
	private void collectAnnotations(ReferenceBinding[] referenceBindings) {
65
	private void collectAnnotations(ReferenceBinding[] referenceBindings) {
65
		for (ReferenceBinding referenceBinding : referenceBindings) {
66
		for (ReferenceBinding referenceBinding : referenceBindings) {
66
			// collect all annotations from the binary types
67
			// collect all annotations from the binary types
68
			if (referenceBinding instanceof ParameterizedTypeBinding) {
69
				referenceBinding = ((ParameterizedTypeBinding) referenceBinding).genericType();
70
			}
67
			AnnotationBinding[] annotationBindings = referenceBinding.getAnnotations();
71
			AnnotationBinding[] annotationBindings = referenceBinding.getAnnotations();
68
			for (AnnotationBinding annotationBinding : annotationBindings) {
72
			for (AnnotationBinding annotationBinding : annotationBindings) {
69
				TypeElement anno = (TypeElement)_factory.newElement(annotationBinding.getAnnotationType()); 
73
				TypeElement anno = (TypeElement)_factory.newElement(annotationBinding.getAnnotationType()); 
Lines 127-133 Link Here
127
			Set<Element> annotatedElements = new HashSet<Element>(_annoToUnit.getValues(a));
131
			Set<Element> annotatedElements = new HashSet<Element>(_annoToUnit.getValues(a));
128
			// For all other root elements that are TypeElements, and for their recursively enclosed
132
			// For all other root elements that are TypeElements, and for their recursively enclosed
129
			// types, add each element if it has a superclass are annotated with 'a'
133
			// types, add each element if it has a superclass are annotated with 'a'
130
			ReferenceBinding annoTypeBinding = (ReferenceBinding)((TypeElementImpl)a)._binding;
134
			ReferenceBinding annoTypeBinding = (ReferenceBinding) annoBinding;
131
			for (TypeElement element : ElementFilter.typesIn(getRootElements())) {
135
			for (TypeElement element : ElementFilter.typesIn(getRootElements())) {
132
				ReferenceBinding typeBinding = (ReferenceBinding)((TypeElementImpl)element)._binding;
136
				ReferenceBinding typeBinding = (ReferenceBinding)((TypeElementImpl)element)._binding;
133
				addAnnotatedElements(annoTypeBinding, typeBinding, annotatedElements);
137
				addAnnotatedElements(annoTypeBinding, typeBinding, annotatedElements);
Lines 162-176 Link Here
162
	 * @return true if element has a superclass that is annotated with anno
166
	 * @return true if element has a superclass that is annotated with anno
163
	 */
167
	 */
164
	private boolean inheritsAnno(ReferenceBinding element, ReferenceBinding anno) {
168
	private boolean inheritsAnno(ReferenceBinding element, ReferenceBinding anno) {
169
		ReferenceBinding searchedElement = element;
165
		do {
170
		do {
166
			AnnotationBinding[] annos = element.getAnnotations();
171
			if (searchedElement instanceof ParameterizedTypeBinding) {
172
				searchedElement = ((ParameterizedTypeBinding) searchedElement).genericType();
173
			}
174
			AnnotationBinding[] annos = searchedElement.getAnnotations();
167
			for (AnnotationBinding annoBinding : annos) {
175
			for (AnnotationBinding annoBinding : annos) {
168
				if (annoBinding.getAnnotationType() == anno) {
176
				if (annoBinding.getAnnotationType() == anno) {
169
					// element is annotated with anno
177
					// element is annotated with anno
170
					return true;
178
					return true;
171
				}
179
				}
172
			}
180
			}
173
		} while (null != (element = element.superclass()));
181
		} while (null != (searchedElement = searchedElement.superclass()));
174
		return false;
182
		return false;
175
	}
183
	}
176
	
184
	
(-)src/org/eclipse/jdt/internal/compiler/apt/model/ElementsImpl.java (+4 lines)
Lines 49-54 Link Here
49
import org.eclipse.jdt.internal.compiler.lookup.MethodBinding;
49
import org.eclipse.jdt.internal.compiler.lookup.MethodBinding;
50
import org.eclipse.jdt.internal.compiler.lookup.MethodVerifier;
50
import org.eclipse.jdt.internal.compiler.lookup.MethodVerifier;
51
import org.eclipse.jdt.internal.compiler.lookup.PackageBinding;
51
import org.eclipse.jdt.internal.compiler.lookup.PackageBinding;
52
import org.eclipse.jdt.internal.compiler.lookup.ParameterizedTypeBinding;
52
import org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding;
53
import org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding;
53
import org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding;
54
import org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding;
54
import org.eclipse.jdt.internal.compiler.lookup.TagBits;
55
import org.eclipse.jdt.internal.compiler.lookup.TagBits;
Lines 88-93 Link Here
88
			Set<ReferenceBinding> annotationTypes = new HashSet<ReferenceBinding>();
89
			Set<ReferenceBinding> annotationTypes = new HashSet<ReferenceBinding>();
89
			ReferenceBinding binding = (ReferenceBinding)((TypeElementImpl)e)._binding;
90
			ReferenceBinding binding = (ReferenceBinding)((TypeElementImpl)e)._binding;
90
			while (null != binding) {
91
			while (null != binding) {
92
				if (binding instanceof ParameterizedTypeBinding) {
93
					binding = ((ParameterizedTypeBinding) binding).genericType();
94
				}
91
				for (AnnotationBinding annotation : binding.getAnnotations()) {
95
				for (AnnotationBinding annotation : binding.getAnnotations()) {
92
					if (annotation == null) continue;
96
					if (annotation == null) continue;
93
					ReferenceBinding annotationType = annotation.getAnnotationType();
97
					ReferenceBinding annotationType = annotation.getAnnotationType();
(-)processors/org/eclipse/jdt/compiler/apt/tests/processors/inherited/ArgsConstructorProcessor.java (-2 / +33 lines)
Lines 15-23 Link Here
15
import java.util.Map.Entry;
15
import java.util.Map.Entry;
16
import java.util.Set;
16
import java.util.Set;
17
17
18
import javax.annotation.processing.AbstractProcessor;
19
import javax.annotation.processing.RoundEnvironment;
18
import javax.annotation.processing.RoundEnvironment;
19
import javax.lang.model.element.AnnotationMirror;
20
import javax.lang.model.element.Element;
20
import javax.lang.model.element.Element;
21
import javax.lang.model.element.ElementKind;
21
import javax.lang.model.element.TypeElement;
22
import javax.lang.model.element.TypeElement;
22
import javax.annotation.processing.*;
23
import javax.annotation.processing.*;
23
import javax.lang.model.SourceVersion;
24
import javax.lang.model.SourceVersion;
Lines 28-37 Link Here
28
import javax.tools.Diagnostic.Kind;
29
import javax.tools.Diagnostic.Kind;
29
30
30
import org.eclipse.jdt.compiler.apt.tests.annotations.ArgsConstructor;
31
import org.eclipse.jdt.compiler.apt.tests.annotations.ArgsConstructor;
32
import org.eclipse.jdt.compiler.apt.tests.processors.base.BaseProcessor;
31
33
32
@SupportedAnnotationTypes("org.eclipse.jdt.compiler.apt.tests.annotations.ArgsConstructor")
34
@SupportedAnnotationTypes("org.eclipse.jdt.compiler.apt.tests.annotations.ArgsConstructor")
33
@SupportedSourceVersion(SourceVersion.RELEASE_6)
35
@SupportedSourceVersion(SourceVersion.RELEASE_6)
34
public class ArgsConstructorProcessor extends AbstractProcessor {
36
public class ArgsConstructorProcessor extends BaseProcessor {
37
	private TypeElement _elementAC;
35
38
36
	@Override
39
	@Override
37
	public boolean process(Set<? extends TypeElement> annotations,
40
	public boolean process(Set<? extends TypeElement> annotations,
Lines 40-47 Link Here
40
		for (TypeElement type : annotations) {
43
		for (TypeElement type : annotations) {
41
			processArgsConstructorClasses(env, type);
44
			processArgsConstructorClasses(env, type);
42
		}
45
		}
46
47
		if (!collectElements()) {
48
			reportError("Failed");
49
			return false;
50
		}
51
		TypeMirror superclass = _elementAC.getSuperclass();
52
		if (TypeKind.DECLARED != superclass.getKind()) {
53
			reportError("Wrong type: should be a declared type");
54
			return false;
55
		}
56
		Element typeElement = _typeUtils.asElement(superclass);
57
		if (typeElement.getAnnotationMirrors().size() != 1) {
58
			reportError("Should contain an annotation");
59
			return false;
60
		}
61
		reportSuccess();
43
		return true;
62
		return true;
63
	}
44
64
65
	/**
66
	 * Collect some elements that will be reused in various tests
67
	 * @return true if all tests passed
68
	 */
69
	private boolean collectElements() {
70
		_elementAC = _elementUtils.getTypeElement("targets.inherited.TestGenericChild");
71
		if (_elementAC == null) {
72
			reportError("TestGenericChild was not found");
73
			return false;
74
		}
75
		return true;
45
	}
76
	}
46
77
47
	private void processArgsConstructorClasses(RoundEnvironment env,
78
	private void processArgsConstructorClasses(RoundEnvironment env,
(-)src/org/eclipse/jdt/compiler/apt/tests/NegativeTests.java (+35 lines)
Lines 61-66 Link Here
61
61
62
	// See corresponding usages in the NegativeModelProc class
62
	// See corresponding usages in the NegativeModelProc class
63
	private static final String NEGATIVEMODELPROCNAME = "org.eclipse.jdt.compiler.apt.tests.processors.negative.NegativeModelProc";
63
	private static final String NEGATIVEMODELPROCNAME = "org.eclipse.jdt.compiler.apt.tests.processors.negative.NegativeModelProc";
64
	private static final String INHERITED_PROCNAME ="org.eclipse.jdt.compiler.apt.tests.processors.inherited.ArgsConstructorProcessor";
64
	private static final String IGNOREJAVACBUGS = "ignoreJavacBugs";
65
	private static final String IGNOREJAVACBUGS = "ignoreJavacBugs";
65
	
66
	
66
	@Override
67
	@Override
Lines 184-189 Link Here
184
	public void testNegativeModel10WithEclipseCompiler() throws IOException {
185
	public void testNegativeModel10WithEclipseCompiler() throws IOException {
185
		JavaCompiler compiler = BatchTestUtils.getEclipseCompiler();
186
		JavaCompiler compiler = BatchTestUtils.getEclipseCompiler();
186
		System.clearProperty(NEGATIVEMODELPROCNAME);
187
		System.clearProperty(NEGATIVEMODELPROCNAME);
188
		System.clearProperty(INHERITED_PROCNAME);
187
		File targetFolder = TestUtils.concatPath(BatchTestUtils.getSrcFolderName(), "targets", "inherited");
189
		File targetFolder = TestUtils.concatPath(BatchTestUtils.getSrcFolderName(), "targets", "inherited");
188
		BatchTestUtils.copyResources("targets/inherited", targetFolder);
190
		BatchTestUtils.copyResources("targets/inherited", targetFolder);
189
191
Lines 202-207 Link Here
202
				"Class targets.inherited.TestNormalChild lacks a public constructor with args: java.awt.Point";
204
				"Class targets.inherited.TestNormalChild lacks a public constructor with args: java.awt.Point";
203
205
204
		assertEquals("Wrong output", expectedErrors, String.valueOf(errBuffer));
206
		assertEquals("Wrong output", expectedErrors, String.valueOf(errBuffer));
207
		String property = System.getProperty(INHERITED_PROCNAME);
208
		assertNotNull("No property - probably processing did not take place", property);
209
		assertEquals("succeeded", property);
210
	}
211
212
	/*
213
	 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=328575 
214
	 */
215
	public void testNegativeModel10WithSystemCompiler() throws IOException {
216
		JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
217
		if (compiler == null) {
218
			System.out.println("No system java compiler available");
219
			return;
220
		}
221
		System.clearProperty(NEGATIVEMODELPROCNAME);
222
		System.clearProperty(INHERITED_PROCNAME);
223
		File targetFolder = TestUtils.concatPath(BatchTestUtils.getSrcFolderName(), "targets", "inherited");
224
		BatchTestUtils.copyResources("targets/inherited", targetFolder);
225
226
		// Invoke processing by compiling the targets.model resources
227
		ByteArrayOutputStream errBuffer = new ByteArrayOutputStream();
228
		PrintWriter printWriter = new PrintWriter(errBuffer);
229
		TestDiagnosticListener diagnosticListener = new TestDiagnosticListener(printWriter);
230
		boolean success = BatchTestUtils.compileTreeWithErrors(compiler, new ArrayList<String>(), targetFolder, diagnosticListener);
231
		
232
		assertTrue("Compilation should have failed due to expected errors, but it didn't", !success);
233
		assertEquals("Two errors should be reported", 2, diagnosticListener.errorCounter);
234
		printWriter.flush();
235
		printWriter.close();
236
237
		String property = System.getProperty(INHERITED_PROCNAME);
238
		assertNotNull("No property - probably processing did not take place", property);
239
		assertEquals("succeeded", property);
205
	}
240
	}
206
241
207
	/**
242
	/**

Return to bug 328575