mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-03-22 15:19:59 +07:00
[java-inspections] TrivialFunctionalExpressionUsage: do not report for any parent statement
Also: report any lambda inside parent return statement Fixes IDEA-356003 Method call should not be simplified GitOrigin-RevId: cb39dd33d27ba402a503707daffcc831ab59b49e
This commit is contained in:
committed by
intellij-monorepo-bot
parent
de8298a11f
commit
2c766e6df0
@@ -93,11 +93,13 @@ public final class TrivialFunctionalExpressionUsageInspection extends AbstractBa
|
||||
return callParent instanceof PsiStatement || callParent instanceof PsiLocalVariable || expression.isValueCompatible();
|
||||
}
|
||||
|
||||
if (callParent instanceof PsiReturnStatement) {
|
||||
return true;
|
||||
}
|
||||
|
||||
PsiStatement[] statements = ((PsiCodeBlock)body).getStatements();
|
||||
if (statements.length == 1) {
|
||||
return callParent instanceof PsiStatement
|
||||
|| callParent instanceof PsiLocalVariable
|
||||
|| statements[0] instanceof PsiReturnStatement && expression.isValueCompatible();
|
||||
return statements[0] instanceof PsiReturnStatement && expression.isValueCompatible();
|
||||
}
|
||||
|
||||
final PsiReturnStatement[] returnStatements = PsiUtil.findReturnStatements((PsiCodeBlock)body);
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
// "Replace method call on lambda with lambda body" "true-preview"
|
||||
import java.util.function.Supplier;
|
||||
|
||||
class Test {
|
||||
public static int test() {
|
||||
for (int i = 0; i < 10; i++) {
|
||||
final int finalI = i;
|
||||
System.out.println("hello");
|
||||
try {
|
||||
if (finalI > 3) {
|
||||
return 123;
|
||||
}
|
||||
System.out.println(finalI);
|
||||
} catch (Exception ignored) {
|
||||
return 456;
|
||||
}
|
||||
return 456;
|
||||
}
|
||||
System.out.println("Hello");
|
||||
return 3;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(test());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
// "Replace method call on lambda with lambda body" "false"
|
||||
class Test {
|
||||
public static void main(String[] args) {
|
||||
for (int i = 0; i < 10; i++) {
|
||||
final int finalI = i;
|
||||
((Runnable) () -> {
|
||||
try {
|
||||
if (finalI > 3) {
|
||||
return;
|
||||
}
|
||||
System.out.println(finalI);
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}).ru<caret>n();
|
||||
}
|
||||
System.out.println("Hello");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
// "Replace method call on lambda with lambda body" "true-preview"
|
||||
import java.util.function.Supplier;
|
||||
|
||||
class Test {
|
||||
public static int test() {
|
||||
for (int i = 0; i < 10; i++) {
|
||||
final int finalI = i;
|
||||
return ((Supplier<Integer>) () -> {
|
||||
System.out.println("hello");
|
||||
try {
|
||||
if (finalI > 3) {
|
||||
return 123;
|
||||
}
|
||||
System.out.println(finalI);
|
||||
} catch (Exception ignored) {
|
||||
return 456;
|
||||
}
|
||||
return 456;
|
||||
}).<caret>get();
|
||||
}
|
||||
System.out.println("Hello");
|
||||
return 3;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(test());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user