mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
new inference: find current method
This commit is contained in:
@@ -448,8 +448,7 @@ public class LambdaUtil {
|
||||
if (lambdaIdx > -1) {
|
||||
|
||||
PsiType cachedType = null;
|
||||
final Map<PsiElement,Pair<PsiMethod,PsiSubstitutor>> currentMethodCandidates = MethodCandidateInfo.CURRENT_CANDIDATE.get();
|
||||
final Pair<PsiMethod, PsiSubstitutor> method = currentMethodCandidates != null ? currentMethodCandidates.get(parent) : null;
|
||||
final Pair<PsiMethod, PsiSubstitutor> method = MethodCandidateInfo.getCurrentMethod(parent);
|
||||
if (method != null) {
|
||||
final PsiParameter[] parameters = method.first.getParameterList().getParameters();
|
||||
cachedType = lambdaIdx < parameters.length ? method.second.substitute(getNormalizedType(parameters[adjustLambdaIdx(lambdaIdx, method.first, parameters)])) : null;
|
||||
@@ -698,14 +697,8 @@ public class LambdaUtil {
|
||||
if (parent instanceof PsiExpressionList) {
|
||||
final PsiElement gParent = parent.getParent();
|
||||
if (gParent instanceof PsiCall) {
|
||||
final Map<PsiElement, Pair<PsiMethod, PsiSubstitutor>> map = MethodCandidateInfo.CURRENT_CANDIDATE.get();
|
||||
if (map != null) {
|
||||
final Pair<PsiMethod, PsiSubstitutor> pair = map.get(parent);
|
||||
myMethod = pair != null ? pair.first : null;
|
||||
}
|
||||
else {
|
||||
myMethod = null;
|
||||
}
|
||||
final Pair<PsiMethod, PsiSubstitutor> pair = MethodCandidateInfo.getCurrentMethod(parent);
|
||||
myMethod = pair != null ? pair.first : null;
|
||||
if (myMethod == null) {
|
||||
myMethod = ((PsiCall)gParent).resolveMethod();
|
||||
}
|
||||
|
||||
@@ -223,6 +223,12 @@ public class MethodCandidateInfo extends CandidateInfo{
|
||||
return myArgumentList != null && myArgumentList.isValid();
|
||||
}
|
||||
|
||||
|
||||
public static Pair<PsiMethod, PsiSubstitutor> getCurrentMethod(PsiElement context) {
|
||||
final Map<PsiElement,Pair<PsiMethod,PsiSubstitutor>> currentMethodCandidates = CURRENT_CANDIDATE.get();
|
||||
return currentMethodCandidates != null ? currentMethodCandidates.get(context) : null;
|
||||
}
|
||||
|
||||
public static class ApplicabilityLevel {
|
||||
public static final int NOT_APPLICABLE = 1;
|
||||
public static final int VARARGS = 2;
|
||||
|
||||
+3
-6
@@ -93,12 +93,9 @@ public class InferenceSession {
|
||||
|
||||
private static Pair<PsiMethod, PsiCallExpression> getPair(PsiElement parent) {
|
||||
if (parent instanceof PsiCallExpression) {
|
||||
final Map<PsiElement, Pair<PsiMethod, PsiSubstitutor>> map = MethodCandidateInfo.CURRENT_CANDIDATE.get();
|
||||
if (map != null) {
|
||||
final Pair<PsiMethod, PsiSubstitutor> pair = map.get(((PsiCallExpression)parent).getArgumentList());
|
||||
if (pair != null) {
|
||||
return Pair.create(pair.first, (PsiCallExpression)parent);
|
||||
}
|
||||
final Pair<PsiMethod, PsiSubstitutor> pair = MethodCandidateInfo.getCurrentMethod(((PsiCallExpression)parent).getArgumentList());
|
||||
if (pair != null) {
|
||||
return Pair.create(pair.first, (PsiCallExpression)parent);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
+1
-2
@@ -76,8 +76,7 @@ public class ExpressionCompatibilityConstraint extends InputOutputConstraintForm
|
||||
if (myExpression instanceof PsiCallExpression) {
|
||||
final PsiExpressionList argumentList = ((PsiCallExpression)myExpression).getArgumentList();
|
||||
if (argumentList != null) {
|
||||
final Map<PsiElement,Pair<PsiMethod,PsiSubstitutor>> map = MethodCandidateInfo.CURRENT_CANDIDATE.get();
|
||||
final Pair<PsiMethod,PsiSubstitutor> pair = map != null ? map.get(argumentList) : null;
|
||||
final Pair<PsiMethod,PsiSubstitutor> pair = MethodCandidateInfo.getCurrentMethod(argumentList);
|
||||
final PsiMethod method = pair != null ? pair.first : ((PsiCallExpression)myExpression).resolveMethod();
|
||||
PsiType returnType = null;
|
||||
InferenceSession callSession = null;
|
||||
|
||||
Reference in New Issue
Block a user