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

Collapse All | Expand All

(-)codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java (+31 lines)
Lines 520-525 Link Here
520
	boolean assistNodeIsConstructor;
520
	boolean assistNodeIsConstructor;
521
	boolean assistNodeIsSuperType;
521
	boolean assistNodeIsSuperType;
522
	boolean assistNodeIsExtendedType;
522
	boolean assistNodeIsExtendedType;
523
	boolean assistNodeIsInterfaceExcludingAnnotation; // https://bugs.eclipse.org/bugs/show_bug.cgi?id=310423
523
	int  assistNodeInJavadoc = 0;
524
	int  assistNodeInJavadoc = 0;
524
	boolean assistNodeCanBeSingleMemberAnnotation = false;
525
	boolean assistNodeCanBeSingleMemberAnnotation = false;
525
	
526
	
Lines 2780-2785 Link Here
2780
			this.assistNodeIsInterface = ref.isInterface();
2781
			this.assistNodeIsInterface = ref.isInterface();
2781
			this.assistNodeIsSuperType = ref.isSuperType();
2782
			this.assistNodeIsSuperType = ref.isSuperType();
2782
			this.assistNodeIsExtendedType = assistNodeIsExtendedType(astNode, astNodeParent);
2783
			this.assistNodeIsExtendedType = assistNodeIsExtendedType(astNode, astNodeParent);
2784
			this.assistNodeIsInterfaceExcludingAnnotation = assistNodeIsInterfaceExcludingAnnotation(astNode, astNodeParent);
2783
2785
2784
			this.completionToken = ref.completionIdentifier;
2786
			this.completionToken = ref.completionIdentifier;
2785
			long completionPosition = ref.sourcePositions[ref.tokens.length];
2787
			long completionPosition = ref.sourcePositions[ref.tokens.length];
Lines 2842-2847 Link Here
2842
		return false;
2844
		return false;
2843
	}
2845
	}
2844
	
2846
	
2847
	private boolean assistNodeIsInterfaceExcludingAnnotation(ASTNode astNode, ASTNode astNodeParent) {
2848
		// https://bugs.eclipse.org/bugs/show_bug.cgi?id=310423, don't propose annotations for implements.
2849
		if (astNodeParent == null)
2850
			return false;
2851
		if (astNodeParent instanceof TypeDeclaration) {
2852
			TypeDeclaration typeDeclaration = (TypeDeclaration) astNodeParent;
2853
			TypeReference [] superInterfaces = typeDeclaration.superInterfaces;
2854
			int length = superInterfaces == null ? 0 : superInterfaces.length;
2855
			for (int i = 0; i < length; i++) {
2856
				if (superInterfaces[i] == astNode)
2857
					return true;
2858
			}
2859
		}
2860
		return false;
2861
	}
2862
	
2845
	private void completionOnQualifiedAllocationExpression(ASTNode astNode, Binding qualifiedBinding, Scope scope) {
2863
	private void completionOnQualifiedAllocationExpression(ASTNode astNode, Binding qualifiedBinding, Scope scope) {
2846
		setSourceAndTokenRange(astNode.sourceStart, astNode.sourceEnd, false);
2864
		setSourceAndTokenRange(astNode.sourceStart, astNode.sourceEnd, false);
2847
2865
Lines 3041-3046 Link Here
3041
		this.assistNodeIsConstructor = ref.isConstructorType;
3059
		this.assistNodeIsConstructor = ref.isConstructorType;
3042
		this.assistNodeIsSuperType = ref.isSuperType();
3060
		this.assistNodeIsSuperType = ref.isSuperType();
3043
		this.assistNodeIsExtendedType = assistNodeIsExtendedType(astNode, astNodeParent);
3061
		this.assistNodeIsExtendedType = assistNodeIsExtendedType(astNode, astNodeParent);
3062
		this.assistNodeIsInterfaceExcludingAnnotation = assistNodeIsInterfaceExcludingAnnotation(astNode, astNodeParent);
3044
3063
3045
		this.completionToken = ref.completionIdentifier;
3064
		this.completionToken = ref.completionIdentifier;
3046
		long completionPosition = ref.sourcePositions[ref.tokens.length];
3065
		long completionPosition = ref.sourcePositions[ref.tokens.length];
Lines 3175-3180 Link Here
3175
		this.assistNodeIsConstructor = singleRef.isConstructorType;
3194
		this.assistNodeIsConstructor = singleRef.isConstructorType;
3176
		this.assistNodeIsSuperType = singleRef.isSuperType();
3195
		this.assistNodeIsSuperType = singleRef.isSuperType();
3177
		this.assistNodeIsExtendedType = assistNodeIsExtendedType(astNode, astNodeParent);
3196
		this.assistNodeIsExtendedType = assistNodeIsExtendedType(astNode, astNodeParent);
3197
		this.assistNodeIsInterfaceExcludingAnnotation = assistNodeIsInterfaceExcludingAnnotation(astNode, astNodeParent);
3178
3198
3179
		// can be the start of a qualified type name
3199
		// can be the start of a qualified type name
3180
		if (qualifiedBinding == null) {
3200
		if (qualifiedBinding == null) {
Lines 9291-9296 Link Here
9291
			typesFound.add(memberType);
9311
			typesFound.add(memberType);
9292
9312
9293
			if (this.assistNodeIsExtendedType && memberType.isFinal()) continue next;
9313
			if (this.assistNodeIsExtendedType && memberType.isFinal()) continue next;
9314
			if (this.assistNodeIsInterfaceExcludingAnnotation && memberType.isAnnotationType()) continue next;
9294
			if(!this.insideQualifiedReference) {
9315
			if(!this.insideQualifiedReference) {
9295
				if(this.assistNodeIsClass) {
9316
				if(this.assistNodeIsClass) {
9296
					if(!memberType.isClass()) continue next;
9317
					if(!memberType.isClass()) continue next;
Lines 9779-9784 Link Here
9779
								}
9800
								}
9780
9801
9781
								if (this.assistNodeIsExtendedType && localType.isFinal()) continue next;
9802
								if (this.assistNodeIsExtendedType && localType.isFinal()) continue next;
9803
								if (this.assistNodeIsInterfaceExcludingAnnotation && localType.isAnnotationType()) continue next;
9782
								if(this.assistNodeIsClass) {
9804
								if(this.assistNodeIsClass) {
9783
									if(!localType.isClass()) continue next;
9805
									if(!localType.isClass()) continue next;
9784
								} else if(this.assistNodeIsInterface) {
9806
								} else if(this.assistNodeIsInterface) {
Lines 10160-10165 Link Here
10160
				typesFound.add(sourceType);
10182
				typesFound.add(sourceType);
10161
10183
10162
				if (this.assistNodeIsExtendedType && sourceType.isFinal()) continue next;
10184
				if (this.assistNodeIsExtendedType && sourceType.isFinal()) continue next;
10185
				if (this.assistNodeIsInterfaceExcludingAnnotation && sourceType.isAnnotationType()) continue next;
10163
				if(this.assistNodeIsClass) {
10186
				if(this.assistNodeIsClass) {
10164
					if(!sourceType.isClass()) continue next;
10187
					if(!sourceType.isClass()) continue next;
10165
				} else if(this.assistNodeIsInterface) {
10188
				} else if(this.assistNodeIsInterface) {
Lines 10293-10298 Link Here
10293
				int searchFor = IJavaSearchConstants.TYPE;
10316
				int searchFor = IJavaSearchConstants.TYPE;
10294
				if(this.assistNodeIsClass) {
10317
				if(this.assistNodeIsClass) {
10295
					searchFor = IJavaSearchConstants.CLASS;
10318
					searchFor = IJavaSearchConstants.CLASS;
10319
				} else if (this.assistNodeIsInterfaceExcludingAnnotation) {
10320
					searchFor = IJavaSearchConstants.INTERFACE;
10296
				} else if(this.assistNodeIsInterface) {
10321
				} else if(this.assistNodeIsInterface) {
10297
					searchFor = IJavaSearchConstants.INTERFACE_AND_ANNOTATION;
10322
					searchFor = IJavaSearchConstants.INTERFACE_AND_ANNOTATION;
10298
				} else if(this.assistNodeIsEnum) {
10323
				} else if(this.assistNodeIsEnum) {
Lines 10385-10390 Link Here
10385
					continue;
10410
					continue;
10386
10411
10387
			    if (this.assistNodeIsExtendedType && sourceType.isFinal()) continue;
10412
			    if (this.assistNodeIsExtendedType && sourceType.isFinal()) continue;
10413
			    if (this.assistNodeIsInterfaceExcludingAnnotation && sourceType.isAnnotationType()) continue;
10388
				int accessibility = IAccessRule.K_ACCESSIBLE;
10414
				int accessibility = IAccessRule.K_ACCESSIBLE;
10389
				if(sourceType.hasRestrictedAccess()) {
10415
				if(sourceType.hasRestrictedAccess()) {
10390
					AccessRestriction accessRestriction = this.lookupEnvironment.getAccessRestriction(sourceType);
10416
					AccessRestriction accessRestriction = this.lookupEnvironment.getAccessRestriction(sourceType);
Lines 10472-10477 Link Here
10472
			int searchFor = IJavaSearchConstants.TYPE;
10498
			int searchFor = IJavaSearchConstants.TYPE;
10473
			if(this.assistNodeIsClass) {
10499
			if(this.assistNodeIsClass) {
10474
				searchFor = IJavaSearchConstants.CLASS;
10500
				searchFor = IJavaSearchConstants.CLASS;
10501
			} else if (this.assistNodeIsInterfaceExcludingAnnotation) {
10502
				searchFor = IJavaSearchConstants.INTERFACE;
10475
			} else if(this.assistNodeIsInterface) {
10503
			} else if(this.assistNodeIsInterface) {
10476
				searchFor = IJavaSearchConstants.INTERFACE_AND_ANNOTATION;
10504
				searchFor = IJavaSearchConstants.INTERFACE_AND_ANNOTATION;
10477
			} else if(this.assistNodeIsEnum) {
10505
			} else if(this.assistNodeIsEnum) {
Lines 10578-10583 Link Here
10578
						}
10606
						}
10579
10607
10580
						if (this.assistNodeIsExtendedType && refBinding.isFinal()) continue next;
10608
						if (this.assistNodeIsExtendedType && refBinding.isFinal()) continue next;
10609
						if (this.assistNodeIsInterfaceExcludingAnnotation && refBinding.isAnnotationType()) continue next;
10581
						if(this.assistNodeIsClass) {
10610
						if(this.assistNodeIsClass) {
10582
							if(!refBinding.isClass()) continue next;
10611
							if(!refBinding.isClass()) continue next;
10583
						} else if(this.assistNodeIsInterface) {
10612
						} else if(this.assistNodeIsInterface) {
Lines 10708-10713 Link Here
10708
							typesFound.add(typeBinding);
10737
							typesFound.add(typeBinding);
10709
							
10738
							
10710
							if (this.assistNodeIsExtendedType && typeBinding.isFinal()) continue;
10739
							if (this.assistNodeIsExtendedType && typeBinding.isFinal()) continue;
10740
							if (this.assistNodeIsInterfaceExcludingAnnotation && typeBinding.isAnnotationType()) continue;
10711
							if(this.assistNodeIsClass) {
10741
							if(this.assistNodeIsClass) {
10712
								if(!typeBinding.isClass()) continue;
10742
								if(!typeBinding.isClass()) continue;
10713
							} else if(this.assistNodeIsInterface) {
10743
							} else if(this.assistNodeIsInterface) {
Lines 10811-10816 Link Here
10811
							typesFound.add(typeBinding);
10841
							typesFound.add(typeBinding);
10812
10842
10813
							if (this.assistNodeIsExtendedType && typeBinding.isFinal()) continue;
10843
							if (this.assistNodeIsExtendedType && typeBinding.isFinal()) continue;
10844
							if (this.assistNodeIsInterfaceExcludingAnnotation && typeBinding.isAnnotationType()) continue;
10814
							if(this.assistNodeIsClass) {
10845
							if(this.assistNodeIsClass) {
10815
								if(!typeBinding.isClass()) continue;
10846
								if(!typeBinding.isClass()) continue;
10816
							} else if(this.assistNodeIsInterface) {
10847
							} else if(this.assistNodeIsInterface) {
(-)codeassist/org/eclipse/jdt/internal/codeassist/complete/CompletionParser.java (+15 lines)
Lines 2157-2162 Link Here
2157
		}
2157
		}
2158
	}
2158
	}
2159
}
2159
}
2160
protected void consumeClassHeaderImplements() {
2161
	super.consumeClassHeaderImplements();
2162
	if (this.assistNode != null && this.assistNodeParent == null) {
2163
		TypeDeclaration typeDecl = (TypeDeclaration) this.astStack[this.astPtr];
2164
		if (typeDecl != null) {
2165
			TypeReference[] superInterfaces = typeDecl.superInterfaces;
2166
			int length = superInterfaces == null ? 0 : superInterfaces.length;
2167
			for (int i = 0; i < length; i++) {
2168
				if (superInterfaces[i] == this.assistNode) {
2169
					this.assistNodeParent = typeDecl;
2170
				}	
2171
			}
2172
		}
2173
	}
2174
}
2160
protected void consumeClassTypeElt() {
2175
protected void consumeClassTypeElt() {
2161
	pushOnElementStack(K_NEXT_TYPEREF_IS_EXCEPTION);
2176
	pushOnElementStack(K_NEXT_TYPEREF_IS_EXCEPTION);
2162
	super.consumeClassTypeElt();
2177
	super.consumeClassTypeElt();
(-)src/org/eclipse/jdt/core/tests/compiler/parser/CompletionParserTest.java (-1 / +55 lines)
Lines 12-18 Link Here
12
12
13
import junit.framework.Test;
13
import junit.framework.Test;
14
14
15
import org.eclipse.jdt.internal.codeassist.complete.*;
15
import org.eclipse.jdt.internal.codeassist.complete.InvalidCursorLocation;
16
16
17
public class CompletionParserTest extends AbstractCompletionTest {
17
public class CompletionParserTest extends AbstractCompletionTest {
18
public CompletionParserTest(String testName) {
18
public CompletionParserTest(String testName) {
Lines 8634-8637 Link Here
8634
		expectedReplacedSource,
8634
		expectedReplacedSource,
8635
		testName);
8635
		testName);
8636
}
8636
}
8637
8638
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=310423
8639
// To verify that assist node parent is set to the the type declaration
8640
// when completion is requested after implements in a type declaration.
8641
public void testBug310423(){
8642
	String str =
8643
		"import java.lang.annotation.Annotation;\n" +
8644
		"interface In {}\n" +
8645
		"interface Inn {\n" +
8646
		"	interface Inn2 {}\n" +
8647
		"	@interface InAnnot {}\n" +
8648
		"}\n" +
8649
		"@interface InnAnnot {}\n"+
8650
		"public class Test implements In{\n" +
8651
		"}\n";
8652
8653
	String testName = "";
8654
	String completeBehind = "In";
8655
	String expectedCompletionNodeToString = "<CompleteOnInterface:In>";
8656
	String expectedParentNodeToString = 
8657
		"public class Test implements <CompleteOnInterface:In> {\n" + 
8658
		"  public Test() {\n" + 
8659
		"  }\n" + 
8660
		"}";
8661
	String completionIdentifier = "In";
8662
	String expectedReplacedSource = "In";
8663
	int cursorLocation = str.lastIndexOf("In") + completeBehind.length() - 1;
8664
	String expectedUnitDisplayString =
8665
		"import java.lang.annotation.Annotation;\n" + 
8666
		"interface In {\n" + 
8667
		"}\n" + 
8668
		"interface Inn {\n" + 
8669
		"  interface Inn2 {\n" + 
8670
		"  }\n" + 
8671
		"  @interface InAnnot {\n" + 
8672
		"  }\n" + 
8673
		"}\n" + 
8674
		"@interface InnAnnot {\n" + 
8675
		"}\n" + 
8676
		"public class Test implements <CompleteOnInterface:In> {\n" + 
8677
		"  public Test() {\n" + 
8678
		"  }\n" +
8679
		"}\n";
8680
8681
	checkDietParse(
8682
		str.toCharArray(),
8683
		cursorLocation,
8684
		expectedCompletionNodeToString,
8685
		expectedParentNodeToString,
8686
		expectedUnitDisplayString,
8687
		completionIdentifier,
8688
		expectedReplacedSource,
8689
		testName);
8690
}
8637
}
8691
}
(-)src/org/eclipse/jdt/core/tests/compiler/parser/GenericsCompletionParserTest.java (-1 / +5 lines)
Lines 461-467 Link Here
461
	String completeBehind = "Y<Z>.";
461
	String completeBehind = "Y<Z>.";
462
	int cursorLocation = str.indexOf("Y<Z>.") + completeBehind.length() - 1;
462
	int cursorLocation = str.indexOf("Y<Z>.") + completeBehind.length() - 1;
463
	String expectedCompletionNodeToString = "<CompleteOnInterface:Y<Z>.>";
463
	String expectedCompletionNodeToString = "<CompleteOnInterface:Y<Z>.>";
464
	String expectedParentNodeToString = "<NONE>";
464
	String expectedParentNodeToString = 
465
		"public class X implements I1, <CompleteOnInterface:Y<Z>.> {\n" + 
466
		"  public X() {\n" + 
467
		"  }\n" + 
468
		"}";
465
	String completionIdentifier = "";
469
	String completionIdentifier = "";
466
	String expectedReplacedSource = "Y<Z>.";
470
	String expectedReplacedSource = "Y<Z>.";
467
	String expectedUnitDisplayString =
471
	String expectedUnitDisplayString =
(-)src/org/eclipse/jdt/core/tests/model/CompletionTests_1_5.java (-1 / +56 lines)
Lines 6602-6608 Link Here
6602
	            result.context);
6602
	            result.context);
6603
6603
6604
	    assertResults(
6604
	    assertResults(
6605
	            "ZZType.ZZAnnotation[TYPE_REF]{p.ZZType.ZZAnnotation, p, Lp.ZZType$ZZAnnotation;, null, null, " + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_INTERFACE + R_NON_RESTRICTED) + "}\n" +
6606
				"ZZType.ZZInterface[TYPE_REF]{p.ZZType.ZZInterface, p, Lp.ZZType$ZZInterface;, null, null, " + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_INTERFACE + R_NON_RESTRICTED) + "}",
6605
				"ZZType.ZZInterface[TYPE_REF]{p.ZZType.ZZInterface, p, Lp.ZZType$ZZInterface;, null, null, " + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_INTERFACE + R_NON_RESTRICTED) + "}",
6607
	            result.proposals);
6606
	            result.proposals);
6608
	} finally {
6607
	} finally {
Lines 13815-13818 Link Here
13815
			"\ud842\udf9fabc[LABEL_REF]{\ud842\udf9fabc, null, null, \ud842\udf9fabc, null, " + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_NON_RESTRICTED) + "}",
13814
			"\ud842\udf9fabc[LABEL_REF]{\ud842\udf9fabc, null, null, \ud842\udf9fabc, null, " + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_NON_RESTRICTED) + "}",
13816
			requestor.getResults());
13815
			requestor.getResults());
13817
}
13816
}
13817
13818
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=310423
13819
// Annotation types are not proposed after 'implements' in a Single type ref
13820
public void testBug310423a() throws JavaModelException {
13821
	this.workingCopies = new ICompilationUnit[1];
13822
	this.workingCopies[0] = getWorkingCopy(
13823
		"/Completion/src/label/Test.java",
13824
		"import java.lang.annotation.Annotation;\n" +
13825
		"interface In {}\n" +
13826
		"interface Inn {\n" +
13827
		"	interface Inn2 {}\n" +
13828
		"	@interface IAnnot {}\n" +
13829
		"}\n" +
13830
		"@interface InnAnnot {}\n"+
13831
		"public class Test implements {\n" +
13832
		"}\n");
13833
13834
	CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
13835
	String str = this.workingCopies[0].getSource();
13836
	String completeBehind = "implements";
13837
	int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length() + 1;
13838
	this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
13839
13840
	assertResults(
13841
			"Inn.Inn2[TYPE_REF]{label.Inn.Inn2, label, Llabel.Inn$Inn2;, null, null, 44}\n" +
13842
			"In[TYPE_REF]{In, label, Llabel.In;, null, null, 47}\n" +
13843
			"Inn[TYPE_REF]{Inn, label, Llabel.Inn;, null, null, 47}",
13844
			requestor.getResults());
13845
}
13846
13847
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=310423
13848
// Annotation types are not proposed after 'implements' in a Qualified type ref
13849
public void testBug310423b() throws JavaModelException {
13850
	this.workingCopies = new ICompilationUnit[1];
13851
	this.workingCopies[0] = getWorkingCopy(
13852
		"/Completion/src/label/Test.java",
13853
		"interface In{}\n" +
13854
		"interface Inn{\n" +
13855
		"	interface Inn2{}\n" +
13856
		"	interface Inn3{}\n" +
13857
		"	@interface IAnnot {}\n" +
13858
		"}"+
13859
		"public class Test implements Inn. {\n" +
13860
		"}\n");
13861
13862
	CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
13863
	String str = this.workingCopies[0].getSource();
13864
	String completeBehind = "Inn.";
13865
	int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length() + 1;
13866
	this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
13867
13868
	assertResults(
13869
			"Inn.Inn2[TYPE_REF]{Inn2, label, Llabel.Inn$Inn2;, null, null, 44}\n" +
13870
			"Inn.Inn3[TYPE_REF]{Inn3, label, Llabel.Inn$Inn3;, null, null, 44}",
13871
			requestor.getResults());
13872
}
13818
}
13873
}

Return to bug 310423