mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-19 13:02:30 +07:00
forbid forward references from lambda again (IDEA-119936)
This commit is contained in:
@@ -1765,7 +1765,7 @@ public class HighlightUtil extends HighlightUtilBase {
|
||||
if (expression.getTextRange().getStartOffset() >= referencedField.getTextRange().getEndOffset()) return null;
|
||||
// only simple reference can be illegal
|
||||
if (expression.getQualifierExpression() != null) return null;
|
||||
PsiField initField = findEnclosingFieldInitializer(expression, true);
|
||||
PsiField initField = findEnclosingFieldInitializer(expression);
|
||||
PsiClassInitializer classInitializer = findParentClassInitializer(expression);
|
||||
if (initField == null && classInitializer == null) return null;
|
||||
// instance initializers may access static fields
|
||||
@@ -1786,11 +1786,6 @@ public class HighlightUtil extends HighlightUtilBase {
|
||||
*/
|
||||
@Nullable
|
||||
public static PsiField findEnclosingFieldInitializer(@Nullable PsiElement element) {
|
||||
return findEnclosingFieldInitializer(element, false);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static PsiField findEnclosingFieldInitializer(@Nullable PsiElement element, boolean stopAtLambda) {
|
||||
while (element != null) {
|
||||
PsiElement parent = element.getParent();
|
||||
if (parent instanceof PsiField) {
|
||||
@@ -1798,7 +1793,7 @@ public class HighlightUtil extends HighlightUtilBase {
|
||||
if (element == field.getInitializer()) return field;
|
||||
if (field instanceof PsiEnumConstant && element == ((PsiEnumConstant)field).getArgumentList()) return field;
|
||||
}
|
||||
if (element instanceof PsiClass || element instanceof PsiMethod || (stopAtLambda && parent instanceof PsiLambdaExpression)) return null;
|
||||
if (element instanceof PsiClass || element instanceof PsiMethod) return null;
|
||||
element = parent;
|
||||
}
|
||||
return null;
|
||||
|
||||
@@ -129,7 +129,6 @@ public class AnonymousCanBeLambdaInspection extends BaseJavaBatchLocalInspection
|
||||
if (field != null) {
|
||||
final PsiElement resolved = expression.resolve();
|
||||
if (resolved instanceof PsiField &&
|
||||
((PsiField)resolved).hasModifierProperty(PsiModifier.FINAL) &&
|
||||
!((PsiField)resolved).hasInitializer() &&
|
||||
((PsiField)resolved).getContainingClass() == field.getContainingClass()) {
|
||||
bodyContainsForbiddenRefs[0] = true;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
public class LambdaTest {
|
||||
Op lambda_fib = (n) -> (n < 2) ? 1 : lambda_fib.op(n - 1) + lambda_fib.op(n - 2);
|
||||
Op lambda_fib = (n) -> (n < 2) ? 1 : <error descr="Illegal forward reference">lambda_fib</error>.op(n - 1) + <error descr="Illegal forward reference">lambda_fib</error>.op(n - 2);
|
||||
|
||||
{
|
||||
Op lambda_fib = (n) -> (n < 2) ? 1 : <error descr="Variable 'lambda_fib' might not have been initialized">lambda_fib</error>.op(n - 1) + lambda_fib.op(n - 2);
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
// "Replace with lambda" "false"
|
||||
class MyTest {
|
||||
final Runnable anonymRunnable = new Run<caret>nable() {
|
||||
@Override
|
||||
public void run() {
|
||||
System.out.println(o);
|
||||
}
|
||||
};
|
||||
|
||||
Object o;
|
||||
}
|
||||
Reference in New Issue
Block a user