diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/NullAnnotationModelTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/NullAnnotationModelTests.java index 87812d2..ee592e5 100644 --- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/NullAnnotationModelTests.java +++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/NullAnnotationModelTests.java @@ -22,8 +22,13 @@ import org.eclipse.core.resources.IFile; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.FileLocator; import org.eclipse.core.runtime.Platform; +import org.eclipse.jdt.core.ICompilationUnit; import org.eclipse.jdt.core.IJavaProject; import org.eclipse.jdt.core.JavaCore; +import org.eclipse.jdt.core.compiler.IProblem; +import org.eclipse.jdt.core.dom.AST; +import org.eclipse.jdt.core.dom.ASTParser; +import org.eclipse.jdt.core.dom.CompilationUnit; public class NullAnnotationModelTests extends ReconcilerTests { @@ -222,4 +227,58 @@ public class NullAnnotationModelTests extends ReconcilerTests { // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=302850#c25 } } + + public void testMissingAnnotation3() throws CoreException { + try { + // Resources creation + IJavaProject p = createJavaProject("P", new String[] {""}, new String[] {"JCL15_LIB", this.ANNOTATION_LIB}, "bin", "1.5"); + p.setOption(JavaCore.COMPILER_ANNOTATION_NULL_ANALYSIS, JavaCore.ENABLED); + p.setOption(JavaCore.COMPILER_NONNULL_ANNOTATION_NAME, "invalid"); + + this.createFolder("/P/p1"); + String c1SourceString = + "package p1;\n" + + "@org.eclipse.jdt.annotation.NonNullByDefault\n" + + "public class C1 {\n" + + " public String foo(Object arg) {\n" + + " return arg == null ? \"\" : arg.toString();\n" + + " }\n" + + "}\n"; + this.createFile( + "/P/p1/C1.java", + c1SourceString); + + this.problemRequestor.initialize(c1SourceString.toCharArray()); + + final ICompilationUnit unit = getCompilationUnit("/P/p1/C1.java").getWorkingCopy(this.wcOwner, null); + assertProblems("Unexpected problems", + "----------\n" + + "1. ERROR in /P/p1/C1.java (at line 0)\n" + + " package p1;\n" + + " ^\n" + + "Cannot use the unqualified name \'invalid\' as an annotation name for null specification\n" + + "----------\n"); + + ASTParser parser = ASTParser.newParser(AST.JLS4); + parser.setProject(p); + parser.setResolveBindings(true); + parser.setSource(unit); + CompilationUnit ast = (CompilationUnit) parser.createAST(null); + assertNotNull("ast should not be null", ast); + this.problemRequestor.reset(); + this.problemRequestor.beginReporting(); + IProblem[] problems = ast.getProblems(); + for (int i=0; i