diff options
author | Harry Terkelsen | 2015-01-08 00:47:50 +0000 |
---|---|---|
committer | Jay Arthanareeswaran | 2015-01-12 11:46:14 +0000 |
commit | b18d6adb25f48ecf7c7eab00f32abaea5a8b60ae (patch) | |
tree | b626026539742ae83ee51cdc89445ebe13556e36 /org.eclipse.jdt.compiler.apt.tests | |
parent | 93064d94293a0408d3fca5808908fb56902798a3 (diff) | |
download | eclipse.jdt.core-b18d6adb25f48ecf7c7eab00f32abaea5a8b60ae.tar.gz eclipse.jdt.core-b18d6adb25f48ecf7c7eab00f32abaea5a8b60ae.tar.xz eclipse.jdt.core-b18d6adb25f48ecf7c7eab00f32abaea5a8b60ae.zip |
Fixes Bug 456986 - Bogus error when annotation processor generates
annotation types
Change-Id: I2e27e073e7534b9777ba664f9a4224a5158422f0
Signed-off-by: Harry Terkelsen <het@google.com>
Diffstat (limited to 'org.eclipse.jdt.compiler.apt.tests')
5 files changed, 110 insertions, 2 deletions
diff --git a/org.eclipse.jdt.compiler.apt.tests/lib/apttestprocessors.jar b/org.eclipse.jdt.compiler.apt.tests/lib/apttestprocessors.jar Binary files differindex ee4b0ceb6d..589c60884e 100644 --- a/org.eclipse.jdt.compiler.apt.tests/lib/apttestprocessors.jar +++ b/org.eclipse.jdt.compiler.apt.tests/lib/apttestprocessors.jar diff --git a/org.eclipse.jdt.compiler.apt.tests/processors/org/eclipse/jdt/compiler/apt/tests/processors/AnnotationProcessorTests/Bug456986Proc.java b/org.eclipse.jdt.compiler.apt.tests/processors/org/eclipse/jdt/compiler/apt/tests/processors/AnnotationProcessorTests/Bug456986Proc.java new file mode 100644 index 0000000000..51358977ce --- /dev/null +++ b/org.eclipse.jdt.compiler.apt.tests/processors/org/eclipse/jdt/compiler/apt/tests/processors/AnnotationProcessorTests/Bug456986Proc.java @@ -0,0 +1,58 @@ +/******************************************************************************* + * Copyright (c) 2015 Google, Inc. 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: + * het@google.com - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.compiler.apt.tests.processors.AnnotationProcessorTests; + +import java.io.IOException; +import java.io.Writer; +import java.util.Set; + +import javax.annotation.processing.AbstractProcessor; +import javax.annotation.processing.Filer; +import javax.annotation.processing.RoundEnvironment; +import javax.annotation.processing.SupportedAnnotationTypes; +import javax.annotation.processing.SupportedSourceVersion; +import javax.lang.model.SourceVersion; +import javax.lang.model.element.TypeElement; +import javax.tools.JavaFileObject; + +@SupportedAnnotationTypes("targets.AnnotationProcessorTests.Bug456986.Bug456986") +@SupportedSourceVersion(SourceVersion.RELEASE_6) +public class Bug456986Proc extends AbstractProcessor +{ + @Override + public boolean process(Set<? extends TypeElement> annotations, + RoundEnvironment roundEnv) { + Filer filer = processingEnv.getFiler(); + if (!annotations.isEmpty()) { + try { + JavaFileObject jfo = filer.createSourceFile("gen.anno.Annos"); + Writer writer = jfo.openWriter(); + writer.write("package gen.anno;\n"); + writer.write("import java.lang.annotation.ElementType;\n"); + writer.write("import java.lang.annotation.Retention;\n"); + writer.write("import java.lang.annotation.RetentionPolicy;\n"); + writer.write("import java.lang.annotation.Target;\n"); + writer.write("public final class Annos {\n"); + writer.write(" @Retention(RetentionPolicy.RUNTIME)\n"); + writer.write(" @Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER})\n"); + writer.write(" public @interface GenAnno {}\n"); + writer.write("\n"); + writer.write(" private Annos() {}\n"); + writer.write("}\n"); + writer.close(); + return true; + } catch (IOException e) { + return false; + } + } + return true; + } +} diff --git a/org.eclipse.jdt.compiler.apt.tests/resources/targets/AnnotationProcessorTests/bug456986/B.java b/org.eclipse.jdt.compiler.apt.tests/resources/targets/AnnotationProcessorTests/bug456986/B.java new file mode 100644 index 0000000000..3ba4c799ee --- /dev/null +++ b/org.eclipse.jdt.compiler.apt.tests/resources/targets/AnnotationProcessorTests/bug456986/B.java @@ -0,0 +1,20 @@ +/******************************************************************************* + * Copyright (c) 2015 Google, Inc. 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: + * het@google.com - initial API and implementation + *******************************************************************************/ +package targets.AnnotationProcessorTests.Bug456986; + +import gen.anno.Annos.GenAnno; + +@Bug456986 +public class B { + public void foo(@GenAnno int x) { + return; + } +} diff --git a/org.eclipse.jdt.compiler.apt.tests/resources/targets/AnnotationProcessorTests/bug456986/Bug456986.java b/org.eclipse.jdt.compiler.apt.tests/resources/targets/AnnotationProcessorTests/bug456986/Bug456986.java new file mode 100644 index 0000000000..8ab444d90f --- /dev/null +++ b/org.eclipse.jdt.compiler.apt.tests/resources/targets/AnnotationProcessorTests/bug456986/Bug456986.java @@ -0,0 +1,13 @@ +/******************************************************************************* + * Copyright (c) 2015 Google, Inc. 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: + * het@google.com - initial API and implementation + *******************************************************************************/ +package targets.AnnotationProcessorTests.Bug456986; + +public @interface Bug456986 {}
\ No newline at end of file diff --git a/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/AnnotationProcessorTests.java b/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/AnnotationProcessorTests.java index 954a1f3551..23aac19ebb 100644 --- a/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/AnnotationProcessorTests.java +++ b/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/AnnotationProcessorTests.java @@ -7,16 +7,19 @@ * * Contributors: * IBM Corporation - initial API and implementation + * het@google.com - Bug 456986 - Bogus error when annotation processor generates annotation types. *******************************************************************************/ package org.eclipse.jdt.compiler.apt.tests; -import java.io.IOException; import junit.framework.TestCase; -import javax.tools.JavaCompiler; + import java.io.File; +import java.io.IOException; import java.util.ArrayList; import java.util.List; +import javax.tools.JavaCompiler; + public class AnnotationProcessorTests extends TestCase { @Override protected void setUp() throws Exception { @@ -37,4 +40,18 @@ public class AnnotationProcessorTests extends TestCase { boolean success = BatchTestUtils.compileTreeWithErrors(compiler, options, targetFolder, null); assertEquals(true, success); } + + public void testBug456986() throws IOException { + JavaCompiler compiler = BatchTestUtils.getEclipseCompiler(); + File targetFolder = TestUtils.concatPath(BatchTestUtils.getSrcFolderName(), "targets", "AnnotationProcessorTests", "bug456986"); + BatchTestUtils.copyResources("targets/AnnotationProcessorTests/bug456986", targetFolder); + List<String> options = new ArrayList<String>(); + final String PROC = "org.eclipse.jdt.compiler.apt.tests.processors.AnnotationProcessorTests.Bug456986Proc"; + options.add("-processorpath"); + options.add(" "); + options.add("-processor"); + options.add(PROC); + boolean success = BatchTestUtils.compileTreeWithErrors(compiler, options, targetFolder, null); + assertEquals(true, success); + } }
\ No newline at end of file |