overly strong type casts: ignore casts with functional expressions when expected type is not functional (IDEA-126764)

This commit is contained in:
Anna Kozlova
2014-07-02 12:26:18 +02:00
parent 53cf6f6905
commit 62f2167fc7
3 changed files with 11 additions and 1 deletions
@@ -175,6 +175,9 @@ public class OverlyStrongTypeCastInspection extends BaseInspection {
if (castTypeElement == null) {
return;
}
if (operand instanceof PsiFunctionalExpression && !LambdaUtil.isFunctionalType(expectedType)) {
return;
}
registerError(castTypeElement, expectedType);
}
@@ -65,3 +65,9 @@ class SubClass2 extends SubClass{
super.doSmth();
}
}
class SAM {
{
Object runnable = (Runnable) () -> {};
}
}
@@ -1,5 +1,6 @@
package com.siyeh.ig.abstraction;
import com.intellij.codeInspection.ex.LocalInspectionToolWrapper;
import com.siyeh.ig.IGInspectionTestCase;
public class OverlyStrongTypeCastInspectionTest extends IGInspectionTestCase {
@@ -7,6 +8,6 @@ public class OverlyStrongTypeCastInspectionTest extends IGInspectionTestCase {
public void test() throws Exception {
final OverlyStrongTypeCastInspection tool = new OverlyStrongTypeCastInspection();
tool.ignoreInMatchingInstanceof = true;
doTest("com/siyeh/igtest/abstraction/overly_strong_type_cast", tool);
doTest("com/siyeh/igtest/abstraction/overly_strong_type_cast", new LocalInspectionToolWrapper(tool), "java 1.8");
}
}