redundant cast: mark raw cast as redundant when raw is expected (IDEA-162022)

This commit is contained in:
Anna.Kozlova
2016-10-04 18:45:14 +02:00
parent 1cf1300ab1
commit 1f41202f49
3 changed files with 18 additions and 2 deletions
@@ -794,8 +794,6 @@ public class RedundantCastUtil {
}
else if (castType instanceof PsiClassType && ((PsiClassType)castType).hasParameters()) {
if (opType instanceof PsiClassType && ((PsiClassType)opType).isRaw()) return true;
} else if (castType instanceof PsiClassType && ((PsiClassType)castType).isRaw()) {
if (opType instanceof PsiClassType && ((PsiClassType)opType).hasParameters()) return true;
}
final PsiExpression stripParenthesisOperand = PsiUtil.skipParenthesizedExprDown(operand);
@@ -0,0 +1,17 @@
import java.util.Map;
class Main {
private final Map<String, BreakpointState<?,?,?>> myBreakpointsDefaults = null;
@SuppressWarnings("unchecked")
public BreakpointState<String, String, String> foo1(String type, BreakpointState<?, ?, ?> defaults) {
return (BreakpointState) myBreakpointsDefaults.computeIfAbsent(type, k -> defaults);
}
public BreakpointState foo2(String type, BreakpointState<?, ?, ?> defaults) {
return (<warning descr="Casting 'myBreakpointsDefaults.computeIfAbsent(type, k -> defaults)' to 'BreakpointState' is redundant">BreakpointState</warning>) myBreakpointsDefaults.computeIfAbsent(type, k -> defaults);
}
private static class BreakpointState<A, B, C> {}
}
@@ -41,4 +41,5 @@ public class RedundantCast18Test extends LightDaemonAnalyzerTestCase {
public void testForeachValue() throws Exception { doTest(); }
public void testConditional() throws Exception { doTest(); }
public void testInferApplicabilityError() throws Exception { doTest(); }
public void testCastToRawType() throws Exception { doTest(); }
}