### 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 20 Apr 2010 09:28:44 -0000 @@ -16,13 +16,14 @@ 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.SingleTypeReference; import org.eclipse.jdt.internal.compiler.ast.Statement; import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration; @@ -247,7 +248,8 @@ updateSourceEndIfNecessary(braceEnd - 1); return this.parent; } else { - this.alreadyCompletedFieldInitialization = true; + if (this.fieldDeclaration.declarationSourceEnd > 0) + this.alreadyCompletedFieldInitialization = true; } } return this; @@ -276,6 +278,14 @@ this.bracketBalance++; return null; // no update is necessary (enum constant) } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=308980 + if (this.fieldDeclaration.declarationSourceEnd == 0 + && this.fieldDeclaration.type instanceof SingleTypeReference) { + // array initializer somewhere in the field declaration even when it isn't an array + // type (eg. int x = new int[] { ...) + this.bracketBalance++; + return null; + } // might be an array initializer this.updateSourceEndIfNecessary(braceStart - 1, braceEnd - 1); return this.parent.updateOnOpeningBrace(braceStart, braceEnd); #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 20 Apr 2010 09:28:57 -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 20 Apr 2010 09:29:04 -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.215 diff -u -r1.215 CompletionTests.java --- src/org/eclipse/jdt/core/tests/model/CompletionTests.java 7 Apr 2010 12:42:43 -0000 1.215 +++ src/org/eclipse/jdt/core/tests/model/CompletionTests.java 20 Apr 2010 09:29:41 -0000 @@ -21043,4 +21043,48 @@ "equals[METHOD_REF]{equals(), Ljava.lang.Object;, (Ljava.lang.Object;)Z, equals, (obj), 27}", requestor.getResults()); } + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=308980 +public void testBug308980() 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 Try {\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()); +} }