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

Collapse All | Expand All

(-)dom/org/eclipse/jdt/core/dom/AnnotationBinding.java (-5 / +21 lines)
Lines 49-66 Link Here
49
	}
49
	}
50
	
50
	
51
	public IMemberValuePairBinding[] getDeclaredMemberValuePairs() {
51
	public IMemberValuePairBinding[] getDeclaredMemberValuePairs() {
52
		ReferenceBinding typeBinding = this.binding.getAnnotationType();
53
		if (typeBinding == null || ((typeBinding.tagBits & TagBits.HasMissingType) != 0)) {
54
			return MemberValuePairBinding.NoPair;
55
		}
52
		ElementValuePair[] internalPairs = this.binding.getElementValuePairs();
56
		ElementValuePair[] internalPairs = this.binding.getElementValuePairs();
53
		int length = internalPairs.length;
57
		int length = internalPairs.length;
54
		IMemberValuePairBinding[] pairs = length == 0 ? MemberValuePairBinding.NoPair : new MemberValuePairBinding[length];
58
		IMemberValuePairBinding[] pairs = length == 0 ? MemberValuePairBinding.NoPair : new MemberValuePairBinding[length];
55
		for (int i = 0; i < length; i++)
59
		int counter = 0;
56
			pairs[i] = this.bindingResolver.getMemberValuePairBinding(internalPairs[i]);
60
		for (int i = 0; i < length; i++) {
61
			ElementValuePair valuePair = internalPairs[i];
62
			if (valuePair.binding == null) continue;
63
			pairs[counter++] = this.bindingResolver.getMemberValuePairBinding(valuePair);
64
		}
65
		if (counter == 0) return MemberValuePairBinding.NoPair;
66
		if (counter != length) {
67
			// resize
68
			System.arraycopy(pairs, 0, (pairs = new MemberValuePairBinding[counter]), 0, counter);
69
		}
57
		return pairs;
70
		return pairs;
58
	}
71
	}
59
72
60
	public IMemberValuePairBinding[] getAllMemberValuePairs() {
73
	public IMemberValuePairBinding[] getAllMemberValuePairs() {
61
		IMemberValuePairBinding[] pairs = getDeclaredMemberValuePairs();
74
		IMemberValuePairBinding[] pairs = getDeclaredMemberValuePairs();
62
		ReferenceBinding typeBinding = this.binding.getAnnotationType();
75
		ReferenceBinding typeBinding = this.binding.getAnnotationType();
63
		if (typeBinding == null) return pairs;
76
		if (typeBinding == null || ((typeBinding.tagBits & TagBits.HasMissingType) != 0)) return pairs;
64
		MethodBinding[] methods = typeBinding.availableMethods(); // resilience
77
		MethodBinding[] methods = typeBinding.availableMethods(); // resilience
65
		int methodLength = methods == null ? 0 : methods.length;
78
		int methodLength = methods == null ? 0 : methods.length;
66
		if (methodLength == 0) return pairs;
79
		if (methodLength == 0) return pairs;
Lines 70-77 Link Here
70
			return pairs;
83
			return pairs;
71
84
72
		HashtableOfObject table = new HashtableOfObject(declaredLength);
85
		HashtableOfObject table = new HashtableOfObject(declaredLength);
73
		for (int i = 0; i < declaredLength; i++)
86
		for (int i = 0; i < declaredLength; i++) {
74
			table.put(((MemberValuePairBinding) pairs[i]).internalName(), pairs[i]);
87
			char[] internalName = ((MemberValuePairBinding) pairs[i]).internalName();
88
			if (internalName == null) continue;
89
			table.put(internalName, pairs[i]);
90
		}
75
91
76
		// handle case of more methods than declared members
92
		// handle case of more methods than declared members
77
		IMemberValuePairBinding[] allPairs = new  IMemberValuePairBinding[methodLength];
93
		IMemberValuePairBinding[] allPairs = new  IMemberValuePairBinding[methodLength];
(-)dom/org/eclipse/jdt/core/dom/DefaultBindingResolver.java (-1 / +7 lines)
Lines 246-252 Link Here
246
	}
246
	}
247
247
248
	synchronized IMemberValuePairBinding getMemberValuePairBinding(ElementValuePair valuePair) {
248
	synchronized IMemberValuePairBinding getMemberValuePairBinding(ElementValuePair valuePair) {
249
		if (valuePair == null) return null;
249
		if (valuePair == null || valuePair.binding == null) return null;
250
		IMemberValuePairBinding binding =
250
		IMemberValuePairBinding binding =
251
			(IMemberValuePairBinding) this.bindingTables.compilerBindingsToASTBindings.get(valuePair);
251
			(IMemberValuePairBinding) this.bindingTables.compilerBindingsToASTBindings.get(valuePair);
252
		if (binding != null)
252
		if (binding != null)
Lines 480-485 Link Here
480
480
481
	synchronized IAnnotationBinding getAnnotationInstance(org.eclipse.jdt.internal.compiler.lookup.AnnotationBinding internalInstance) {
481
	synchronized IAnnotationBinding getAnnotationInstance(org.eclipse.jdt.internal.compiler.lookup.AnnotationBinding internalInstance) {
482
		if (internalInstance == null) return null;
482
		if (internalInstance == null) return null;
483
		ReferenceBinding annotationType = internalInstance.getAnnotationType();
484
		if (annotationType == null || ((annotationType.tagBits & TagBits.HasMissingType) != 0)) {
485
			if (!this.isRecoveringBindings) {
486
				return null;
487
			}
488
		}
483
		IAnnotationBinding domInstance =
489
		IAnnotationBinding domInstance =
484
			(IAnnotationBinding) this.bindingTables.compilerBindingsToASTBindings.get(internalInstance);
490
			(IAnnotationBinding) this.bindingTables.compilerBindingsToASTBindings.get(internalInstance);
485
		if (domInstance != null)
491
		if (domInstance != null)
(-)src/org/eclipse/jdt/core/tests/dom/ASTConverter15Test.java (-20 / +207 lines)
Lines 46-53 Link Here
46
	}
46
	}
47
47
48
	static {
48
	static {
49
//		TESTS_NUMBERS = new int[] { 286 };
49
//		TESTS_NUMBERS = new int[] { 287 };
50
//		TESTS_RANGE = new int[] { 277, -1 };
50
//		TESTS_RANGE = new int[] { 287, -1 };
51
//		TESTS_NAMES = new String[] {"test0204"};
51
//		TESTS_NAMES = new String[] {"test0204"};
52
	}
52
	}
53
	public static Test suite() {
53
	public static Test suite() {
Lines 6330-6359 Link Here
6330
	public void test0208() throws JavaModelException {
6330
	public void test0208() throws JavaModelException {
6331
		this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
6331
		this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
6332
		String contents =
6332
		String contents =
6333
			"@Override(x= 1)\n" +
6333
			"/*start*/@Override(x= 1)/*end*/\n" +
6334
			"public class X { }";
6334
			"public class X { }";
6335
		ASTNode node = buildAST(
6335
		NormalAnnotation normalAnnotation = (NormalAnnotation) buildAST(
6336
				contents,
6336
				contents,
6337
				this.workingCopy,
6337
				this.workingCopy,
6338
				false,
6339
				true,
6338
				false);
6340
				false);
6339
		assertNotNull("No node", node);
6340
		assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
6341
		CompilationUnit compilationUnit = (CompilationUnit) node;
6342
		String problems =
6343
			"The annotation @Override is disallowed for this location\n" +
6344
			"The attribute x is undefined for the annotation type Override";
6345
		assertProblemsSize(compilationUnit, 2, problems);
6346
		node = getASTNode(compilationUnit, 0);
6347
		assertEquals("Not a type declaration", ASTNode.TYPE_DECLARATION, node.getNodeType());
6348
		TypeDeclaration typeDeclaration = (TypeDeclaration) node;
6349
		List modifiers = typeDeclaration.modifiers();
6350
		assertEquals("Wrong size", 2, modifiers.size());
6351
		assertTrue("Wrong type", modifiers.get(0) instanceof NormalAnnotation);
6352
		NormalAnnotation normalAnnotation = (NormalAnnotation) modifiers.get(0);
6353
		IAnnotationBinding annotationBinding = normalAnnotation.resolveAnnotationBinding();
6341
		IAnnotationBinding annotationBinding = normalAnnotation.resolveAnnotationBinding();
6354
		IMemberValuePairBinding[] pairs = annotationBinding.getDeclaredMemberValuePairs();
6342
		IMemberValuePairBinding[] pairs = annotationBinding.getDeclaredMemberValuePairs();
6355
		assertEquals("Wrong size", 1, pairs.length);
6343
		assertEquals("Wrong size", 0, pairs.length);
6356
		assertNotNull("Should not be null", pairs[0].getValue());
6344
		List values = normalAnnotation.values();
6345
		assertEquals("Wrong size", 1, values.size());
6346
		MemberValuePair pair = (MemberValuePair) values.get(0);
6347
		assertNotNull("no value", pair.getValue());
6357
	}
6348
	}
6358
6349
6359
	public void test0209() throws JavaModelException {
6350
	public void test0209() throws JavaModelException {
Lines 9613-9616 Link Here
9613
		assertTrue("Not assignmentCompatible: Integer -> int", typeBinding2.isAssignmentCompatible(typeBinding));
9604
		assertTrue("Not assignmentCompatible: Integer -> int", typeBinding2.isAssignmentCompatible(typeBinding));
9614
		assertTrue("Not assignmentCompatible: int -> Integer", typeBinding.isAssignmentCompatible(typeBinding2));
9605
		assertTrue("Not assignmentCompatible: int -> Integer", typeBinding.isAssignmentCompatible(typeBinding2));
9615
	}
9606
	}
9607
	/**
9608
	 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=228651
9609
	 */
9610
	public void test0287() throws JavaModelException {
9611
		this.workingCopy = getWorkingCopy("/Converter15/src/test0287/A.java", true/*resolve*/);
9612
		MemberValuePair pair = (MemberValuePair) buildAST(
9613
			"package test0287;\n" +
9614
			"@ABC (/*start*/name1=\"\"/*end*/)\n" + 
9615
			"public class A {}",
9616
			this.workingCopy, 
9617
			false/*don't report errors*/,
9618
			true,
9619
			true);
9620
		IMemberValuePairBinding resolveMemberValuePairBinding = pair.resolveMemberValuePairBinding();
9621
		assertNull("Got a binding", resolveMemberValuePairBinding);
9622
	}
9623
	/**
9624
	 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=228651
9625
	 */
9626
	public void test0288() throws JavaModelException {
9627
		this.workingCopy = getWorkingCopy("/Converter15/src/test0288/A.java", true/*resolve*/);
9628
		MemberValuePair pair = (MemberValuePair) buildAST(
9629
			"package test0288;\n" +
9630
			"@ABC (/*start*/name1=\"\"/*end*/)\n" + 
9631
			"public class A {}",
9632
			this.workingCopy, 
9633
			false/*don't report errors*/,
9634
			true,
9635
			false);
9636
		IMemberValuePairBinding resolveMemberValuePairBinding = pair.resolveMemberValuePairBinding();
9637
		assertNull("Got a binding", resolveMemberValuePairBinding);
9638
	}
9639
	/**
9640
	 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=228651
9641
	 */
9642
	public void test0289() throws JavaModelException {
9643
		this.workingCopy = getWorkingCopy("/Converter15/src/test0289/A.java", true/*resolve*/);
9644
		NormalAnnotation annotation = (NormalAnnotation) buildAST(
9645
			"package test0289;\n" +
9646
			"/*start*/@ABC (name1=\"\")/*end*/\n" + 
9647
			"public class A {}",
9648
			this.workingCopy, 
9649
			false/*don't report errors*/,
9650
			true,
9651
			false);
9652
		IAnnotationBinding resolveAnnotationBinding = annotation.resolveAnnotationBinding();
9653
		assertNull("No binding", resolveAnnotationBinding);
9654
	}
9655
9656
	/**
9657
	 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=228651
9658
	 */
9659
	public void test0290() throws JavaModelException {
9660
		this.workingCopy = getWorkingCopy("/Converter15/src/test0290/A.java", true/*resolve*/);
9661
		NormalAnnotation annotation = (NormalAnnotation) buildAST(
9662
			"package test0290;\n" +
9663
			"/*start*/@ABC (name1=\"\")/*end*/\n" + 
9664
			"public class A {}",
9665
			this.workingCopy, 
9666
			false/*don't report errors*/,
9667
			true,
9668
			true);
9669
		IAnnotationBinding resolveAnnotationBinding = annotation.resolveAnnotationBinding();
9670
		assertTrue("Not recovered", resolveAnnotationBinding.isRecovered());
9671
	}
9672
9673
	/**
9674
	 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=228651
9675
	 */
9676
	public void test0291() throws JavaModelException {
9677
		this.workingCopy = getWorkingCopy("/Converter15/src/test0291/A.java", true/*resolve*/);
9678
		NormalAnnotation annotation = (NormalAnnotation) buildAST(
9679
			"package test0291;\n" +
9680
			"/*start*/@ABC (name1=\"\")/*end*/\n" + 
9681
			"public class A {}",
9682
			this.workingCopy, 
9683
			false/*don't report errors*/,
9684
			true,
9685
			true);
9686
		IAnnotationBinding resolveAnnotationBinding = annotation.resolveAnnotationBinding();
9687
		assertEquals("Wrong size", 0, resolveAnnotationBinding.getAllMemberValuePairs().length);
9688
	}
9689
	/**
9690
	 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=228651
9691
	 */
9692
	public void test0292() throws JavaModelException {
9693
		this.workingCopy = getWorkingCopy("/Converter15/src/test0292/A.java", true/*resolve*/);
9694
		NormalAnnotation annotation = (NormalAnnotation) buildAST(
9695
			"package test0292;\n" +
9696
			"@interface ABC {\n" +
9697
			"	String name1() default \"\";\n" +
9698
			"}\n" +
9699
			"/*start*/@ABC(name1=\"\", id=0)/*end*/\n" + 
9700
			"public class A {}",
9701
			this.workingCopy, 
9702
			false/*don't report errors*/,
9703
			true,
9704
			true);
9705
		IAnnotationBinding resolveAnnotationBinding = annotation.resolveAnnotationBinding();
9706
		assertFalse("Recovered", resolveAnnotationBinding.isRecovered());
9707
	}
9708
	/**
9709
	 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=228651
9710
	 */
9711
	public void test0293() throws JavaModelException {
9712
		this.workingCopy = getWorkingCopy("/Converter15/src/test0293/A.java", true/*resolve*/);
9713
		NormalAnnotation annotation = (NormalAnnotation) buildAST(
9714
			"package test0293;\n" +
9715
			"@interface ABC {\n" +
9716
			"	String name1() default \"\";\n" +
9717
			"}\n" +
9718
			"/*start*/@ABC(name1=\"\", id=0)/*end*/\n" + 
9719
			"public class A {}",
9720
			this.workingCopy, 
9721
			false/*don't report errors*/,
9722
			true,
9723
			true);
9724
		IAnnotationBinding resolveAnnotationBinding = annotation.resolveAnnotationBinding();
9725
		assertEquals("Wrong size", 1, resolveAnnotationBinding.getAllMemberValuePairs().length);
9726
	}
9727
	/**
9728
	 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=228651
9729
	 */
9730
	public void test0294() throws JavaModelException {
9731
		this.workingCopy = getWorkingCopy("/Converter15/src/test0294/A.java", true/*resolve*/);
9732
		NormalAnnotation annotation = (NormalAnnotation) buildAST(
9733
			"package test0294;\n" +
9734
			"@interface ABC {\n" +
9735
			"	String name1() default \"\";\n" +
9736
			"}\n" +
9737
			"/*start*/@ABC(name1=\"\", id=0)/*end*/\n" + 
9738
			"public class A {}",
9739
			this.workingCopy, 
9740
			false/*don't report errors*/,
9741
			true,
9742
			true);
9743
		IAnnotationBinding resolveAnnotationBinding = annotation.resolveAnnotationBinding();
9744
		assertEquals("Wrong size", 1, resolveAnnotationBinding.getDeclaredMemberValuePairs().length);
9745
	}
9746
	/**
9747
	 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=228651
9748
	 */
9749
	public void test0295() throws JavaModelException {
9750
		this.workingCopy = getWorkingCopy("/Converter15/src/test0295/A.java", true/*resolve*/);
9751
		NormalAnnotation annotation = (NormalAnnotation) buildAST(
9752
			"package test0295;\n" +
9753
			"@interface ABC {\n" +
9754
			"	String name1() default \"\";\n" +
9755
			"}\n" +
9756
			"/*start*/@ABC(id=0)/*end*/\n" + 
9757
			"public class A {}",
9758
			this.workingCopy, 
9759
			false/*don't report errors*/,
9760
			true,
9761
			true);
9762
		IAnnotationBinding resolveAnnotationBinding = annotation.resolveAnnotationBinding();
9763
		assertEquals("Wrong size", 1, resolveAnnotationBinding.getAllMemberValuePairs().length);
9764
	}
9765
	/**
9766
	 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=228651
9767
	 */
9768
	public void test0296() throws JavaModelException {
9769
		this.workingCopy = getWorkingCopy("/Converter15/src/test0296/A.java", true/*resolve*/);
9770
		NormalAnnotation annotation = (NormalAnnotation) buildAST(
9771
			"package test0296;\n" +
9772
			"@interface ABC {\n" +
9773
			"	String name1() default \"\";\n" +
9774
			"}\n" +
9775
			"/*start*/@ABC(id=0)/*end*/\n" + 
9776
			"public class A {}",
9777
			this.workingCopy, 
9778
			false/*don't report errors*/,
9779
			true,
9780
			false);
9781
		IAnnotationBinding resolveAnnotationBinding = annotation.resolveAnnotationBinding();
9782
		assertEquals("Wrong size", 1, resolveAnnotationBinding.getAllMemberValuePairs().length);
9783
	}
9784
	/**
9785
	 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=228651
9786
	 */
9787
	public void test0297() throws JavaModelException {
9788
		this.workingCopy = getWorkingCopy("/Converter15/src/test0297/A.java", true/*resolve*/);
9789
		NormalAnnotation annotation = (NormalAnnotation) buildAST(
9790
			"package test0297;\n" +
9791
			"@interface ABC {\n" +
9792
			"	String name1() default \"\";\n" +
9793
			"}\n" +
9794
			"/*start*/@ABC(name1=\"\", id=0)/*end*/\n" + 
9795
			"public class A {}",
9796
			this.workingCopy, 
9797
			false/*don't report errors*/,
9798
			true,
9799
			false);
9800
		IAnnotationBinding resolveAnnotationBinding = annotation.resolveAnnotationBinding();
9801
		assertEquals("Wrong size", 1, resolveAnnotationBinding.getDeclaredMemberValuePairs().length);
9802
	}
9616
}
9803
}
(-)src/org/eclipse/jdt/core/tests/dom/ASTConverterBugsTest.java (-7 / +30 lines)
Lines 974-980 Link Here
974
			"Invalid float literal number\n",
974
			"Invalid float literal number\n",
975
			result);
975
			result);
976
}
976
}
977
978
/**
977
/**
979
 * @bug 223838: [dom] AnnotationBinding.isRecovered() always return false
978
 * @bug 223838: [dom] AnnotationBinding.isRecovered() always return false
980
 * @test That the annotation binding is well flagged as recovered when the annotation is an unknown type
979
 * @test That the annotation binding is well flagged as recovered when the annotation is an unknown type
Lines 988-998 Link Here
988
		"public class Test {\n" + 
987
		"public class Test {\n" + 
989
		"}\n";
988
		"}\n";
990
	ICompilationUnit workingCopy = getWorkingCopy(
989
	ICompilationUnit workingCopy = getWorkingCopy(
991
   			"/Converter15/src/b223838/Test.java",
990
			"/Converter15/src/b223838/Test.java",
992
   			contents,
991
			contents,
993
   			true/*resolve*/
992
			true/*resolve*/
994
   		);
993
		);
995
   	ASTNode node = buildAST(contents, workingCopy, false);
994
	ASTNode node = buildAST(contents, workingCopy, false, false, true);
996
	CompilationUnit unit = (CompilationUnit) node;
995
	CompilationUnit unit = (CompilationUnit) node;
997
	List types = unit.types();
996
	List types = unit.types();
998
	TypeDeclaration type = (TypeDeclaration) types.get(0);
997
	TypeDeclaration type = (TypeDeclaration) types.get(0);
Lines 1000-1006 Link Here
1000
	IAnnotationBinding[] annotations = typeBinding.getAnnotations();
999
	IAnnotationBinding[] annotations = typeBinding.getAnnotations();
1001
	assertTrue("Expected recovered annotation binding!", annotations[1].isRecovered());
1000
	assertTrue("Expected recovered annotation binding!", annotations[1].isRecovered());
1002
}
1001
}
1003
1002
/**
1003
 * @bug 223838: [dom] AnnotationBinding.isRecovered() always return false
1004
 * @test That the annotation binding is not reported when the recovery is off
1005
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=223838"
1006
 */
1007
public void testBug223838a() throws JavaModelException {
1008
	String contents =
1009
		"package b223838;\n" +
1010
		"@Deprecated\n" + 
1011
		"@Invalid\n" + 
1012
		"public class Test {\n" + 
1013
		"}\n";
1014
	ICompilationUnit workingCopy = getWorkingCopy(
1015
			"/Converter15/src/b223838/Test.java",
1016
			contents,
1017
			true/*resolve*/
1018
		);
1019
	ASTNode node = buildAST(contents, workingCopy, false, false, false);
1020
	CompilationUnit unit = (CompilationUnit) node;
1021
	List types = unit.types();
1022
	TypeDeclaration type = (TypeDeclaration) types.get(0);
1023
	ITypeBinding typeBinding = type.resolveBinding();
1024
	IAnnotationBinding[] annotations = typeBinding.getAnnotations();
1025
	assertEquals("Got more than one annotation binding", 1, annotations.length);
1026
}
1004
/**
1027
/**
1005
 * @bug 226357: NPE in MethodBinding.getParameterAnnotations() if some, but not all parameters are annotated
1028
 * @bug 226357: NPE in MethodBinding.getParameterAnnotations() if some, but not all parameters are annotated
1006
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=226357"
1029
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=226357"

Return to bug 228651