mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-20 13:31:28 +07:00
anonymous -> lambda: treat class initializers as fields when forward references are check (IDEA-153254)
This commit is contained in:
@@ -497,15 +497,15 @@ public class AnonymousCanBeLambdaInspection extends BaseJavaBatchLocalInspection
|
||||
|
||||
super.visitReferenceExpression(expression);
|
||||
if (!(expression.getParent() instanceof PsiMethodCallExpression)) {
|
||||
final PsiField field = PsiTreeUtil.getParentOfType(expression, PsiField.class);
|
||||
if (field != null) {
|
||||
final PsiMember member = PsiTreeUtil.getParentOfType(myAnonymClass, PsiMember.class);
|
||||
if (member instanceof PsiField || member instanceof PsiClassInitializer) {
|
||||
final PsiElement resolved = expression.resolve();
|
||||
if (resolved instanceof PsiField &&
|
||||
((PsiField)resolved).getContainingClass() == field.getContainingClass() &&
|
||||
if (resolved instanceof PsiField &&
|
||||
((PsiField)resolved).getContainingClass() == member.getContainingClass() &&
|
||||
expression.getQualifierExpression() == null) {
|
||||
final PsiExpression initializer = ((PsiField)resolved).getInitializer();
|
||||
if (initializer == null ||
|
||||
resolved == field ||
|
||||
resolved == member ||
|
||||
initializer.getTextOffset() > myAnonymClass.getTextOffset() && !((PsiField)resolved).hasModifierProperty(PsiModifier.STATIC)) {
|
||||
myBodyContainsForbiddenRefs = true;
|
||||
return;
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
// "Replace with lambda" "false"
|
||||
class ForwardReference {
|
||||
Runnable TREE_UPDATER;
|
||||
|
||||
{
|
||||
TREE_UPDATER = new Runna<caret>ble() {
|
||||
@Override
|
||||
public void run() {
|
||||
myTree.toString();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Object myTree;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
// "Replace with lambda" "false"
|
||||
class ForwardReference {
|
||||
static Runnable TREE_UPDATER;
|
||||
|
||||
static {
|
||||
TREE_UPDATER = new Runna<caret>ble() {
|
||||
@Override
|
||||
public void run() {
|
||||
myTree.toString();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
static Object myTree;
|
||||
}
|
||||
Reference in New Issue
Block a user