diff --git a/java/java-impl/src/com/intellij/codeInsight/completion/methodChains/search/ChainsSearcher.java b/java/java-impl/src/com/intellij/codeInsight/completion/methodChains/search/ChainsSearcher.java index 5f41c38cc578..660e0f7f67c3 100644 --- a/java/java-impl/src/com/intellij/codeInsight/completion/methodChains/search/ChainsSearcher.java +++ b/java/java-impl/src/com/intellij/codeInsight/completion/methodChains/search/ChainsSearcher.java @@ -151,7 +151,7 @@ public class ChainsSearcher { } final MethodsChain methodsChain = currentVertexUnderlying.second.addEdge(resolved, sign.getUnderlying().getOwner(), sign.getWeight()); - if (ParametersMatcher.matchParameters(methodsChain, context).noUnmatched()) { + if (ParametersMatcher.matchParameters(methodsChain, context).noUnmatchedAndHasMatched()) { updated = true; q.addFirst(new WeightAware>( new Pair(sign.getUnderlying(), methodsChain), sign.getWeight())); @@ -221,6 +221,14 @@ public class ChainsSearcher { } } + private static int sumWeight(MaxSizeTreeSet> weightAwareSignatures) { + int weight = 0; + for (WeightAware weightAware : weightAwareSignatures) { + weight += weightAware.getWeight(); + } + return weight; + } + private static boolean doChoose(final SortedSet bigrams, final int currentWeight, final int maxResultSize) { if (bigrams.size() == 1) { return true; diff --git a/java/java-impl/src/com/intellij/codeInsight/completion/methodChains/search/MethodsChain.java b/java/java-impl/src/com/intellij/codeInsight/completion/methodChains/search/MethodsChain.java index 4faef3dd3ce8..517a1d6181b8 100644 --- a/java/java-impl/src/com/intellij/codeInsight/completion/methodChains/search/MethodsChain.java +++ b/java/java-impl/src/com/intellij/codeInsight/completion/methodChains/search/MethodsChain.java @@ -2,12 +2,14 @@ package com.intellij.codeInsight.completion.methodChains.search; import com.intellij.codeInsight.completion.methodChains.completion.context.ChainCompletionContext; import com.intellij.openapi.util.text.StringUtil; -import com.intellij.psi.*; -import com.intellij.psi.util.InheritanceUtil; +import com.intellij.psi.PsiManager; +import com.intellij.psi.PsiMethod; import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.Nullable; -import java.util.*; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; import static com.intellij.util.containers.ContainerUtil.reverse; @@ -81,8 +83,7 @@ public class MethodsChain { if (thisNext == null || thatNext == null) { throw new NullPointerException(); } - if (((thisNext.isConstructor() != thatNext.isConstructor())) - || !thisNext.getName().equals(thatNext.getName())) { + if (((thisNext.isConstructor() != thatNext.isConstructor())) || !thisNext.getName().equals(thatNext.getName())) { return CompareResult.NOT_EQUAL; } } @@ -94,21 +95,25 @@ public class MethodsChain { } - final PsiClass leftQualifier = JavaPsiFacade.getInstance(context.getProject()).findClass(left.getQualifierClassName(), context.getResolveScope()); - final PsiClass rightQualifier = JavaPsiFacade.getInstance(context.getProject()).findClass(left.getQualifierClassName(), context.getResolveScope()); - return hasBaseClass(leftQualifier, rightQualifier, PsiManager.getInstance(context.getProject())) ? CompareResult.EQUAL : CompareResult.NOT_EQUAL; + return hasBaseMethod(left.getPath().get(0), right.getPath().get(0), PsiManager.getInstance(context.getProject())) + ? CompareResult.EQUAL + : CompareResult.NOT_EQUAL; } - private static boolean hasBaseClass(final PsiClass left, final PsiClass right, final PsiManager psiManager) { - //todo so slow - final Set leftSupers = InheritanceUtil.getSuperClasses(left); - final Set rightSupers = InheritanceUtil.getSuperClasses(right); - for (final PsiClass leftSuper : leftSupers) { - if (!CommonClassNames.JAVA_LANG_OBJECT.equals(leftSuper.getQualifiedName()) && rightSupers.contains(leftSuper)) { - return true; + private static boolean hasBaseMethod(final PsiMethod[] left, final PsiMethod[] right, final PsiManager psiManager) { + for (PsiMethod rightMethod : right) { + final PsiMethod[] rightSupers = rightMethod.findDeepestSuperMethods(); + if (rightSupers.length != 0) { + for (final PsiMethod leftMethod : left) { + final PsiMethod[] leftSupers = leftMethod.findDeepestSuperMethods(); + if (leftSupers.length != 0) { + if (psiManager.areElementsEquivalent(leftSupers[0], rightSupers[0])) { + return true; + } + } + } } - } - return false; + } return false; } public enum CompareResult { diff --git a/java/java-impl/src/com/intellij/codeInsight/completion/methodChains/search/ParametersMatcher.java b/java/java-impl/src/com/intellij/codeInsight/completion/methodChains/search/ParametersMatcher.java index 4210d58630a3..2c2a563cef8c 100644 --- a/java/java-impl/src/com/intellij/codeInsight/completion/methodChains/search/ParametersMatcher.java +++ b/java/java-impl/src/com/intellij/codeInsight/completion/methodChains/search/ParametersMatcher.java @@ -66,8 +66,8 @@ public class ParametersMatcher { return new MatchResult(getMatched() + other.getMatched(), getUnMatched() + other.getUnMatched()); } - public boolean noUnmatched() { - return myUnMatched == 0; + public boolean noUnmatchedAndHasMatched() { + return myUnMatched == 0 && myMatched != 0; } @Override