mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Lambda inlining: handle try-catches in lambda
This commit is contained in:
+4
@@ -1865,6 +1865,8 @@ public class ControlFlowAnalyzer extends JavaElementVisitor {
|
||||
PsiLambdaExpression oldLambda = myAnalyzer.myLambdaExpression;
|
||||
myAnalyzer.myLambdaExpression = lambda;
|
||||
myAnalyzer.startElement(lambda);
|
||||
// Transfer value is pushed to avoid emptying stack beyond this point
|
||||
push(getFactory().controlTransfer(ReturnTransfer.INSTANCE, myAnalyzer.myTrapStack));
|
||||
try {
|
||||
PsiElement body = lambda.getBody();
|
||||
Objects.requireNonNull(body).accept(myAnalyzer);
|
||||
@@ -1876,6 +1878,8 @@ public class ControlFlowAnalyzer extends JavaElementVisitor {
|
||||
}
|
||||
}
|
||||
finally {
|
||||
// Pop transfer value (which is second value in stack now)
|
||||
splice(2, 0);
|
||||
myAnalyzer.finishElement(lambda);
|
||||
myAnalyzer.myLambdaExpression = oldLambda;
|
||||
}
|
||||
|
||||
@@ -12,4 +12,19 @@ public class LambdaInlining {
|
||||
System.out.println("oops");
|
||||
}
|
||||
}
|
||||
|
||||
void testLambdaTryCatch() {
|
||||
int x = ((IntSupplier)(() -> {
|
||||
try {
|
||||
return Math.random() > 0.5 ? 2 : 3;
|
||||
}
|
||||
catch (Exception ex) {
|
||||
|
||||
}
|
||||
return 1;
|
||||
})).getAsInt();
|
||||
if(<warning descr="Condition 'x == 0' is always 'false'">x == 0</warning>) {
|
||||
System.out.println("oops");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user