### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core 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.209 diff -u -r1.209 CompletionParser.java --- codeassist/org/eclipse/jdt/internal/codeassist/complete/CompletionParser.java 16 Oct 2009 11:29:40 -0000 1.209 +++ codeassist/org/eclipse/jdt/internal/codeassist/complete/CompletionParser.java 11 Feb 2010 11:06:05 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. + * Copyright (c) 2000, 2010 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -561,7 +561,8 @@ return; } } - if(expression == this.assistNode + if(expression == this.assistNode + || (expression instanceof Assignment && ((Assignment) expression).expression == this.assistNode) || (expression instanceof AllocationExpression && ((AllocationExpression)expression).type == this.assistNode)){ buildMoreCompletionContext(expression); @@ -575,6 +576,21 @@ } } } + + if (this.astPtr > -1 && this.astStack[this.astPtr] instanceof LocalDeclaration) { + LocalDeclaration local = (LocalDeclaration) this.astStack[this.astPtr]; + if (local.initialization == this.assistNode) { + Statement enclosing = buildMoreCompletionEnclosingContext(local); + if (enclosing != local && enclosing instanceof IfStatement) { + if (this.currentElement instanceof RecoveredBlock) { + // RecoveredLocalVariable must be removed from its parent because the IfStatement will be added instead + RecoveredBlock recoveredBlock = (RecoveredBlock) this.currentElement; + recoveredBlock.statements[--recoveredBlock.statementCount] = null; + this.currentElement = this.currentElement.add(enclosing, 0); + } + } + } + } } public Object becomeSimpleParser() { CompletionScanner completionScanner = (CompletionScanner)this.scanner; #P org.eclipse.jdt.core.tests.model Index: src/org/eclipse/jdt/core/tests/model/CompletionTests.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests.java,v retrieving revision 1.210 diff -u -r1.210 CompletionTests.java --- src/org/eclipse/jdt/core/tests/model/CompletionTests.java 7 Oct 2009 10:42:00 -0000 1.210 +++ src/org/eclipse/jdt/core/tests/model/CompletionTests.java 11 Feb 2010 11:06:21 -0000 @@ -20600,4 +20600,76 @@ requestor.getResults()); } +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=287939 +public void testCompletionAfterInstanceof25_01() throws JavaModelException { + this.workingCopies = new ICompilationUnit[1]; + this.workingCopies[0] = getWorkingCopy( + "/Completion/src/test/CompletionAfterInstanceOf.java", + "package test;\n" + + "public class CompletionAfterInstanceOf {\n" + + " public int returnZero(){ return 0;}\n" + + " public Object a;\n" + + " void bar(){\n" + + " if (this.a instanceof CompletionAfterInstanceOf) {\n" + + " int j = 0;\n" + + " int k = 2;\n" + + " int i = this.a.r\n" + + " int p = 12;\n" + + " }\n" + + "}\n"); + + CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true, false, true, true, true, true); + requestor.allowAllRequiredProposals(); + String str = this.workingCopies[0].getSource(); + String completeBehind = "this.a.r"; + int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length(); + this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner); + + int relevance1 = R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_NON_STATIC + R_NON_RESTRICTED; + int start1 = str.lastIndexOf("r") + "r".length(); + int end1 = start1 + "r".length(); + int start2 = str.lastIndexOf("this.a.r"); + int end2 = start2 + "this.a.r".length(); + int start3 = str.lastIndexOf("this.a."); + int end3 = start3 + "this.a".length(); + assertResults( + "returnZero[METHOD_REF_WITH_CASTED_RECEIVER]{((CompletionAfterInstanceOf)this.a).returnZero(), Ltest.CompletionAfterInstanceOf;, I, Ltest.CompletionAfterInstanceOf;, returnZero, null, replace["+start2+", "+end2+"], token["+start1+", "+end1+"], receiver["+start3+", "+end3+"], " + (relevance1) + "}", + requestor.getResults()); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=287939 +public void testCompletionAfterInstanceof25_02() throws JavaModelException { + this.workingCopies = new ICompilationUnit[1]; + this.workingCopies[0] = getWorkingCopy( + "/Completion/src/test/CompletionAfterInstanceOf.java", + "package test;\n" + + "public class CompletionAfterInstanceOf {\n" + + " public int returnZero(){ return 0;}\n" + + " public Object a;\n" + + " void bar(){\n" + + " int i;\n" + + " if (this.a instanceof CompletionAfterInstanceOf) {\n" + + " i = this.a.r\n" + + " }\n" + + "}\n"); + + CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true, false, true, true, true, true); + requestor.allowAllRequiredProposals(); + String str = this.workingCopies[0].getSource(); + String completeBehind = "this.a.r"; + int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length(); + this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner); + + int relevance1 = R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_NON_STATIC + R_NON_RESTRICTED; + int start1 = str.lastIndexOf("r") + "r".length(); + int end1 = start1 + "r".length(); + int start2 = str.lastIndexOf("this.a.r"); + int end2 = start2 + "this.a.r".length(); + int start3 = str.lastIndexOf("this.a."); + int end3 = start3 + "this.a".length(); + assertResults( + "returnZero[METHOD_REF_WITH_CASTED_RECEIVER]{((CompletionAfterInstanceOf)this.a).returnZero(), Ltest.CompletionAfterInstanceOf;, I, Ltest.CompletionAfterInstanceOf;, returnZero, null, replace["+start2+", "+end2+"], token["+start1+", "+end1+"], receiver["+start3+", "+end3+"], " + (relevance1) + "}", + requestor.getResults()); +} + }