View | Details | Raw Unified | Return to bug 325481 | Differences between
and this patch

Collapse All | Expand All

(-)codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java (-10 / +21 lines)
Lines 5975-5987 Link Here
5975
		int receiverEnd) {
5975
		int receiverEnd) {
5976
5976
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
5979
		int fieldBeingCompletedId = -1;
5980
		for (int f = fields.length; --f >=0;) {
5981
			FieldBinding field = fields[f];
5982
			FieldDeclaration fieldDeclaration = field.sourceField();
5983
			if (fieldDeclaration != null && fieldDeclaration.initialization != null) {
5984
				// We're asking for a proposal inside this field's initialization. So record its id
5985
				fieldBeingCompletedId = field.id;
5986
				break;
5987
			}
5988
		}
5978
		// Inherited fields which are hidden by subclasses are filtered out
5989
		// Inherited fields which are hidden by subclasses are filtered out
5979
		// No visibility checks can be performed without the scope & invocationSite
5990
		// No visibility checks can be performed without the scope & invocationSite
5980
5991
5981
		int fieldLength = fieldName.length;
5992
		int fieldLength = fieldName.length;
5982
		next : for (int f = fields.length; --f >= 0;) {
5993
		next : for (int f = fields.length; --f >= 0;) {
5983
			FieldBinding field = fields[f];
5994
			FieldBinding field = fields[f];
5984
5995
			
5996
			if (fieldBeingCompletedId >= 0) {
5997
				// Content assist invoked inside some field's initialization.
5998
				// bug 310427 and 325481
5999
				if (field.id >= fieldBeingCompletedId)
6000
					// Don't propose field which is being declared currently
6001
					// Don't propose fields declared after the current field declaration statement
6002
					continue next;
6003
			}
6004
			
5985
			if (field.isSynthetic())	continue next;
6005
			if (field.isSynthetic())	continue next;
5986
6006
5987
			if (onlyStaticFields && !field.isStatic()) continue next;
6007
			if (onlyStaticFields && !field.isStatic()) continue next;
Lines 6003-6017 Link Here
6003
			// https://bugs.eclipse.org/bugs/show_bug.cgi?id=195346
6023
			// https://bugs.eclipse.org/bugs/show_bug.cgi?id=195346
6004
			if (this.assistNodeIsInsideCase && field.type instanceof ArrayBinding)
6024
			if (this.assistNodeIsInsideCase && field.type instanceof ArrayBinding)
6005
				continue next;
6025
				continue next;
6006
			
6007
			// https://bugs.eclipse.org/bugs/show_bug.cgi?id=310427
6008
			// Don't propose field which is being declared currently
6009
			// Don't propose fields declared after the current field declaration statement
6010
			if (this.parser.assistNodeParent instanceof FieldDeclaration) {
6011
				FieldDeclaration fieldDeclaration = (FieldDeclaration) this.parser.assistNodeParent;
6012
				if (field.id >= fieldDeclaration.binding.id)
6013
					continue next;
6014
			}
6015
6026
6016
			boolean prefixRequired = false;
6027
			boolean prefixRequired = false;
6017
6028
(-)src/org/eclipse/jdt/core/tests/model/CompletionTests.java (+31 lines)
Lines 21696-21699 Link Here
21696
			"returnZero[METHOD_REF_WITH_CASTED_RECEIVER]{((CompletionAfterInstanceOf)a).returnZero(), Ltest.CompletionAfterInstanceOf;, ()I, Ltest.CompletionAfterInstanceOf;, returnZero, null, replace["+start2+", "+end2+"], token["+start1+", "+end1+"], receiver["+start3+", "+end3+"], " + (relevance1) + "}",
21696
			"returnZero[METHOD_REF_WITH_CASTED_RECEIVER]{((CompletionAfterInstanceOf)a).returnZero(), Ltest.CompletionAfterInstanceOf;, ()I, Ltest.CompletionAfterInstanceOf;, returnZero, null, replace["+start2+", "+end2+"], token["+start1+", "+end1+"], receiver["+start3+", "+end3+"], " + (relevance1) + "}",
21697
			requestor.getResults());
21697
			requestor.getResults());
21698
}
21698
}
21699
21700
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=325481
21701
// To verify that when content assist is invoked inside a field initialization,
21702
// the field being declared and the ones declared after it are not proposed.
21703
public void test325481() throws JavaModelException {
21704
    this.workingCopies = new ICompilationUnit[1];
21705
    this.workingCopies[0] = getWorkingCopy(
21706
        "/Completion/src3/test/X.java",
21707
        "package test;\n" +
21708
        "public class X {\n" +
21709
        "    void foo(String s) {}\n" +
21710
        "    String myString = \"\";\n" +
21711
        "    String myString2 = \"\";\n" +
21712
        "    String myString3 = (myString = String.format(String.format(my\n" +
21713
        "	 String myString4 = \"hello\";\n" +		// should not be proposed
21714
        "}");
21715
21716
    CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
21717
    String str = this.workingCopies[0].getSource();
21718
    final String completeBehind = "String.format(my";
21719
    int cursorLocation = str.lastIndexOf(completeBehind) +
21720
    completeBehind.length();
21721
    this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
21722
21723
    assertResults(
21724
            "MyClass[TYPE_REF]{mypackage.MyClass, mypackage, Lmypackage.MyClass;, null, null, " + (R_NON_STATIC + R_UNQUALIFIED) + "}\n" + 
21725
            "mypackage[PACKAGE_REF]{mypackage, mypackage, null, null, null, " + (R_NON_STATIC + R_UNQUALIFIED + R_CASE) + "}\n" + 
21726
            "myString[FIELD_REF]{myString, Ltest.X;, Ljava.lang.String;, myString, null, " + (R_NON_STATIC + R_UNQUALIFIED + R_CASE + R_NON_RESTRICTED) + "}\n" +
21727
            "myString2[FIELD_REF]{myString2, Ltest.X;, Ljava.lang.String;, myString2, null, " + (R_NON_STATIC + R_UNQUALIFIED + R_CASE + R_NON_RESTRICTED) + "}",
21728
            requestor.getResults());
21729
}
21699
}
21730
}

Return to bug 325481