mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-16 22:51:17 +07:00
TrivialFunctionalExpressionUsageInspection: disable for multi-statement lambda in "for" init/update
This commit is contained in:
@@ -53,7 +53,7 @@ public class BytecodeAnalysisIndex extends ScalarIndexExtension<Bytes> {
|
||||
private static final ID<Bytes, Void> NAME = ID.create("bytecodeAnalysis");
|
||||
private static final HKeyDescriptor KEY_DESCRIPTOR = new HKeyDescriptor();
|
||||
private static final VirtualFileGist<Map<Bytes, HEquations>> ourGist = GistManager.getInstance().newVirtualFileGist(
|
||||
"BytecodeAnalysisIndex", 4, new HEquationsExternalizer(), new ClassDataIndexer());
|
||||
"BytecodeAnalysisIndex", 5, new HEquationsExternalizer(), new ClassDataIndexer());
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
|
||||
@@ -556,9 +556,6 @@ final class HardCodedPurity {
|
||||
// Maybe overloaded and be not pure, but this would be definitely bad code style
|
||||
// Used in Throwable(Throwable) ctor, so this helps to infer purity of many exception constructors
|
||||
new Method("java/lang/Throwable", "toString", "()Ljava/lang/String;"),
|
||||
// Declared in final class StringBuilder
|
||||
new Method("java/lang/StringBuilder", "toString", "()Ljava/lang/String;"),
|
||||
new Method("java/lang/StringBuffer", "toString", "()Ljava/lang/String;"),
|
||||
// Native
|
||||
new Method("java/lang/Object", "getClass", "()Ljava/lang/Class;"),
|
||||
new Method("java/lang/Class", "getComponentType", "()Ljava/lang/Class;"),
|
||||
@@ -596,7 +593,8 @@ final class HardCodedPurity {
|
||||
}
|
||||
|
||||
static boolean isPureMethod(Key key) {
|
||||
return pureMethods.contains(key.method);
|
||||
return key.method.methodName.equals("toString") && key.method.methodDesc.equals("()Ljava/lang/String;") ||
|
||||
pureMethods.contains(key.method);
|
||||
}
|
||||
|
||||
static boolean isOwnedField(FieldInsnNode fieldInsn) {
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
// "Replace method call on lambda with lambda body" "false"
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
int i = 0;
|
||||
for (((Runnable) (() -> {
|
||||
System.out.println("Hello");
|
||||
System.out.println("World");
|
||||
})).r<caret>un(); i < 10; ) {
|
||||
System.out.println(i++);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// "Replace method call on lambda with lambda body" "false"
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
for (int i = 0; i < 10; ((Runnable) (() -> {
|
||||
System.out.println("Hello");
|
||||
System.out.println("World");
|
||||
return;
|
||||
})).ru<caret>n()) {
|
||||
System.out.println(i++);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -75,8 +75,13 @@ public class TrivialFunctionalExpressionUsageInspection extends BaseJavaBatchLoc
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return true;
|
||||
}
|
||||
|
||||
if(callParent instanceof PsiExpressionStatement) {
|
||||
PsiElement statementParent = callParent.getParent();
|
||||
// Disable in "for" initialization or update
|
||||
if(statementParent instanceof PsiForStatement && callParent != ((PsiForStatement)statementParent).getBody()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user