### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core Index: codeassist/org/eclipse/jdt/internal/codeassist/complete/CompletionParser.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/complete/CompletionParser.java,v retrieving revision 1.211 diff -u -r1.211 CompletionParser.java --- codeassist/org/eclipse/jdt/internal/codeassist/complete/CompletionParser.java 30 Mar 2010 06:36:00 -0000 1.211 +++ codeassist/org/eclipse/jdt/internal/codeassist/complete/CompletionParser.java 6 Apr 2010 15:05:36 -0000 @@ -4321,7 +4321,14 @@ this.qualifier = -1; popUntilElement(K_SWITCH_LABEL); if(topKnownElementKind(COMPLETION_OR_ASSIST_PARSER) != K_SWITCH_LABEL) { - popUntilElement(K_BLOCK_DELIMITER); + if (topKnownElementKind(COMPLETION_OR_ASSIST_PARSER) == K_ARRAY_INITIALIZER) { + // if recovery is taking place in an array initializer, we should prevent popping + // upto the enclosing block until the array initializer is properly closed + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=249704 + popUntilElement(K_ARRAY_INITIALIZER); + } else { + popUntilElement(K_BLOCK_DELIMITER); + } } } public void initializeScanner(){ @@ -4606,7 +4613,13 @@ case TokenNameRBRACE : super.recoveryTokenCheck(); if(this.currentElement != oldElement && oldElement instanceof RecoveredBlock) { - popElement(K_BLOCK_DELIMITER); + if (topKnownElementKind(COMPLETION_OR_ASSIST_PARSER) == K_ARRAY_INITIALIZER) { + // When inside an array initializer, we shud not prematurely pop the enclosing block + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=249704 + popElement(K_ARRAY_INITIALIZER); + } else { + popElement(K_BLOCK_DELIMITER); + } } break; case TokenNamecase : #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.214 diff -u -r1.214 CompletionTests.java --- src/org/eclipse/jdt/core/tests/model/CompletionTests.java 31 Mar 2010 06:49:11 -0000 1.214 +++ src/org/eclipse/jdt/core/tests/model/CompletionTests.java 6 Apr 2010 15:06:05 -0000 @@ -21004,4 +21004,43 @@ "Try[TYPE_REF]{Try, test, Ltest.Try;, null, null, 27}", requestor.getResults()); } + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=249704 +public void testBug249704() throws JavaModelException { + this.workingCopies = new ICompilationUnit[1]; + this.workingCopies[0] = getWorkingCopy( + "/Completion/src/test/Try.java", + "package test;\n" + + "import java.util.Arrays;\n" + + "public class Try {\n" + + " Object obj = new Object() {\n" + + " public void method() {\n" + + " Object obj = new Object() {\n" + + " int a = 1;\n" + + " public void anotherMethod() {\n" + + " try {}\n" + + " catch (Throwable e) {}\n" + + " Arrays.sort(new String[]{\"\"});\n" + + " }\n" + + " };\n" + + " e\n" + + " }\n" + + " };\n" + + "}\n"); + + CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true); + requestor.allowAllRequiredProposals(); + String str = this.workingCopies[0].getSource(); + String completeBehind = "e"; + int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length(); + this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner); + + assertResults( + // without the fix no proposals obtained. + "Error[TYPE_REF]{Error, java.lang, Ljava.lang.Error;, null, null, 17}\n" + + "Exception[TYPE_REF]{Exception, java.lang, Ljava.lang.Exception;, null, null, 17}\n" + + "equals[METHOD_REF]{Try.this.equals(), Ljava.lang.Object;, (Ljava.lang.Object;)Z, equals, (obj), 24}\n" + + "equals[METHOD_REF]{equals(), Ljava.lang.Object;, (Ljava.lang.Object;)Z, equals, (obj), 27}", + requestor.getResults()); +} }