From fddf282e165946b80016bcdc2e5cd169d16409de Mon Sep 17 00:00:00 2001 From: peter Date: Thu, 13 Jul 2017 18:37:16 +0200 Subject: [PATCH] IDEA-175677 Duplicate generic method suggestion when inheriting from a raw type --- .../completion/scope/CompletionElement.java | 8 ++++++-- ...MethodSuggestionWhenInheritingFromRawType.java | 15 +++++++++++++++ .../completion/NormalCompletionTest.groovy | 6 ++++++ 3 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 java/java-tests/testData/codeInsight/completion/normal/DuplicateGenericMethodSuggestionWhenInheritingFromRawType.java diff --git a/java/java-psi-impl/src/com/intellij/codeInsight/completion/scope/CompletionElement.java b/java/java-psi-impl/src/com/intellij/codeInsight/completion/scope/CompletionElement.java index db56f2aa759e..aa62504a8823 100644 --- a/java/java-psi-impl/src/com/intellij/codeInsight/completion/scope/CompletionElement.java +++ b/java/java-psi-impl/src/com/intellij/codeInsight/completion/scope/CompletionElement.java @@ -16,13 +16,15 @@ package com.intellij.codeInsight.completion.scope; import com.intellij.openapi.util.Comparing; -import com.intellij.openapi.util.Pair; +import com.intellij.openapi.util.Trinity; import com.intellij.psi.*; import com.intellij.psi.util.MethodSignature; import com.intellij.psi.util.MethodSignatureUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.Arrays; + public class CompletionElement{ private final Object myElement; private final PsiSubstitutor mySubstitutor; @@ -63,7 +65,9 @@ public class CompletionElement{ return ((PsiPackage)myElement).getQualifiedName(); } if(myElement instanceof PsiMethod){ - return Pair.create(((PsiMethod)myElement).getSignature(mySubstitutor), myQualifierText); + return Trinity.create(((PsiMethod)myElement).getName(), + Arrays.asList(MethodSignatureUtil.calcErasedParameterTypes(((PsiMethod)myElement).getSignature(mySubstitutor))), + myQualifierText); } if (myElement instanceof PsiVariable) { return "#" + ((PsiVariable)myElement).getName(); diff --git a/java/java-tests/testData/codeInsight/completion/normal/DuplicateGenericMethodSuggestionWhenInheritingFromRawType.java b/java/java-tests/testData/codeInsight/completion/normal/DuplicateGenericMethodSuggestionWhenInheritingFromRawType.java new file mode 100644 index 000000000000..e83bcc97505e --- /dev/null +++ b/java/java-tests/testData/codeInsight/completion/normal/DuplicateGenericMethodSuggestionWhenInheritingFromRawType.java @@ -0,0 +1,15 @@ +interface I { + int indexOf(Enum e); +} +abstract class C implements I { + @Override + public int indexOf(Enum e) { + } +} + + +class C2 extends C { + { + index + } +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/java/codeInsight/completion/NormalCompletionTest.groovy b/java/java-tests/testSrc/com/intellij/java/codeInsight/completion/NormalCompletionTest.groovy index e9e270281000..19f2550435a8 100644 --- a/java/java-tests/testSrc/com/intellij/java/codeInsight/completion/NormalCompletionTest.groovy +++ b/java/java-tests/testSrc/com/intellij/java/codeInsight/completion/NormalCompletionTest.groovy @@ -1785,4 +1785,10 @@ class Bar { doTest('<') } + void testDuplicateGenericMethodSuggestionWhenInheritingFromRawType() { + CodeInsightSettings.instance.AUTOINSERT_PAIR_BRACKET = false + configure() + assert myFixture.lookupElementStrings == ['indexOf'] + } + }