mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-05-06 05:10:22 +07:00
create local from usage: check containing code block (IDEA-178443)
This commit is contained in:
@@ -56,12 +56,7 @@ public class CreateLocalFromUsageFix extends CreateVarFromUsageFix {
|
||||
protected boolean isAvailableImpl(int offset) {
|
||||
if (!super.isAvailableImpl(offset)) return false;
|
||||
if(myReferenceExpression.isQualified()) return false;
|
||||
PsiElement scope = PsiTreeUtil.getParentOfType(myReferenceExpression, PsiModifierListOwner.class);
|
||||
if (scope instanceof PsiAnonymousClass) {
|
||||
scope = PsiTreeUtil.getParentOfType(scope, PsiModifierListOwner.class, true);
|
||||
}
|
||||
return scope instanceof PsiMethod || scope instanceof PsiClassInitializer ||
|
||||
scope instanceof PsiLocalVariable;
|
||||
return PsiTreeUtil.getParentOfType(myReferenceExpression, PsiCodeBlock.class) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
// "Create local variable 'x'" "true"
|
||||
class other {
|
||||
Runnable field = () -> {
|
||||
Object x;
|
||||
x};
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
// "Create local variable 'x'" "true"
|
||||
class other {
|
||||
Runnable field = () -> {<caret>x};
|
||||
}
|
||||
Reference in New Issue
Block a user