### Eclipse Workspace Patch 1.0 #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.248 diff -u -r1.248 ASTConverter15Test.java --- src/org/eclipse/jdt/core/tests/dom/ASTConverter15Test.java 22 Jun 2007 15:50:16 -0000 1.248 +++ src/org/eclipse/jdt/core/tests/dom/ASTConverter15Test.java 4 Jul 2007 17:49:44 -0000 @@ -9156,4 +9156,44 @@ annotations = binding.getAnnotations(); assertEquals("Wrong size", 1, annotations.length); } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=192774 + //Test ability to distinguish AST nodes of multiple similar annotations. + public void test0276() throws JavaModelException { + this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/); + String contents = + "@interface Annot {\n" + + " public int value();\n" + + "}\n" + + "\n" + + "public class X {\n" + + " @Annot(1) String foo1() { return null; }\n" + + " @Annot(1) String foo2() { return null; }\n" + + "}"; + this.workingCopy.getBuffer().setContents(contents); + + class CompilationUnitRequestor extends ASTRequestor { + public void acceptAST(ICompilationUnit source, CompilationUnit node) { + MethodDeclaration methodDeclaration = (MethodDeclaration)getASTNode(node, 1, 0); + IMethodBinding methodBinding = methodDeclaration.resolveBinding(); + IAnnotationBinding annoBinding = methodBinding.getAnnotations()[0]; + ASTNode annoNode = node.findDeclaringNode(annoBinding); + int position1 = annoNode.getStartPosition(); + + methodDeclaration = (MethodDeclaration)getASTNode(node, 1, 1); + methodBinding = methodDeclaration.resolveBinding(); + IAnnotationBinding annoBinding2 = methodBinding.getAnnotations()[0]; + annoNode = node.findDeclaringNode(annoBinding2); + int position2 = annoNode.getStartPosition(); + assertTrue("Anno 2 position <= anno 1 position", position2 > position1); + } + } + + CompilationUnitRequestor requestor = new CompilationUnitRequestor(); + ASTParser parser = ASTParser.newParser(AST.JLS3); + parser.setResolveBindings(true); + parser.setProject(this.getJavaProject("Converter15")); + parser.setKind(ASTParser.K_COMPILATION_UNIT); + parser.createASTs(new ICompilationUnit[]{this.workingCopy}, new String[0], requestor, null); + } } Index: compiler/org/eclipse/jdt/internal/compiler/lookup/LookupEnvironment.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/LookupEnvironment.java,v retrieving revision 1.84 diff -u -r1.84 LookupEnvironment.java --- compiler/org/eclipse/jdt/internal/compiler/lookup/LookupEnvironment.java 27 Apr 2007 15:51:39 -0000 1.84 +++ compiler/org/eclipse/jdt/internal/compiler/lookup/LookupEnvironment.java 4 Jul 2007 17:49:45 -0000 @@ -62,7 +62,6 @@ private SimpleLookupTable uniqueRawTypeBindings; private SimpleLookupTable uniqueWildcardBindings; private SimpleLookupTable uniqueParameterizedGenericMethodBindings; - private SimpleLookupTable uniqueAnnotationBindings; public CompilationUnitDeclaration unitBeingCompleted = null; // only set while completing units public Object missingClassFileLocation = null; // only set when resolving certain references, to help locating problems @@ -82,7 +81,6 @@ this.uniqueArrayBindings[0] = new ArrayBinding[50]; // start off the most common 1 dimension array @ 50 this.uniqueParameterizedTypeBindings = new SimpleLookupTable(3); this.uniqueRawTypeBindings = new SimpleLookupTable(3); - this.uniqueAnnotationBindings = new SimpleLookupTable(3); this.uniqueWildcardBindings = new SimpleLookupTable(3); this.uniqueParameterizedGenericMethodBindings = new SimpleLookupTable(3); this.accessRestrictions = new HashMap(3); @@ -539,63 +537,10 @@ * Used to guarantee annotation identity. */ public AnnotationBinding createAnnotation(ReferenceBinding annotationType, ElementValuePair[] pairs) { - // cached info is array of already created annotation binding for this type - AnnotationBinding[] cachedInfo = (AnnotationBinding[])this.uniqueAnnotationBindings.get(annotationType); - boolean needToGrow = false; - int index = 0; if (pairs.length != 0) { AnnotationBinding.setMethodBindings(annotationType, pairs); } - if (cachedInfo != null){ - nextCachedType : - // iterate existing parameterized for reusing one with same type arguments if any - for (int max = cachedInfo.length; index < max; index++){ - AnnotationBinding cachedType = cachedInfo[index]; - if (cachedType == null) break nextCachedType; - ElementValuePair[] elementValuePairs = cachedType.pairs; - int length2 = pairs.length; - if (length2 != elementValuePairs.length) continue nextCachedType; - loop: for (int i = 0; i < length2; i++) { - ElementValuePair pair = elementValuePairs[i]; - // loop on the given pair to make sure one will match - for (int j = 0; j < length2; j++) { - ElementValuePair pair2 = pairs[j]; - if (pair.binding == pair2.binding) { - if (pair.value == null) { - if (pair2.value == null) { - continue loop; - } - continue nextCachedType; - } else { - if (pair2.value == null - || !pair2.value.equals(pair.value)) { - continue nextCachedType; - } - } - continue loop; - } - } - // no match found for pair so we create a new annotation binding - continue nextCachedType; - } - // cached type match, reuse current - return cachedType; - } - needToGrow = true; - } else { - cachedInfo = new AnnotationBinding[1]; - this.uniqueAnnotationBindings.put(annotationType, cachedInfo); - } - // grow cache ? - int length = cachedInfo.length; - if (needToGrow && index == length){ - System.arraycopy(cachedInfo, 0, cachedInfo = new AnnotationBinding[length*2], 0, length); - this.uniqueAnnotationBindings.put(annotationType, cachedInfo); - } - // add new binding - AnnotationBinding annotationBinding = new AnnotationBinding(annotationType, pairs); - cachedInfo[index] = annotationBinding; - return annotationBinding; + return new AnnotationBinding(annotationType, pairs); } /* @@ -1248,7 +1193,6 @@ this.uniqueRawTypeBindings = new SimpleLookupTable(3); this.uniqueWildcardBindings = new SimpleLookupTable(3); this.uniqueParameterizedGenericMethodBindings = new SimpleLookupTable(3); - this.uniqueAnnotationBindings = new SimpleLookupTable(3); for (int i = this.units.length; --i >= 0;) this.units[i] = null; Index: compiler/org/eclipse/jdt/internal/compiler/lookup/ElementValuePair.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ElementValuePair.java,v retrieving revision 1.3 diff -u -r1.3 ElementValuePair.java --- compiler/org/eclipse/jdt/internal/compiler/lookup/ElementValuePair.java 6 Sep 2006 04:58:45 -0000 1.3 +++ compiler/org/eclipse/jdt/internal/compiler/lookup/ElementValuePair.java 4 Jul 2007 17:49:45 -0000 @@ -16,8 +16,8 @@ public class ElementValuePair { char[] name; - Object value; - MethodBinding binding; + public Object value; + public MethodBinding binding; public static Object getValue(Expression expression) { if (expression == null) #P org.eclipse.jdt.compiler.apt Index: src/org/eclipse/jdt/internal/compiler/apt/model/AnnotationMirrorImpl.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/model/AnnotationMirrorImpl.java,v retrieving revision 1.13 diff -u -r1.13 AnnotationMirrorImpl.java --- src/org/eclipse/jdt/internal/compiler/apt/model/AnnotationMirrorImpl.java 28 Apr 2007 18:29:27 -0000 1.13 +++ src/org/eclipse/jdt/internal/compiler/apt/model/AnnotationMirrorImpl.java 4 Jul 2007 17:49:48 -0000 @@ -56,11 +56,42 @@ if (this._binding == null) { return ((AnnotationMirrorImpl) obj)._binding == null; } - return this._binding.equals(((AnnotationMirrorImpl) obj)._binding); + return equals(this._binding, ((AnnotationMirrorImpl) obj)._binding); } return false; } + private static boolean equals(AnnotationBinding annotationBinding, AnnotationBinding annotationBinding2) { + if (annotationBinding.getAnnotationType() != annotationBinding2.getAnnotationType()) return false; + final ElementValuePair[] elementValuePairs = annotationBinding.getElementValuePairs(); + final ElementValuePair[] elementValuePairs2 = annotationBinding2.getElementValuePairs(); + final int length = elementValuePairs.length; + if (length != elementValuePairs2.length) return false; + loop: for (int i = 0; i < length; i++) { + ElementValuePair pair = elementValuePairs[i]; + // loop on the given pair to make sure one will match + for (int j = 0; j < length; j++) { + ElementValuePair pair2 = elementValuePairs2[j]; + if (pair.binding == pair2.binding) { + if (pair.value == null) { + if (pair2.value == null) { + continue loop; + } + return false; + } else { + if (pair2.value == null + || !pair2.value.equals(pair.value)) { + return false; + } + } + continue loop; + } + } + return false; + } + return true; + } + public DeclaredType getAnnotationType() { if (this._binding == null) { return _env.getFactory().getErrorType();