diff options
| author | Anirban | 2013-03-11 20:41:11 +0000 |
|---|---|---|
| committer | ssankaran | 2013-03-11 20:41:11 +0000 |
| commit | 7dd940af8bfbaf46f5a69ec7b85437ba951f7d8e (patch) | |
| tree | e2a59bfd2cdf500002915195f750e2b0fc324001 | |
| parent | c4e062ebcfc48b14b7c36c591e88d44ce5b3b5c0 (diff) | |
| download | eclipse.jdt.core-7dd940af8bfbaf46f5a69ec7b85437ba951f7d8e.tar.gz eclipse.jdt.core-7dd940af8bfbaf46f5a69ec7b85437ba951f7d8e.tar.xz eclipse.jdt.core-7dd940af8bfbaf46f5a69ec7b85437ba951f7d8e.zip | |
Fixed Bug 401487 - [1.8][assist] default modifier not proposed while
completing modifiers in interfaces
2 files changed, 188 insertions, 4 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 a050ffe037..2b22377cf8 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 @@ -5,6 +5,10 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * + * This is an implementation of an early-draft specification developed under the Java + * Community Process (JCP) and is made available for testing and evaluation purposes + * only. The code is not compatible with any specification of the JCP. + * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ @@ -1032,6 +1036,11 @@ public static Test suite() { suite.addTest(new CompletionTests("testBug350652l")); suite.addTest(new CompletionTests("testBug350652m")); suite.addTest(new CompletionTests("testBug350652n")); + suite.addTest(new CompletionTests("testBug401487a")); + suite.addTest(new CompletionTests("testBug401487b")); + suite.addTest(new CompletionTests("testBug401487c")); + suite.addTest(new CompletionTests("testBug401487d")); + suite.addTest(new CompletionTests("testBug401487e")); suite.addTest(new CompletionTests("testBug351444")); suite.addTest(new CompletionTests("testBug351444a")); suite.addTest(new CompletionTests("testBug351444b")); @@ -24822,6 +24831,171 @@ public void testBug350652c() throws JavaModelException { COMPLETION_PROJECT.setOptions(options); } } + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=401487 +// Bug 401487 - [1.8][assist] default modifier not proposed while completing modifiers in interfaces +public void testBug401487a() throws JavaModelException { + Map options = COMPLETION_PROJECT.getOptions(true); + Object savedOptionCompliance = options.get(CompilerOptions.OPTION_Compliance); + Object savedOptionSource = options.get(CompilerOptions.OPTION_Source); + try { + options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_8); + options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_8); + COMPLETION_PROJECT.setOptions(options); + this.workingCopies = new ICompilationUnit[3]; + this.workingCopies[0] = getWorkingCopy( + "/Completion/src/test/Test.java", + "package test;"+ + "interface P { \n" + + " def" + + "}\n"); + + CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true); + String str = this.workingCopies[0].getSource(); + String completeBehind = " def"; + int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length(); + this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner); + + assertResults( + "def[POTENTIAL_METHOD_DECLARATION]{def, Ltest.P;, ()V, def, null, 14}\n" + "default[KEYWORD]{default, null, null, default, null, 24}" , + requestor.getResults()); + } finally { + // Restore compliance settings. + options.put(CompilerOptions.OPTION_Compliance, savedOptionCompliance); + options.put(CompilerOptions.OPTION_Source, savedOptionSource); + COMPLETION_PROJECT.setOptions(options); + } +} +public void testBug401487b() throws JavaModelException { + Map options = COMPLETION_PROJECT.getOptions(true); + Object savedOptionCompliance = options.get(CompilerOptions.OPTION_Compliance); + Object savedOptionSource = options.get(CompilerOptions.OPTION_Source); + try { + options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_8); + options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_8); + COMPLETION_PROJECT.setOptions(options); + this.workingCopies = new ICompilationUnit[3]; + this.workingCopies[0] = getWorkingCopy( + "/Completion/src/test/Test.java", + "package test;"+ + "@interface P { \n" + + " def" + + "}\n"); + + CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true); + String str = this.workingCopies[0].getSource(); + String completeBehind = " def"; + int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length(); + this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner); + + assertResults( + "" , + requestor.getResults()); + } finally { + // Restore compliance settings. + options.put(CompilerOptions.OPTION_Compliance, savedOptionCompliance); + options.put(CompilerOptions.OPTION_Source, savedOptionSource); + COMPLETION_PROJECT.setOptions(options); + } +} +public void testBug401487c() throws JavaModelException { + Map options = COMPLETION_PROJECT.getOptions(true); + Object savedOptionCompliance = options.get(CompilerOptions.OPTION_Compliance); + Object savedOptionSource = options.get(CompilerOptions.OPTION_Source); + try { + options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_8); + options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_8); + COMPLETION_PROJECT.setOptions(options); + this.workingCopies = new ICompilationUnit[3]; + this.workingCopies[0] = getWorkingCopy( + "/Completion/src/test/Test.java", + "package test;"+ + "class P { \n" + + " def" + + "}\n"); + + CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true); + String str = this.workingCopies[0].getSource(); + String completeBehind = " def"; + int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length(); + this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner); + + assertResults( + "def[POTENTIAL_METHOD_DECLARATION]{def, Ltest.P;, ()V, def, null, 14}" , + requestor.getResults()); + } finally { + // Restore compliance settings. + options.put(CompilerOptions.OPTION_Compliance, savedOptionCompliance); + options.put(CompilerOptions.OPTION_Source, savedOptionSource); + COMPLETION_PROJECT.setOptions(options); + } +} +public void testBug401487d() throws JavaModelException { + Map options = COMPLETION_PROJECT.getOptions(true); + Object savedOptionCompliance = options.get(CompilerOptions.OPTION_Compliance); + Object savedOptionSource = options.get(CompilerOptions.OPTION_Source); + try { + options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_8); + options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_8); + COMPLETION_PROJECT.setOptions(options); + this.workingCopies = new ICompilationUnit[3]; + this.workingCopies[0] = getWorkingCopy( + "/Completion/src/test/Test.java", + "package test;"+ + "enum P { \n" + + " def" + + "}\n"); + + CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true); + String str = this.workingCopies[0].getSource(); + String completeBehind = " def"; + int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length(); + this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner); + + assertResults( + "" , + requestor.getResults()); + } finally { + // Restore compliance settings. + options.put(CompilerOptions.OPTION_Compliance, savedOptionCompliance); + options.put(CompilerOptions.OPTION_Source, savedOptionSource); + COMPLETION_PROJECT.setOptions(options); + } +} +public void testBug401487e() throws JavaModelException { + Map options = COMPLETION_PROJECT.getOptions(true); + Object savedOptionCompliance = options.get(CompilerOptions.OPTION_Compliance); + Object savedOptionSource = options.get(CompilerOptions.OPTION_Source); + try { + options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_8); + options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_8); + COMPLETION_PROJECT.setOptions(options); + this.workingCopies = new ICompilationUnit[3]; + this.workingCopies[0] = getWorkingCopy( + "/Completion/src/test/Test.java", + "package test;"+ + "public class ZZ { \n" + + " public interface I {" + + " def" + + " }" + + "}\n"); + + CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true); + String str = this.workingCopies[0].getSource(); + String completeBehind = " def"; + int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length(); + this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner); + + assertResults( + "def[POTENTIAL_METHOD_DECLARATION]{def, Ltest.ZZ$I;, ()V, def, null, 14}\n" + "default[KEYWORD]{default, null, null, default, null, 24}" , + requestor.getResults()); + } finally { + // Restore compliance settings. + options.put(CompilerOptions.OPTION_Compliance, savedOptionCompliance); + options.put(CompilerOptions.OPTION_Source, savedOptionSource); + COMPLETION_PROJECT.setOptions(options); + } +} // https://bugs.eclipse.org/bugs/show_bug.cgi?id=350652 // superclass exception type is allowed in multi-catch // types in same CU. Relevance of super type will be less. diff --git a/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java b/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java index 4333cd5df3..0409ada870 100644 --- a/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java +++ b/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java @@ -4,6 +4,10 @@ * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html + * + * This is an implementation of an early-draft specification developed under the Java + * Community Process (JCP) and is made available for testing and evaluation purposes + * only. The code is not compatible with any specification of the JCP. * * Contributors: * IBM Corporation - initial API and implementation @@ -33,7 +37,6 @@ import org.eclipse.jdt.core.compiler.CategorizedProblem; import org.eclipse.jdt.core.compiler.CharOperation; import org.eclipse.jdt.core.compiler.IProblem; import org.eclipse.jdt.core.search.IJavaSearchConstants; - import org.eclipse.jdt.internal.codeassist.complete.*; import org.eclipse.jdt.internal.codeassist.impl.AssistParser; import org.eclipse.jdt.internal.codeassist.impl.Engine; @@ -2181,7 +2184,7 @@ public final class CompletionEngine findTypesAndPackages(this.completionToken, scope, true, true, new ObjectVector()); if (!this.requestor.isIgnored(CompletionProposal.KEYWORD)) { - findKeywordsForMember(this.completionToken, field.modifiers); + findKeywordsForMember(this.completionToken, field.modifiers, astNode); } if (!field.isLocalVariable && field.modifiers == ClassFileConstants.AccDefault) { @@ -2795,7 +2798,7 @@ public final class CompletionEngine setSourceAndTokenRange(type.sourceStart, type.sourceEnd); findTypesAndPackages(this.completionToken, scope.parent, true, true, new ObjectVector()); if (!this.requestor.isIgnored(CompletionProposal.KEYWORD)) { - findKeywordsForMember(this.completionToken, method.modifiers); + findKeywordsForMember(this.completionToken, method.modifiers, null); } if (method.modifiers == ClassFileConstants.AccDefault) { @@ -8125,7 +8128,7 @@ public final class CompletionEngine } } } - private void findKeywordsForMember(char[] token, int modifiers) { + private void findKeywordsForMember(char[] token, int modifiers, ASTNode astNode) { char[][] keywords = new char[Keywords.COUNT][]; int count = 0; @@ -8140,6 +8143,13 @@ public final class CompletionEngine } } + if (astNode instanceof CompletionOnFieldType && + this.compilerOptions.sourceLevel >= ClassFileConstants.JDK1_8) { + FieldBinding astNodeBinding = ((CompletionOnFieldType) astNode).binding; + ReferenceBinding declaringClass = astNodeBinding != null ? astNodeBinding.declaringClass : null; + if (declaringClass != null && declaringClass.isInterface() && !declaringClass.isAnnotationType()) + keywords[count++] = Keywords.DEFAULT; + } if((modifiers & ClassFileConstants.AccAbstract) == 0) { // abtract if((modifiers & ~(ExtraCompilerModifiers.AccVisibilityMASK | ClassFileConstants.AccStatic)) == 0) { |
