### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core Index: dom/org/eclipse/jdt/core/dom/AnnotationBinding.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/AnnotationBinding.java,v retrieving revision 1.8 diff -u -r1.8 AnnotationBinding.java --- dom/org/eclipse/jdt/core/dom/AnnotationBinding.java 25 Mar 2008 17:58:56 -0000 1.8 +++ dom/org/eclipse/jdt/core/dom/AnnotationBinding.java 30 Apr 2008 16:34:10 -0000 @@ -49,18 +49,31 @@ } public IMemberValuePairBinding[] getDeclaredMemberValuePairs() { + ReferenceBinding typeBinding = this.binding.getAnnotationType(); + if (typeBinding == null || ((typeBinding.tagBits & TagBits.HasMissingType) != 0)) { + return MemberValuePairBinding.NoPair; + } ElementValuePair[] internalPairs = this.binding.getElementValuePairs(); int length = internalPairs.length; IMemberValuePairBinding[] pairs = length == 0 ? MemberValuePairBinding.NoPair : new MemberValuePairBinding[length]; - for (int i = 0; i < length; i++) - pairs[i] = this.bindingResolver.getMemberValuePairBinding(internalPairs[i]); + int counter = 0; + for (int i = 0; i < length; i++) { + ElementValuePair valuePair = internalPairs[i]; + if (valuePair.binding == null) continue; + pairs[counter++] = this.bindingResolver.getMemberValuePairBinding(valuePair); + } + if (counter == 0) return MemberValuePairBinding.NoPair; + if (counter != length) { + // resize + System.arraycopy(pairs, 0, (pairs = new MemberValuePairBinding[counter]), 0, counter); + } return pairs; } public IMemberValuePairBinding[] getAllMemberValuePairs() { IMemberValuePairBinding[] pairs = getDeclaredMemberValuePairs(); ReferenceBinding typeBinding = this.binding.getAnnotationType(); - if (typeBinding == null) return pairs; + if (typeBinding == null || ((typeBinding.tagBits & TagBits.HasMissingType) != 0)) return pairs; MethodBinding[] methods = typeBinding.availableMethods(); // resilience int methodLength = methods == null ? 0 : methods.length; if (methodLength == 0) return pairs; @@ -70,8 +83,11 @@ return pairs; HashtableOfObject table = new HashtableOfObject(declaredLength); - for (int i = 0; i < declaredLength; i++) - table.put(((MemberValuePairBinding) pairs[i]).internalName(), pairs[i]); + for (int i = 0; i < declaredLength; i++) { + char[] internalName = ((MemberValuePairBinding) pairs[i]).internalName(); + if (internalName == null) continue; + table.put(internalName, pairs[i]); + } // handle case of more methods than declared members IMemberValuePairBinding[] allPairs = new IMemberValuePairBinding[methodLength]; Index: dom/org/eclipse/jdt/core/dom/DefaultBindingResolver.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/DefaultBindingResolver.java,v retrieving revision 1.161 diff -u -r1.161 DefaultBindingResolver.java --- dom/org/eclipse/jdt/core/dom/DefaultBindingResolver.java 22 Apr 2008 14:27:36 -0000 1.161 +++ dom/org/eclipse/jdt/core/dom/DefaultBindingResolver.java 30 Apr 2008 16:34:10 -0000 @@ -246,7 +246,7 @@ } synchronized IMemberValuePairBinding getMemberValuePairBinding(ElementValuePair valuePair) { - if (valuePair == null) return null; + if (valuePair == null || valuePair.binding == null) return null; IMemberValuePairBinding binding = (IMemberValuePairBinding) this.bindingTables.compilerBindingsToASTBindings.get(valuePair); if (binding != null) @@ -480,6 +480,12 @@ synchronized IAnnotationBinding getAnnotationInstance(org.eclipse.jdt.internal.compiler.lookup.AnnotationBinding internalInstance) { if (internalInstance == null) return null; + ReferenceBinding annotationType = internalInstance.getAnnotationType(); + if (annotationType == null || ((annotationType.tagBits & TagBits.HasMissingType) != 0)) { + if (!this.isRecoveringBindings) { + return null; + } + } IAnnotationBinding domInstance = (IAnnotationBinding) this.bindingTables.compilerBindingsToASTBindings.get(internalInstance); if (domInstance != null) #P org.eclipse.jdt.core.tests.model Index: src/org/eclipse/jdt/core/tests/dom/ASTConverter15Test.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter15Test.java,v retrieving revision 1.264 diff -u -r1.264 ASTConverter15Test.java --- src/org/eclipse/jdt/core/tests/dom/ASTConverter15Test.java 26 Apr 2008 14:33:16 -0000 1.264 +++ src/org/eclipse/jdt/core/tests/dom/ASTConverter15Test.java 30 Apr 2008 16:34:11 -0000 @@ -46,8 +46,8 @@ } static { -// TESTS_NUMBERS = new int[] { 286 }; -// TESTS_RANGE = new int[] { 277, -1 }; +// TESTS_NUMBERS = new int[] { 287 }; +// TESTS_RANGE = new int[] { 287, -1 }; // TESTS_NAMES = new String[] {"test0204"}; } public static Test suite() { @@ -6330,30 +6330,21 @@ public void test0208() throws JavaModelException { this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/); String contents = - "@Override(x= 1)\n" + + "/*start*/@Override(x= 1)/*end*/\n" + "public class X { }"; - ASTNode node = buildAST( + NormalAnnotation normalAnnotation = (NormalAnnotation) buildAST( contents, this.workingCopy, + false, + true, false); - assertNotNull("No node", node); - assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType()); - CompilationUnit compilationUnit = (CompilationUnit) node; - String problems = - "The annotation @Override is disallowed for this location\n" + - "The attribute x is undefined for the annotation type Override"; - assertProblemsSize(compilationUnit, 2, problems); - node = getASTNode(compilationUnit, 0); - assertEquals("Not a type declaration", ASTNode.TYPE_DECLARATION, node.getNodeType()); - TypeDeclaration typeDeclaration = (TypeDeclaration) node; - List modifiers = typeDeclaration.modifiers(); - assertEquals("Wrong size", 2, modifiers.size()); - assertTrue("Wrong type", modifiers.get(0) instanceof NormalAnnotation); - NormalAnnotation normalAnnotation = (NormalAnnotation) modifiers.get(0); IAnnotationBinding annotationBinding = normalAnnotation.resolveAnnotationBinding(); IMemberValuePairBinding[] pairs = annotationBinding.getDeclaredMemberValuePairs(); - assertEquals("Wrong size", 1, pairs.length); - assertNotNull("Should not be null", pairs[0].getValue()); + assertEquals("Wrong size", 0, pairs.length); + List values = normalAnnotation.values(); + assertEquals("Wrong size", 1, values.size()); + MemberValuePair pair = (MemberValuePair) values.get(0); + assertNotNull("no value", pair.getValue()); } public void test0209() throws JavaModelException { @@ -9613,4 +9604,200 @@ assertTrue("Not assignmentCompatible: Integer -> int", typeBinding2.isAssignmentCompatible(typeBinding)); assertTrue("Not assignmentCompatible: int -> Integer", typeBinding.isAssignmentCompatible(typeBinding2)); } + /** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=228651 + */ + public void test0287() throws JavaModelException { + this.workingCopy = getWorkingCopy("/Converter15/src/test0287/A.java", true/*resolve*/); + MemberValuePair pair = (MemberValuePair) buildAST( + "package test0287;\n" + + "@ABC (/*start*/name1=\"\"/*end*/)\n" + + "public class A {}", + this.workingCopy, + false/*don't report errors*/, + true, + true); + IMemberValuePairBinding resolveMemberValuePairBinding = pair.resolveMemberValuePairBinding(); + assertNull("Got a binding", resolveMemberValuePairBinding); + } + /** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=228651 + */ + public void test0288() throws JavaModelException { + this.workingCopy = getWorkingCopy("/Converter15/src/test0288/A.java", true/*resolve*/); + MemberValuePair pair = (MemberValuePair) buildAST( + "package test0288;\n" + + "@ABC (/*start*/name1=\"\"/*end*/)\n" + + "public class A {}", + this.workingCopy, + false/*don't report errors*/, + true, + false); + IMemberValuePairBinding resolveMemberValuePairBinding = pair.resolveMemberValuePairBinding(); + assertNull("Got a binding", resolveMemberValuePairBinding); + } + /** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=228651 + */ + public void test0289() throws JavaModelException { + this.workingCopy = getWorkingCopy("/Converter15/src/test0289/A.java", true/*resolve*/); + NormalAnnotation annotation = (NormalAnnotation) buildAST( + "package test0289;\n" + + "/*start*/@ABC (name1=\"\")/*end*/\n" + + "public class A {}", + this.workingCopy, + false/*don't report errors*/, + true, + false); + IAnnotationBinding resolveAnnotationBinding = annotation.resolveAnnotationBinding(); + assertNull("No binding", resolveAnnotationBinding); + } + + /** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=228651 + */ + public void test0290() throws JavaModelException { + this.workingCopy = getWorkingCopy("/Converter15/src/test0290/A.java", true/*resolve*/); + NormalAnnotation annotation = (NormalAnnotation) buildAST( + "package test0290;\n" + + "/*start*/@ABC (name1=\"\")/*end*/\n" + + "public class A {}", + this.workingCopy, + false/*don't report errors*/, + true, + true); + IAnnotationBinding resolveAnnotationBinding = annotation.resolveAnnotationBinding(); + assertTrue("Not recovered", resolveAnnotationBinding.isRecovered()); + } + + /** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=228651 + */ + public void test0291() throws JavaModelException { + this.workingCopy = getWorkingCopy("/Converter15/src/test0291/A.java", true/*resolve*/); + NormalAnnotation annotation = (NormalAnnotation) buildAST( + "package test0291;\n" + + "/*start*/@ABC (name1=\"\")/*end*/\n" + + "public class A {}", + this.workingCopy, + false/*don't report errors*/, + true, + true); + IAnnotationBinding resolveAnnotationBinding = annotation.resolveAnnotationBinding(); + assertEquals("Wrong size", 0, resolveAnnotationBinding.getAllMemberValuePairs().length); + } + /** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=228651 + */ + public void test0292() throws JavaModelException { + this.workingCopy = getWorkingCopy("/Converter15/src/test0292/A.java", true/*resolve*/); + NormalAnnotation annotation = (NormalAnnotation) buildAST( + "package test0292;\n" + + "@interface ABC {\n" + + " String name1() default \"\";\n" + + "}\n" + + "/*start*/@ABC(name1=\"\", id=0)/*end*/\n" + + "public class A {}", + this.workingCopy, + false/*don't report errors*/, + true, + true); + IAnnotationBinding resolveAnnotationBinding = annotation.resolveAnnotationBinding(); + assertFalse("Recovered", resolveAnnotationBinding.isRecovered()); + } + /** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=228651 + */ + public void test0293() throws JavaModelException { + this.workingCopy = getWorkingCopy("/Converter15/src/test0293/A.java", true/*resolve*/); + NormalAnnotation annotation = (NormalAnnotation) buildAST( + "package test0293;\n" + + "@interface ABC {\n" + + " String name1() default \"\";\n" + + "}\n" + + "/*start*/@ABC(name1=\"\", id=0)/*end*/\n" + + "public class A {}", + this.workingCopy, + false/*don't report errors*/, + true, + true); + IAnnotationBinding resolveAnnotationBinding = annotation.resolveAnnotationBinding(); + assertEquals("Wrong size", 1, resolveAnnotationBinding.getAllMemberValuePairs().length); + } + /** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=228651 + */ + public void test0294() throws JavaModelException { + this.workingCopy = getWorkingCopy("/Converter15/src/test0294/A.java", true/*resolve*/); + NormalAnnotation annotation = (NormalAnnotation) buildAST( + "package test0294;\n" + + "@interface ABC {\n" + + " String name1() default \"\";\n" + + "}\n" + + "/*start*/@ABC(name1=\"\", id=0)/*end*/\n" + + "public class A {}", + this.workingCopy, + false/*don't report errors*/, + true, + true); + IAnnotationBinding resolveAnnotationBinding = annotation.resolveAnnotationBinding(); + assertEquals("Wrong size", 1, resolveAnnotationBinding.getDeclaredMemberValuePairs().length); + } + /** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=228651 + */ + public void test0295() throws JavaModelException { + this.workingCopy = getWorkingCopy("/Converter15/src/test0295/A.java", true/*resolve*/); + NormalAnnotation annotation = (NormalAnnotation) buildAST( + "package test0295;\n" + + "@interface ABC {\n" + + " String name1() default \"\";\n" + + "}\n" + + "/*start*/@ABC(id=0)/*end*/\n" + + "public class A {}", + this.workingCopy, + false/*don't report errors*/, + true, + true); + IAnnotationBinding resolveAnnotationBinding = annotation.resolveAnnotationBinding(); + assertEquals("Wrong size", 1, resolveAnnotationBinding.getAllMemberValuePairs().length); + } + /** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=228651 + */ + public void test0296() throws JavaModelException { + this.workingCopy = getWorkingCopy("/Converter15/src/test0296/A.java", true/*resolve*/); + NormalAnnotation annotation = (NormalAnnotation) buildAST( + "package test0296;\n" + + "@interface ABC {\n" + + " String name1() default \"\";\n" + + "}\n" + + "/*start*/@ABC(id=0)/*end*/\n" + + "public class A {}", + this.workingCopy, + false/*don't report errors*/, + true, + false); + IAnnotationBinding resolveAnnotationBinding = annotation.resolveAnnotationBinding(); + assertEquals("Wrong size", 1, resolveAnnotationBinding.getAllMemberValuePairs().length); + } + /** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=228651 + */ + public void test0297() throws JavaModelException { + this.workingCopy = getWorkingCopy("/Converter15/src/test0297/A.java", true/*resolve*/); + NormalAnnotation annotation = (NormalAnnotation) buildAST( + "package test0297;\n" + + "@interface ABC {\n" + + " String name1() default \"\";\n" + + "}\n" + + "/*start*/@ABC(name1=\"\", id=0)/*end*/\n" + + "public class A {}", + this.workingCopy, + false/*don't report errors*/, + true, + false); + IAnnotationBinding resolveAnnotationBinding = annotation.resolveAnnotationBinding(); + assertEquals("Wrong size", 1, resolveAnnotationBinding.getDeclaredMemberValuePairs().length); + } } Index: src/org/eclipse/jdt/core/tests/dom/ASTConverterBugsTest.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterBugsTest.java,v retrieving revision 1.19 diff -u -r1.19 ASTConverterBugsTest.java --- src/org/eclipse/jdt/core/tests/dom/ASTConverterBugsTest.java 11 Apr 2008 13:40:26 -0000 1.19 +++ src/org/eclipse/jdt/core/tests/dom/ASTConverterBugsTest.java 30 Apr 2008 16:34:11 -0000 @@ -974,7 +974,6 @@ "Invalid float literal number\n", result); } - /** * @bug 223838: [dom] AnnotationBinding.isRecovered() always return false * @test That the annotation binding is well flagged as recovered when the annotation is an unknown type @@ -988,11 +987,11 @@ "public class Test {\n" + "}\n"; ICompilationUnit workingCopy = getWorkingCopy( - "/Converter15/src/b223838/Test.java", - contents, - true/*resolve*/ - ); - ASTNode node = buildAST(contents, workingCopy, false); + "/Converter15/src/b223838/Test.java", + contents, + true/*resolve*/ + ); + ASTNode node = buildAST(contents, workingCopy, false, false, true); CompilationUnit unit = (CompilationUnit) node; List types = unit.types(); TypeDeclaration type = (TypeDeclaration) types.get(0); @@ -1000,7 +999,31 @@ IAnnotationBinding[] annotations = typeBinding.getAnnotations(); assertTrue("Expected recovered annotation binding!", annotations[1].isRecovered()); } - +/** + * @bug 223838: [dom] AnnotationBinding.isRecovered() always return false + * @test That the annotation binding is not reported when the recovery is off + * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=223838" + */ +public void testBug223838a() throws JavaModelException { + String contents = + "package b223838;\n" + + "@Deprecated\n" + + "@Invalid\n" + + "public class Test {\n" + + "}\n"; + ICompilationUnit workingCopy = getWorkingCopy( + "/Converter15/src/b223838/Test.java", + contents, + true/*resolve*/ + ); + ASTNode node = buildAST(contents, workingCopy, false, false, false); + CompilationUnit unit = (CompilationUnit) node; + List types = unit.types(); + TypeDeclaration type = (TypeDeclaration) types.get(0); + ITypeBinding typeBinding = type.resolveBinding(); + IAnnotationBinding[] annotations = typeBinding.getAnnotations(); + assertEquals("Got more than one annotation binding", 1, annotations.length); +} /** * @bug 226357: NPE in MethodBinding.getParameterAnnotations() if some, but not all parameters are annotated * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=226357"