diff options
| author | Anirban Chakraborty | 2013-05-16 08:00:29 +0000 |
|---|---|---|
| committer | Jayaprakash Arthanareeswaran | 2013-05-16 10:59:20 +0000 |
| commit | e20104710b1c718dfc518349b7e3e3e20903238f (patch) | |
| tree | 637f9a365f2f1defceb9f0e5b20552e8d282718c | |
| parent | b0085304483984f0cc2d0511332c026b3464a6e0 (diff) | |
| download | eclipse.jdt.core-e20104710b1c718dfc518349b7e3e3e20903238f.tar.gz eclipse.jdt.core-e20104710b1c718dfc518349b7e3e3e20903238f.tar.xz eclipse.jdt.core-e20104710b1c718dfc518349b7e3e3e20903238f.zip | |
Fixed Bug 370971 - Content Assist autocomplete broken within an array of
anonymous classes instances
2 files changed, 61 insertions, 3 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 354bb4a363..b73d13dc6b 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 @@ -1059,7 +1059,7 @@ public static Test suite() { suite.addTest(new CompletionTests("testBug402812b")); suite.addTest(new CompletionTests("testBug402812c")); suite.addTest(new CompletionTests("testBug402812d")); - + suite.addTest(new CompletionTests("testBug370971")); return suite; } public CompletionTests(String name) { @@ -26332,4 +26332,47 @@ public void testBug402812d() throws Exception { COMPLETION_PROJECT.setOptions(completionProjectOptions); } } +//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; |
