Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephan Herrmann2015-02-15 00:33:18 +0000
committerStephan Herrmann2015-02-15 00:33:18 +0000
commit44bc9bf097b01a140189409a17e90e964843c019 (patch)
treee1ea74853592d3b51d1a57970a4ec9cea67c5477 /org.eclipse.jdt.core.tests.compiler
parentcfc352b34fa06e82001f50e0e1d44fa5dc05a141 (diff)
downloadorg.eclipse.objectteams-44bc9bf097b01a140189409a17e90e964843c019.tar.gz
org.eclipse.objectteams-44bc9bf097b01a140189409a17e90e964843c019.tar.xz
org.eclipse.objectteams-44bc9bf097b01a140189409a17e90e964843c019.zip
(external null annotations)
Diffstat (limited to 'org.eclipse.jdt.core.tests.compiler')
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java115
1 files changed, 113 insertions, 2 deletions
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java
index 3ad09f8d8..08020dba1 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java
@@ -25,6 +25,7 @@
* bug 381443 - [compiler][null] Allow parameter widening from @NonNull to unannotated
* bug 383368 - [compiler][null] syntactic null analysis for field references
* Bug 392099 - [1.8][compiler][null] Apply null annotation on types for null analysis
+ * Bug 440477 - [null] Infrastructure for feeding external annotations into compilation
* Jesper Steen Moller - Contributions for
* bug 404146 - [1.7][compiler] nested try-catch-finally-blocks leads to unrunnable Java byte code
* bug 407297 - [1.8][compiler] Control generation of parameter names by option
@@ -89,8 +90,53 @@ public class BatchCompilerTest extends AbstractRegressionTest {
"public @interface NonNull{\n" +
"}\n";
+ private static final String ELEMENT_TYPE_18_CONTENT = "package java.lang.annotation;\n" +
+ "public enum ElementType {\n" +
+ " TYPE,\n" +
+ " FIELD,\n" +
+ " METHOD,\n" +
+ " PARAMETER,\n" +
+ " CONSTRUCTOR,\n" +
+ " LOCAL_VARIABLE,\n" +
+ " ANNOTATION_TYPE,\n" +
+ " PACKAGE,\n" +
+ " TYPE_PARAMETER,\n" +
+ " TYPE_USE\n" +
+ "}\n" +
+ "";
+ private static final String NONNULL_ANNOTATION_18_CONTENT = "package org.eclipse.jdt.annotation;\n" +
+ "import java.lang.annotation.ElementType;\n" +
+ "import java.lang.annotation.*;\n" +
+ "@Documented\n" +
+ "@Retention(RetentionPolicy.CLASS)\n" +
+ "@Target({ ElementType.TYPE_USE })\n" +
+ "public @interface NonNull{\n" +
+ "}\n";
+ private static final String NONNULL_BY_DEFAULT_ANNOTATION_18_CONTENT = "package org.eclipse.jdt.annotation;\n" +
+ "import java.lang.annotation.ElementType;\n" +
+ "import static org.eclipse.jdt.annotation.DefaultLocation.*;\n" +
+ "\n" +
+ "import java.lang.annotation.Retention;\n" +
+ "import java.lang.annotation.RetentionPolicy;\n" +
+ "import java.lang.annotation.Target;\n" +
+ "@Retention(RetentionPolicy.CLASS)\n" +
+ "@Target({ ElementType.PACKAGE, ElementType.TYPE, ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.FIELD, ElementType.LOCAL_VARIABLE })\n" +
+ "public @interface NonNullByDefault {\n" +
+ " DefaultLocation[] value() default { PARAMETER, RETURN_TYPE, FIELD, TYPE_BOUND, TYPE_ARGUMENT };\n" +
+ "}\n";
+ private static final String DEFAULT_LOCATION_CONTENT = "package org.eclipse.jdt.annotation;\n" +
+ "public enum DefaultLocation {\n" +
+ " PARAMETER,\n" +
+ " RETURN_TYPE,\n" +
+ " FIELD,\n" +
+ " TYPE_PARAMETER,\n" +
+ " TYPE_BOUND,\n" +
+ " TYPE_ARGUMENT,\n" +
+ " ARRAY_CONTENTS\n" +
+ "}\n";
+
static {
-// TESTS_NAMES = new String[] { "test320_warn_options" };
+// TESTS_NAMES = new String[] { "test440477" };
// TESTS_NUMBERS = new int[] { 306 };
// TESTS_RANGE = new int[] { 298, -1 };
}
@@ -1667,7 +1713,10 @@ public void test012(){
" -genericsignature generate generic signature for lambda expressions\n" +
" -Xemacs used to enable emacs-style output in the console.\n" +
" It does not affect the xml log output\n" +
- " -missingNullDefault report missing default nullness annotation\n" +
+ " -missingNullDefault report missing default nullness annotation\n" +
+ " -annotationpath <path>\n" +
+ " Path to a base directory or zip file holding external\n" +
+ " annotations to support annotation-based null analysis\n" +
" \n" +
" -? -help print this help message\n" +
" -v -version print compiler version\n" +
@@ -14122,6 +14171,68 @@ public void testBug419351() {
new File(lib1Path).delete();
}
}
+// Bug 440477 - [null] Infrastructure for feeding external annotations into compilation
+// - single external annotation directory
+public void test440477() throws IOException {
+ String annots_dir = Util.getOutputDirectory() + File.separator + "annots";
+ String annots_java_util = annots_dir + File.separator + "java/util";
+ new File(annots_java_util).mkdirs();
+ Util.createFile(
+ annots_java_util + File.separator + "Map.eea",
+ "class java/util/Map\n" +
+ " <K:V:>\n" +
+ "\n" +
+ "get\n" +
+ " (Ljava/lang/Object;)TV;\n" +
+ " (Ljava/lang/Object;)T0V;\n" +
+ "put\n" +
+ " (TK;TV;)TV;\n" +
+ " (TK;TV;)T0V;\n" +
+ "remove\n" +
+ " (Ljava/lang/Object;)TV;\n" +
+ " (Ljava/lang/Object;)T0V;\n");
+
+ String o_e_j_annotation_dir = OUTPUT_DIR + File.separator +
+ "org" + File.separator + "eclipse" + File.separator + "jdt" + File.separator + "annotation";
+ String j_l_annotation_dir = OUTPUT_DIR + File.separator +
+ "java" + File.separator + "lang" + File.separator + "annotation";
+ this.runConformTest(
+ new String[] {
+ "java/lang/annotation/ElementType.java",
+ ELEMENT_TYPE_18_CONTENT,
+ "org/eclipse/jdt/annotation/NonNull.java",
+ NONNULL_ANNOTATION_18_CONTENT,
+ "org/eclipse/jdt/annotation/DefaultLocation.java",
+ DEFAULT_LOCATION_CONTENT,
+ "org/eclipse/jdt/annotation/NonNullByDefault.java",
+ NONNULL_BY_DEFAULT_ANNOTATION_18_CONTENT,
+ "test1/Test1.java",
+ "package test1;\n" +
+ "\n" +
+ "import java.util.Map;\n" +
+ "import org.eclipse.jdt.annotation.*;\n" +
+ "\n" +
+ "@NonNullByDefault\n" +
+ "public class Test1 {\n" +
+ " void test(Map<String,Test1> map, String key) {\n" +
+ " Test1 v = map.get(key);\n" +
+ " if (v == null)\n" +
+ " throw new RuntimeException(); // should not be reported as dead code, although V is a '@NonNull Test1'\n" +
+ " }\n" +
+ "}\n"
+ },
+ " -1.8 -proc:none -d none -warn:+nullAnnot -annotationpath " + annots_dir +
+ " -sourcepath \"" + OUTPUT_DIR + "\" " +
+ // explicitly mention all files to ensure a good order, cannot pull in source of NNBD on demand
+ "\"" + j_l_annotation_dir + File.separator + "ElementType.java\" " +
+ "\"" + o_e_j_annotation_dir + File.separator + "NonNull.java\" " +
+ "\"" + o_e_j_annotation_dir + File.separator + "DefaultLocation.java\" " +
+ "\"" + o_e_j_annotation_dir + File.separator + "NonNullByDefault.java\" " +
+ "\"" + OUTPUT_DIR + File.separator + "test1" + File.separator + "Test1.java\"",
+ "",
+ "",
+ true);
+}
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=439750
public void test439750() {
this.runConformTest(

Back to the top