Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarry Terkelsen2015-01-24 02:46:26 +0000
committerJayaprakash Arthanareeswaran2015-02-09 04:35:23 +0000
commita6fddb558f09852d0df8b3655125e6a25d3ce37b (patch)
tree039e996be421d1c6962eebba805c1f2c9a0f1c60 /org.eclipse.jdt.compiler.apt.tests
parent8a17153af69ddcddcc6ac5bd94649f0b523f5b72 (diff)
downloadeclipse.jdt.core-a6fddb558f09852d0df8b3655125e6a25d3ce37b.tar.gz
eclipse.jdt.core-a6fddb558f09852d0df8b3655125e6a25d3ce37b.tar.xz
eclipse.jdt.core-a6fddb558f09852d0df8b3655125e6a25d3ce37b.zip
Bug 415274 - Annotation processing throws a NPE in
getElementsAnnotatedWith() Change-Id: Ida1de83407012cdcd6f08faf4cb5505c6690a3ea Signed-off-by: Harry Terkelsen <het@google.com>
Diffstat (limited to 'org.eclipse.jdt.compiler.apt.tests')
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/lib/apttestprocessors.jarbin184661 -> 187472 bytes
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/processors/org/eclipse/jdt/compiler/apt/tests/processors/AnnotationProcessorTests/Bug415274Anno.java17
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/processors/org/eclipse/jdt/compiler/apt/tests/processors/AnnotationProcessorTests/Bug415274Proc.java35
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/resources/targets/AnnotationProcessorTests/bug415274/B.java18
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/resources/targets/AnnotationProcessorTests/bug415274/Bug415274.java13
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/AnnotationProcessorTests.java23
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/BatchTestUtils.java73
7 files changed, 144 insertions, 35 deletions
diff --git a/org.eclipse.jdt.compiler.apt.tests/lib/apttestprocessors.jar b/org.eclipse.jdt.compiler.apt.tests/lib/apttestprocessors.jar
index 589c60884e..6856ad1c63 100644
--- a/org.eclipse.jdt.compiler.apt.tests/lib/apttestprocessors.jar
+++ b/org.eclipse.jdt.compiler.apt.tests/lib/apttestprocessors.jar
Binary files differ
diff --git a/org.eclipse.jdt.compiler.apt.tests/processors/org/eclipse/jdt/compiler/apt/tests/processors/AnnotationProcessorTests/Bug415274Anno.java b/org.eclipse.jdt.compiler.apt.tests/processors/org/eclipse/jdt/compiler/apt/tests/processors/AnnotationProcessorTests/Bug415274Anno.java
new file mode 100644
index 0000000000..fcec605aab
--- /dev/null
+++ b/org.eclipse.jdt.compiler.apt.tests/processors/org/eclipse/jdt/compiler/apt/tests/processors/AnnotationProcessorTests/Bug415274Anno.java
@@ -0,0 +1,17 @@
+/*******************************************************************************
+ * 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;
+
+/**
+ * This annotation type should only be visible to the processor.
+ */
+public @interface Bug415274Anno {
+}
diff --git a/org.eclipse.jdt.compiler.apt.tests/processors/org/eclipse/jdt/compiler/apt/tests/processors/AnnotationProcessorTests/Bug415274Proc.java b/org.eclipse.jdt.compiler.apt.tests/processors/org/eclipse/jdt/compiler/apt/tests/processors/AnnotationProcessorTests/Bug415274Proc.java
new file mode 100644
index 0000000000..69db8d52f2
--- /dev/null
+++ b/org.eclipse.jdt.compiler.apt.tests/processors/org/eclipse/jdt/compiler/apt/tests/processors/AnnotationProcessorTests/Bug415274Proc.java
@@ -0,0 +1,35 @@
+/*******************************************************************************
+ * 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.util.Set;
+
+import javax.annotation.processing.AbstractProcessor;
+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.Element;
+import javax.lang.model.element.TypeElement;
+
+@SupportedAnnotationTypes("targets.AnnotationProcessorTests.Bug415274.Bug415274")
+@SupportedSourceVersion(SourceVersion.RELEASE_6)
+public class Bug415274Proc extends AbstractProcessor
+{
+ @Override
+ public boolean process(Set<? extends TypeElement> annotations,
+ RoundEnvironment roundEnv) {
+ for (Element element : roundEnv.getElementsAnnotatedWith(Bug415274Anno.class)) {
+ System.out.println(element);
+ }
+ return true;
+ }
+}
diff --git a/org.eclipse.jdt.compiler.apt.tests/resources/targets/AnnotationProcessorTests/bug415274/B.java b/org.eclipse.jdt.compiler.apt.tests/resources/targets/AnnotationProcessorTests/bug415274/B.java
new file mode 100644
index 0000000000..74f4a2eb11
--- /dev/null
+++ b/org.eclipse.jdt.compiler.apt.tests/resources/targets/AnnotationProcessorTests/bug415274/B.java
@@ -0,0 +1,18 @@
+/*******************************************************************************
+ * 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.Bug415274;
+
+@Bug415274
+public class B {
+ public void foo(int x) {
+ return;
+ }
+}
diff --git a/org.eclipse.jdt.compiler.apt.tests/resources/targets/AnnotationProcessorTests/bug415274/Bug415274.java b/org.eclipse.jdt.compiler.apt.tests/resources/targets/AnnotationProcessorTests/bug415274/Bug415274.java
new file mode 100644
index 0000000000..3d6ecc2328
--- /dev/null
+++ b/org.eclipse.jdt.compiler.apt.tests/resources/targets/AnnotationProcessorTests/bug415274/Bug415274.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.Bug415274;
+
+public @interface Bug415274 {}
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 23aac19ebb..89c0d3dc4c 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2014 IBM Corporation and others.
+ * Copyright (c) 2014, 2015 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
@@ -8,11 +8,10 @@
* Contributors:
* IBM Corporation - initial API and implementation
* het@google.com - Bug 456986 - Bogus error when annotation processor generates annotation types.
+ * Bug 415274 - Annotation processing throws a NPE in getElementsAnnotatedWith()
*******************************************************************************/
package org.eclipse.jdt.compiler.apt.tests;
-import junit.framework.TestCase;
-
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
@@ -20,6 +19,8 @@ import java.util.List;
import javax.tools.JavaCompiler;
+import junit.framework.TestCase;
+
public class AnnotationProcessorTests extends TestCase {
@Override
protected void setUp() throws Exception {
@@ -54,4 +55,18 @@ public class AnnotationProcessorTests extends TestCase {
boolean success = BatchTestUtils.compileTreeWithErrors(compiler, options, targetFolder, null);
assertEquals(true, success);
}
-} \ No newline at end of file
+
+ public void testBug415274() throws IOException {
+ JavaCompiler compiler = BatchTestUtils.getEclipseCompiler();
+ File targetFolder = TestUtils.concatPath(BatchTestUtils.getSrcFolderName(), "targets", "AnnotationProcessorTests", "bug415274");
+ BatchTestUtils.copyResources("targets/AnnotationProcessorTests/bug415274", targetFolder);
+ List<String> options = new ArrayList<String>();
+ final String PROC = "org.eclipse.jdt.compiler.apt.tests.processors.AnnotationProcessorTests.Bug415274Proc";
+ options.add("-processorpath");
+ options.add(" ");
+ options.add("-processor");
+ options.add(PROC);
+ boolean success = BatchTestUtils.compileTreeWithErrors(compiler, options, targetFolder, null, false);
+ assertEquals(true, success);
+ }
+}
diff --git a/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/BatchTestUtils.java b/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/BatchTestUtils.java
index 3a8a0abb8f..443ea10ef2 100644
--- a/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/BatchTestUtils.java
+++ b/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/BatchTestUtils.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2014 BEA Systems, Inc.
+ * Copyright (c) 2007, 2015 BEA Systems, Inc.
* 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
@@ -8,10 +8,14 @@
* Contributors:
* wharley@bea.com - initial API and implementation
* IBM Corporation - fix for 342936
-*******************************************************************************/
+ * het@google.com - Bug 415274 - Annotation processing throws a NPE in getElementsAnnotatedWith()
+ *******************************************************************************/
package org.eclipse.jdt.compiler.apt.tests;
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.Platform;
+
import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
@@ -33,9 +37,6 @@ import javax.tools.JavaCompiler.CompilationTask;
import javax.tools.JavaFileObject;
import javax.tools.StandardJavaFileManager;
-import org.eclipse.core.runtime.FileLocator;
-import org.eclipse.core.runtime.Platform;
-
/**
* Helper class to support compilation and results checking for tests running in batch mode.
* @since 3.3
@@ -81,7 +82,7 @@ public class BatchTestUtils {
options.add(_tmpBinFolderName);
options.add("-s");
options.add(_tmpGenFolderName);
- addProcessorPaths(options, useJLS8Processors);
+ addProcessorPaths(options, useJLS8Processors, true);
options.add("-XprintRounds");
options.add("-XprintProcessorInfo");
CompilationTask task = compiler.getTask(printWriter, manager, null, options, null, units);
@@ -97,8 +98,8 @@ public class BatchTestUtils {
public static void compileTree(JavaCompiler compiler, List<String> options, File targetFolder) {
compileTree(compiler, options, targetFolder, false);
}
-
- public static void compileTree(JavaCompiler compiler, List<String> options, File targetFolder,
+
+ public static void compileTree(JavaCompiler compiler, List<String> options, File targetFolder,
DiagnosticListener<? super JavaFileObject> listener) {
compileTree(compiler, options, targetFolder, false, listener);
}
@@ -123,7 +124,7 @@ public class BatchTestUtils {
options.add(_tmpBinFolderName);
options.add("-s");
options.add(_tmpGenFolderName);
- addProcessorPaths(options, useJLS8Processors);
+ addProcessorPaths(options, useJLS8Processors, true);
options.add("-XprintRounds");
CompilationTask task = compiler.getTask(printWriter, manager, listener, options, null, units);
Boolean result = task.call();
@@ -134,7 +135,7 @@ public class BatchTestUtils {
junit.framework.TestCase.assertTrue("Compilation failed : " + errorOutput, false);
}
}
-
+
/**
* Compile the contents of a directory tree, collecting errors so that they can be
* compared with expected errors.
@@ -149,14 +150,22 @@ public class BatchTestUtils {
List<String> options,
File targetFolder,
DiagnosticListener<? super JavaFileObject> diagnosticListener) {
- return compileTreeWithErrors(compiler, options, targetFolder, diagnosticListener, false);
+ return compileTreeWithErrors(compiler, options, targetFolder, diagnosticListener, false, true);
}
public static boolean compileTreeWithErrors(
JavaCompiler compiler,
List<String> options,
File targetFolder,
DiagnosticListener<? super JavaFileObject> diagnosticListener,
- boolean useJLS8Processors) {
+ boolean addProcessorsToClasspath) {
+ return compileTreeWithErrors(compiler, options, targetFolder, diagnosticListener, false, addProcessorsToClasspath);
+ }
+ public static boolean compileTreeWithErrors(
+ JavaCompiler compiler,
+ List<String> options,
+ File targetFolder,
+ DiagnosticListener<? super JavaFileObject> diagnosticListener,
+ boolean useJLS8Processors, boolean addProcessorsToClasspath) {
StandardJavaFileManager manager = compiler.getStandardFileManager(null, Locale.getDefault(), Charset.defaultCharset());
// create new list containing inputfile
@@ -168,7 +177,7 @@ public class BatchTestUtils {
options.add(_tmpBinFolderName);
options.add("-s");
options.add(_tmpGenFolderName);
- addProcessorPaths(options, useJLS8Processors);
+ addProcessorPaths(options, useJLS8Processors, addProcessorsToClasspath);
// use writer to prevent System.out/err to be polluted with problems
StringWriter writer = new StringWriter();
CompilationTask task = compiler.getTask(writer, manager, diagnosticListener, options, null, units);
@@ -176,7 +185,7 @@ public class BatchTestUtils {
return result.booleanValue();
}
-
+
/**
* Recursively collect all the files under some root. Ignore directories named "CVS".
* Used when compiling multiple source files.
@@ -280,14 +289,16 @@ public class BatchTestUtils {
junit.framework.TestCase.assertNotNull("No Eclipse compiler found", _eclipseCompiler);
}
- private static void addProcessorPaths(List<String> options, boolean useJLS8Processors) {
+ private static void addProcessorPaths(List<String> options, boolean useJLS8Processors, boolean addToNormalClasspath) {
String path = useJLS8Processors ? _jls8ProcessorJarPath : _processorJarPath;
- options.add("-cp");
- options.add(_tmpSrcFolderName + File.pathSeparator + _tmpGenFolderName + File.pathSeparator + path);
+ if (addToNormalClasspath) {
+ options.add("-cp");
+ options.add(_tmpSrcFolderName + File.pathSeparator + _tmpGenFolderName + File.pathSeparator + path);
+ }
options.add("-processorpath");
options.add(path);
}
-
+
public static void tearDown() {
new File(_processorJarPath).deleteOnExit();
new File(_jls8ProcessorJarPath).deleteOnExit();
@@ -324,7 +335,7 @@ public class BatchTestUtils {
}
return fileBytes;
}
-
+
/**
* @return true if this file's end-of-line delimiters should be replaced with
* a platform-independent value, e.g. for compilation.
@@ -332,12 +343,12 @@ public class BatchTestUtils {
public static boolean shouldConvertToIndependentLineDelimiter(File file) {
return file.getName().endsWith(".java");
}
-
+
/**
* Copy a file from one location to another, unless the destination file already exists and has
* the same timestamp and file size. Create the destination location if necessary. Convert line
* delimiters according to {@link #shouldConvertToIndependentLineDelimiter(File)}.
- *
+ *
* @param src
* the full path to the resource location.
* @param destFolder
@@ -346,12 +357,12 @@ public class BatchTestUtils {
*/
public static void copyResource(File src, File dest) throws IOException {
if (dest.exists() &&
- src.lastModified() < dest.lastModified() &&
- src.length() == dest.length())
+ src.lastModified() < dest.lastModified() &&
+ src.length() == dest.length())
{
return;
}
-
+
// read source bytes
byte[] srcBytes = null;
srcBytes = read(src);
@@ -385,7 +396,7 @@ public class BatchTestUtils {
* Copy a resource that is located under the <code>resources</code> folder of the plugin to a
* corresponding location under the specified target folder. Convert line delimiters according
* to {@link #shouldConvertToIndependentLineDelimiter(File)}.
- *
+ *
* @param resourcePath
* the relative path under <code>[plugin-root]/resources</code> of the resource to
* be copied
@@ -402,25 +413,25 @@ public class BatchTestUtils {
copyResource(resourceFile, targetFile);
return targetFile;
}
-
+
/**
* Copy all the files under the directory specified by src to the directory
* specified by dest. The src and dest directories must exist; child directories
* under dest will be created as required. Existing files in dest will be
- * overwritten. Newlines will be converted according to
+ * overwritten. Newlines will be converted according to
* {@link #shouldConvertToIndependentLineDelimiter(File)}. Directories
* named "CVS" will be ignored.
* @param resourceFolderName the name of the source folder, relative to
* <code>[plugin-root]/resources</code>
* @param the absolute path of the destination folder
- * @throws IOException
+ * @throws IOException
*/
public static void copyResources(String resourceFolderName, File destFolder) throws IOException {
File resDir = new File(getPluginDirectoryPath(), RESOURCES_DIR);
File resourceFolder = new File(resDir, resourceFolderName);
copyResources(resourceFolder, destFolder);
}
-
+
private static void copyResources(File resourceFolder, File destFolder) throws IOException {
if (resourceFolder == null) {
return;
@@ -445,7 +456,7 @@ public class BatchTestUtils {
}
}
}
-
+
public static String setupProcessorJar(String processorJar, String tmpDir) throws IOException {
File libDir = new File(getPluginDirectoryPath());
File libFile = new File(libDir, processorJar);
@@ -487,7 +498,7 @@ public class BatchTestUtils {
return false;
}
char[] contents = new char[512];
-
+
Reader r = null;
try {
r = new BufferedReader(new FileReader(genTextFile));

Back to the top