mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
lambda: cleanup
This commit is contained in:
@@ -142,7 +142,7 @@ public class LambdaUtil {
|
||||
}
|
||||
else if (parent instanceof PsiExpressionList) {
|
||||
final PsiExpressionList expressionList = (PsiExpressionList)parent;
|
||||
final int lambdaIdx = ArrayUtil.find(expressionList.getExpressions(), lambdaExpression);
|
||||
final int lambdaIdx = getLambdaIdx(expressionList, lambdaExpression);
|
||||
if (lambdaIdx > -1) {
|
||||
final PsiElement gParent = expressionList.getParent();
|
||||
if (gParent instanceof PsiMethodCallExpression) {
|
||||
@@ -320,6 +320,17 @@ public class LambdaUtil {
|
||||
return lambdaReturnType != null && methodReturnType.isAssignableFrom(lambdaReturnType);
|
||||
}
|
||||
|
||||
public static int getLambdaIdx(PsiExpressionList expressionList, final PsiLambdaExpression element) {
|
||||
PsiExpression[] expressions = expressionList.getExpressions();
|
||||
for (int i = 0; i < expressions.length; i++) {
|
||||
PsiExpression expression = expressions[i];
|
||||
if (PsiTreeUtil.isAncestor(expression, element, false)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
private static class TypeParamsChecker extends PsiTypeVisitor<Boolean> {
|
||||
private final PsiLambdaExpression myExpression;
|
||||
|
||||
|
||||
+3
-1
@@ -544,7 +544,8 @@ public class PsiResolveHelperImpl implements PsiResolveHelper {
|
||||
final PsiExpressionList expressionList = (PsiExpressionList)parent;
|
||||
final PsiMethod method = expressionList.getUserData(MethodCandidateInfo.CURRENT_CANDIDATE);
|
||||
if (method != null) {
|
||||
final int i = ((PsiLambdaExpressionImpl)lambdaExpression).getLambdaIdx(expressionList);
|
||||
final int i = LambdaUtil.getLambdaIdx(expressionList,
|
||||
((PsiLambdaExpressionImpl)lambdaExpression));
|
||||
if (i < 0) return null;
|
||||
final PsiParameter[] parameters = method.getParameterList().getParameters();
|
||||
if (parameters.length <= i) return null;
|
||||
@@ -589,6 +590,7 @@ public class PsiResolveHelperImpl implements PsiResolveHelper {
|
||||
} else if (exprType instanceof PsiLambdaExpressionType) {
|
||||
return inferConstraintFromFunctionalInterfaceMethod(typeParam, ((PsiLambdaExpressionType)exprType).getExpression(), returnType);
|
||||
}
|
||||
if (exprType == null) return null;
|
||||
Pair<PsiType, ConstraintType> constraint =
|
||||
getSubstitutionForTypeParameterConstraint(typeParam, returnType, exprType, false, PsiUtil.getLanguageLevel(method));
|
||||
if (constraint != null) {
|
||||
|
||||
+1
-12
@@ -93,7 +93,7 @@ public class PsiLambdaExpressionImpl extends ExpressionPsiElement implements Psi
|
||||
}
|
||||
else if (parent instanceof PsiExpressionList) {
|
||||
final PsiExpressionList expressionList = (PsiExpressionList)parent;
|
||||
int lambdaIdx = getLambdaIdx(expressionList);
|
||||
int lambdaIdx = LambdaUtil.getLambdaIdx(expressionList, this);
|
||||
|
||||
if (lambdaIdx > -1) {
|
||||
final PsiElement gParent = expressionList.getParent();
|
||||
@@ -132,17 +132,6 @@ public class PsiLambdaExpressionImpl extends ExpressionPsiElement implements Psi
|
||||
return type;
|
||||
}
|
||||
|
||||
public int getLambdaIdx(PsiExpressionList expressionList) {
|
||||
PsiExpression[] expressions = expressionList.getExpressions();
|
||||
for (int i = 0; i < expressions.length; i++) {
|
||||
PsiExpression expression = expressions[i];
|
||||
if (PsiTreeUtil.isAncestor(expression, this, false)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PsiType getType() {
|
||||
return new PsiLambdaExpressionType(this);
|
||||
|
||||
Reference in New Issue
Block a user