mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-13 21:55:01 +07:00
redundant cast: don't highlight conditional with functional branches (IDEA-161971)
This commit is contained in:
@@ -807,6 +807,13 @@ public class RedundantCastUtil {
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (stripParenthesisOperand instanceof PsiConditionalExpression) {
|
||||
final PsiExpression thenExpr = PsiUtil.skipParenthesizedExprDown(((PsiConditionalExpression)stripParenthesisOperand).getThenExpression());
|
||||
final PsiExpression elseExpr = PsiUtil.skipParenthesizedExprDown(((PsiConditionalExpression)stripParenthesisOperand).getElseExpression());
|
||||
if (thenExpr instanceof PsiFunctionalExpression || elseExpr instanceof PsiFunctionalExpression) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
PsiElement parent = typeCast.getParent();
|
||||
while(parent instanceof PsiParenthesizedExpression) parent = parent.getParent();
|
||||
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
import java.util.function.Function;
|
||||
|
||||
class Main {
|
||||
public static void main(String[] args) {
|
||||
Test test = new Test();
|
||||
((Function<String, Long>)(args.length == 2 ? (<error descr="Method reference expression is not expected here">test::foo</error>) : <error descr="Method reference expression is not expected here">test::bar</error>)).apply("");
|
||||
}
|
||||
|
||||
static class Test {
|
||||
public long foo(String s) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public long bar(String s) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
+4
@@ -84,6 +84,10 @@ public class LambdaRedundantCastTest extends LightDaemonAnalyzerTestCase {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testInvalidConditional() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
private void doTest() {
|
||||
doTest(BASE_PATH + "/" + getTestName(false) + ".java", true, false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user