View | Details | Raw Unified | Return to bug 192774 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/jdt/core/tests/dom/ASTConverter15Test.java (+40 lines)
Lines 9156-9159 Link Here
9156
		annotations = binding.getAnnotations();
9156
		annotations = binding.getAnnotations();
9157
		assertEquals("Wrong size", 1, annotations.length);
9157
		assertEquals("Wrong size", 1, annotations.length);
9158
	}
9158
	}
9159
9160
	//https://bugs.eclipse.org/bugs/show_bug.cgi?id=192774
9161
	//Test ability to distinguish AST nodes of multiple similar annotations.
9162
	public void test0276() throws JavaModelException {
9163
		this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
9164
		String contents =
9165
			"@interface Annot {\n" +
9166
			"  public int value();\n" +
9167
			"}\n" +
9168
			"\n" + 
9169
			"public class X {\n" +
9170
			"  @Annot(1) String foo1() { return null; }\n" +
9171
			"  @Annot(1) String foo2() { return null; }\n" +
9172
			"}";
9173
		this.workingCopy.getBuffer().setContents(contents);
9174
		
9175
		class CompilationUnitRequestor extends ASTRequestor {
9176
			public void acceptAST(ICompilationUnit source, CompilationUnit node) {
9177
				MethodDeclaration methodDeclaration = (MethodDeclaration)getASTNode(node, 1, 0);
9178
				IMethodBinding methodBinding = methodDeclaration.resolveBinding();
9179
				IAnnotationBinding annoBinding = methodBinding.getAnnotations()[0];
9180
				ASTNode annoNode = node.findDeclaringNode(annoBinding);
9181
				int position1 = annoNode.getStartPosition();
9182
9183
				methodDeclaration = (MethodDeclaration)getASTNode(node, 1, 1);
9184
				methodBinding = methodDeclaration.resolveBinding();
9185
				IAnnotationBinding annoBinding2 = methodBinding.getAnnotations()[0];
9186
				annoNode = node.findDeclaringNode(annoBinding2);
9187
				int position2 = annoNode.getStartPosition();
9188
				assertTrue("Anno 2 position <= anno 1 position", position2 > position1);
9189
			}
9190
		}
9191
9192
		CompilationUnitRequestor requestor = new CompilationUnitRequestor();
9193
		ASTParser parser = ASTParser.newParser(AST.JLS3);
9194
		parser.setResolveBindings(true);
9195
		parser.setProject(this.getJavaProject("Converter15"));
9196
		parser.setKind(ASTParser.K_COMPILATION_UNIT);
9197
		parser.createASTs(new ICompilationUnit[]{this.workingCopy}, new String[0], requestor, null);
9198
	}	
9159
}
9199
}
(-)compiler/org/eclipse/jdt/internal/compiler/lookup/LookupEnvironment.java (-57 / +1 lines)
Lines 62-68 Link Here
62
	private SimpleLookupTable uniqueRawTypeBindings;
62
	private SimpleLookupTable uniqueRawTypeBindings;
63
	private SimpleLookupTable uniqueWildcardBindings;
63
	private SimpleLookupTable uniqueWildcardBindings;
64
	private SimpleLookupTable uniqueParameterizedGenericMethodBindings;
64
	private SimpleLookupTable uniqueParameterizedGenericMethodBindings;
65
	private SimpleLookupTable uniqueAnnotationBindings;
66
	
65
	
67
	public CompilationUnitDeclaration unitBeingCompleted = null; // only set while completing units
66
	public CompilationUnitDeclaration unitBeingCompleted = null; // only set while completing units
68
	public Object missingClassFileLocation = null; // only set when resolving certain references, to help locating problems
67
	public Object missingClassFileLocation = null; // only set when resolving certain references, to help locating problems
Lines 82-88 Link Here
82
	this.uniqueArrayBindings[0] = new ArrayBinding[50]; // start off the most common 1 dimension array @ 50
81
	this.uniqueArrayBindings[0] = new ArrayBinding[50]; // start off the most common 1 dimension array @ 50
83
	this.uniqueParameterizedTypeBindings = new SimpleLookupTable(3);
82
	this.uniqueParameterizedTypeBindings = new SimpleLookupTable(3);
84
	this.uniqueRawTypeBindings = new SimpleLookupTable(3);
83
	this.uniqueRawTypeBindings = new SimpleLookupTable(3);
85
	this.uniqueAnnotationBindings = new SimpleLookupTable(3);
86
	this.uniqueWildcardBindings = new SimpleLookupTable(3);
84
	this.uniqueWildcardBindings = new SimpleLookupTable(3);
87
	this.uniqueParameterizedGenericMethodBindings = new SimpleLookupTable(3);
85
	this.uniqueParameterizedGenericMethodBindings = new SimpleLookupTable(3);
88
	this.accessRestrictions = new HashMap(3);
86
	this.accessRestrictions = new HashMap(3);
Lines 539-601 Link Here
539
 *  Used to guarantee annotation identity.
537
 *  Used to guarantee annotation identity.
540
 */
538
 */
541
public AnnotationBinding createAnnotation(ReferenceBinding annotationType, ElementValuePair[] pairs) {
539
public AnnotationBinding createAnnotation(ReferenceBinding annotationType, ElementValuePair[] pairs) {
542
	// cached info is array of already created annotation binding for this type
543
	AnnotationBinding[] cachedInfo = (AnnotationBinding[])this.uniqueAnnotationBindings.get(annotationType);
544
	boolean needToGrow = false;
545
	int index = 0;
546
	if (pairs.length != 0) {
540
	if (pairs.length != 0) {
547
		AnnotationBinding.setMethodBindings(annotationType, pairs);
541
		AnnotationBinding.setMethodBindings(annotationType, pairs);
548
	}
542
	}
549
	if (cachedInfo != null){
543
	return new AnnotationBinding(annotationType, pairs);
550
		nextCachedType : 
551
			// iterate existing parameterized for reusing one with same type arguments if any
552
			for (int max = cachedInfo.length; index < max; index++){
553
				AnnotationBinding cachedType = cachedInfo[index];
554
				if (cachedType == null) break nextCachedType;
555
				ElementValuePair[] elementValuePairs = cachedType.pairs;
556
				int length2 = pairs.length;
557
				if (length2 != elementValuePairs.length) continue nextCachedType;
558
				loop: for (int i = 0; i < length2; i++) {
559
					ElementValuePair pair = elementValuePairs[i];
560
					// loop on the given pair to make sure one will match
561
					for (int j = 0; j < length2; j++) {
562
						ElementValuePair pair2 = pairs[j];
563
						if (pair.binding == pair2.binding) {
564
							if (pair.value == null) {
565
								if (pair2.value == null) {
566
									continue loop;
567
								}
568
								continue nextCachedType;
569
							} else {
570
								if (pair2.value == null
571
										|| !pair2.value.equals(pair.value)) {
572
									continue nextCachedType;
573
								}
574
							}
575
							continue loop;
576
						}
577
					}
578
					// no match found for pair so we create a new annotation binding
579
					continue nextCachedType;
580
				}
581
				// cached type match, reuse current
582
				return cachedType;
583
		}
584
		needToGrow = true;
585
	} else {
586
		cachedInfo = new AnnotationBinding[1];
587
		this.uniqueAnnotationBindings.put(annotationType, cachedInfo);
588
	}
589
	// grow cache ?
590
	int length = cachedInfo.length;
591
	if (needToGrow && index == length){
592
		System.arraycopy(cachedInfo, 0, cachedInfo = new AnnotationBinding[length*2], 0, length);
593
		this.uniqueAnnotationBindings.put(annotationType, cachedInfo);
594
	}
595
	// add new binding
596
	AnnotationBinding annotationBinding = new AnnotationBinding(annotationType, pairs);
597
	cachedInfo[index] = annotationBinding;
598
	return annotationBinding;
599
}
544
}
600
545
601
/*
546
/*
Lines 1248-1254 Link Here
1248
	this.uniqueRawTypeBindings = new SimpleLookupTable(3);
1193
	this.uniqueRawTypeBindings = new SimpleLookupTable(3);
1249
	this.uniqueWildcardBindings = new SimpleLookupTable(3);
1194
	this.uniqueWildcardBindings = new SimpleLookupTable(3);
1250
	this.uniqueParameterizedGenericMethodBindings = new SimpleLookupTable(3);
1195
	this.uniqueParameterizedGenericMethodBindings = new SimpleLookupTable(3);
1251
	this.uniqueAnnotationBindings = new SimpleLookupTable(3);
1252
	
1196
	
1253
	for (int i = this.units.length; --i >= 0;)
1197
	for (int i = this.units.length; --i >= 0;)
1254
		this.units[i] = null;
1198
		this.units[i] = null;
(-)compiler/org/eclipse/jdt/internal/compiler/lookup/ElementValuePair.java (-2 / +2 lines)
Lines 16-23 Link Here
16
16
17
public class ElementValuePair {
17
public class ElementValuePair {
18
	char[] name;
18
	char[] name;
19
	Object value;
19
	public Object value;
20
	MethodBinding binding;
20
	public MethodBinding binding;
21
21
22
public static Object getValue(Expression expression) {
22
public static Object getValue(Expression expression) {
23
	if (expression == null)
23
	if (expression == null)
(-)src/org/eclipse/jdt/internal/compiler/apt/model/AnnotationMirrorImpl.java (-1 / +32 lines)
Lines 56-66 Link Here
56
			if (this._binding == null) {
56
			if (this._binding == null) {
57
				return ((AnnotationMirrorImpl) obj)._binding == null;
57
				return ((AnnotationMirrorImpl) obj)._binding == null;
58
			}
58
			}
59
			return this._binding.equals(((AnnotationMirrorImpl) obj)._binding);
59
			return equals(this._binding, ((AnnotationMirrorImpl) obj)._binding);
60
		}
60
		}
61
		return false;
61
		return false;
62
	}
62
	}
63
63
64
	private static boolean equals(AnnotationBinding annotationBinding, AnnotationBinding annotationBinding2) {
65
		if (annotationBinding.getAnnotationType() != annotationBinding2.getAnnotationType()) return false;
66
		final ElementValuePair[] elementValuePairs = annotationBinding.getElementValuePairs();
67
		final ElementValuePair[] elementValuePairs2 = annotationBinding2.getElementValuePairs();
68
		final int length = elementValuePairs.length;
69
		if (length != elementValuePairs2.length) return false;
70
		loop: for (int i = 0; i < length; i++) {
71
			ElementValuePair pair = elementValuePairs[i];
72
			// loop on the given pair to make sure one will match
73
			for (int j = 0; j < length; j++) {
74
				ElementValuePair pair2 = elementValuePairs2[j];
75
				if (pair.binding == pair2.binding) {
76
					if (pair.value == null) {
77
						if (pair2.value == null) {
78
							continue loop;
79
						}
80
						return false;
81
					} else {
82
						if (pair2.value == null
83
								|| !pair2.value.equals(pair.value)) {
84
							return false;
85
						}
86
					}
87
					continue loop;
88
				}
89
			}
90
			return false;
91
		}
92
		return true;
93
	}
94
64
	public DeclaredType getAnnotationType() {
95
	public DeclaredType getAnnotationType() {
65
		if (this._binding == null) {
96
		if (this._binding == null) {
66
			return _env.getFactory().getErrorType();
97
			return _env.getFactory().getErrorType();

Return to bug 192774