mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
new inference: cleanup checkFunctionalType
This commit is contained in:
+2
-5
@@ -77,8 +77,7 @@ public class AnonymousCanBeLambdaInspection extends BaseJavaBatchLocalInspection
|
||||
super.visitAnonymousClass(aClass);
|
||||
if (PsiUtil.getLanguageLevel(aClass).isAtLeast(LanguageLevel.JDK_1_8)) {
|
||||
final PsiClassType baseClassType = aClass.getBaseClassType();
|
||||
final String functionalInterfaceErrorMessage = LambdaHighlightingUtil.checkInterfaceFunctional(baseClassType);
|
||||
if (functionalInterfaceErrorMessage == null) {
|
||||
if (LambdaUtil.isFunctionalType(baseClassType)) {
|
||||
final PsiMethod[] methods = aClass.getMethods();
|
||||
if (methods.length == 1 && aClass.getFields().length == 0) {
|
||||
final PsiCodeBlock body = methods[0].getBody();
|
||||
@@ -288,9 +287,7 @@ public class AnonymousCanBeLambdaInspection extends BaseJavaBatchLocalInspection
|
||||
}
|
||||
|
||||
private static boolean isInferred(PsiLambdaExpression lambdaExpression, PsiType interfaceType) {
|
||||
return interfaceType == null || !LambdaUtil.isLambdaFullyInferred(lambdaExpression, interfaceType) || LambdaHighlightingUtil
|
||||
.checkInterfaceFunctional(
|
||||
interfaceType) != null;
|
||||
return interfaceType == null || !LambdaUtil.isLambdaFullyInferred(lambdaExpression, interfaceType) || !LambdaUtil.isFunctionalType(interfaceType);
|
||||
}
|
||||
|
||||
private static String composeLambdaText(PsiMethod method, final boolean appendType) {
|
||||
|
||||
+1
-2
@@ -67,8 +67,7 @@ public class AnonymousCanBeMethodReferenceInspection extends BaseJavaBatchLocalI
|
||||
super.visitAnonymousClass(aClass);
|
||||
if (PsiUtil.getLanguageLevel(aClass).isAtLeast(LanguageLevel.JDK_1_8)) {
|
||||
final PsiClassType baseClassType = aClass.getBaseClassType();
|
||||
final String functionalInterfaceErrorMessage = LambdaHighlightingUtil.checkInterfaceFunctional(baseClassType);
|
||||
if (functionalInterfaceErrorMessage == null) {
|
||||
if (LambdaUtil.isFunctionalType(baseClassType)) {
|
||||
final PsiMethod[] methods = aClass.getMethods();
|
||||
if (methods.length == 1 && aClass.getFields().length == 0) {
|
||||
final PsiCodeBlock body = methods[0].getBody();
|
||||
|
||||
+1
-1
@@ -40,7 +40,7 @@ public class LambdaCompletionProvider extends CompletionProvider<CompletionParam
|
||||
final ExpectedTypeInfo[] expectedTypes = JavaSmartCompletionContributor.getExpectedTypes(parameters);
|
||||
for (ExpectedTypeInfo expectedType : expectedTypes) {
|
||||
final PsiType defaultType = expectedType.getDefaultType();
|
||||
if (LambdaHighlightingUtil.checkInterfaceFunctional(defaultType) == null) {
|
||||
if (LambdaUtil.isFunctionalType(defaultType)) {
|
||||
final PsiMethod method = LambdaUtil.getFunctionalInterfaceMethod(defaultType);
|
||||
if (method != null) {
|
||||
final PsiParameter[] params = method.getParameterList().getParameters();
|
||||
|
||||
+3
-4
@@ -19,9 +19,8 @@ import com.intellij.codeInsight.ExpectedTypeInfo;
|
||||
import com.intellij.codeInsight.ExpectedTypeInfoImpl;
|
||||
import com.intellij.codeInsight.TailType;
|
||||
import com.intellij.codeInsight.lookup.LookupElement;
|
||||
import com.intellij.codeInsight.lookup.LookupElementBuilder;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.filters.ElementFilter;
|
||||
import com.intellij.psi.LambdaUtil;
|
||||
import com.intellij.psi.PsiType;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import com.intellij.util.Consumer;
|
||||
import com.intellij.util.ProcessingContext;
|
||||
@@ -36,7 +35,7 @@ public class MethodReferenceCompletionProvider extends CompletionProvider<Comple
|
||||
final ExpectedTypeInfo[] expectedTypes = JavaSmartCompletionContributor.getExpectedTypes(parameters);
|
||||
for (ExpectedTypeInfo expectedType : expectedTypes) {
|
||||
final PsiType defaultType = expectedType.getDefaultType();
|
||||
if (LambdaHighlightingUtil.checkInterfaceFunctional(defaultType) == null) {
|
||||
if (LambdaUtil.isFunctionalType(defaultType)) {
|
||||
final PsiType returnType = LambdaUtil.getFunctionalInterfaceReturnType(defaultType);
|
||||
if (returnType != null) {
|
||||
final ExpectedTypeInfoImpl typeInfo =
|
||||
|
||||
+1
-1
@@ -49,7 +49,7 @@ public abstract class InputOutputConstraintFormula implements ConstraintFormula
|
||||
if (inferenceVariable != null) {
|
||||
return Collections.singleton(inferenceVariable);
|
||||
}
|
||||
if (LambdaHighlightingUtil.checkInterfaceFunctional(type) == null) {
|
||||
if (LambdaUtil.isFunctionalType(type)) {
|
||||
final PsiType functionType =
|
||||
psiExpression instanceof PsiLambdaExpression
|
||||
? FunctionalInterfaceParameterizationUtil.getGroundTargetType(type, (PsiLambdaExpression)psiExpression)
|
||||
|
||||
+1
-1
@@ -155,7 +155,7 @@ public class ReplaceLambdaWithAnonymousIntention extends Intention {
|
||||
return functionalInterfaceType != null &&
|
||||
LambdaUtil.getFunctionalInterfaceMethod(functionalInterfaceType) != null &&
|
||||
LambdaUtil.isLambdaFullyInferred(lambdaExpression, functionalInterfaceType) &&
|
||||
LambdaHighlightingUtil.checkInterfaceFunctional(functionalInterfaceType) == null;
|
||||
LambdaUtil.isFunctionalType(functionalInterfaceType);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user