From 3e0d7a41c954ae0ac7e5ece80d1ad761df4a42a4 Mon Sep 17 00:00:00 2001 From: peter Date: Tue, 18 Dec 2012 18:23:56 +0100 Subject: [PATCH] suggest extends&super in wildcards (IDEA-97765, IDEA-57321) --- .../completion/Java15CompletionData.java | 13 ------------- .../completion/JavaCompletionData.java | 8 +++++++- .../keywords/extendsInCastTypeParameters.java | 16 ---------------- .../keywords/extendsInCastTypeParameters2.java | 9 +++++++++ .../extendsInCastTypeParameters_after.java | 16 ---------------- .../completion/KeywordCompletionTest.java | 1 + 6 files changed, 17 insertions(+), 46 deletions(-) create mode 100644 java/java-tests/testData/codeInsight/completion/keywords/extendsInCastTypeParameters2.java diff --git a/java/java-impl/src/com/intellij/codeInsight/completion/Java15CompletionData.java b/java/java-impl/src/com/intellij/codeInsight/completion/Java15CompletionData.java index 82721d62bf1c..b9abe931f720 100644 --- a/java/java-impl/src/com/intellij/codeInsight/completion/Java15CompletionData.java +++ b/java/java-impl/src/com/intellij/codeInsight/completion/Java15CompletionData.java @@ -53,17 +53,4 @@ public class Java15CompletionData extends JavaCompletionData { } } - @Override - protected void initVariantsInClassScope() { - super.initVariantsInClassScope(); - { - //Completion of "extends" & "super" inside wildcards - final CompletionVariant variant = new CompletionVariant(JavaMemberNameCompletionContributor.INSIDE_TYPE_PARAMS_PATTERN); - variant.includeScopeClass(PsiVariable.class, true); - variant.includeScopeClass(PsiExpressionStatement.class, true); - variant.addCompletion(PsiKeyword.SUPER, TailType.HUMBLE_SPACE_BEFORE_WORD); - variant.addCompletion(PsiKeyword.EXTENDS, TailType.HUMBLE_SPACE_BEFORE_WORD); - registerVariant(variant); - } - } } diff --git a/java/java-impl/src/com/intellij/codeInsight/completion/JavaCompletionData.java b/java/java-impl/src/com/intellij/codeInsight/completion/JavaCompletionData.java index d9d4a9dfe31a..99dbcff4bbba 100644 --- a/java/java-impl/src/com/intellij/codeInsight/completion/JavaCompletionData.java +++ b/java/java-impl/src/com/intellij/codeInsight/completion/JavaCompletionData.java @@ -135,7 +135,8 @@ public class JavaCompletionData extends JavaAwareCompletionData { not(psiElement().afterLeaf(PsiKeyword.CASE)), not(psiElement().afterLeaf(psiElement().withText(".").afterLeaf(PsiKeyword.THIS, PsiKeyword.SUPER))), not(psiElement().inside(PsiAnnotation.class)), - not(START_SWITCH)); + not(START_SWITCH), + not(JavaMemberNameCompletionContributor.INSIDE_TYPE_PARAMS_PATTERN)); private static final String[] PRIMITIVE_TYPES = new String[]{ PsiKeyword.SHORT, PsiKeyword.BOOLEAN, @@ -522,6 +523,11 @@ public class JavaCompletionData extends JavaAwareCompletionData { new SameSignatureCallParametersProvider().addCompletions(parameters, new ProcessingContext(), result); } } + + if (JavaMemberNameCompletionContributor.INSIDE_TYPE_PARAMS_PATTERN.accepts(position)) { + result.addElement(new OverrideableSpace(createKeyword(position, PsiKeyword.EXTENDS), TailType.HUMBLE_SPACE_BEFORE_WORD)); + result.addElement(new OverrideableSpace(createKeyword(position, PsiKeyword.SUPER), TailType.HUMBLE_SPACE_BEFORE_WORD)); + } } private static boolean isExpressionPosition(PsiElement position) { diff --git a/java/java-tests/testData/codeInsight/completion/keywords/extendsInCastTypeParameters.java b/java/java-tests/testData/codeInsight/completion/keywords/extendsInCastTypeParameters.java index 78fb3e9f244f..74a5758fd39b 100644 --- a/java/java-tests/testData/codeInsight/completion/keywords/extendsInCastTypeParameters.java +++ b/java/java-tests/testData/codeInsight/completion/keywords/extendsInCastTypeParameters.java @@ -1,19 +1,3 @@ - -/* - * Copyright 2000-2012 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ public class Main { public static void main() { diff --git a/java/java-tests/testData/codeInsight/completion/keywords/extendsInCastTypeParameters2.java b/java/java-tests/testData/codeInsight/completion/keywords/extendsInCastTypeParameters2.java new file mode 100644 index 000000000000..9cf75150bf5e --- /dev/null +++ b/java/java-tests/testData/codeInsight/completion/keywords/extendsInCastTypeParameters2.java @@ -0,0 +1,9 @@ +public class Main { + + public int compare(Object value1, Object value2) { + if (value1 instanceof Comparable && value2 instanceof Comparable) { + return ((Comparable>) value1).compareTo(value2); + } + throw new IllegalArgumentException(); + } +} diff --git a/java/java-tests/testData/codeInsight/completion/keywords/extendsInCastTypeParameters_after.java b/java/java-tests/testData/codeInsight/completion/keywords/extendsInCastTypeParameters_after.java index 4a001127b4c4..7b66670c7198 100644 --- a/java/java-tests/testData/codeInsight/completion/keywords/extendsInCastTypeParameters_after.java +++ b/java/java-tests/testData/codeInsight/completion/keywords/extendsInCastTypeParameters_after.java @@ -1,19 +1,3 @@ - -/* - * Copyright 2000-2012 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ public class Main { public static void main() { diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/completion/KeywordCompletionTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/completion/KeywordCompletionTest.java index ec7b120f74e8..c50a4b5de7cc 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/completion/KeywordCompletionTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/KeywordCompletionTest.java @@ -85,6 +85,7 @@ public class KeywordCompletionTest extends LightCompletionTestCase { checkResultByFile(BASE_PATH + "/" + getTestName(true) + "_after.java"); } public void testExtendsInCastTypeParameters() throws Exception { doTest(false); } + public void testExtendsInCastTypeParameters2() throws Exception { doTest(2, "extends", "super"); } public void testExtendsWithRightContextInClassTypeParameters() throws Exception { doTest(false); } public void testTrueInVariableDeclaration() throws Exception { doTest(true); } public void testNullInIf() throws Exception { doTest(true); }