diff options
| author | Anirban Chakraborty | 2013-05-13 07:08:50 +0000 |
|---|---|---|
| committer | ssankaran | 2013-05-13 07:08:50 +0000 |
| commit | 4cf047ed8142f9c3048e153b5178c9b3d96df1fb (patch) | |
| tree | 7440997f470a8216972e60f6ce78bfbca283caf8 | |
| parent | 7888e9aab7a7900265cb9a598a42d6a1379c3e64 (diff) | |
| download | eclipse.jdt.core-4cf047ed8142f9c3048e153b5178c9b3d96df1fb.tar.gz eclipse.jdt.core-4cf047ed8142f9c3048e153b5178c9b3d96df1fb.tar.xz eclipse.jdt.core-4cf047ed8142f9c3048e153b5178c9b3d96df1fb.zip | |
Fixed Bug 370971 - Content Assist autocomplete broken within an array of
anonymous classes instances
2 files changed, 61 insertions, 2 deletions
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests.java index ae82b1067c..88b1843536 100644 --- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests.java +++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests.java @@ -1046,6 +1046,7 @@ public static Test suite() { suite.addTest(new CompletionTests("testBug385858c")); suite.addTest(new CompletionTests("testBug385858d")); suite.addTest(new CompletionTests("testBug402574")); + suite.addTest(new CompletionTests("testBug370971")); return suite; } public CompletionTests(String name) { @@ -25933,4 +25934,47 @@ public void testBug402574() throws JavaModelException { COMPLETION_PROJECT.setOptions(options); } } +//Bug 370971 - Content Assist autocomplete broken within an array of anonymous classes instances +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=370971 +public void testBug370971() throws JavaModelException { + Map options = COMPLETION_PROJECT.getOptions(true); + Object savedOptionCompliance = options.get(CompilerOptions.OPTION_Source); + try { + options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_7); + COMPLETION_PROJECT.setOptions(options); + this.workingCopies = new ICompilationUnit[1]; + this.workingCopies[0] = getWorkingCopy( + "/Completion/src/test/ExampleEnumNoAutocomplete.java", + "public class X {\n" + + " private Object[] items = new Object[] {\n" + + " new Object() {\n" + + " @Override\n" + + " public String toString() {\n" + + " return super.toS;\n" + + " }\n" + + " },\n" + + " new Object() { }\n" + + " } ;\n" + + "}\n"); + CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true, false, false, false, true); + requestor.allowAllRequiredProposals(); + requestor.setRequireExtendedContext(true); + requestor.setComputeEnclosingElement(true); + NullProgressMonitor monitor = new NullProgressMonitor(); + String str = this.workingCopies[0].getSource(); + String completeBehind = "return super.toS"; + int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length(); + this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner, monitor); + + assertResults( + "toString[METHOD_REF]{toString(), Ljava.lang.Object;, ()Ljava.lang.String;, toString, null, 65}", + requestor.getResults()); + assertEquals(false, + requestor.canUseDiamond(0)); + } finally { + // Restore compliance settings. + options.put(CompilerOptions.OPTION_Source, savedOptionCompliance); + COMPLETION_PROJECT.setOptions(options); + } +} } diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/RecoveredField.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/RecoveredField.java index 37e922af3e..b4423aa678 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/RecoveredField.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/RecoveredField.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2011 IBM Corporation and others. + * Copyright (c) 2000, 2013 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 @@ -19,6 +19,7 @@ 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.ArrayInitializer; import org.eclipse.jdt.internal.compiler.ast.ArrayQualifiedTypeReference; import org.eclipse.jdt.internal.compiler.ast.ArrayTypeReference; import org.eclipse.jdt.internal.compiler.ast.Expression; @@ -198,6 +199,12 @@ public FieldDeclaration updatedFieldDeclaration(int depth, Set knownTypes){ if (this.anonymousTypes != null) { if(this.fieldDeclaration.initialization == null) { + ArrayInitializer recoveredInitializers = null; + int recoveredInitializersCount = 0; + if (this.anonymousTypeCount > 1) { + recoveredInitializers = new ArrayInitializer(); + recoveredInitializers.expressions = new Expression[this.anonymousTypeCount]; + } for (int i = 0; i < this.anonymousTypeCount; i++){ RecoveredType recoveredType = this.anonymousTypes[i]; TypeDeclaration typeDeclaration = recoveredType.typeDeclaration; @@ -208,7 +215,15 @@ public FieldDeclaration updatedFieldDeclaration(int depth, Set knownTypes){ if (recoveredType.preserveContent){ TypeDeclaration anonymousType = recoveredType.updatedTypeDeclaration(depth + 1, knownTypes); if (anonymousType != null) { - this.fieldDeclaration.initialization = anonymousType.allocation; + if (this.anonymousTypeCount > 1) { + if (recoveredInitializersCount == 0) { + this.fieldDeclaration.initialization = recoveredInitializers; + } + recoveredInitializers.expressions[recoveredInitializersCount++] = anonymousType.allocation; + } + else { + this.fieldDeclaration.initialization = anonymousType.allocation; + } int end = anonymousType.declarationSourceEnd; if (end > this.fieldDeclaration.declarationSourceEnd) { // https://bugs.eclipse.org/bugs/show_bug.cgi?id=307337 this.fieldDeclaration.declarationSourceEnd = end; |
