mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
cleanup ExpectedTypesProvider
GitOrigin-RevId: 7d72b153f057d83ce7175f2767c082963da079c9
This commit is contained in:
committed by
intellij-monorepo-bot
parent
e39513f5e6
commit
0c4037c12c
@@ -11,7 +11,6 @@ import com.intellij.openapi.components.ServiceManager;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Computable;
|
||||
import com.intellij.openapi.util.NullableComputable;
|
||||
import com.intellij.pom.java.LanguageLevel;
|
||||
import com.intellij.psi.*;
|
||||
@@ -47,9 +46,6 @@ public class ExpectedTypesProvider {
|
||||
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.codeInsight.ExpectedTypesProvider");
|
||||
|
||||
private ExpectedTypesProvider() {
|
||||
}
|
||||
|
||||
public static ExpectedTypesProvider getInstance(@NotNull Project project) {
|
||||
return ServiceManager.getService(project, ExpectedTypesProvider.class);
|
||||
}
|
||||
@@ -629,7 +625,7 @@ public class ExpectedTypesProvider {
|
||||
if (parent instanceof PsiMethodCallExpression) {
|
||||
PsiMethodCallExpression methodCall = (PsiMethodCallExpression)parent;
|
||||
CandidateInfo[] candidates = helper.getReferencedMethodCandidates(methodCall, false, true);
|
||||
Collections.addAll(myResult, getExpectedArgumentTypesForMethodCall(candidates, list, myExpr, myForCompletion, methodCall.resolveMethod()));
|
||||
Collections.addAll(myResult, getExpectedArgumentTypesForMethodCall(candidates, list, myExpr, myForCompletion));
|
||||
}
|
||||
else if (parent instanceof PsiEnumConstant) {
|
||||
getExpectedArgumentsTypesForEnumConstant((PsiEnumConstant)parent, list);
|
||||
@@ -659,7 +655,7 @@ public class ExpectedTypesProvider {
|
||||
final PsiClass aClass = enumConstant.getContainingClass();
|
||||
if (aClass != null) {
|
||||
LOG.assertTrue(aClass.isEnum());
|
||||
getExpectedTypesForConstructorCall(aClass, list, PsiSubstitutor.EMPTY, enumConstant.resolveMethod());
|
||||
getExpectedTypesForConstructorCall(aClass, list, PsiSubstitutor.EMPTY);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -669,8 +665,7 @@ public class ExpectedTypesProvider {
|
||||
final List<CandidateInfo> candidates = PsiDiamondTypeImpl.collectStaticFactories(newExpr);
|
||||
if (candidates != null) {
|
||||
final PsiExpressionList argumentList = Objects.requireNonNull(newExpr.getArgumentList());
|
||||
Collections.addAll(myResult, getExpectedArgumentTypesForMethodCall(candidates.toArray(CandidateInfo.EMPTY_ARRAY), argumentList, myExpr, myForCompletion,
|
||||
newExpr.resolveMethod()));
|
||||
Collections.addAll(myResult, getExpectedArgumentTypesForMethodCall(candidates.toArray(CandidateInfo.EMPTY_ARRAY), argumentList, myExpr, myForCompletion));
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -691,19 +686,19 @@ public class ExpectedTypesProvider {
|
||||
else {
|
||||
return;
|
||||
}
|
||||
getExpectedTypesForConstructorCall(newClass, list, substitutor, newExpr.resolveMethod());
|
||||
getExpectedTypesForConstructorCall(newClass, list, substitutor);
|
||||
}
|
||||
}
|
||||
|
||||
private void getExpectedTypesForConstructorCall(@NotNull final PsiClass referencedClass,
|
||||
@NotNull final PsiExpressionList argumentList,
|
||||
@NotNull PsiSubstitutor substitutor, PsiMethod method) {
|
||||
private void getExpectedTypesForConstructorCall(@NotNull PsiClass referencedClass,
|
||||
@NotNull PsiExpressionList argumentList,
|
||||
@NotNull PsiSubstitutor substitutor) {
|
||||
List<CandidateInfo> array = new ArrayList<>();
|
||||
for (PsiMethod constructor : referencedClass.getConstructors()) {
|
||||
array.add(new MethodCandidateInfo(constructor, substitutor, false, false, argumentList, null, argumentList.getExpressionTypes(), null));
|
||||
}
|
||||
CandidateInfo[] candidates = array.toArray(CandidateInfo.EMPTY_ARRAY);
|
||||
Collections.addAll(myResult, getExpectedArgumentTypesForMethodCall(candidates, argumentList, myExpr, myForCompletion, method));
|
||||
Collections.addAll(myResult, getExpectedArgumentTypesForMethodCall(candidates, argumentList, myExpr, myForCompletion));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1010,8 +1005,7 @@ public class ExpectedTypesProvider {
|
||||
private ExpectedTypeInfo[] getExpectedArgumentTypesForMethodCall(@NotNull CandidateInfo[] allCandidates,
|
||||
@NotNull PsiExpressionList argumentList,
|
||||
@NotNull PsiExpression argument,
|
||||
boolean forCompletion,
|
||||
@Nullable PsiMethod targetMethod) {
|
||||
boolean forCompletion) {
|
||||
if (allCandidates.length == 0) {
|
||||
return ExpectedTypeInfo.EMPTY_ARRAY;
|
||||
}
|
||||
@@ -1033,7 +1027,6 @@ public class ExpectedTypesProvider {
|
||||
}
|
||||
if (methodCandidates.isEmpty()) {
|
||||
Collections.addAll(methodCandidates, allCandidates);
|
||||
methodCandidates.remove(toExclude);
|
||||
}
|
||||
|
||||
final PsiExpression[] args = argumentList.getExpressions().clone();
|
||||
@@ -1059,9 +1052,8 @@ public class ExpectedTypesProvider {
|
||||
PsiMethod method = (PsiMethod)candidateInfo.getElement();
|
||||
PsiSubstitutor substitutor;
|
||||
if (candidateInfo instanceof MethodCandidateInfo) {
|
||||
final MethodCandidateInfo info = (MethodCandidateInfo)candidateInfo;
|
||||
Computable<PsiSubstitutor> computable = () -> info.inferSubstitutorFromArgs(policy, args);
|
||||
substitutor = computable.compute();
|
||||
MethodCandidateInfo info = (MethodCandidateInfo)candidateInfo;
|
||||
substitutor = info.inferSubstitutorFromArgs(policy, args);
|
||||
if (!info.isStaticsScopeCorrect() && !method.hasModifierProperty(PsiModifier.STATIC) || info.getInferenceErrorMessage() != null) continue;
|
||||
}
|
||||
else {
|
||||
@@ -1074,8 +1066,7 @@ public class ExpectedTypesProvider {
|
||||
if (set.size() >= myMaxCandidates) break;
|
||||
|
||||
if (leftArgs != null && candidateInfo instanceof MethodCandidateInfo) {
|
||||
Computable<PsiSubstitutor> computable = () -> ((MethodCandidateInfo)candidateInfo).inferSubstitutorFromArgs(policy, leftArgs);
|
||||
substitutor = computable.compute();
|
||||
substitutor = ((MethodCandidateInfo)candidateInfo).inferSubstitutorFromArgs(policy, leftArgs);
|
||||
if (substitutor != null) {
|
||||
inferMethodCallArgumentTypes(argument, forCompletion, leftArgs, index, method, substitutor, set);
|
||||
if (set.size() >= myMaxCandidates) break;
|
||||
@@ -1289,7 +1280,7 @@ public class ExpectedTypesProvider {
|
||||
}
|
||||
final PsiManager manager = methodCallExpr.getManager();
|
||||
final JavaPsiFacade facade = JavaPsiFacade.getInstance(manager.getProject());
|
||||
Set<PsiMethod> psiMethods = mapToDeepestSuperMethods(myClassProvider.findDeclaredMethods(manager, reference.getReferenceName()));
|
||||
Set<PsiMethod> psiMethods = mapToDeepestSuperMethods(myClassProvider.findDeclaredMethods(manager, Objects.requireNonNull(reference.getReferenceName())));
|
||||
Set<ExpectedTypeInfo> types = new THashSet<>();
|
||||
for (PsiMethod method : psiMethods) {
|
||||
final PsiClass aClass = method.getContainingClass();
|
||||
@@ -1332,7 +1323,7 @@ public class ExpectedTypesProvider {
|
||||
@NotNull
|
||||
private ExpectedTypeInfo[] findClassesWithDeclaredField(@NotNull PsiReferenceExpression expression) {
|
||||
final JavaPsiFacade facade = JavaPsiFacade.getInstance(expression.getProject());
|
||||
PsiField[] fields = myClassProvider.findDeclaredFields(expression.getManager(), expression.getReferenceName());
|
||||
PsiField[] fields = myClassProvider.findDeclaredFields(expression.getManager(), Objects.requireNonNull(expression.getReferenceName()));
|
||||
List<ExpectedTypeInfo> types = new ArrayList<>();
|
||||
for (PsiField field : fields) {
|
||||
final PsiClass aClass = field.getContainingClass();
|
||||
|
||||
Reference in New Issue
Block a user