View | Details | Raw Unified | Return to bug 332268
Collapse All | Expand All

(-)codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java (-1 / +11 lines)
Lines 5977-5982 Link Here
5977
		ObjectVector newFieldsFound = new ObjectVector();
5977
		ObjectVector newFieldsFound = new ObjectVector();
5978
		// if the proposal is being asked inside a field's initialization, we'll record its id
5978
		// if the proposal is being asked inside a field's initialization, we'll record its id
5979
		int fieldBeingCompletedId = -1;
5979
		int fieldBeingCompletedId = -1;
5980
		boolean isFieldBeingCompletedStatic = false;
5980
		for (int f = fields.length; --f >=0;) {
5981
		for (int f = fields.length; --f >=0;) {
5981
			FieldBinding field = fields[f];
5982
			FieldBinding field = fields[f];
5982
			FieldDeclaration fieldDeclaration = field.sourceField();
5983
			FieldDeclaration fieldDeclaration = field.sourceField();
Lines 5988-5999 Link Here
5988
						astNode.sourceEnd <= fieldDeclaration.initialization.sourceEnd) {
5989
						astNode.sourceEnd <= fieldDeclaration.initialization.sourceEnd) {
5989
						// completion is inside a field initializer
5990
						// completion is inside a field initializer
5990
						fieldBeingCompletedId = field.id;
5991
						fieldBeingCompletedId = field.id;
5992
						isFieldBeingCompletedStatic = field.isStatic();
5991
						break;
5993
						break;
5992
					}
5994
					}
5993
				} else { // The sourceEnd may not yet be set
5995
				} else { // The sourceEnd may not yet be set
5994
					CompletionNodeDetector detector = new CompletionNodeDetector(astNode, fieldDeclaration.initialization);
5996
					CompletionNodeDetector detector = new CompletionNodeDetector(astNode, fieldDeclaration.initialization);
5995
					if (detector.containsCompletionNode()) {  // completion is inside a field initializer
5997
					if (detector.containsCompletionNode()) {  // completion is inside a field initializer
5996
						fieldBeingCompletedId = field.id;
5998
						fieldBeingCompletedId = field.id;
5999
						isFieldBeingCompletedStatic = field.isStatic();
5997
						break;
6000
						break;
5998
					}
6001
					}
5999
				}
6002
				}
Lines 6011-6017 Link Here
6011
			if (fieldBeingCompletedId >= 0 && field.id >= fieldBeingCompletedId) {
6014
			if (fieldBeingCompletedId >= 0 && field.id >= fieldBeingCompletedId) {
6012
				// Don't propose field which is being declared currently
6015
				// Don't propose field which is being declared currently
6013
				// Don't propose fields declared after the current field declaration statement
6016
				// Don't propose fields declared after the current field declaration statement
6014
				continue next;
6017
				// Though, if field is static, then it can be still be proposed
6018
				if (!field.isStatic()) { 
6019
					continue next;
6020
				} else if (isFieldBeingCompletedStatic) {
6021
					// static fields can't be proposed before they are actually declared if the 
6022
					// field currently being declared is also static
6023
					continue next;
6024
				}
6015
			}
6025
			}
6016
			
6026
			
6017
			if (field.isSynthetic())	continue next;
6027
			if (field.isSynthetic())	continue next;
(-)src/org/eclipse/jdt/core/tests/model/CompletionTests.java (+58 lines)
Lines 21893-21896 Link Here
21893
		COMPLETION_PROJECT.setOptions(options);	
21893
		COMPLETION_PROJECT.setOptions(options);	
21894
	}
21894
	}
21895
}
21895
}
21896
21897
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=332268
21898
// To verify that we DO get proposals for static fields that have not yet been declared
21899
// inside a field declaration statement, iff current field is not static
21900
public void testBug332268a() throws JavaModelException {
21901
	this.workingCopies = new ICompilationUnit[1];
21902
	this.workingCopies[0] = getWorkingCopy(
21903
		"/Completion/src/test/Test.java",
21904
		"package test;"+
21905
		"public class Test {\n" +
21906
		"       int myVar1 = 1;\n" +
21907
		"		int myVar2 = 1;\n" +
21908
		"		int myVar3 = myVar;\n" +
21909
		"       int myVar4 = 1;\n" +
21910
		"		static int myVar5 = 1;\n" +
21911
		"	}\n" +
21912
		"}\n");
21913
21914
	CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
21915
	String str = this.workingCopies[0].getSource();
21916
	String completeBehind = "int myVar3 = myVar";
21917
	int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
21918
	this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
21919
21920
	assertResults(
21921
			"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" +
21922
			"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" +
21923
			"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) + "}",
21924
			requestor.getResults());
21925
}
21926
21927
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=332268
21928
// To verify that we do not get proposals for static fields that have not yet been declared
21929
// inside a field declaration statement, if current field is static
21930
public void testBug332268b() throws JavaModelException {
21931
	this.workingCopies = new ICompilationUnit[1];
21932
	this.workingCopies[0] = getWorkingCopy(
21933
		"/Completion/src/test/Test.java",
21934
		"package test;"+
21935
		"public class Test {\n" +
21936
		"       static int myVar1 = 1;\n" +
21937
		"		int myVar2 = 1;\n" +
21938
		"		static int myVar3 = myVar;\n" +
21939
		"       int myVar4 = 1;\n" +
21940
		"		static int myVar5 = 1;\n" +
21941
		"	}\n" +
21942
		"}\n");
21943
21944
	CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
21945
	String str = this.workingCopies[0].getSource();
21946
	String completeBehind = "int myVar3 = myVar";
21947
	int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
21948
	this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
21949
21950
	assertResults(
21951
			"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) + "}",
21952
			requestor.getResults());
21953
}
21896
}
21954
}

Return to bug 332268