mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-19 04:51:24 +07:00
anonym -> lambda: do not suggest when forward references are detected (IDEA-120699)
This commit is contained in:
@@ -130,10 +130,12 @@ public class AnonymousCanBeLambdaInspection extends BaseJavaBatchLocalInspection
|
||||
final PsiField field = PsiTreeUtil.getParentOfType(expression, PsiField.class);
|
||||
if (field != null) {
|
||||
final PsiElement resolved = expression.resolve();
|
||||
if (resolved instanceof PsiField &&
|
||||
!((PsiField)resolved).hasInitializer() &&
|
||||
((PsiField)resolved).getContainingClass() == field.getContainingClass()) {
|
||||
bodyContainsForbiddenRefs[0] = true;
|
||||
if (resolved instanceof PsiField && ((PsiField)resolved).getContainingClass() == field.getContainingClass()) {
|
||||
final PsiExpression initializer = ((PsiField)resolved).getInitializer();
|
||||
if (initializer == null ||
|
||||
initializer.getTextOffset() > aClass.getTextOffset() && !((PsiField)resolved).hasModifierProperty(PsiModifier.STATIC)) {
|
||||
bodyContainsForbiddenRefs[0] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
// "Replace with lambda" "true"
|
||||
class HelloLambda {
|
||||
private final Runnable r = () -> {
|
||||
System.out.println(x);
|
||||
};
|
||||
private static int x = 0;
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
// "Replace with lambda" "false"
|
||||
class HelloLambda {
|
||||
private final Runnable r = new Run<caret>nable() {
|
||||
@Override
|
||||
public void run() {
|
||||
System.out.println(x);
|
||||
}
|
||||
};
|
||||
private int x = 0;
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
// "Replace with lambda" "true"
|
||||
class HelloLambda {
|
||||
private final Runnable r = new Run<caret>nable() {
|
||||
@Override
|
||||
public void run() {
|
||||
System.out.println(x);
|
||||
}
|
||||
};
|
||||
private static int x = 0;
|
||||
}
|
||||
Reference in New Issue
Block a user