mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-10-06 06:21:16 +07:00
EqualsBetweenInconvertibleTypesInspection: one more fix for captured types with 2+ type arguments
GitOrigin-RevId: 010a4462b407d7ce628aca43182e2a42e808930e
This commit is contained in:
committed by
intellij-monorepo-bot
parent
5ec50a91ce
commit
dba42cc50f
+2
-2
@@ -27,7 +27,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
|
||||
public class EqualsBetweenInconvertibleTypesInspection extends BaseInspection {
|
||||
|
||||
@@ -92,7 +92,7 @@ public class EqualsBetweenInconvertibleTypesInspection extends BaseInspection {
|
||||
!TypeUtils.areConvertible(lhsType, rhsType) /* red code */) {
|
||||
return;
|
||||
}
|
||||
createInconvertibleTypesChecker().deepCheck(lhsType, rhsType, expression.getOperationSign(), new HashMap<>(), WARN_IF_NO_MUTUAL_SUBCLASS_FOUND, isOnTheFly());
|
||||
createInconvertibleTypesChecker().deepCheck(lhsType, rhsType, expression.getOperationSign(), new HashSet<>(), WARN_IF_NO_MUTUAL_SUBCLASS_FOUND, isOnTheFly());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+6
-9
@@ -1,14 +1,15 @@
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.siyeh.ig.bugs;
|
||||
|
||||
import com.intellij.openapi.util.Couple;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import com.siyeh.ig.psiutils.InheritanceUtil;
|
||||
import com.siyeh.ig.psiutils.TypeUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public abstract class InconvertibleTypesChecker {
|
||||
protected abstract void registerEqualsError(PsiElement highlightLocation,
|
||||
@@ -26,7 +27,7 @@ public abstract class InconvertibleTypesChecker {
|
||||
return;
|
||||
}
|
||||
if (TypeUtils.areConvertible(leftType, rightType) || TypeUtils.mayBeEqualByContract(leftType, rightType)) {
|
||||
deepCheck(leftType, rightType, name, new HashMap<>(), warnIfNoMutualSubclassFound, onTheFly);
|
||||
deepCheck(leftType, rightType, name, new HashSet<>(), warnIfNoMutualSubclassFound, onTheFly);
|
||||
return;
|
||||
}
|
||||
registerEqualsError(name, leftType, rightType, false);
|
||||
@@ -35,7 +36,7 @@ public abstract class InconvertibleTypesChecker {
|
||||
protected void deepCheck(@NotNull PsiType leftType,
|
||||
@NotNull PsiType rightType,
|
||||
PsiElement highlightLocation,
|
||||
Map<PsiType, PsiType> checked,
|
||||
Set<Couple<PsiType>> checked,
|
||||
boolean warnIfNoMutualSubclassFound,
|
||||
boolean onTheFly) {
|
||||
if (leftType instanceof PsiCapturedWildcardType) {
|
||||
@@ -44,11 +45,7 @@ public abstract class InconvertibleTypesChecker {
|
||||
if (rightType instanceof PsiCapturedWildcardType) {
|
||||
rightType = ((PsiCapturedWildcardType)rightType).getUpperBound();
|
||||
}
|
||||
PsiType checkedRight = checked.putIfAbsent(leftType, rightType);
|
||||
if (checkedRight != null) {
|
||||
if (!checkedRight.equals(rightType)) {
|
||||
registerEqualsError(highlightLocation, leftType, rightType, false);
|
||||
}
|
||||
if (!checked.add(Couple.of(leftType, rightType))) {
|
||||
return;
|
||||
}
|
||||
if (leftType.isAssignableFrom(rightType) || rightType.isAssignableFrom(leftType)) return;
|
||||
|
||||
+2
@@ -211,9 +211,11 @@ public class EqualsBetweenInconvertibleTypesInspectionTest extends LightJavaInsp
|
||||
public void testCapture() {
|
||||
doTest("class X<A, B> {\n" +
|
||||
" static final X<?, ?> CONST = new X<>();\n" +
|
||||
" static final X<Integer, String> CONST2 = new X<>();\n" +
|
||||
" \n" +
|
||||
" void test(X<?, ?>[] data) {\n" +
|
||||
" if (data[0] == CONST) {}\n" +
|
||||
" if (data[0] == CONST2) {}\n" +
|
||||
" }\n" +
|
||||
"}");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user