From 1d08cd44007ce514f9a6e9af40b6e0eb14137b4e Mon Sep 17 00:00:00 2001 From: anna Date: Wed, 23 Oct 2013 12:10:58 +0200 Subject: [PATCH] merge completion variants with same method erasures --- .../scope/JavaCompletionProcessor.java | 23 +++++++++++++++---- .../completion/normal/SuperErasure.java | 15 ++++++++++++ .../completion/normal/SuperErasure_after.java | 15 ++++++++++++ .../completion/NormalCompletionTest.groovy | 5 ++++ 4 files changed, 54 insertions(+), 4 deletions(-) create mode 100644 java/java-tests/testData/codeInsight/completion/normal/SuperErasure.java create mode 100644 java/java-tests/testData/codeInsight/completion/normal/SuperErasure_after.java diff --git a/java/java-impl/src/com/intellij/codeInsight/completion/scope/JavaCompletionProcessor.java b/java/java-impl/src/com/intellij/codeInsight/completion/scope/JavaCompletionProcessor.java index 8260793676fc..87cea9397b93 100644 --- a/java/java-impl/src/com/intellij/codeInsight/completion/scope/JavaCompletionProcessor.java +++ b/java/java-impl/src/com/intellij/codeInsight/completion/scope/JavaCompletionProcessor.java @@ -30,10 +30,9 @@ import com.intellij.psi.infos.CandidateInfo; import com.intellij.psi.scope.BaseScopeProcessor; import com.intellij.psi.scope.ElementClassHint; import com.intellij.psi.scope.JavaScopeProcessorEvent; -import com.intellij.psi.util.PsiTreeUtil; -import com.intellij.psi.util.PsiUtil; -import com.intellij.psi.util.PsiUtilCore; +import com.intellij.psi.util.*; import gnu.trove.THashSet; +import gnu.trove.TObjectHashingStrategy; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -50,7 +49,23 @@ public class JavaCompletionProcessor extends BaseScopeProcessor implements Eleme private boolean myStatic = false; private PsiElement myDeclarationHolder = null; - private final Set myResultNames = new THashSet(); + private final Set myResultNames = new THashSet(new TObjectHashingStrategy() { + @Override + public int computeHashCode(Object object) { + if (object instanceof MethodSignature) { + return MethodSignatureUtil.METHOD_PARAMETERS_ERASURE_EQUALITY.computeHashCode((MethodSignature)object); + } + return object.hashCode(); + } + + @Override + public boolean equals(Object o1, Object o2) { + if (o1 instanceof MethodSignature && o2 instanceof MethodSignature) { + return MethodSignatureUtil.METHOD_PARAMETERS_ERASURE_EQUALITY.equals((MethodSignature)o1, (MethodSignature)o2); + } + return o1.equals(o2); + } + }); private final List myResults = new ArrayList(); private final List myFilteredResults = new ArrayList(); private final PsiElement myElement; diff --git a/java/java-tests/testData/codeInsight/completion/normal/SuperErasure.java b/java/java-tests/testData/codeInsight/completion/normal/SuperErasure.java new file mode 100644 index 000000000000..2304ec8e977c --- /dev/null +++ b/java/java-tests/testData/codeInsight/completion/normal/SuperErasure.java @@ -0,0 +1,15 @@ +import java.util.*; +abstract class GenericPanelControl { + protected abstract void _performAction(List rowVector); +} + +class WorkflowPanelControl extends GenericPanelControl { + protected void _performAction(List rowVector) { + } +} + +class WorkflowSubPanelControl extends WorkflowPanelControl { + protected void _performAction(List rowVector) { + super._ + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/completion/normal/SuperErasure_after.java b/java/java-tests/testData/codeInsight/completion/normal/SuperErasure_after.java new file mode 100644 index 000000000000..594751db59dd --- /dev/null +++ b/java/java-tests/testData/codeInsight/completion/normal/SuperErasure_after.java @@ -0,0 +1,15 @@ +import java.util.*; +abstract class GenericPanelControl { + protected abstract void _performAction(List rowVector); +} + +class WorkflowPanelControl extends GenericPanelControl { + protected void _performAction(List rowVector) { + } +} + +class WorkflowSubPanelControl extends WorkflowPanelControl { + protected void _performAction(List rowVector) { + super._performAction(); + } +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionTest.groovy b/java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionTest.groovy index bdfbfe597f3d..48febc3e52c2 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionTest.groovy +++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionTest.groovy @@ -323,6 +323,11 @@ public class NormalCompletionTest extends LightFixtureCompletionTestCase { checkResultByFile("MethodWithLeftParTailType2_after.java"); } + public void testSuperErasure() throws Exception { + configureByFile("SuperErasure.java"); + checkResultByFile("SuperErasure_after.java"); + } + public void testMethodWithLeftParTailTypeNoPairBrace() throws Exception { final boolean old = CodeInsightSettings.getInstance().AUTOINSERT_PAIR_BRACKET; CodeInsightSettings.getInstance().AUTOINSERT_PAIR_BRACKET = false;