### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core Index: compiler/org/eclipse/jdt/internal/compiler/parser/RecoveredField.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/RecoveredField.java,v retrieving revision 1.41 diff -u -r1.41 RecoveredField.java --- compiler/org/eclipse/jdt/internal/compiler/parser/RecoveredField.java 31 Mar 2010 04:57:50 -0000 1.41 +++ compiler/org/eclipse/jdt/internal/compiler/parser/RecoveredField.java 21 Apr 2010 19:30:37 -0000 @@ -16,11 +16,11 @@ import java.util.HashSet; import java.util.Set; +import org.eclipse.jdt.internal.compiler.ast.ASTNode; import org.eclipse.jdt.internal.compiler.ast.AbstractVariableDeclaration; import org.eclipse.jdt.internal.compiler.ast.Annotation; import org.eclipse.jdt.internal.compiler.ast.ArrayQualifiedTypeReference; import org.eclipse.jdt.internal.compiler.ast.ArrayTypeReference; -import org.eclipse.jdt.internal.compiler.ast.ASTNode; import org.eclipse.jdt.internal.compiler.ast.Expression; import org.eclipse.jdt.internal.compiler.ast.FieldDeclaration; import org.eclipse.jdt.internal.compiler.ast.Statement; @@ -247,7 +247,8 @@ updateSourceEndIfNecessary(braceEnd - 1); return this.parent; } else { - this.alreadyCompletedFieldInitialization = true; + if (this.fieldDeclaration.declarationSourceEnd > 0) + this.alreadyCompletedFieldInitialization = true; } } return this; @@ -265,11 +266,18 @@ * in which case the bodyStart is updated. */ public RecoveredElement updateOnOpeningBrace(int braceStart, int braceEnd){ - if (this.fieldDeclaration.declarationSourceEnd == 0 - && (this.fieldDeclaration.type instanceof ArrayTypeReference || this.fieldDeclaration.type instanceof ArrayQualifiedTypeReference) - && !this.alreadyCompletedFieldInitialization){ - this.bracketBalance++; - return null; // no update is necessary (array initializer) + if (this.fieldDeclaration.declarationSourceEnd == 0) { + if (this.fieldDeclaration.type instanceof ArrayTypeReference || this.fieldDeclaration.type instanceof ArrayQualifiedTypeReference) { + if (!this.alreadyCompletedFieldInitialization) { + this.bracketBalance++; + return null; // no update is necessary (array initializer) + } + } else { // https://bugs.eclipse.org/bugs/show_bug.cgi?id=308980 + // in case an initializer bracket is opened in a non-array field + // eg. int field = {.. + this.bracketBalance++; + return null; // no update is necessary (array initializer) + } } if (this.fieldDeclaration.declarationSourceEnd == 0 && this.fieldDeclaration.getKind() == AbstractVariableDeclaration.ENUM_CONSTANT){ #P org.eclipse.jdt.core.tests.compiler Index: src/org/eclipse/jdt/core/tests/compiler/parser/CompletionParserTest2.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/CompletionParserTest2.java,v retrieving revision 1.51 diff -u -r1.51 CompletionParserTest2.java --- src/org/eclipse/jdt/core/tests/compiler/parser/CompletionParserTest2.java 28 Apr 2009 17:17:31 -0000 1.51 +++ src/org/eclipse/jdt/core/tests/compiler/parser/CompletionParserTest2.java 21 Apr 2010 19:30:49 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. + * Copyright (c) 2000, 2010 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -1839,7 +1839,7 @@ String completeBehind = "zzz"; int cursorLocation = str.indexOf("zzz") + completeBehind.length() - 1; - String expectedCompletionNodeToString = ""; + String expectedCompletionNodeToString = ""; String expectedParentNodeToString = ""; String completionIdentifier = "zzz"; String expectedReplacedSource = "zzz"; @@ -1848,6 +1848,7 @@ "public class X {\n" + " Object o;\n" + " {\n" + + " ;\n" + " }\n" + " public X() {\n" + " }\n" + @@ -2063,7 +2064,7 @@ String completeBehind = "zzz"; int cursorLocation = str.indexOf("zzz") + completeBehind.length() - 1; - String expectedCompletionNodeToString = ""; + String expectedCompletionNodeToString = ""; String expectedParentNodeToString = ""; String completionIdentifier = "zzz"; String expectedReplacedSource = "zzz"; @@ -2072,6 +2073,7 @@ "public class X {\n" + " Object o;\n" + " {\n" + + " ;\n" + " }\n" + " public X() {\n" + " }\n" + @@ -4115,16 +4117,14 @@ String completeBehind = "zzz"; int cursorLocation = str.indexOf("zzz") + completeBehind.length() - 1; - String expectedCompletionNodeToString = ""; - String expectedParentNodeToString = ""; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = "new X[]{}"; String completionIdentifier = "zzz"; String expectedReplacedSource = "zzz"; String expectedUnitDisplayString = "package p;\n" + "public class X {\n" + - " Object o;\n" + - " {\n" + - " }\n" + + " Object o = new X[]{};\n" + " public X() {\n" + " }\n" + "}\n"; @@ -4150,16 +4150,13 @@ int cursorLocation = str.indexOf("zzz") + completeBehind.length() - 1; String expectedCompletionNodeToString = ""; - String expectedParentNodeToString = ""; + String expectedParentNodeToString = "new X[]{}"; String completionIdentifier = "zzz"; String expectedReplacedSource = "zzz"; String expectedUnitDisplayString = "package p;\n" + "public class X {\n" + - " Object o;\n" + - " {\n" + - " ;\n" + - " }\n" + + " Object o = new X[]{};\n" + " public X() {\n" + " }\n" + "}\n"; @@ -4332,16 +4329,14 @@ String completeBehind = "zzz"; int cursorLocation = str.indexOf("zzz") + completeBehind.length() - 1; - String expectedCompletionNodeToString = ""; - String expectedParentNodeToString = ""; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = "new X[]{}"; String completionIdentifier = "zzz"; String expectedReplacedSource = "zzz"; String expectedUnitDisplayString = "package p;\n" + "public class X {\n" + - " Object o;\n" + - " {\n" + - " }\n" + + " Object o = new X[]{};\n" + " public X() {\n" + " }\n" + "}\n"; @@ -4368,16 +4363,13 @@ int cursorLocation = str.indexOf("zzz") + completeBehind.length() - 1; String expectedCompletionNodeToString = ""; - String expectedParentNodeToString = ""; + String expectedParentNodeToString = "new X[]{}"; String completionIdentifier = "zzz"; String expectedReplacedSource = "zzz"; String expectedUnitDisplayString = "package p;\n" + "public class X {\n" + - " Object o;\n" + - " {\n" + - " ;\n" + - " }\n" + + " Object o = new X[]{};\n" + " public X() {\n" + " }\n" + "}\n"; @@ -4927,16 +4919,14 @@ String completeBehind = "zzz"; int cursorLocation = str.indexOf("zzz") + completeBehind.length() - 1; - String expectedCompletionNodeToString = ""; - String expectedParentNodeToString = ""; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = "new int[]{}"; String completionIdentifier = "zzz"; String expectedReplacedSource = "zzz"; String expectedUnitDisplayString = "package p;\n" + "public class X {\n" + - " int o;\n" + - " {\n" + - " }\n" + + " int o = new int[]{};\n" + " public X() {\n" + " }\n" + "}\n"; @@ -4962,16 +4952,13 @@ int cursorLocation = str.indexOf("zzz") + completeBehind.length() - 1; String expectedCompletionNodeToString = ""; - String expectedParentNodeToString = ""; + String expectedParentNodeToString = "new int[]{}"; String completionIdentifier = "zzz"; String expectedReplacedSource = "zzz"; String expectedUnitDisplayString = "package p;\n" + "public class X {\n" + - " int o;\n" + - " {\n" + - " ;\n" + - " }\n" + + " int o = new int[]{};\n" + " public X() {\n" + " }\n" + "}\n"; @@ -5148,16 +5135,14 @@ String completeBehind = "zzz"; int cursorLocation = str.indexOf("zzz") + completeBehind.length() - 1; - String expectedCompletionNodeToString = ""; - String expectedParentNodeToString = ""; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = "new int[]{}"; String completionIdentifier = "zzz"; String expectedReplacedSource = "zzz"; String expectedUnitDisplayString = "package p;\n" + "public class X {\n" + - " int o;\n" + - " {\n" + - " }\n" + + " int o = new int[]{};\n" + " public X() {\n" + " }\n" + "}\n"; @@ -5184,16 +5169,13 @@ int cursorLocation = str.indexOf("zzz") + completeBehind.length() - 1; String expectedCompletionNodeToString = ""; - String expectedParentNodeToString = ""; + String expectedParentNodeToString = "new int[]{}"; String completionIdentifier = "zzz"; String expectedReplacedSource = "zzz"; String expectedUnitDisplayString = "package p;\n" + "public class X {\n" + - " int o;\n" + - " {\n" + - " ;\n" + - " }\n" + + " int o = new int[]{};\n" + " public X() {\n" + " }\n" + "}\n"; @@ -5381,16 +5363,14 @@ String completeBehind = "zzz"; int cursorLocation = str.indexOf("zzz") + completeBehind.length() - 1; - String expectedCompletionNodeToString = ""; - String expectedParentNodeToString = ""; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = "new X[]{}"; String completionIdentifier = "zzz"; String expectedReplacedSource = "zzz"; String expectedUnitDisplayString = "package p;\n" + "public class X {\n" + - " X o;\n" + - " {\n" + - " }\n" + + " X o = new X[]{};\n" + " public X() {\n" + " }\n" + "}\n"; @@ -5416,16 +5396,13 @@ int cursorLocation = str.indexOf("zzz") + completeBehind.length() - 1; String expectedCompletionNodeToString = ""; - String expectedParentNodeToString = ""; + String expectedParentNodeToString = "new X[]{}"; String completionIdentifier = "zzz"; String expectedReplacedSource = "zzz"; String expectedUnitDisplayString = "package p;\n" + "public class X {\n" + - " X o;\n" + - " {\n" + - " ;\n" + - " }\n" + + " X o = new X[]{};\n" + " public X() {\n" + " }\n" + "}\n"; @@ -5601,16 +5578,14 @@ String completeBehind = "zzz"; int cursorLocation = str.indexOf("zzz") + completeBehind.length() - 1; - String expectedCompletionNodeToString = ""; - String expectedParentNodeToString = ""; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = "new X[]{}"; String completionIdentifier = "zzz"; String expectedReplacedSource = "zzz"; String expectedUnitDisplayString = "package p;\n" + "public class X {\n" + - " X o;\n" + - " {\n" + - " }\n" + + " X o = new X[]{};\n" + " public X() {\n" + " }\n" + "}\n"; @@ -5637,16 +5612,13 @@ int cursorLocation = str.indexOf("zzz") + completeBehind.length() - 1; String expectedCompletionNodeToString = ""; - String expectedParentNodeToString = ""; + String expectedParentNodeToString = "new X[]{}"; String completionIdentifier = "zzz"; String expectedReplacedSource = "zzz"; String expectedUnitDisplayString = "package p;\n" + "public class X {\n" + - " X o;\n" + - " {\n" + - " ;\n" + - " }\n" + + " X o = new X[]{};\n" + " public X() {\n" + " }\n" + "}\n"; Index: src/org/eclipse/jdt/core/tests/compiler/parser/DietRecoveryTest.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/DietRecoveryTest.java,v retrieving revision 1.62 diff -u -r1.62 DietRecoveryTest.java --- src/org/eclipse/jdt/core/tests/compiler/parser/DietRecoveryTest.java 31 Mar 2010 06:49:22 -0000 1.62 +++ src/org/eclipse/jdt/core/tests/compiler/parser/DietRecoveryTest.java 21 Apr 2010 19:30:55 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. + * Copyright (c) 2000, 2010 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -3952,8 +3952,6 @@ " class Y {\n" + " public String s;\n" + " static int y;\n" + - " {\n" + - " }\n" + " public int i = 0;\n" + " Y() {\n" + " }\n" + @@ -3973,9 +3971,6 @@ " class Y {\n" + " public String s;\n" + " static int y;\n" + - " {\n" + - " ;\n" + - " }\n" + " public int i = 0;\n" + " Y() {\n" + " super();\n" + @@ -4000,8 +3995,6 @@ " class Y {\n" + " public String s;\n" + " static int y;\n" + - " {\n" + - " }\n" + " public int i;\n" + " Y() {\n" + " }\n" + @@ -6386,10 +6379,6 @@ String expectedCompletionDietUnitToString = "public class X {\n" + " static int B;\n" + - " {\n" + - " }\n" + - " {\n" + - " }\n" + " public X() {\n" + " }\n" + " () {\n" + @@ -6517,10 +6506,7 @@ String expectedCompletionDietUnitToString = "public class X {\n" + " int a;\n" + - " {\n" + - " }\n" + - " {\n" + - " }\n" + + " int b;\n" + " public X() {\n" + " }\n" + "}\n"; #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.216 diff -u -r1.216 CompletionTests.java --- src/org/eclipse/jdt/core/tests/model/CompletionTests.java 21 Apr 2010 12:06:41 -0000 1.216 +++ src/org/eclipse/jdt/core/tests/model/CompletionTests.java 21 Apr 2010 19:31:15 -0000 @@ -21097,4 +21097,93 @@ "toWelcome[METHOD_REF_WITH_CASTED_RECEIVER]{((MyString)chars).toWelcome(), Ltest.MyString;, ()Ljava.lang.String;, Ltest.MyString;, null, null, toWelcome, null, replace[" + start2 +", " + end2 + "], token[" + start1 + ", " + end1 + "], receiver[" + start3 + ", " + end3 + "], " + relevance1 + "}", requestor.getResults()); } + + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=308980 +public void testBug308980a() 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" + + " public static final AClass a1 = new JustTry(\n" + + " new byte[][] {\n" + + " {0x00,0x3C},\n" + + " {0x04,0x2C}}) {\n" + + " int justReturn (int a){\n" + + " return a;\n" + + " }\n" + + " };\n" + + " public static final AC" + + "}\n" + + "class AClass{\n" + + " public byte[][] field1;\n" + + " public AClass(byte[][] byteArray) {\n" + + " field1 = byteArray;\n" + + " }\n" + + "}\n" + + "abstract class JustTry extends AClass {\n" + + " public byte[][] field1;\n" + + " public JustTry (byte[][] byteArray){\n" + + " field1 = byteArray;\n" + + " }\n" + + " abstract int justReturn(int a);\n" + + "}\n"); + + CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true); + requestor.allowAllRequiredProposals(); + String str = this.workingCopies[0].getSource(); + String completeBehind = "public static final AC"; + int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length(); + this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner); + + assertResults( + "AClass[TYPE_REF]{AClass, test, Ltest.AClass;, null, null, 27}", + requestor.getResults()); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=308980 +public void testBug308980b() 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" + + " public static final test.AClass a1 = new JustTry(\n" + + " new byte[][] {\n" + + " {0x00,0x3C},\n" + + " {0x04,0x2C}}) {\n" + + " int justReturn (int a){\n" + + " return a;\n" + + " }\n" + + " };\n" + + " public static final AC" + + "}\n" + + "class AClass{\n" + + " public byte[][] field1;\n" + + " public AClass(byte[][] byteArray) {\n" + + " field1 = byteArray;\n" + + " }\n" + + "}\n" + + "abstract class JustTry extends AClass {\n" + + " public byte[][] field1;\n" + + " public JustTry (byte[][] byteArray){\n" + + " field1 = byteArray;\n" + + " }\n" + + " abstract int justReturn(int a);\n" + + "}\n"); + + CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true); + requestor.allowAllRequiredProposals(); + String str = this.workingCopies[0].getSource(); + String completeBehind = "public static final AC"; + int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length(); + this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner); + + assertResults( + "AClass[TYPE_REF]{AClass, test, Ltest.AClass;, null, null, 27}", + requestor.getResults()); +} }