### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.compiler.apt.tests Index: processors/META-INF/services/javax.annotation.processing.Processor =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.compiler.apt.tests/processors/META-INF/services/javax.annotation.processing.Processor,v retrieving revision 1.11 diff -u -r1.11 javax.annotation.processing.Processor --- processors/META-INF/services/javax.annotation.processing.Processor 2 Oct 2007 20:51:20 -0000 1.11 +++ processors/META-INF/services/javax.annotation.processing.Processor 5 May 2011 21:01:30 -0000 @@ -10,3 +10,4 @@ org.eclipse.jdt.compiler.apt.tests.processors.typemirror.TypeMirrorProc org.eclipse.jdt.compiler.apt.tests.processors.typeutils.TypeUtilsProc org.eclipse.jdt.compiler.apt.tests.processors.negative.NegativeModelProc +org.eclipse.jdt.compiler.apt.tests.processors.inherited.ArgsConstructorProcessor \ No newline at end of file Index: processors/org/eclipse/jdt/compiler/apt/tests/annotations/ArgsConstructor.java =================================================================== RCS file: processors/org/eclipse/jdt/compiler/apt/tests/annotations/ArgsConstructor.java diff -N processors/org/eclipse/jdt/compiler/apt/tests/annotations/ArgsConstructor.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ processors/org/eclipse/jdt/compiler/apt/tests/annotations/ArgsConstructor.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,28 @@ +/******************************************************************************* + * Copyright (c) 2011 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.compiler.apt.tests.annotations; + +import java.lang.annotation.Documented; +import java.lang.annotation.Inherited; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import static java.lang.annotation.ElementType.TYPE; +import static java.lang.annotation.RetentionPolicy.SOURCE; + +@Inherited +@Documented +@Retention(SOURCE) +@Target(TYPE) +public @interface ArgsConstructor { + + Class[] value(); +} Index: processors/org/eclipse/jdt/compiler/apt/tests/processors/inherited/ArgsConstructorProcessor.java =================================================================== RCS file: processors/org/eclipse/jdt/compiler/apt/tests/processors/inherited/ArgsConstructorProcessor.java diff -N processors/org/eclipse/jdt/compiler/apt/tests/processors/inherited/ArgsConstructorProcessor.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ processors/org/eclipse/jdt/compiler/apt/tests/processors/inherited/ArgsConstructorProcessor.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,151 @@ +/******************************************************************************* + * Copyright (c) 2011 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.compiler.apt.tests.processors.inherited; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map.Entry; +import java.util.Set; + +import javax.annotation.processing.AbstractProcessor; +import javax.annotation.processing.RoundEnvironment; +import javax.lang.model.element.Element; +import javax.lang.model.element.TypeElement; +import javax.annotation.processing.*; +import javax.lang.model.SourceVersion; +import javax.lang.model.element.*; +import javax.lang.model.type.*; +import javax.lang.model.util.SimpleTypeVisitor6; +import javax.lang.model.util.Types; +import javax.tools.Diagnostic.Kind; + +import org.eclipse.jdt.compiler.apt.tests.annotations.ArgsConstructor; + +@SupportedAnnotationTypes("org.eclipse.jdt.compiler.apt.tests.annotations.ArgsConstructor") +@SupportedSourceVersion(SourceVersion.RELEASE_6) +public class ArgsConstructorProcessor extends AbstractProcessor { + + @Override + public boolean process(Set annotations, + RoundEnvironment env) { + + for (TypeElement type : annotations) { + processArgsConstructorClasses(env, type); + } + return true; + + } + + private void processArgsConstructorClasses(RoundEnvironment env, + TypeElement type) { + for (Element element : env.getElementsAnnotatedWith(type)) { + processClass(element); + processingEnv.getMessager().printMessage(Kind.NOTE, + "Class " + element + " is processed"); + } + } + + private void processClass(Element element) { + + String actionName = ArgsConstructor.class.getName(); + AnnotationValue action = null; + for (AnnotationMirror am : processingEnv.getElementUtils() + .getAllAnnotationMirrors(element)) { + if (actionName.equals(am.getAnnotationType().toString())) { + for (Entry entry : am + .getElementValues().entrySet()) { + if ("value".equals(entry.getKey().getSimpleName() + .toString())) { + action = entry.getValue(); + break; + } + + } + + } + } + + if (action == null) { + processingEnv.getMessager() + .printMessage( + Kind.WARNING, + "Class " + element + + " lacks a annotation with required args", + element); + return; + } + + List mirrors = new ArrayList(); + for (Object val : (List) action.getValue()) { + AnnotationValue v = (AnnotationValue) val; + TypeMirror m = (TypeMirror) v.getValue(); + mirrors.add(m); + } + + if (!doesClassContainArgsConstructor(element, mirrors)) { + String s = ""; + for (TypeMirror tm : mirrors) { + if (!s.isEmpty()) { + s += ","; + } + s += tm.toString(); + + } + processingEnv.getMessager().printMessage( + Kind.ERROR, + "Class " + element + + " lacks a public constructor with args: " + s, + element); + } else { + processingEnv.getMessager().printMessage(Kind.NOTE, + "Processed type: " + element); + } + } + + private boolean doesClassContainArgsConstructor(Element el, + List annotTypes) { + for (Element subelement : el.getEnclosedElements()) { + if (subelement.getKind() == ElementKind.CONSTRUCTOR + && subelement.getModifiers().contains(Modifier.PUBLIC)) { + TypeMirror mirror = subelement.asType(); + if (mirror.accept(argsVisitor, annotTypes)) + return true; + } + } + return false; + } + + private final TypeVisitor> argsVisitor = new SimpleTypeVisitor6>() { + public Boolean visitExecutable(ExecutableType t, + List annotatedTypes) { + + List types = t.getParameterTypes(); + if (annotatedTypes.size() != types.size()) { + return false; + } + Types tutil = processingEnv.getTypeUtils(); + + for (int i = 0; i < types.size(); i++) { + TypeMirror test = tutil.erasure(types.get(i));// because same + // type bad + // Map + // != Map + TypeMirror expected = tutil.erasure(annotatedTypes.get(i)); + + if (!tutil.isAssignable(expected, test)) { + return false; + } + } + return true; + } + }; + +} Index: resources/targets/inherited/TestGeneric.java =================================================================== RCS file: resources/targets/inherited/TestGeneric.java diff -N resources/targets/inherited/TestGeneric.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ resources/targets/inherited/TestGeneric.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,22 @@ +/******************************************************************************* + * Copyright (c) 2011 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package targets.inherited; + +import java.awt.Point; + +import org.eclipse.jdt.compiler.apt.tests.annotations.ArgsConstructor; + +@ArgsConstructor({ Point.class }) +public class TestGeneric { + + public TestGeneric(K k) { + } +} Index: resources/targets/inherited/TestGenericChild.java =================================================================== RCS file: resources/targets/inherited/TestGenericChild.java diff -N resources/targets/inherited/TestGenericChild.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ resources/targets/inherited/TestGenericChild.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,19 @@ +/******************************************************************************* + * Copyright (c) 2011 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package targets.inherited; + +public class TestGenericChild extends TestGeneric { + + public TestGenericChild(int i, TestPoint k) { + super(k); + } + +} Index: resources/targets/inherited/TestNormal.java =================================================================== RCS file: resources/targets/inherited/TestNormal.java diff -N resources/targets/inherited/TestNormal.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ resources/targets/inherited/TestNormal.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,22 @@ +/******************************************************************************* + * Copyright (c) 2011 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package targets.inherited; + +import java.awt.Point; + +import org.eclipse.jdt.compiler.apt.tests.annotations.ArgsConstructor; + +@ArgsConstructor({ Point.class }) +public class TestNormal { + + public TestNormal(Point p) { + } +} Index: resources/targets/inherited/TestNormalChild.java =================================================================== RCS file: resources/targets/inherited/TestNormalChild.java diff -N resources/targets/inherited/TestNormalChild.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ resources/targets/inherited/TestNormalChild.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,20 @@ +/******************************************************************************* + * Copyright (c) 2011 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package targets.inherited; + +import java.awt.Point; + +public class TestNormalChild extends TestNormal { + + public TestNormalChild(Point p, int i) { + super(p); + } +} Index: resources/targets/inherited/TestPoint.java =================================================================== RCS file: resources/targets/inherited/TestPoint.java diff -N resources/targets/inherited/TestPoint.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ resources/targets/inherited/TestPoint.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,17 @@ +/******************************************************************************* + * Copyright (c) 2011 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package targets.inherited; + +import java.awt.Point; + +public class TestPoint extends Point { + +} Index: src/org/eclipse/jdt/compiler/apt/tests/NegativeTests.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/NegativeTests.java,v retrieving revision 1.11 diff -u -r1.11 NegativeTests.java --- src/org/eclipse/jdt/compiler/apt/tests/NegativeTests.java 15 Apr 2011 17:47:44 -0000 1.11 +++ src/org/eclipse/jdt/compiler/apt/tests/NegativeTests.java 5 May 2011 21:01:33 -0000 @@ -12,8 +12,10 @@ package org.eclipse.jdt.compiler.apt.tests; +import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; +import java.io.PrintWriter; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -21,7 +23,10 @@ import java.util.Set; import javax.lang.model.SourceVersion; +import javax.tools.Diagnostic; +import javax.tools.DiagnosticListener; import javax.tools.JavaCompiler; +import javax.tools.JavaFileObject; import javax.tools.ToolProvider; import junit.framework.TestCase; @@ -29,8 +34,31 @@ /** * Test cases for annotation processing behavior when code contains semantic errors */ -public class NegativeTests extends TestCase -{ +public class NegativeTests extends TestCase { + static class TestDiagnosticListener implements DiagnosticListener { + public static final int NONE = 0; + public static final int ERROR = 1; + public static final int INFO = 2; + public static final int WARNING = 4; + + public int errorCounter; + private PrintWriter writer; + + public TestDiagnosticListener(PrintWriter writer) { + this.writer = writer; + } + + @Override + public void report(Diagnostic diagnostic) { + switch(diagnostic.getKind()) { + case ERROR : + this.writer.print(diagnostic.getMessage(null)); + this.errorCounter++; + break; + } + } + } + // See corresponding usages in the NegativeModelProc class private static final String NEGATIVEMODELPROCNAME = "org.eclipse.jdt.compiler.apt.tests.processors.negative.NegativeModelProc"; private static final String IGNOREJAVACBUGS = "ignoreJavacBugs"; @@ -149,6 +177,33 @@ JavaCompiler compiler = BatchTestUtils.getEclipseCompiler(); internalTestNegativeModel(compiler, 9, null); } + + /* + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=328575 + */ + public void testNegativeModel10WithEclipseCompiler() throws IOException { + JavaCompiler compiler = BatchTestUtils.getEclipseCompiler(); + System.clearProperty(NEGATIVEMODELPROCNAME); + File targetFolder = TestUtils.concatPath(BatchTestUtils.getSrcFolderName(), "targets", "inherited"); + BatchTestUtils.copyResources("targets/inherited", targetFolder); + + // Invoke processing by compiling the targets.model resources + ByteArrayOutputStream errBuffer = new ByteArrayOutputStream(); + PrintWriter printWriter = new PrintWriter(errBuffer); + TestDiagnosticListener diagnosticListener = new TestDiagnosticListener(printWriter); + boolean success = BatchTestUtils.compileTreeWithErrors(compiler, new ArrayList(), targetFolder, diagnosticListener); + + assertTrue("Compilation should have failed due to expected errors, but it didn't", !success); + assertEquals("Two errors should be reported", 2, diagnosticListener.errorCounter); + printWriter.flush(); + printWriter.close(); + String expectedErrors = + "Class targets.inherited.TestGenericChild lacks a public constructor with args: java.awt.Point" + + "Class targets.inherited.TestNormalChild lacks a public constructor with args: java.awt.Point"; + + assertEquals("Wrong output", expectedErrors, String.valueOf(errBuffer)); + } + /** * Attempt to report errors on various elements. * @throws IOException @@ -168,7 +223,6 @@ boolean success = BatchTestUtils.compileTreeWithErrors(compiler, options, targetFolder, null); assertTrue("Compilation should have failed due to expected errors, but it didn't", !success); - // If it succeeded, the processor will have set this property to "succeeded"; // if not, it will set it to an error value. String property = System.getProperty(NEGATIVEMODELPROCNAME); #P org.eclipse.jdt.core Index: compiler/org/eclipse/jdt/internal/compiler/lookup/ParameterizedTypeBinding.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ParameterizedTypeBinding.java,v retrieving revision 1.120 diff -u -r1.120 ParameterizedTypeBinding.java --- compiler/org/eclipse/jdt/internal/compiler/lookup/ParameterizedTypeBinding.java 23 Dec 2010 13:57:49 -0000 1.120 +++ compiler/org/eclipse/jdt/internal/compiler/lookup/ParameterizedTypeBinding.java 5 May 2011 21:01:35 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2010 IBM Corporation and others. + * Copyright (c) 2005, 2011 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -438,9 +438,13 @@ * @see org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding#getAnnotationTagBits() */ public long getAnnotationTagBits() { - return this.type.getAnnotationTagBits(); + return genericType().getAnnotationTagBits(); } + public AnnotationBinding[] getAnnotations() { + return genericType().getAnnotations(); + } + public int getEnclosingInstancesSlotSize() { return genericType().getEnclosingInstancesSlotSize(); }