### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core.tests.builder Index: src/org/eclipse/jdt/core/tests/builder/ParticipantBuildTests.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/ParticipantBuildTests.java,v retrieving revision 1.21 diff -u -r1.21 ParticipantBuildTests.java --- src/org/eclipse/jdt/core/tests/builder/ParticipantBuildTests.java 27 Jun 2008 16:02:02 -0000 1.21 +++ src/org/eclipse/jdt/core/tests/builder/ParticipantBuildTests.java 28 Apr 2009 01:28:51 -0000 @@ -510,4 +510,85 @@ assertEquals("unexpected problems count", 1, problems.length); assertEquals("unexpected generated by attribute", specificGeneratedBy, problems[0].getSourceId()); } + +/** + * Test processing of annotations that are @Inherited. + * See Bug 270754 + */ +public void testInheritedAnnotations() throws JavaModelException { + IPath projectPath = env.addProject("Project", "1.5"); //$NON-NLS-1$ //$NON-NLS-2$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$ + IPath root = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$ + env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + + env.addClass(root, "", "TestAnnotation", //$NON-NLS-1$ //$NON-NLS-2$ + "import java.lang.annotation.Inherited;\n" + //$NON-NLS-1$ + "@Inherited\n" + //$NON-NLS-1$ + "@interface TestAnnotation {\n" + //$NON-NLS-1$ + " int value();\n" + //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + env.addClass(root, "", "Base", //$NON-NLS-1$ //$NON-NLS-2$ + "@TestAnnotation(0)\n" + //$NON-NLS-1$ + "public class Base {}" //$NON-NLS-1$ + ); + + // Because Sub extends Base, it should be treated as if it were annotated with TestAnnotation + env.addClass(root, "", "Sub", //$NON-NLS-1$ //$NON-NLS-2$ + "public class Sub extends Base {\n" + //$NON-NLS-1$ + "}" //$NON-NLS-1$ + ); + + final Set processedFiles = new HashSet(); + + // install compilationParticipant + new BuildTestParticipant() { + public boolean isAnnotationProcessor() { + return true; + } + public void processAnnotations(BuildContext[] files) { + // record the files + for (int i = 0; i < files.length; ++i) { + processedFiles.add(files[i].getFile().getName()); + } + } + }; + + // Do a full build; expect that all files are processed + processedFiles.clear(); + fullBuild(projectPath); + assertEquals(3, processedFiles.size()); + assertTrue(processedFiles.contains("TestAnnotation.java")); + assertTrue(processedFiles.contains("Base.java")); + assertTrue(processedFiles.contains("Sub.java")); + expectingNoProblems(); + + // Modify annotation on class "Base"; expect that Base and Sub are reprocessed + env.addClass(root, "", "Base", //$NON-NLS-1$ //$NON-NLS-2$ + "@TestAnnotation(1)\n" + //$NON-NLS-1$ + "public class Base {}" //$NON-NLS-1$ + ); + processedFiles.clear(); + incrementalBuild(projectPath); + assertEquals(2, processedFiles.size()); + assertTrue(processedFiles.contains("Base.java")); + assertTrue(processedFiles.contains("Sub.java")); + expectingNoProblems(); + + // Modify class "Sub"; expect that Sub is reprocessed, since it should be treated as if it were annotated + env.addClass(root, "", "Sub", //$NON-NLS-1$ //$NON-NLS-2$ + "public class Sub extends Base {\n" + //$NON-NLS-1$ + " // this line is new\n" + //$NON-NLS-1$ + "}" //$NON-NLS-1$ + ); + processedFiles.clear(); + incrementalBuild(projectPath); + assertTrue(processedFiles.contains("Sub.java")); + assertEquals(1, processedFiles.size()); + expectingNoProblems(); +} + + }