mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
IDEA-205881 Remove redundant cast leads to incompilable code
This commit is contained in:
@@ -829,7 +829,16 @@ public class LambdaUtil {
|
||||
anEnum.add(resolveMethod);
|
||||
return (PsiCall)anEnum.add(call);
|
||||
}
|
||||
PsiType type = PsiTypesUtil.getExpectedTypeByParent(call);
|
||||
PsiElement expressionForType = call;
|
||||
while (true) {
|
||||
PsiElement parent = PsiUtil.skipParenthesizedExprUp(expressionForType.getParent());
|
||||
if (!(parent instanceof PsiConditionalExpression) ||
|
||||
PsiTreeUtil.isAncestor(((PsiConditionalExpression)parent).getCondition(), expressionForType, false)) {
|
||||
break;
|
||||
}
|
||||
expressionForType = parent;
|
||||
}
|
||||
PsiType type = PsiTypesUtil.getExpectedTypeByParent(expressionForType);
|
||||
if (type != null && PsiTypesUtil.isDenotableType(type, call)) {
|
||||
return (PsiCall)copyWithExpectedType(call, type);
|
||||
}
|
||||
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
import java.util.function.*;
|
||||
import java.util.*;
|
||||
|
||||
class Y {
|
||||
<T> List<T> filter(Collection<? extends T> collection,
|
||||
Predicate<? super T> condition) {return null;}
|
||||
boolean testString(String s) {return s.isEmpty();}
|
||||
List<Object> test(List<String> input, boolean b) {
|
||||
return b ? new ArrayList<>() : filter(input, o -> o instanceof String && testString((String)o));
|
||||
}
|
||||
}
|
||||
+3
@@ -90,6 +90,9 @@ public class LambdaRedundantCastTest extends LightDaemonAnalyzerTestCase {
|
||||
public void testInvalidConditional() {
|
||||
doTest();
|
||||
}
|
||||
public void testSuperBoundLambda() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
private void doTest() {
|
||||
doTest(BASE_PATH + "/" + getTestName(false) + ".java", true, false);
|
||||
|
||||
Reference in New Issue
Block a user