From ba7f04af95b384ffa734d25347e9e9b15dd95cae Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Fri, 27 Jun 2014 13:38:53 +0400 Subject: [PATCH] cleanup --- .../psi/infos/MethodCandidateInfo.java | 1 + .../intellij/psi/impl/PsiClassImplUtil.java | 2 +- .../tree/java/MethodReferenceResolver.java | 4 +- .../JavaMethodsConflictResolver.java | 72 ++++++++++--------- 4 files changed, 44 insertions(+), 35 deletions(-) diff --git a/java/java-psi-api/src/com/intellij/psi/infos/MethodCandidateInfo.java b/java/java-psi-api/src/com/intellij/psi/infos/MethodCandidateInfo.java index 917a88888d40..e7506ebd92fd 100644 --- a/java/java-psi-api/src/com/intellij/psi/infos/MethodCandidateInfo.java +++ b/java/java-psi-api/src/com/intellij/psi/infos/MethodCandidateInfo.java @@ -158,6 +158,7 @@ public class MethodCandidateInfo extends CandidateInfo{ return level; } + @NotNull public PsiSubstitutor getSiteSubstitutor() { PsiSubstitutor incompleteSubstitutor = super.getSubstitutor(); if (myTypeArguments != null) { diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/PsiClassImplUtil.java b/java/java-psi-impl/src/com/intellij/psi/impl/PsiClassImplUtil.java index 107bff5e60f2..3496b98f5ddf 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/PsiClassImplUtil.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/PsiClassImplUtil.java @@ -760,7 +760,6 @@ public class PsiClassImplUtil { @NotNull private static PsiClass[] getSupersInner(@NotNull PsiClass psiClass) { PsiClassType[] extendsListTypes = psiClass.getExtendsListTypes(); - PsiClassType[] implementsListTypes = psiClass.getImplementsListTypes(); if (psiClass.isInterface()) { return resolveClassReferenceList(extendsListTypes, psiClass.getManager(), psiClass.getResolveScope(), true); @@ -792,6 +791,7 @@ public class PsiClassImplUtil { return resolveClassReferenceList(extendsListTypes, psiClass.getManager(), psiClass.getResolveScope(), false); } + PsiClassType[] implementsListTypes = psiClass.getImplementsListTypes(); PsiClass[] interfaces = resolveClassReferenceList(implementsListTypes, psiClass.getManager(), psiClass.getResolveScope(), false); PsiClass superClass = getSuperClass(psiClass); diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/MethodReferenceResolver.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/MethodReferenceResolver.java index 9e31f7b88656..4066c6cc4a78 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/MethodReferenceResolver.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/MethodReferenceResolver.java @@ -219,7 +219,7 @@ public class MethodReferenceResolver implements ResolveCache.PolyVariantContextR } @Override - protected int getPertinentApplicabilityLevel(MethodCandidateInfo conflict) { + protected int getPertinentApplicabilityLevel(@NotNull MethodCandidateInfo conflict) { return conflict.isVarargs() ? MethodCandidateInfo.ApplicabilityLevel.VARARGS : MethodCandidateInfo.ApplicabilityLevel.FIXED_ARITY; } @@ -299,7 +299,7 @@ public class MethodReferenceResolver implements ResolveCache.PolyVariantContextR } @Override - protected boolean nonComparable(CandidateInfo method, CandidateInfo conflict) { + protected boolean nonComparable(@NotNull CandidateInfo method, @NotNull CandidateInfo conflict) { if (method == conflict) return true; PsiElement psiElement = method.getElement(); PsiElement conflictElement = conflict.getElement(); diff --git a/java/java-psi-impl/src/com/intellij/psi/scope/conflictResolvers/JavaMethodsConflictResolver.java b/java/java-psi-impl/src/com/intellij/psi/scope/conflictResolvers/JavaMethodsConflictResolver.java index aa18e6e6b8a4..f136c843aa87 100644 --- a/java/java-psi-impl/src/com/intellij/psi/scope/conflictResolvers/JavaMethodsConflictResolver.java +++ b/java/java-psi-impl/src/com/intellij/psi/scope/conflictResolvers/JavaMethodsConflictResolver.java @@ -131,9 +131,11 @@ public class JavaMethodsConflictResolver implements PsiConflictResolver{ private static PsiLambdaExpression findNestedLambdaExpression(PsiExpression expression) { if (expression instanceof PsiLambdaExpression) { return (PsiLambdaExpression)expression; - } else if (expression instanceof PsiParenthesizedExpression) { + } + else if (expression instanceof PsiParenthesizedExpression) { return findNestedLambdaExpression(((PsiParenthesizedExpression)expression).getExpression()); - } else if (expression instanceof PsiConditionalExpression) { + } + else if (expression instanceof PsiConditionalExpression) { PsiLambdaExpression lambdaExpression = findNestedLambdaExpression(((PsiConditionalExpression)expression).getThenExpression()); if (lambdaExpression != null) { return lambdaExpression; @@ -143,7 +145,7 @@ public class JavaMethodsConflictResolver implements PsiConflictResolver{ return null; } - private static void checkLambdaApplicable(List conflicts, int i, PsiLambdaExpression lambdaExpression) { + private static void checkLambdaApplicable(@NotNull List conflicts, int i, @NotNull PsiLambdaExpression lambdaExpression) { for (Iterator iterator = conflicts.iterator(); iterator.hasNext(); ) { ProgressManager.checkCanceled(); final CandidateInfo conflict = iterator.next(); @@ -192,12 +194,12 @@ public class JavaMethodsConflictResolver implements PsiConflictResolver{ } } - protected boolean nonComparable(CandidateInfo method, CandidateInfo conflict) { + protected boolean nonComparable(@NotNull CandidateInfo method, @NotNull CandidateInfo conflict) { assert method != conflict; return false; } - protected static void checkAccessStaticLevels(List conflicts, boolean checkAccessible) { + protected static void checkAccessStaticLevels(@NotNull List conflicts, boolean checkAccessible) { int conflictsCount = conflicts.size(); int maxCheckLevel = -1; @@ -350,13 +352,13 @@ public class JavaMethodsConflictResolver implements PsiConflictResolver{ } } - private static boolean areTypeParametersAgree(CandidateInfo info) { + private static boolean areTypeParametersAgree(@NotNull CandidateInfo info) { return ((MethodCandidateInfo)info).getPertinentApplicabilityLevel() != MethodCandidateInfo.ApplicabilityLevel.NOT_APPLICABLE; } - private static boolean checkParametersNumber(final List conflicts, - final int argumentsCount, - boolean ignoreIfStaticsProblem) { + private static boolean checkParametersNumber(@NotNull List conflicts, + final int argumentsCount, + boolean ignoreIfStaticsProblem) { boolean atLeastOneMatch = false; TIntArrayList unmatchedIndices = null; for (int i = 0; i < conflicts.size(); i++) { @@ -392,7 +394,7 @@ public class JavaMethodsConflictResolver implements PsiConflictResolver{ } @MethodCandidateInfo.ApplicabilityLevelConstant - protected int checkApplicability(List conflicts) { + protected int checkApplicability(@NotNull List conflicts) { @MethodCandidateInfo.ApplicabilityLevelConstant int maxApplicabilityLevel = 0; boolean toFilter = false; for (CandidateInfo conflict : conflicts) { @@ -420,27 +422,29 @@ public class JavaMethodsConflictResolver implements PsiConflictResolver{ return maxApplicabilityLevel; } - protected int getPertinentApplicabilityLevel(MethodCandidateInfo conflict) { + protected int getPertinentApplicabilityLevel(@NotNull MethodCandidateInfo conflict) { return conflict.getPertinentApplicabilityLevel(); } - private static int getCheckAccessLevel(MethodCandidateInfo method){ + private static int getCheckAccessLevel(@NotNull MethodCandidateInfo method){ boolean visible = method.isAccessible(); return visible ? 1 : 0; } - private static int getCheckStaticLevel(MethodCandidateInfo method){ + private static int getCheckStaticLevel(@NotNull MethodCandidateInfo method){ boolean available = method.isStaticsScopeCorrect(); return (available ? 1 : 0) << 1 | (method.getCurrentFileResolveScope() instanceof PsiImportStaticStatement ? 0 : 1); } + @NotNull private PsiType[] getActualParameterTypes() { - if (myActualParameterTypes == null) { + PsiType[] types = myActualParameterTypes; + if (types == null) { LOG.assertTrue(myArgumentsList instanceof PsiExpressionList, myArgumentsList); - myActualParameterTypes = getArgumentTypes(); + myActualParameterTypes = types = getArgumentTypes(); } - return myActualParameterTypes; + return types; } private int getActualParametersLength() { @@ -451,6 +455,7 @@ public class JavaMethodsConflictResolver implements PsiConflictResolver{ return myActualParameterTypes.length; } + @NotNull protected PsiType[] getArgumentTypes() { return ((PsiExpressionList)myArgumentsList).getExpressionTypes(); } @@ -470,8 +475,8 @@ public class JavaMethodsConflictResolver implements PsiConflictResolver{ return TypeConversionUtil.boxingConversionApplicable(parameterType, argType); } - private Specifics isMoreSpecific(final MethodCandidateInfo info1, - final MethodCandidateInfo info2, + private Specifics isMoreSpecific(@NotNull MethodCandidateInfo info1, + @NotNull MethodCandidateInfo info2, @MethodCandidateInfo.ApplicabilityLevelConstant int applicabilityLevel, @NotNull LanguageLevel languageLevel) { PsiMethod method1 = info1.getElement(); @@ -684,11 +689,11 @@ public class JavaMethodsConflictResolver implements PsiConflictResolver{ return Specifics.NEITHER; } - private boolean isApplicableTo(PsiType[] types2AtSite, - PsiMethod method1, - LanguageLevel languageLevel, + private boolean isApplicableTo(@NotNull PsiType[] types2AtSite, + @NotNull PsiMethod method1, + @NotNull LanguageLevel languageLevel, boolean varargsPosition, - final PsiSubstitutor methodSubstitutor1, + @NotNull PsiSubstitutor methodSubstitutor1, PsiMethod method2, PsiSubstitutor siteSubstitutor1) { if (languageLevel.isAtLeast(LanguageLevel.JDK_1_8) && method2 != null && method1.getTypeParameters().length > 0 && myArgumentsList instanceof PsiExpressionList) { @@ -701,7 +706,8 @@ public class JavaMethodsConflictResolver implements PsiConflictResolver{ return applicabilityLevel > MethodCandidateInfo.ApplicabilityLevel.NOT_APPLICABLE; } - private static PsiType[] typesAtSite(PsiType[] types1, PsiSubstitutor siteSubstitutor1) { + @NotNull + private static PsiType[] typesAtSite(@NotNull PsiType[] types1, @NotNull PsiSubstitutor siteSubstitutor1) { final PsiType[] types = PsiType.createArray(types1.length); for (int i = 0; i < types1.length; i++) { types[i] = siteSubstitutor1.substitute(types1[i]); @@ -709,11 +715,12 @@ public class JavaMethodsConflictResolver implements PsiConflictResolver{ return types; } - private static PsiSubstitutor calculateMethodSubstitutor(final PsiTypeParameter[] typeParameters, - final PsiMethod method, - final PsiSubstitutor siteSubstitutor, - final PsiType[] types1, - final PsiType[] types2, + @NotNull + private static PsiSubstitutor calculateMethodSubstitutor(@NotNull PsiTypeParameter[] typeParameters, + @NotNull PsiMethod method, + @NotNull PsiSubstitutor siteSubstitutor, + @NotNull PsiType[] types1, + @NotNull PsiType[] types2, @NotNull LanguageLevel languageLevel) { PsiSubstitutor substitutor = PsiResolveHelper.SERVICE.getInstance(method.getProject()) .inferTypeArguments(typeParameters, types1, types2, languageLevel); @@ -742,7 +749,7 @@ public class JavaMethodsConflictResolver implements PsiConflictResolver{ return substitutor; } - public void checkPrimitiveVarargs(final List conflicts, + public void checkPrimitiveVarargs(@NotNull List conflicts, final int argumentsCount) { if (JavaVersionService.getInstance().isAtLeast(myArgumentsList, JavaSdkVersion.JDK_1_7)) return; CandidateInfo objectVararg = null; @@ -778,7 +785,7 @@ public class JavaMethodsConflictResolver implements PsiConflictResolver{ } @Nullable - private static PsiType getFunctionalType(int functionalTypeIdx, CandidateInfo candidateInfo) { + private static PsiType getFunctionalType(int functionalTypeIdx, @NotNull CandidateInfo candidateInfo) { final PsiMethod psiMethod = (PsiMethod)candidateInfo.getElement(); LOG.assertTrue(true); final PsiParameter[] methodParameters = psiMethod.getParameterList().getParameters(); @@ -787,8 +794,9 @@ public class JavaMethodsConflictResolver implements PsiConflictResolver{ return ((MethodCandidateInfo)candidateInfo).getSiteSubstitutor().substitute(param.getType()); } - private static Specifics isFunctionalTypeMoreSpecific(CandidateInfo method, - CandidateInfo conflict, + @NotNull + private static Specifics isFunctionalTypeMoreSpecific(@NotNull CandidateInfo method, + @NotNull CandidateInfo conflict, PsiExpression expr, int functionalInterfaceIdx) { if (expr instanceof PsiParenthesizedExpression) {