### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core Index: codeassist/org/eclipse/jdt/internal/codeassist/InternalExtendedCompletionContext.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/InternalExtendedCompletionContext.java,v retrieving revision 1.18 diff -u -r1.18 InternalExtendedCompletionContext.java --- codeassist/org/eclipse/jdt/internal/codeassist/InternalExtendedCompletionContext.java 7 Sep 2010 19:14:26 -0000 1.18 +++ codeassist/org/eclipse/jdt/internal/codeassist/InternalExtendedCompletionContext.java 8 Sep 2010 14:52:23 -0000 @@ -19,7 +19,6 @@ import org.eclipse.jdt.core.JavaModelException; import org.eclipse.jdt.core.WorkingCopyOwner; import org.eclipse.jdt.core.compiler.CharOperation; -import org.eclipse.jdt.internal.codeassist.complete.CompletionNodeDetector; import org.eclipse.jdt.internal.codeassist.complete.CompletionParser; import org.eclipse.jdt.internal.codeassist.impl.AssistCompilationUnit; import org.eclipse.jdt.internal.compiler.ast.ASTNode; @@ -188,13 +187,39 @@ } } else { FieldDeclaration fieldDeclaration = fields[i]; - if (fieldDeclaration.initialization != null && - fieldDeclaration.initialization.sourceStart <= astNode.sourceStart && - astNode.sourceEnd <= fieldDeclaration.initialization.sourceEnd) { + if (fieldDeclaration.initialization != null) { // completion is inside a field initializer searchVisibleVariablesAndMethods(scope, this.visibleLocalVariables, this.visibleFields, this.visibleMethods, notInJavadoc); + // remove this field from visibleFields list because completion is being asked in its + // intialization and so this has not yet been declared successfully. + if (this.visibleFields.size > 0 && this.visibleFields.contains(fieldDeclaration.binding)) { + this.visibleFields.remove(fieldDeclaration.binding); + } break done; } + /*(Incase fieldDeclaration != null is not sufficient to infer that + proposal is being asked inside initializer of field decl, use the below if + block instead of the above) + if (fieldDeclaration.initialization != null) { + + if (fieldDeclaration.initialization.sourceEnd > 0) { + if (fieldDeclaration.initialization.sourceStart <= astNode.sourceStart && + astNode.sourceEnd <= fieldDeclaration.initialization.sourceEnd) { + // completion is inside a field initializer + searchVisibleVariablesAndMethods(scope, this.visibleLocalVariables, this.visibleFields, this.visibleMethods, notInJavadoc); + } + } else { // The sourceEnd may not yet be set + CompletionNodeDetector detector = new CompletionNodeDetector(this.assistNode, fieldDeclaration.initialization); + if (detector.containsCompletionNode()) { + searchVisibleVariablesAndMethods(scope, this.visibleLocalVariables, this.visibleFields, this.visibleMethods, notInJavadoc); + } + } + // remove this field from visibleFields list because completion is being asked in its + // intialization and so this has not yet been declared successfully. + if (this.visibleFields.size > 0 && this.visibleFields.contains(fieldDeclaration.binding)) { + this.visibleFields.remove(fieldDeclaration.binding); + } + }*/ } } } @@ -724,11 +749,13 @@ // If the local variable declaration's initialization statement itself has the completion, // then don't propose the local variable if (local.declaration.initialization != null) { - if(local.declaration.initialization.sourceEnd > 0) { - if (this.assistNode.sourceEnd <= local.declaration.initialization.sourceEnd - && this.assistNode.sourceStart >= local.declaration.initialization.sourceStart) { - continue next; - } + /*(use this if-else block if it is found that local.declaration.initialization != null is not sufficient to + guarantee that proposal is being asked inside a local variable declaration's initializer) + if(local.declaration.initialization.sourceEnd > 0) { + if (this.assistNode.sourceEnd <= local.declaration.initialization.sourceEnd + && this.assistNode.sourceStart >= local.declaration.initialization.sourceStart) { + continue next; + } } else { CompletionNodeDetector detector = new CompletionNodeDetector( this.assistNode, @@ -736,7 +763,8 @@ if (detector.containsCompletionNode()) { continue next; } - } + }*/ + continue next; } for (int f = 0; f < localsFound.size; f++) { LocalVariableBinding otherLocal = #P org.eclipse.jdt.core.tests.model Index: src/org/eclipse/jdt/core/tests/model/CompletionContextTests.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionContextTests.java,v retrieving revision 1.18 diff -u -r1.18 CompletionContextTests.java --- src/org/eclipse/jdt/core/tests/model/CompletionContextTests.java 16 Apr 2010 13:25:08 -0000 1.18 +++ src/org/eclipse/jdt/core/tests/model/CompletionContextTests.java 8 Sep 2010 14:52:25 -0000 @@ -4002,7 +4002,6 @@ "expectedTypesKeys={I}\n" + "completion token location=UNKNOWN\n" + "visibleElements={\n" + - " field1 {key=Ltest/X;.field1)I} [in X [in [Working copy] X.java [in test [in src3 [in Completion]]]]],\n" + " field0 {key=Ltest/X;.field0)I} [in X [in [Working copy] X.java [in test [in src3 [in Completion]]]]],\n" + " wait(long, int) {key=Ljava/lang/Object;.wait(JI)V|Ljava/lang/IllegalMonitorStateException;|Ljava/lang/InterruptedException;} [in Object [in Object.class [in java.lang [in "+jclPath+"]]]],\n" + " wait(long) {key=Ljava/lang/Object;.wait(J)V|Ljava/lang/IllegalMonitorStateException;|Ljava/lang/InterruptedException;} [in Object [in Object.class [in java.lang [in "+jclPath+"]]]],\n" + @@ -5291,4 +5290,139 @@ "}", result.context); } + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=312603 +public void test0174() throws JavaModelException { + this.workingCopies = new ICompilationUnit[3]; + this.workingCopies[0] = getWorkingCopy( + "/Completion/src3/test/X.java", + "package test;\n" + + "import java.text.MessageFormat;\n" + + "public class X {\n" + + " String fooBar = \"Hi\";" + + " String furchtbar= MessageFormat.format\n" + + "}"); + + String str = this.workingCopies[0].getSource(); + int tokenStart = str.lastIndexOf("format"); + int tokenEnd = tokenStart + "format".length() - 1; + int cursorLocation = str.lastIndexOf("format") + "format".length(); + + CompletionResult result = contextComplete(this.workingCopies[0], cursorLocation, true, true); + String jclPath = getExternalJCLPathString(); + assertResults( + "completion offset="+(cursorLocation)+"\n" + + "completion range=["+(tokenStart)+", "+(tokenEnd)+"]\n" + + "completion token=\"format\"\n" + + "completion token kind=TOKEN_KIND_NAME\n" + + "expectedTypesSignatures={Ljava.lang.String;}\n" + + "expectedTypesKeys={Ljava/lang/String;}\n" + + "completion token location=UNKNOWN\n" + + "enclosingElement=furchtbar {key=Ltest/X;.furchtbar)Ljava/lang/String;} [in X [in [Working copy] X.java [in test [in src3 [in Completion]]]]]\n" + + "visibleElements={\n" + + " fooBar {key=Ltest/X;.fooBar)Ljava/lang/String;} [in X [in [Working copy] X.java [in test [in src3 [in Completion]]]]],\n" + + " wait(long, int) {key=Ljava/lang/Object;.wait(JI)V|Ljava/lang/IllegalMonitorStateException;|Ljava/lang/InterruptedException;} [in Object [in Object.class [in java.lang [in " + jclPath + "]]]],\n" + + " wait(long) {key=Ljava/lang/Object;.wait(J)V|Ljava/lang/IllegalMonitorStateException;|Ljava/lang/InterruptedException;} [in Object [in Object.class [in java.lang [in " + jclPath + "]]]],\n" + + " wait() {key=Ljava/lang/Object;.wait()V|Ljava/lang/IllegalMonitorStateException;|Ljava/lang/InterruptedException;} [in Object [in Object.class [in java.lang [in " + jclPath + "]]]],\n" + + " toString() {key=Ljava/lang/Object;.toString()Ljava/lang/String;} [in Object [in Object.class [in java.lang [in " + jclPath + "]]]],\n" + + " notifyAll() {key=Ljava/lang/Object;.notifyAll()V|Ljava/lang/IllegalMonitorStateException;} [in Object [in Object.class [in java.lang [in " + jclPath + "]]]],\n" + + " notify() {key=Ljava/lang/Object;.notify()V|Ljava/lang/IllegalMonitorStateException;} [in Object [in Object.class [in java.lang [in " + jclPath + "]]]],\n" + + " hashCode() {key=Ljava/lang/Object;.hashCode()I} [in Object [in Object.class [in java.lang [in " + jclPath + "]]]],\n" + + " getClass() {key=Ljava/lang/Object;.getClass()Ljava/lang/Class;} [in Object [in Object.class [in java.lang [in " + jclPath +"]]]],\n" + + " finalize() {key=Ljava/lang/Object;.finalize()V|Ljava/lang/Throwable;} [in Object [in Object.class [in java.lang [in " + jclPath + "]]]],\n" + + " equals(java.lang.Object) {key=Ljava/lang/Object;.equals(Ljava/lang/Object;)Z} [in Object [in Object.class [in java.lang [in " + jclPath + "]]]],\n" + + " clone() {key=Ljava/lang/Object;.clone()Ljava/lang/Object;|Ljava/lang/CloneNotSupportedException;} [in Object [in Object.class [in java.lang [in " + jclPath +"]]]],\n" + + "}", + result.context); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=312603 +public void test0175() throws JavaModelException { + this.workingCopies = new ICompilationUnit[3]; + this.workingCopies[0] = getWorkingCopy( + "/Completion/src3/test/X.java", + "package test;\n" + + "import java.text.MessageFormat;\n" + + "public class X {\n" + + " String fooBar = \"Hi\";" + + " String furchtbar= new String(String.format;\n" + + "}"); + + String str = this.workingCopies[0].getSource(); + int tokenStart = str.lastIndexOf("format"); + int tokenEnd = tokenStart + "format".length() - 1; + int cursorLocation = str.lastIndexOf("format") + "format".length(); + + CompletionResult result = contextComplete(this.workingCopies[0], cursorLocation, true, true); + String jclPath = getExternalJCLPathString(); + assertResults( + "completion offset="+(cursorLocation)+"\n" + + "completion range=["+(tokenStart)+", "+(tokenEnd)+"]\n" + + "completion token=\"format\"\n" + + "completion token kind=TOKEN_KIND_NAME\n" + + "expectedTypesSignatures=null\n" + + "expectedTypesKeys=null\n" + + "completion token location=UNKNOWN\n" + + "enclosingElement=X {key=Ltest/X;} [in [Working copy] X.java [in test [in src3 [in Completion]]]]\n" + + "visibleElements={\n" + + " fooBar {key=Ltest/X;.fooBar)Ljava/lang/String;} [in X [in [Working copy] X.java [in test [in src3 [in Completion]]]]],\n" + + " wait(long, int) {key=Ljava/lang/Object;.wait(JI)V|Ljava/lang/IllegalMonitorStateException;|Ljava/lang/InterruptedException;} [in Object [in Object.class [in java.lang [in " + jclPath + "]]]],\n" + + " wait(long) {key=Ljava/lang/Object;.wait(J)V|Ljava/lang/IllegalMonitorStateException;|Ljava/lang/InterruptedException;} [in Object [in Object.class [in java.lang [in " + jclPath + "]]]],\n" + + " wait() {key=Ljava/lang/Object;.wait()V|Ljava/lang/IllegalMonitorStateException;|Ljava/lang/InterruptedException;} [in Object [in Object.class [in java.lang [in " + jclPath + "]]]],\n" + + " toString() {key=Ljava/lang/Object;.toString()Ljava/lang/String;} [in Object [in Object.class [in java.lang [in " + jclPath + "]]]],\n" + + " notifyAll() {key=Ljava/lang/Object;.notifyAll()V|Ljava/lang/IllegalMonitorStateException;} [in Object [in Object.class [in java.lang [in " + jclPath + "]]]],\n" + + " notify() {key=Ljava/lang/Object;.notify()V|Ljava/lang/IllegalMonitorStateException;} [in Object [in Object.class [in java.lang [in " + jclPath + "]]]],\n" + + " hashCode() {key=Ljava/lang/Object;.hashCode()I} [in Object [in Object.class [in java.lang [in " + jclPath + "]]]],\n" + + " getClass() {key=Ljava/lang/Object;.getClass()Ljava/lang/Class;} [in Object [in Object.class [in java.lang [in " + jclPath +"]]]],\n" + + " finalize() {key=Ljava/lang/Object;.finalize()V|Ljava/lang/Throwable;} [in Object [in Object.class [in java.lang [in " + jclPath + "]]]],\n" + + " equals(java.lang.Object) {key=Ljava/lang/Object;.equals(Ljava/lang/Object;)Z} [in Object [in Object.class [in java.lang [in " + jclPath + "]]]],\n" + + " clone() {key=Ljava/lang/Object;.clone()Ljava/lang/Object;|Ljava/lang/CloneNotSupportedException;} [in Object [in Object.class [in java.lang [in " + jclPath +"]]]],\n" + + "}", + result.context); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=312603 +public void test0176() throws JavaModelException { + this.workingCopies = new ICompilationUnit[3]; + this.workingCopies[0] = getWorkingCopy( + "/Completion/src3/test/X.java", + "package test;\n" + + "import java.text.MessageFormat;\n" + + "public class X {\n" + + " String fooBar = \"Hi\";" + + " String furchtbar= (fooBar = new String(String.format;\n" + + "}"); + + String str = this.workingCopies[0].getSource(); + int tokenStart = str.lastIndexOf("format"); + int tokenEnd = tokenStart + "format".length() - 1; + int cursorLocation = str.lastIndexOf("format") + "format".length(); + + CompletionResult result = contextComplete(this.workingCopies[0], cursorLocation, true, true); + String jclPath = getExternalJCLPathString(); + assertResults( + "completion offset="+(cursorLocation)+"\n" + + "completion range=["+(tokenStart)+", "+(tokenEnd)+"]\n" + + "completion token=\"format\"\n" + + "completion token kind=TOKEN_KIND_NAME\n" + + "expectedTypesSignatures=null\n" + + "expectedTypesKeys=null\n" + + "completion token location=UNKNOWN\n" + + "enclosingElement=X {key=Ltest/X;} [in [Working copy] X.java [in test [in src3 [in Completion]]]]\n" + + "visibleElements={\n" + + " fooBar {key=Ltest/X;.fooBar)Ljava/lang/String;} [in X [in [Working copy] X.java [in test [in src3 [in Completion]]]]],\n" + + " wait(long, int) {key=Ljava/lang/Object;.wait(JI)V|Ljava/lang/IllegalMonitorStateException;|Ljava/lang/InterruptedException;} [in Object [in Object.class [in java.lang [in " + jclPath + "]]]],\n" + + " wait(long) {key=Ljava/lang/Object;.wait(J)V|Ljava/lang/IllegalMonitorStateException;|Ljava/lang/InterruptedException;} [in Object [in Object.class [in java.lang [in " + jclPath + "]]]],\n" + + " wait() {key=Ljava/lang/Object;.wait()V|Ljava/lang/IllegalMonitorStateException;|Ljava/lang/InterruptedException;} [in Object [in Object.class [in java.lang [in " + jclPath + "]]]],\n" + + " toString() {key=Ljava/lang/Object;.toString()Ljava/lang/String;} [in Object [in Object.class [in java.lang [in " + jclPath + "]]]],\n" + + " notifyAll() {key=Ljava/lang/Object;.notifyAll()V|Ljava/lang/IllegalMonitorStateException;} [in Object [in Object.class [in java.lang [in " + jclPath + "]]]],\n" + + " notify() {key=Ljava/lang/Object;.notify()V|Ljava/lang/IllegalMonitorStateException;} [in Object [in Object.class [in java.lang [in " + jclPath + "]]]],\n" + + " hashCode() {key=Ljava/lang/Object;.hashCode()I} [in Object [in Object.class [in java.lang [in " + jclPath + "]]]],\n" + + " getClass() {key=Ljava/lang/Object;.getClass()Ljava/lang/Class;} [in Object [in Object.class [in java.lang [in " + jclPath +"]]]],\n" + + " finalize() {key=Ljava/lang/Object;.finalize()V|Ljava/lang/Throwable;} [in Object [in Object.class [in java.lang [in " + jclPath + "]]]],\n" + + " equals(java.lang.Object) {key=Ljava/lang/Object;.equals(Ljava/lang/Object;)Z} [in Object [in Object.class [in java.lang [in " + jclPath + "]]]],\n" + + " clone() {key=Ljava/lang/Object;.clone()Ljava/lang/Object;|Ljava/lang/CloneNotSupportedException;} [in Object [in Object.class [in java.lang [in " + jclPath +"]]]],\n" + + "}", + result.context); +} }