### 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.422 diff -u -r1.422 CompletionEngine.java --- codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java 23 Nov 2010 10:21:48 -0000 1.422 +++ codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java 23 Dec 2010 14:26:54 -0000 @@ -5977,6 +5977,7 @@ ObjectVector newFieldsFound = new ObjectVector(); // if the proposal is being asked inside a field's initialization, we'll record its id int fieldBeingCompletedId = -1; + boolean isFieldBeingCompletedStatic = false; for (int f = fields.length; --f >=0;) { FieldBinding field = fields[f]; FieldDeclaration fieldDeclaration = field.sourceField(); @@ -5988,12 +5989,14 @@ astNode.sourceEnd <= fieldDeclaration.initialization.sourceEnd) { // completion is inside a field initializer fieldBeingCompletedId = field.id; + isFieldBeingCompletedStatic = field.isStatic(); break; } } else { // The sourceEnd may not yet be set CompletionNodeDetector detector = new CompletionNodeDetector(astNode, fieldDeclaration.initialization); if (detector.containsCompletionNode()) { // completion is inside a field initializer fieldBeingCompletedId = field.id; + isFieldBeingCompletedStatic = field.isStatic(); break; } } @@ -6011,7 +6014,14 @@ if (fieldBeingCompletedId >= 0 && field.id >= fieldBeingCompletedId) { // Don't propose field which is being declared currently // Don't propose fields declared after the current field declaration statement - continue next; + // Though, if field is static, then it can be still be proposed + if (!field.isStatic()) { + continue next; + } else if (isFieldBeingCompletedStatic) { + // static fields can't be proposed before they are actually declared if the + // field currently being declared is also static + continue next; + } } if (field.isSynthetic()) continue next; #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.234 diff -u -r1.234 CompletionTests.java --- src/org/eclipse/jdt/core/tests/model/CompletionTests.java 25 Nov 2010 08:43:26 -0000 1.234 +++ src/org/eclipse/jdt/core/tests/model/CompletionTests.java 23 Dec 2010 14:26:56 -0000 @@ -21893,4 +21893,62 @@ COMPLETION_PROJECT.setOptions(options); } } + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=332268 +// To verify that we DO get proposals for static fields that have not yet been declared +// inside a field declaration statement, iff current field is not static +public void testBug332268a() 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" + + " static 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) + "}\n" + + "myVar5[FIELD_REF]{myVar5, Ltest.Test;, I, myVar5, 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=332268 +// To verify that we do not get proposals for static fields that have not yet been declared +// inside a field declaration statement, if current field is static +public void testBug332268b() throws JavaModelException { + this.workingCopies = new ICompilationUnit[1]; + this.workingCopies[0] = getWorkingCopy( + "/Completion/src/test/Test.java", + "package test;"+ + "public class Test {\n" + + " static int myVar1 = 1;\n" + + " int myVar2 = 1;\n" + + " static int myVar3 = myVar;\n" + + " int myVar4 = 1;\n" + + " static 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) + "}", + requestor.getResults()); +} }