### 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.416 diff -u -r1.416 CompletionEngine.java --- codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java 22 Jul 2010 04:25:46 -0000 1.416 +++ codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java 5 Aug 2010 18:52:18 -0000 @@ -6010,6 +6010,13 @@ } ptr--; } + + if (this.parser.assistNodeParent instanceof FieldDeclaration) { + FieldDeclaration fieldDeclaration = (FieldDeclaration) this.parser.assistNodeParent; + if (field.id > fieldDeclaration.binding.id) + // Don't propose fields declared after the current field declaration statement + continue next; + } boolean prefixRequired = false; #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.222 diff -u -r1.222 CompletionTests.java --- src/org/eclipse/jdt/core/tests/model/CompletionTests.java 7 Jul 2010 13:19:15 -0000 1.222 +++ src/org/eclipse/jdt/core/tests/model/CompletionTests.java 5 Aug 2010 18:52:55 -0000 @@ -37,7 +37,7 @@ public class CompletionTests extends AbstractJavaModelCompletionTests { static { -// TESTS_NAMES = new String[] { "testDeprecationCheck17"}; + TESTS_NAMES = new String[] { "testBug310427c"}; } public static Test suite() { return buildModelTestSuite(CompletionTests.class); @@ -21395,6 +21395,36 @@ requestor.getResults()); } + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=310427 +// To verify that we don't get proposals for fields that have not yet been declared +// inside a field declaration statement +public void testBug310427c() throws JavaModelException { + this.workingCopies = new ICompilationUnit[1]; + this.workingCopies[0] = getWorkingCopy( + "/Completion/src/test/Test.java", + "package test;"+ + "public class Test {\n" + + " int myVar1 = 1;\n" + + " int myVar2 = 1;\n" + + " int myVar3 = myVar;\n" + + " int myVar4 = 1;\n" + + " int myVar5 = 1;\n" + + " }\n" + + "}\n"); + + CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true); + String str = this.workingCopies[0].getSource(); + String completeBehind = "int myVar3 = myVar"; + int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length(); + this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner); + + assertResults( + "myVar1[FIELD_REF]{myVar1, Ltest.Test;, I, myVar1, null, " + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED + R_EXACT_EXPECTED_TYPE) + "}\n" + + "myVar2[FIELD_REF]{myVar2, Ltest.Test;, I, myVar2, null, " + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED + R_EXACT_EXPECTED_TYPE) + "}", + requestor.getResults()); +} + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=195346 // To verify that array types aren't proposed inside case, and also // that finals have a higher priority in suggestions inside case expressions.