From fa8310498fbed614024e16dfdb0ffb05059fad8c Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Wed, 4 Mar 2009 16:20:52 +0300 Subject: [PATCH] IDEADEV-35068 --- .../psi/resolve/JavaMethodResolveHelper.java | 5 +- .../src/com/intellij/psi/PsiIntersectionType.java | 9 ++++ .../intellij/psi/infos/MethodCandidateInfo.java | 4 +- .../com/intellij/psi/util/PsiSuperMethodUtil.java | 12 ++++- .../impl/source/resolve/PsiResolveHelperImpl.java | 3 +- .../JavaMethodsConflictResolver.java | 61 +++++++++++++++++----- .../scope/processor/MethodCandidatesProcessor.java | 3 +- 7 files changed, 74 insertions(+), 23 deletions(-) diff --git a/ExtendedApi/src/com/intellij/psi/resolve/JavaMethodResolveHelper.java b/ExtendedApi/src/com/intellij/psi/resolve/JavaMethodResolveHelper.java index 8b6f8bf2f4..553c32616b 100644 --- a/ExtendedApi/src/com/intellij/psi/resolve/JavaMethodResolveHelper.java +++ b/ExtendedApi/src/com/intellij/psi/resolve/JavaMethodResolveHelper.java @@ -40,8 +40,7 @@ public class JavaMethodResolveHelper { protected MethodCandidateInfo createCandidateInfo(final PsiMethod method, final PsiSubstitutor substitutor, final boolean staticProblem, final boolean accessible) { - return new MethodCandidateInfo(method, substitutor, !accessible, staticProblem, argumentList, myCurrentFileContext, - parameterTypes, PsiType.EMPTY_ARRAY); + return new MethodCandidateInfo(method, substitutor, !accessible, staticProblem, argumentList, myCurrentFileContext, parameterTypes, PsiType.EMPTY_ARRAY); } @Override @@ -90,7 +89,7 @@ public class JavaMethodResolveHelper { myProcessor.handleEvent(event, associated); } - public static enum ErrorType { + public enum ErrorType { NONE, STATIC, RESOLVE } diff --git a/openapi/src/com/intellij/psi/PsiIntersectionType.java b/openapi/src/com/intellij/psi/PsiIntersectionType.java index 3d959eae41..1aa4b6c08b 100644 --- a/openapi/src/com/intellij/psi/PsiIntersectionType.java +++ b/openapi/src/com/intellij/psi/PsiIntersectionType.java @@ -145,4 +145,13 @@ public class PsiIntersectionType extends PsiType { public int hashCode() { return myConjuncts[0].hashCode(); } + + @Override + public String toString() { + String s = "PsiIntersectionType: "; + for (PsiType conjunct : myConjuncts) { + s += conjunct.getPresentableText() +", "; + } + return s; + } } diff --git a/openapi/src/com/intellij/psi/infos/MethodCandidateInfo.java b/openapi/src/com/intellij/psi/infos/MethodCandidateInfo.java index caa948e69a..31b82ab19a 100644 --- a/openapi/src/com/intellij/psi/infos/MethodCandidateInfo.java +++ b/openapi/src/com/intellij/psi/infos/MethodCandidateInfo.java @@ -72,9 +72,7 @@ public class MethodCandidateInfo extends CandidateInfo{ if (myArgumentTypes == null) return ApplicabilityLevel.NOT_APPLICABLE; int level = PsiUtil.getApplicabilityLevel(getElement(), getSubstitutor(), myArgumentTypes, PsiUtil.getLanguageLevel(myArgumentList)); - if (level > ApplicabilityLevel.NOT_APPLICABLE) { - if (!isTypeArgumentsApplicable()) level = ApplicabilityLevel.NOT_APPLICABLE; - } + if (level > ApplicabilityLevel.NOT_APPLICABLE && !isTypeArgumentsApplicable()) level = ApplicabilityLevel.NOT_APPLICABLE; return level; } diff --git a/openapi/src/com/intellij/psi/util/PsiSuperMethodUtil.java b/openapi/src/com/intellij/psi/util/PsiSuperMethodUtil.java index 9180ee5e96..ac5d1ae4ae 100644 --- a/openapi/src/com/intellij/psi/util/PsiSuperMethodUtil.java +++ b/openapi/src/com/intellij/psi/util/PsiSuperMethodUtil.java @@ -38,7 +38,7 @@ public class PsiSuperMethodUtil { PsiElement firstChild = statements[0].getFirstChild(); if (firstChild instanceof PsiMethodCallExpression) { PsiReferenceExpression methodExpr = ((PsiMethodCallExpression)firstChild).getMethodExpression(); - final @NonNls String text = methodExpr.getText(); + @NonNls final String text = methodExpr.getText(); if (text.equals("super")) { PsiElement superConstructor = methodExpr.resolve(); if (superConstructor instanceof PsiMethod) { @@ -66,4 +66,14 @@ public class PsiSuperMethodUtil { } return null; } + + public static boolean isSuperMethod(PsiMethod method, PsiMethod superMethod) { + HierarchicalMethodSignature signature = method.getHierarchicalMethodSignature(); + for (HierarchicalMethodSignature supsig : signature.getSuperSignatures()) { + PsiMethod supsigme = supsig.getMethod(); + if (superMethod.equals(supsigme) || isSuperMethod(supsigme, superMethod)) return true; + } + + return false; + } } diff --git a/source/com/intellij/psi/impl/source/resolve/PsiResolveHelperImpl.java b/source/com/intellij/psi/impl/source/resolve/PsiResolveHelperImpl.java index ed08df3247..ed13635711 100644 --- a/source/com/intellij/psi/impl/source/resolve/PsiResolveHelperImpl.java +++ b/source/com/intellij/psi/impl/source/resolve/PsiResolveHelperImpl.java @@ -457,8 +457,7 @@ public class PsiResolveHelperImpl implements PsiResolveHelper { PsiClassType[] superTypes = typeParam.getSuperTypes(); PsiType[] erasureTypes = new PsiType[superTypes.length]; for (int i = 0; i < superTypes.length; i++) { - PsiClassType superType = superTypes[i]; - erasureTypes[i] = TypeConversionUtil.erasure(superType); + erasureTypes[i] = TypeConversionUtil.erasure(superTypes[i]); } PsiType[] types = ArrayUtil.append(erasureTypes, arg, PsiType.class); assert types.length != 0; diff --git a/source/com/intellij/psi/scope/conflictResolvers/JavaMethodsConflictResolver.java b/source/com/intellij/psi/scope/conflictResolvers/JavaMethodsConflictResolver.java index 79f68d993a..064d59c9e0 100644 --- a/source/com/intellij/psi/scope/conflictResolvers/JavaMethodsConflictResolver.java +++ b/source/com/intellij/psi/scope/conflictResolvers/JavaMethodsConflictResolver.java @@ -6,14 +6,11 @@ import com.intellij.psi.infos.CandidateInfo; import com.intellij.psi.infos.MethodCandidateInfo; import com.intellij.psi.scope.PsiConflictResolver; import com.intellij.psi.util.*; -import com.intellij.util.containers.ContainerUtil; import com.intellij.util.Function; +import com.intellij.util.containers.ContainerUtil; import gnu.trove.THashSet; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; +import java.util.*; /** * Created by IntelliJ IDEA. @@ -115,12 +112,13 @@ public class JavaMethodsConflictResolver implements PsiConflictResolver{ // candidates should go in order of class hierarchy traversal // in order for this to work Map signatures = new HashMap(); - for (Iterator iterator = conflicts.iterator(); iterator.hasNext();) { - CandidateInfo info = iterator.next(); + for (int i=0; i li = PsiUtil.typeParametersIterator(method); + while (li.hasNext()) { + PsiTypeParameter typeParameter = li.next(); + PsiType type = substitutor.substitute(typeParameter); + for (PsiClassType bound : typeParameter.getExtendsListTypes()) { + if (!TypeConversionUtil.isAssignable(type, bound)) return false; + } + } + return true; + } + private static void checkParametersNumber(final List conflicts, final int argumentsCount) { boolean parametersNumberMatch = false; for (CandidateInfo info : conflicts) { diff --git a/source/com/intellij/psi/scope/processor/MethodCandidatesProcessor.java b/source/com/intellij/psi/scope/processor/MethodCandidatesProcessor.java index 5776f78219..e1665b03f8 100644 --- a/source/com/intellij/psi/scope/processor/MethodCandidatesProcessor.java +++ b/source/com/intellij/psi/scope/processor/MethodCandidatesProcessor.java @@ -53,7 +53,8 @@ public class MethodCandidatesProcessor extends MethodsProcessor{ protected boolean isAccepted(final PsiMethod candidate) { if (!isConstructor()) { return !candidate.isConstructor() && getName(ResolveState.initial()).equals(candidate.getName()); - } else { + } + else { if (!candidate.isConstructor()) return false; if (myAccessClass == null) return true; if (myAccessClass instanceof PsiAnonymousClass) { -- 2.11.4.GIT