### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core Index: codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java,v retrieving revision 1.411 diff -u -r1.411 CompletionEngine.java --- codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java 22 Apr 2010 16:11:44 -0000 1.411 +++ codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java 7 Jun 2010 10:43:02 -0000 @@ -520,6 +520,7 @@ boolean assistNodeIsConstructor; boolean assistNodeIsSuperType; boolean assistNodeIsExtendedType; + boolean assistNodeIsInterfaceExcludinAnnotation; // https://bugs.eclipse.org/bugs/show_bug.cgi?id=310423 int assistNodeInJavadoc = 0; boolean assistNodeCanBeSingleMemberAnnotation = false; @@ -2780,6 +2781,7 @@ this.assistNodeIsInterface = ref.isInterface(); this.assistNodeIsSuperType = ref.isSuperType(); this.assistNodeIsExtendedType = assistNodeIsExtendedType(astNode, astNodeParent); + this.assistNodeIsInterfaceExcludinAnnotation = assistNodeIsInterfaceExcludingAnnotation(astNode, astNodeParent); this.completionToken = ref.completionIdentifier; long completionPosition = ref.sourcePositions[ref.tokens.length]; @@ -2842,6 +2844,22 @@ return false; } + private boolean assistNodeIsInterfaceExcludingAnnotation(ASTNode astNode, ASTNode astNodeParent) { + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=310423, don't propose annotations for implements. + if (astNodeParent == null) + return false; + if (astNodeParent instanceof TypeDeclaration) { + TypeDeclaration typeDeclaration = (TypeDeclaration) astNodeParent; + TypeReference [] superInterfaces = typeDeclaration.superInterfaces; + int length = superInterfaces == null ? 0 : superInterfaces.length; + for (int i = 0; i < length; i++) { + if (superInterfaces[i] == astNode) + return true; + } + } + return false; + } + private void completionOnQualifiedAllocationExpression(ASTNode astNode, Binding qualifiedBinding, Scope scope) { setSourceAndTokenRange(astNode.sourceStart, astNode.sourceEnd, false); @@ -3041,6 +3059,7 @@ this.assistNodeIsConstructor = ref.isConstructorType; this.assistNodeIsSuperType = ref.isSuperType(); this.assistNodeIsExtendedType = assistNodeIsExtendedType(astNode, astNodeParent); + this.assistNodeIsInterfaceExcludinAnnotation = assistNodeIsInterfaceExcludingAnnotation(astNode, astNodeParent); this.completionToken = ref.completionIdentifier; long completionPosition = ref.sourcePositions[ref.tokens.length]; @@ -3175,6 +3194,7 @@ this.assistNodeIsConstructor = singleRef.isConstructorType; this.assistNodeIsSuperType = singleRef.isSuperType(); this.assistNodeIsExtendedType = assistNodeIsExtendedType(astNode, astNodeParent); + this.assistNodeIsInterfaceExcludinAnnotation = assistNodeIsInterfaceExcludingAnnotation(astNode, astNodeParent); // can be the start of a qualified type name if (qualifiedBinding == null) { @@ -9281,6 +9301,7 @@ typesFound.add(memberType); if (this.assistNodeIsExtendedType && memberType.isFinal()) continue next; + if (this.assistNodeIsInterfaceExcludinAnnotation && memberType.isAnnotationType()) continue next; if(!this.insideQualifiedReference) { if(this.assistNodeIsClass) { if(!memberType.isClass()) continue next; @@ -9769,6 +9790,7 @@ } if (this.assistNodeIsExtendedType && localType.isFinal()) continue next; + if (this.assistNodeIsInterfaceExcludinAnnotation && localType.isAnnotationType()) continue next; if(this.assistNodeIsClass) { if(!localType.isClass()) continue next; } else if(this.assistNodeIsInterface) { @@ -10150,6 +10172,7 @@ typesFound.add(sourceType); if (this.assistNodeIsExtendedType && sourceType.isFinal()) continue next; + if (this.assistNodeIsInterfaceExcludinAnnotation && sourceType.isAnnotationType()) continue next; if(this.assistNodeIsClass) { if(!sourceType.isClass()) continue next; } else if(this.assistNodeIsInterface) { @@ -10283,6 +10306,8 @@ int searchFor = IJavaSearchConstants.TYPE; if(this.assistNodeIsClass) { searchFor = IJavaSearchConstants.CLASS; + } else if (this.assistNodeIsInterfaceExcludinAnnotation) { + searchFor = IJavaSearchConstants.INTERFACE; } else if(this.assistNodeIsInterface) { searchFor = IJavaSearchConstants.INTERFACE_AND_ANNOTATION; } else if(this.assistNodeIsEnum) { @@ -10375,6 +10400,7 @@ continue; if (this.assistNodeIsExtendedType && sourceType.isFinal()) continue; + if (this.assistNodeIsInterfaceExcludinAnnotation && sourceType.isAnnotationType()) continue; int accessibility = IAccessRule.K_ACCESSIBLE; if(sourceType.hasRestrictedAccess()) { AccessRestriction accessRestriction = this.lookupEnvironment.getAccessRestriction(sourceType); @@ -10462,6 +10488,8 @@ int searchFor = IJavaSearchConstants.TYPE; if(this.assistNodeIsClass) { searchFor = IJavaSearchConstants.CLASS; + } else if (this.assistNodeIsInterfaceExcludinAnnotation) { + searchFor = IJavaSearchConstants.INTERFACE; } else if(this.assistNodeIsInterface) { searchFor = IJavaSearchConstants.INTERFACE_AND_ANNOTATION; } else if(this.assistNodeIsEnum) { @@ -10568,6 +10596,7 @@ } if (this.assistNodeIsExtendedType && refBinding.isFinal()) continue next; + if (this.assistNodeIsInterfaceExcludinAnnotation && refBinding.isAnnotationType()) continue next; if(this.assistNodeIsClass) { if(!refBinding.isClass()) continue next; } else if(this.assistNodeIsInterface) { @@ -10698,6 +10727,7 @@ typesFound.add(typeBinding); if (this.assistNodeIsExtendedType && typeBinding.isFinal()) continue; + if (this.assistNodeIsInterfaceExcludinAnnotation && typeBinding.isAnnotationType()) continue; if(this.assistNodeIsClass) { if(!typeBinding.isClass()) continue; } else if(this.assistNodeIsInterface) { @@ -10801,6 +10831,7 @@ typesFound.add(typeBinding); if (this.assistNodeIsExtendedType && typeBinding.isFinal()) continue; + if (this.assistNodeIsInterfaceExcludinAnnotation && typeBinding.isAnnotationType()) continue; if(this.assistNodeIsClass) { if(!typeBinding.isClass()) continue; } else if(this.assistNodeIsInterface) { Index: codeassist/org/eclipse/jdt/internal/codeassist/complete/CompletionParser.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/complete/CompletionParser.java,v retrieving revision 1.216 diff -u -r1.216 CompletionParser.java --- codeassist/org/eclipse/jdt/internal/codeassist/complete/CompletionParser.java 20 May 2010 18:03:14 -0000 1.216 +++ codeassist/org/eclipse/jdt/internal/codeassist/complete/CompletionParser.java 7 Jun 2010 10:43:06 -0000 @@ -2157,6 +2157,21 @@ } } } +protected void consumeClassHeaderImplements() { + super.consumeClassHeaderImplements(); + if (this.assistNode != null && this.assistNodeParent == null) { + TypeDeclaration typeDecl = (TypeDeclaration) this.astStack[this.astPtr]; + if (typeDecl != null) { + TypeReference[] superInterfaces = typeDecl.superInterfaces; + int length = superInterfaces == null ? 0 : superInterfaces.length; + for (int i = 0; i < length; i++) { + if (superInterfaces[i] == this.assistNode) { + this.assistNodeParent = typeDecl; + } + } + } + } +} protected void consumeClassTypeElt() { pushOnElementStack(K_NEXT_TYPEREF_IS_EXCEPTION); super.consumeClassTypeElt(); #P org.eclipse.jdt.core.tests.compiler Index: src/org/eclipse/jdt/core/tests/compiler/parser/CompletionParserTest.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/CompletionParserTest.java,v retrieving revision 1.34 diff -u -r1.34 CompletionParserTest.java --- src/org/eclipse/jdt/core/tests/compiler/parser/CompletionParserTest.java 27 Jun 2008 16:04:46 -0000 1.34 +++ src/org/eclipse/jdt/core/tests/compiler/parser/CompletionParserTest.java 7 Jun 2010 10:43:14 -0000 @@ -12,7 +12,7 @@ import junit.framework.Test; -import org.eclipse.jdt.internal.codeassist.complete.*; +import org.eclipse.jdt.internal.codeassist.complete.InvalidCursorLocation; public class CompletionParserTest extends AbstractCompletionTest { public CompletionParserTest(String testName) { @@ -8634,4 +8634,58 @@ expectedReplacedSource, testName); } + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=310423 +// To verify that assist node parent is set to the the type declaration +// when completion is requested after implements in a type declaration. +public void testBug310423(){ + String str = + "import java.lang.annotation.Annotation;\n" + + "interface In {}\n" + + "interface Inn {\n" + + " interface Inn2 {}\n" + + " @interface InAnnot {}\n" + + "}\n" + + "@interface InnAnnot {}\n"+ + "public class Test implements In{\n" + + "}\n"; + + String testName = ""; + String completeBehind = "In"; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = + "public class Test implements {\n" + + " public Test() {\n" + + " }\n" + + "}"; + String completionIdentifier = "In"; + String expectedReplacedSource = "In"; + int cursorLocation = str.lastIndexOf("In") + completeBehind.length() - 1; + String expectedUnitDisplayString = + "import java.lang.annotation.Annotation;\n" + + "interface In {\n" + + "}\n" + + "interface Inn {\n" + + " interface Inn2 {\n" + + " }\n" + + " @interface InAnnot {\n" + + " }\n" + + "}\n" + + "@interface InnAnnot {\n" + + "}\n" + + "public class Test implements {\n" + + " public Test() {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + testName); +} } Index: src/org/eclipse/jdt/core/tests/compiler/parser/GenericsCompletionParserTest.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/GenericsCompletionParserTest.java,v retrieving revision 1.39 diff -u -r1.39 GenericsCompletionParserTest.java --- src/org/eclipse/jdt/core/tests/compiler/parser/GenericsCompletionParserTest.java 6 May 2009 08:57:01 -0000 1.39 +++ src/org/eclipse/jdt/core/tests/compiler/parser/GenericsCompletionParserTest.java 7 Jun 2010 10:43:19 -0000 @@ -461,7 +461,11 @@ String completeBehind = "Y."; int cursorLocation = str.indexOf("Y.") + completeBehind.length() - 1; String expectedCompletionNodeToString = ".>"; - String expectedParentNodeToString = ""; + String expectedParentNodeToString = + "public class X implements I1, .> {\n" + + " public X() {\n" + + " }\n" + + "}"; String completionIdentifier = ""; String expectedReplacedSource = "Y."; String expectedUnitDisplayString = #P org.eclipse.jdt.core.tests.model Index: src/org/eclipse/jdt/core/tests/model/CompletionTests_1_5.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests_1_5.java,v retrieving revision 1.120 diff -u -r1.120 CompletionTests_1_5.java --- src/org/eclipse/jdt/core/tests/model/CompletionTests_1_5.java 11 May 2010 18:58:14 -0000 1.120 +++ src/org/eclipse/jdt/core/tests/model/CompletionTests_1_5.java 7 Jun 2010 10:43:32 -0000 @@ -6602,7 +6602,6 @@ result.context); assertResults( - "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" + "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) + "}", result.proposals); } finally { @@ -13815,4 +13814,60 @@ "\ud842\udf9fabc[LABEL_REF]{\ud842\udf9fabc, null, null, \ud842\udf9fabc, null, " + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_NON_RESTRICTED) + "}", requestor.getResults()); } + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=310423 +// Annotation types are not proposed after 'implements' in a Single type ref +public void testBug310423a() throws JavaModelException { + this.workingCopies = new ICompilationUnit[1]; + this.workingCopies[0] = getWorkingCopy( + "/Completion/src/label/Test.java", + "import java.lang.annotation.Annotation;\n" + + "interface In {}\n" + + "interface Inn {\n" + + " interface Inn2 {}\n" + + " @interface IAnnot {}\n" + + "}\n" + + "@interface InnAnnot {}\n"+ + "public class Test implements {\n" + + "}\n"); + + CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true); + String str = this.workingCopies[0].getSource(); + String completeBehind = "implements"; + int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length() + 1; + this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner); + + assertResults( + "Inn.Inn2[TYPE_REF]{label.Inn.Inn2, label, Llabel.Inn$Inn2;, null, null, 44}\n" + + "In[TYPE_REF]{In, label, Llabel.In;, null, null, 47}\n" + + "Inn[TYPE_REF]{Inn, label, Llabel.Inn;, null, null, 47}", + requestor.getResults()); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=310423 +// Annotation types are not proposed after 'implements' in a Qualified type ref +public void testBug310423b() throws JavaModelException { + this.workingCopies = new ICompilationUnit[1]; + this.workingCopies[0] = getWorkingCopy( + "/Completion/src/label/Test.java", + "interface In{}\n" + + "interface Inn{\n" + + " interface Inn2{}\n" + + " interface Inn3{}\n" + + " @interface IAnnot {}\n" + + "}"+ + "public class Test implements Inn. {\n" + + "}\n"); + + CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true); + String str = this.workingCopies[0].getSource(); + String completeBehind = "Inn."; + int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length() + 1; + this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner); + + assertResults( + "Inn.Inn2[TYPE_REF]{Inn2, label, Llabel.Inn$Inn2;, null, null, 44}\n" + + "Inn.Inn3[TYPE_REF]{Inn3, label, Llabel.Inn$Inn3;, null, null, 44}", + requestor.getResults()); +} }