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

(-)codeassist/org/eclipse/jdt/internal/codeassist/complete/CompletionParser.java (-2 / +15 lines)
Lines 4321-4327 Link Here
4321
	this.qualifier = -1;
4321
	this.qualifier = -1;
4322
	popUntilElement(K_SWITCH_LABEL);
4322
	popUntilElement(K_SWITCH_LABEL);
4323
	if(topKnownElementKind(COMPLETION_OR_ASSIST_PARSER) != K_SWITCH_LABEL) {
4323
	if(topKnownElementKind(COMPLETION_OR_ASSIST_PARSER) != K_SWITCH_LABEL) {
4324
		popUntilElement(K_BLOCK_DELIMITER);
4324
		if (topKnownElementKind(COMPLETION_OR_ASSIST_PARSER) == K_ARRAY_INITIALIZER) {
4325
			// if recovery is taking place in an array initializer, we should prevent popping
4326
			// upto the enclosing block until the array initializer is properly closed
4327
			// https://bugs.eclipse.org/bugs/show_bug.cgi?id=249704
4328
			popUntilElement(K_ARRAY_INITIALIZER);
4329
		} else {
4330
			popUntilElement(K_BLOCK_DELIMITER);
4331
		}
4325
	}
4332
	}
4326
}
4333
}
4327
public void initializeScanner(){
4334
public void initializeScanner(){
Lines 4606-4612 Link Here
4606
		case TokenNameRBRACE :
4613
		case TokenNameRBRACE :
4607
			super.recoveryTokenCheck();
4614
			super.recoveryTokenCheck();
4608
			if(this.currentElement != oldElement && oldElement instanceof RecoveredBlock) {
4615
			if(this.currentElement != oldElement && oldElement instanceof RecoveredBlock) {
4609
				popElement(K_BLOCK_DELIMITER);
4616
				if (topKnownElementKind(COMPLETION_OR_ASSIST_PARSER) == K_ARRAY_INITIALIZER) {
4617
					// When inside an array initializer, we shud not prematurely pop the enclosing block
4618
					// https://bugs.eclipse.org/bugs/show_bug.cgi?id=249704
4619
					popElement(K_ARRAY_INITIALIZER);
4620
				} else {
4621
					popElement(K_BLOCK_DELIMITER);
4622
				}
4610
			}
4623
			}
4611
			break;
4624
			break;
4612
		case TokenNamecase :
4625
		case TokenNamecase :
(-)src/org/eclipse/jdt/core/tests/model/CompletionTests.java (+39 lines)
Lines 21004-21007 Link Here
21004
			"Try[TYPE_REF]{Try, test, Ltest.Try;, null, null, 27}",
21004
			"Try[TYPE_REF]{Try, test, Ltest.Try;, null, null, 27}",
21005
			requestor.getResults());
21005
			requestor.getResults());
21006
}
21006
}
21007
21008
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=249704
21009
public void testBug249704() throws JavaModelException {
21010
	this.workingCopies = new ICompilationUnit[1];
21011
	this.workingCopies[0] = getWorkingCopy(
21012
		"/Completion/src/test/Try.java",
21013
		"package test;\n" +
21014
		"import java.util.Arrays;\n" +
21015
		"public class Try {\n" +
21016
		"	Object obj = new Object() {\n" +
21017
		"		public void method() {\n" +
21018
		"			Object obj = new Object() {\n" +
21019
		"				int a = 1;\n" +
21020
		"				public void anotherMethod() {\n" +
21021
		"					try {}\n" +
21022
		"					catch (Throwable e) {}\n" +
21023
		"					Arrays.sort(new String[]{\"\"});\n" +
21024
		"				}\n" +
21025
		"			};\n" +
21026
		"			e\n" +
21027
		"		}\n" +
21028
		"	};\n" +
21029
		"}\n");
21030
21031
	CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
21032
	requestor.allowAllRequiredProposals();
21033
	String str = this.workingCopies[0].getSource();
21034
	String completeBehind = "e";
21035
	int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
21036
	this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
21037
21038
	assertResults(
21039
			// without the fix no proposals obtained.
21040
			"Error[TYPE_REF]{Error, java.lang, Ljava.lang.Error;, null, null, 17}\n" +
21041
			"Exception[TYPE_REF]{Exception, java.lang, Ljava.lang.Exception;, null, null, 17}\n" +
21042
			"equals[METHOD_REF]{Try.this.equals(), Ljava.lang.Object;, (Ljava.lang.Object;)Z, equals, (obj), 24}\n" +
21043
			"equals[METHOD_REF]{equals(), Ljava.lang.Object;, (Ljava.lang.Object;)Z, equals, (obj), 27}",
21044
			requestor.getResults());
21045
}
21007
}
21046
}

Return to bug 249704