mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-22 14:31:25 +07:00
Revert "[java-inspections] IDEA-328239 Casting with conjunction"
This reverts commit 97e21dbacccd9382e48387295a911b127882e625. GitOrigin-RevId: 572b3b40ac196132e233d044631ee27b565f0edc
This commit is contained in:
committed by
intellij-monorepo-bot
parent
06509345d6
commit
320f621750
@@ -75,23 +75,17 @@ public final class LambdaHighlightingUtil {
|
||||
if (functionalInterfaceType instanceof PsiIntersectionType) {
|
||||
Set<MethodSignature> signatures = new HashSet<>();
|
||||
for (PsiType type : ((PsiIntersectionType)functionalInterfaceType).getConjuncts()) {
|
||||
String error = checkInterfaceFunctional(type);
|
||||
if (error == null) {
|
||||
MethodSignature signature = LambdaUtil.getLambdaSignatureWithCommonSubstitutor(type);
|
||||
if (checkInterfaceFunctional(type) == null) {
|
||||
MethodSignature signature = LambdaUtil.getFunction(PsiUtil.resolveClassInType(type));
|
||||
LOG.assertTrue(signature != null, type.getCanonicalText());
|
||||
signatures.add(signature);
|
||||
}
|
||||
else {
|
||||
if (!error.equals(JavaErrorBundle.message("target.method.is.generic"))) {
|
||||
return error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (signatures.size() > 1) {
|
||||
return JavaErrorBundle.message("multiple.non.overriding.abstract.methods.found.in.0", functionalInterfaceType.getPresentableText());
|
||||
}
|
||||
return signatures.isEmpty() ? JavaErrorBundle.message("not.a.functional.interface",functionalInterfaceType.getPresentableText()) : null;
|
||||
return null;
|
||||
}
|
||||
PsiClassType.ClassResolveResult resolveResult = PsiUtil.resolveGenericsClassInType(functionalInterfaceType);
|
||||
PsiClass aClass = resolveResult.getElement();
|
||||
|
||||
@@ -526,48 +526,16 @@ public final class LambdaUtil {
|
||||
private static @Nullable PsiType extractFunctionalConjunct(PsiIntersectionType type) {
|
||||
PsiType conjunct = null;
|
||||
MethodSignature commonSignature = null;
|
||||
PsiType commonSignatureType = null;
|
||||
|
||||
for (PsiType psiType : type.getConjuncts()) {
|
||||
MethodSignature signature = getLambdaSignature(psiType);
|
||||
if (signature == null) continue;
|
||||
commonSignature = signature;
|
||||
commonSignatureType = psiType;
|
||||
conjunct = psiType;
|
||||
break;
|
||||
}
|
||||
if (commonSignature == null) {
|
||||
return null;
|
||||
}
|
||||
for (PsiType psiType : type.getConjuncts()) {
|
||||
if (psiType == commonSignatureType) continue;
|
||||
PsiClassType.ClassResolveResult classResolveResult = PsiUtil.resolveGenericsClassInType(psiType);
|
||||
PsiClass aClass = classResolveResult.getElement();
|
||||
PsiClass aClass = PsiUtil.resolveClassInClassTypeOnly(psiType);
|
||||
if (aClass instanceof PsiTypeParameter) continue;
|
||||
MethodSignature signature = getLambdaSignature(psiType);
|
||||
if (signature == null) {
|
||||
//psiType is child and doesn't have function methods, so the method is implemented
|
||||
if (TypeConversionUtil.isAssignable(commonSignatureType, psiType)) {
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
continue;
|
||||
}
|
||||
MethodSignature signature = getFunction(aClass);
|
||||
if (signature == null) continue;
|
||||
if (commonSignature == null) {
|
||||
commonSignature = signature;
|
||||
}
|
||||
if (!MethodSignatureUtil.areSignaturesEqual(commonSignature, signature)) {
|
||||
if (TypeConversionUtil.isAssignable(commonSignatureType, psiType) ||
|
||||
TypeConversionUtil.isAssignable(psiType, commonSignatureType)) {
|
||||
MethodSignature signatureWithInheritance = getLambdaSignatureWithCommonSubstitutor(psiType);
|
||||
MethodSignature commonSignatureWithInheritance = getLambdaSignatureWithCommonSubstitutor(commonSignatureType);
|
||||
if (commonSignatureWithInheritance == null ||
|
||||
signatureWithInheritance == null ||
|
||||
!MethodSignatureUtil.areSignaturesEqual(commonSignatureWithInheritance, signatureWithInheritance)) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
else if (!MethodSignatureUtil.areSignaturesEqual(commonSignature, signature)) {
|
||||
return null;
|
||||
}
|
||||
conjunct = psiType;
|
||||
}
|
||||
@@ -575,24 +543,6 @@ public final class LambdaUtil {
|
||||
return conjunct;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static MethodSignature getLambdaSignatureWithCommonSubstitutor(PsiType psiType) {
|
||||
PsiClassType.ClassResolveResult classResolveResult = PsiUtil.resolveGenericsClassInType(psiType);
|
||||
MethodSignature signatureFromFunction = getLambdaSignature(psiType);
|
||||
if (signatureFromFunction == null) return null;
|
||||
PsiMethod method = getFunctionalInterfaceMethod(psiType);
|
||||
if (method == null) return null;
|
||||
PsiSubstitutor fullSubstitutor = classResolveResult.getSubstitutor().putAll(signatureFromFunction.getSubstitutor());
|
||||
return method.getSignature(fullSubstitutor);
|
||||
}
|
||||
@Nullable
|
||||
public static MethodSignature getLambdaSignature(PsiType psiType) {
|
||||
PsiClassType.ClassResolveResult classResolveResult = PsiUtil.resolveGenericsClassInType(psiType);
|
||||
PsiClass aClass = classResolveResult.getElement();
|
||||
if (aClass instanceof PsiTypeParameter) return null;
|
||||
return getFunction(aClass);
|
||||
}
|
||||
|
||||
private static PsiType getFunctionalInterfaceTypeByContainingLambda(@NotNull PsiLambdaExpression parentLambda) {
|
||||
final PsiType parentInterfaceType = parentLambda.getFunctionalInterfaceType();
|
||||
return parentInterfaceType != null ? getFunctionalInterfaceReturnType(parentInterfaceType) : null;
|
||||
|
||||
@@ -5,41 +5,4 @@ class Test {
|
||||
public static <K extends Comparable<? super K>, V> Comparator<Map.Entry<K, V>> foo() {
|
||||
return (Comparator<Map.Entry<K, V>> & Serializable)(c1, c2) -> c1.getKey().compareTo(c2.getKey());
|
||||
}
|
||||
public static void main(String... args) {
|
||||
var shouldCompile = (Consumer<Integer> & IntConsumerAdapter1)
|
||||
i -> System.out.println("Cons3uming dd" + i);
|
||||
System.out.println(shouldCompile.getClass());
|
||||
shouldCompile.accept(42);
|
||||
shouldCompile.accept(Integer.valueOf(52));
|
||||
|
||||
var shouldNotCompile = (Consumer<Integer> & IntConsumerAdapter2)
|
||||
<error descr="No target method found">i -> System.out.println("Consumins2gs " + i)</error>;
|
||||
shouldNotCompile.accept(42);
|
||||
shouldNotCompile.accept(Integer.valueOf(52));
|
||||
}
|
||||
|
||||
public interface Consumer<T> {
|
||||
void accept(T t);
|
||||
}
|
||||
|
||||
public interface IntConsumer {
|
||||
|
||||
void accept(int value);
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
interface IntConsumerAdapter1 extends IntConsumer, Consumer<Integer> {
|
||||
default void accept(int value) {
|
||||
accept(Integer.valueOf(value));
|
||||
}
|
||||
}
|
||||
|
||||
interface IntConsumerAdapter2 extends IntConsumer, Consumer<Integer> {
|
||||
default void accept(int value) {
|
||||
accept(Integer.valueOf(value));
|
||||
}
|
||||
|
||||
default void accept(Integer integer) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user