mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
suspicious method call: ignore poly conditional expressions in invocation context as their type would be always the same as target type (IDEA-155622)
This commit is contained in:
+2
-2
@@ -97,11 +97,11 @@ public class SuspiciousCollectionsMethodCallsInspection extends BaseJavaBatchLoc
|
||||
|
||||
PsiType argType = args[0].getType();
|
||||
final String plainMessage = SuspiciousMethodCallUtil
|
||||
.getSuspiciousMethodCallMessage(methodCall, argType, reportConvertibleMethodCalls, patternMethods, indices);
|
||||
.getSuspiciousMethodCallMessage(methodCall, args[0], argType, reportConvertibleMethodCalls, patternMethods, indices);
|
||||
if (plainMessage != null) {
|
||||
final PsiType dfaType = GuessManager.getInstance(methodCall.getProject()).getControlFlowExpressionType(args[0]);
|
||||
if (dfaType != null && SuspiciousMethodCallUtil
|
||||
.getSuspiciousMethodCallMessage(methodCall, dfaType, reportConvertibleMethodCalls, patternMethods, indices) == null) {
|
||||
.getSuspiciousMethodCallMessage(methodCall, args[0], dfaType, reportConvertibleMethodCalls, patternMethods, indices) == null) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
+8
@@ -18,6 +18,7 @@ package com.intellij.codeInspection.miscGenerics;
|
||||
import com.intellij.codeInsight.daemon.impl.analysis.JavaGenericsUtil;
|
||||
import com.intellij.codeInspection.InspectionsBundle;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.impl.source.resolve.graphInference.PsiPolyExpressionUtil;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.psi.util.*;
|
||||
import com.intellij.util.containers.IntArrayList;
|
||||
@@ -104,6 +105,7 @@ public class SuspiciousMethodCallUtil {
|
||||
|
||||
@Nullable
|
||||
public static String getSuspiciousMethodCallMessage(@NotNull PsiMethodCallExpression methodCall,
|
||||
PsiExpression arg,
|
||||
PsiType argType,
|
||||
boolean reportConvertibleMethodCalls,
|
||||
@NotNull List<PsiMethod> patternMethods,
|
||||
@@ -117,6 +119,12 @@ public class SuspiciousMethodCallUtil {
|
||||
|
||||
if (argType == null) return null;
|
||||
|
||||
if (arg instanceof PsiConditionalExpression &&
|
||||
PsiPolyExpressionUtil.isPolyExpression(arg) &&
|
||||
argType.equalsToText(CommonClassNames.JAVA_LANG_OBJECT)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final JavaResolveResult resolveResult = methodExpression.advancedResolve(false);
|
||||
PsiMethod calleeMethod = (PsiMethod)resolveResult.getElement();
|
||||
if (calleeMethod == null) return null;
|
||||
|
||||
+1
-1
@@ -116,7 +116,7 @@ public class RedundantCastInspection extends GenericsInspectionToolBase {
|
||||
final PsiElement gParent = parent.getParent();
|
||||
if (gParent instanceof PsiMethodCallExpression && IGNORE_SUSPICIOUS_METHOD_CALLS) {
|
||||
final String message = SuspiciousMethodCallUtil
|
||||
.getSuspiciousMethodCallMessage((PsiMethodCallExpression)gParent, operand.getType(), true, new ArrayList<PsiMethod>(),
|
||||
.getSuspiciousMethodCallMessage((PsiMethodCallExpression)gParent, operand, operand.getType(), true, new ArrayList<PsiMethod>(),
|
||||
new IntArrayList());
|
||||
if (message != null) {
|
||||
return null;
|
||||
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
class Test {
|
||||
|
||||
void m(Map<Class, String> map) {
|
||||
map.get(map.size() > 10 ? Map.class : List.class);
|
||||
}
|
||||
|
||||
}
|
||||
+1
@@ -24,6 +24,7 @@ public class SuspiciousCollectionMethodCallsTest extends LightCodeInsightFixture
|
||||
public void testSetList() throws Exception { doTest(); }
|
||||
public void testUseDfa() throws Exception { doTest(); }
|
||||
public void testWildcard() throws Exception { doTest(); }
|
||||
public void testPolyConditionalExpressionPassedToMapGetCall() throws Exception { doTest(); }
|
||||
public void testIgnoreConvertible() throws Exception {
|
||||
myTool.REPORT_CONVERTIBLE_METHOD_CALLS = false;
|
||||
doTest();
|
||||
|
||||
Reference in New Issue
Block a user