mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-10-02 00:57:59 +07:00
FunctionalExpressionUtils#getFunctionalExpressionType
This commit is contained in:
+1
-3
@@ -1601,9 +1601,7 @@ public class SimplifyStreamApiCallChainsInspection extends AbstractBaseJavaLocal
|
||||
reversed = true;
|
||||
} else {
|
||||
if (maybeComparator == null) return null;
|
||||
PsiType comparatorType = maybeComparator instanceof PsiFunctionalExpression
|
||||
? ((PsiFunctionalExpression)maybeComparator).getFunctionalInterfaceType()
|
||||
: maybeComparator.getType();
|
||||
PsiType comparatorType = FunctionalExpressionUtils.getFunctionalExpressionType(maybeComparator);
|
||||
if (!InheritanceUtil.isInheritor(comparatorType, JAVA_UTIL_COMPARATOR)) return null;
|
||||
comparator = maybeComparator.getText();
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ import com.intellij.refactoring.util.LambdaRefactoringUtil;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.siyeh.ig.psiutils.EquivalenceChecker;
|
||||
import com.siyeh.ig.psiutils.ExpressionUtils;
|
||||
import com.siyeh.ig.psiutils.FunctionalExpressionUtils;
|
||||
import com.siyeh.ig.psiutils.MethodCallUtils;
|
||||
import one.util.streamex.EntryStream;
|
||||
import one.util.streamex.StreamEx;
|
||||
@@ -133,9 +134,7 @@ abstract class FunctionHelper {
|
||||
@Nullable
|
||||
static FunctionHelper create(PsiExpression expression, int paramCount, boolean allowReturns) {
|
||||
if(expression == null) return null;
|
||||
PsiType type = expression instanceof PsiFunctionalExpression
|
||||
? ((PsiFunctionalExpression)expression).getFunctionalInterfaceType()
|
||||
: expression.getType();
|
||||
PsiType type = FunctionalExpressionUtils.getFunctionalExpressionType(expression);
|
||||
if(!(type instanceof PsiClassType)) return null;
|
||||
PsiMethod interfaceMethod = LambdaUtil.getFunctionalInterfaceMethod(type);
|
||||
if (interfaceMethod == null || interfaceMethod.getParameterList().getParametersCount() != paramCount) return null;
|
||||
|
||||
+2
-7
@@ -22,6 +22,7 @@ import com.intellij.psi.util.PsiUtil;
|
||||
import com.siyeh.InspectionGadgetsBundle;
|
||||
import com.siyeh.ig.BaseInspection;
|
||||
import com.siyeh.ig.BaseInspectionVisitor;
|
||||
import com.siyeh.ig.psiutils.FunctionalExpressionUtils;
|
||||
import com.siyeh.ig.psiutils.StreamApiUtil;
|
||||
import com.siyeh.ig.psiutils.TypeUtils;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
@@ -97,13 +98,7 @@ public class SuspiciousToArrayCallInspection extends BaseInspection {
|
||||
}
|
||||
|
||||
private static PsiType getIntFunctionParameterType(PsiExpression argument) {
|
||||
PsiType argumentType;
|
||||
if (argument instanceof PsiFunctionalExpression) {
|
||||
argumentType = ((PsiFunctionalExpression)argument).getFunctionalInterfaceType();
|
||||
}
|
||||
else {
|
||||
argumentType = argument.getType();
|
||||
}
|
||||
PsiType argumentType = FunctionalExpressionUtils.getFunctionalExpressionType(argument);
|
||||
return PsiUtil.substituteTypeParameter(argumentType, "java.util.function.IntFunction", 0, false);
|
||||
}
|
||||
|
||||
|
||||
+18
@@ -106,4 +106,22 @@ public class FunctionalExpressionUtils {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the type of functional expression (not {@link PsiLambdaExpressionType} or {@link PsiMethodReferenceType},
|
||||
* but actual functional interface type).
|
||||
*
|
||||
* @param expression expression to find the type of.
|
||||
* @return type of functional expression.
|
||||
*/
|
||||
public static PsiType getFunctionalExpressionType(PsiExpression expression) {
|
||||
PsiType argumentType;
|
||||
if (expression instanceof PsiFunctionalExpression) {
|
||||
argumentType = ((PsiFunctionalExpression)expression).getFunctionalInterfaceType();
|
||||
}
|
||||
else {
|
||||
argumentType = expression.getType();
|
||||
}
|
||||
return argumentType;
|
||||
}
|
||||
}
|
||||
|
||||
+1
-3
@@ -133,9 +133,7 @@ public class TypeUtils {
|
||||
if (expression == null) {
|
||||
return null;
|
||||
}
|
||||
final PsiType type = expression instanceof PsiFunctionalExpression
|
||||
? ((PsiFunctionalExpression)expression).getFunctionalInterfaceType()
|
||||
: expression.getType();
|
||||
final PsiType type = FunctionalExpressionUtils.getFunctionalExpressionType(expression);
|
||||
if (type == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user