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 assistNodeIsInterfaceExcludinAnnotation; // 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.assistNodeIsInterfaceExcludinAnnotation = 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.assistNodeIsInterfaceExcludinAnnotation = 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.assistNodeIsInterfaceExcludinAnnotation = 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 9281-9286 Link Here
9281
			typesFound.add(memberType);
9301
			typesFound.add(memberType);
9282
9302
9283
			if (this.assistNodeIsExtendedType && memberType.isFinal()) continue next;
9303
			if (this.assistNodeIsExtendedType && memberType.isFinal()) continue next;
9304
			if (this.assistNodeIsInterfaceExcludinAnnotation && memberType.isAnnotationType()) continue next;
9284
			if(!this.insideQualifiedReference) {
9305
			if(!this.insideQualifiedReference) {
9285
				if(this.assistNodeIsClass) {
9306
				if(this.assistNodeIsClass) {
9286
					if(!memberType.isClass()) continue next;
9307
					if(!memberType.isClass()) continue next;
Lines 9769-9774 Link Here
9769
								}
9790
								}
9770
9791
9771
								if (this.assistNodeIsExtendedType && localType.isFinal()) continue next;
9792
								if (this.assistNodeIsExtendedType && localType.isFinal()) continue next;
9793
								if (this.assistNodeIsInterfaceExcludinAnnotation && localType.isAnnotationType()) continue next;
9772
								if(this.assistNodeIsClass) {
9794
								if(this.assistNodeIsClass) {
9773
									if(!localType.isClass()) continue next;
9795
									if(!localType.isClass()) continue next;
9774
								} else if(this.assistNodeIsInterface) {
9796
								} else if(this.assistNodeIsInterface) {
Lines 10150-10155 Link Here
10150
				typesFound.add(sourceType);
10172
				typesFound.add(sourceType);
10151
10173
10152
				if (this.assistNodeIsExtendedType && sourceType.isFinal()) continue next;
10174
				if (this.assistNodeIsExtendedType && sourceType.isFinal()) continue next;
10175
				if (this.assistNodeIsInterfaceExcludinAnnotation && sourceType.isAnnotationType()) continue next;
10153
				if(this.assistNodeIsClass) {
10176
				if(this.assistNodeIsClass) {
10154
					if(!sourceType.isClass()) continue next;
10177
					if(!sourceType.isClass()) continue next;
10155
				} else if(this.assistNodeIsInterface) {
10178
				} else if(this.assistNodeIsInterface) {
Lines 10283-10288 Link Here
10283
				int searchFor = IJavaSearchConstants.TYPE;
10306
				int searchFor = IJavaSearchConstants.TYPE;
10284
				if(this.assistNodeIsClass) {
10307
				if(this.assistNodeIsClass) {
10285
					searchFor = IJavaSearchConstants.CLASS;
10308
					searchFor = IJavaSearchConstants.CLASS;
10309
				} else if (this.assistNodeIsInterfaceExcludinAnnotation) {
10310
					searchFor = IJavaSearchConstants.INTERFACE;
10286
				} else if(this.assistNodeIsInterface) {
10311
				} else if(this.assistNodeIsInterface) {
10287
					searchFor = IJavaSearchConstants.INTERFACE_AND_ANNOTATION;
10312
					searchFor = IJavaSearchConstants.INTERFACE_AND_ANNOTATION;
10288
				} else if(this.assistNodeIsEnum) {
10313
				} else if(this.assistNodeIsEnum) {
Lines 10375-10380 Link Here
10375
					continue;
10400
					continue;
10376
10401
10377
			    if (this.assistNodeIsExtendedType && sourceType.isFinal()) continue;
10402
			    if (this.assistNodeIsExtendedType && sourceType.isFinal()) continue;
10403
			    if (this.assistNodeIsInterfaceExcludinAnnotation && sourceType.isAnnotationType()) continue;
10378
				int accessibility = IAccessRule.K_ACCESSIBLE;
10404
				int accessibility = IAccessRule.K_ACCESSIBLE;
10379
				if(sourceType.hasRestrictedAccess()) {
10405
				if(sourceType.hasRestrictedAccess()) {
10380
					AccessRestriction accessRestriction = this.lookupEnvironment.getAccessRestriction(sourceType);
10406
					AccessRestriction accessRestriction = this.lookupEnvironment.getAccessRestriction(sourceType);
Lines 10462-10467 Link Here
10462
			int searchFor = IJavaSearchConstants.TYPE;
10488
			int searchFor = IJavaSearchConstants.TYPE;
10463
			if(this.assistNodeIsClass) {
10489
			if(this.assistNodeIsClass) {
10464
				searchFor = IJavaSearchConstants.CLASS;
10490
				searchFor = IJavaSearchConstants.CLASS;
10491
			} else if (this.assistNodeIsInterfaceExcludinAnnotation) {
10492
				searchFor = IJavaSearchConstants.INTERFACE;
10465
			} else if(this.assistNodeIsInterface) {
10493
			} else if(this.assistNodeIsInterface) {
10466
				searchFor = IJavaSearchConstants.INTERFACE_AND_ANNOTATION;
10494
				searchFor = IJavaSearchConstants.INTERFACE_AND_ANNOTATION;
10467
			} else if(this.assistNodeIsEnum) {
10495
			} else if(this.assistNodeIsEnum) {
Lines 10568-10573 Link Here
10568
						}
10596
						}
10569
10597
10570
						if (this.assistNodeIsExtendedType && refBinding.isFinal()) continue next;
10598
						if (this.assistNodeIsExtendedType && refBinding.isFinal()) continue next;
10599
						if (this.assistNodeIsInterfaceExcludinAnnotation && refBinding.isAnnotationType()) continue next;
10571
						if(this.assistNodeIsClass) {
10600
						if(this.assistNodeIsClass) {
10572
							if(!refBinding.isClass()) continue next;
10601
							if(!refBinding.isClass()) continue next;
10573
						} else if(this.assistNodeIsInterface) {
10602
						} else if(this.assistNodeIsInterface) {
Lines 10698-10703 Link Here
10698
							typesFound.add(typeBinding);
10727
							typesFound.add(typeBinding);
10699
							
10728
							
10700
							if (this.assistNodeIsExtendedType && typeBinding.isFinal()) continue;
10729
							if (this.assistNodeIsExtendedType && typeBinding.isFinal()) continue;
10730
							if (this.assistNodeIsInterfaceExcludinAnnotation && typeBinding.isAnnotationType()) continue;
10701
							if(this.assistNodeIsClass) {
10731
							if(this.assistNodeIsClass) {
10702
								if(!typeBinding.isClass()) continue;
10732
								if(!typeBinding.isClass()) continue;
10703
							} else if(this.assistNodeIsInterface) {
10733
							} else if(this.assistNodeIsInterface) {
Lines 10801-10806 Link Here
10801
							typesFound.add(typeBinding);
10831
							typesFound.add(typeBinding);
10802
10832
10803
							if (this.assistNodeIsExtendedType && typeBinding.isFinal()) continue;
10833
							if (this.assistNodeIsExtendedType && typeBinding.isFinal()) continue;
10834
							if (this.assistNodeIsInterfaceExcludinAnnotation && typeBinding.isAnnotationType()) continue;
10804
							if(this.assistNodeIsClass) {
10835
							if(this.assistNodeIsClass) {
10805
								if(!typeBinding.isClass()) continue;
10836
								if(!typeBinding.isClass()) continue;
10806
							} else if(this.assistNodeIsInterface) {
10837
							} 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