mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-05-06 05:10:22 +07:00
introduce local variable intention should not go to outer anonymous class (IDEA-141716)
This commit is contained in:
@@ -47,7 +47,7 @@ public class IntroduceVariableIntentionAction extends BaseRefactoringIntentionAc
|
||||
return false;
|
||||
}
|
||||
|
||||
final PsiExpressionStatement statement = PsiTreeUtil.getParentOfType(element,PsiExpressionStatement.class);
|
||||
final PsiExpressionStatement statement = detectExpressionStatement(element);
|
||||
if (statement == null){
|
||||
return false;
|
||||
}
|
||||
@@ -59,11 +59,17 @@ public class IntroduceVariableIntentionAction extends BaseRefactoringIntentionAc
|
||||
|
||||
@Override
|
||||
public void invoke(@NotNull Project project, Editor editor, @NotNull PsiElement element) throws IncorrectOperationException {
|
||||
final PsiExpressionStatement statement = PsiTreeUtil.getParentOfType(element,PsiExpressionStatement.class);
|
||||
final PsiExpressionStatement statement = detectExpressionStatement(element);
|
||||
if (statement == null){
|
||||
return;
|
||||
}
|
||||
|
||||
new IntroduceVariableHandler().invoke(project, editor, statement.getExpression());
|
||||
}
|
||||
|
||||
private static PsiExpressionStatement detectExpressionStatement(@NotNull PsiElement element) {
|
||||
final PsiElement prevSibling = PsiTreeUtil.skipSiblingsBackward(element, PsiWhiteSpace.class);
|
||||
return prevSibling instanceof PsiExpressionStatement ? (PsiExpressionStatement)prevSibling
|
||||
: PsiTreeUtil.getParentOfType(element, PsiExpressionStatement.class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
// "Introduce local variable" "true"
|
||||
class a {
|
||||
void a() {
|
||||
list.add(new Runnable(){
|
||||
@Override
|
||||
public void run() {
|
||||
int i = Integer.parseInt("10");
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
// "Introduce local variable" "true"
|
||||
class a {
|
||||
void a() {
|
||||
list.add(new Runnable(){
|
||||
@Override
|
||||
public void run() {
|
||||
Integer.parseInt("10")<caret>
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,11 @@ import com.intellij.codeInsight.daemon.LightIntentionActionTestCase;
|
||||
public class IntroduceVariableQuickFixTest extends LightIntentionActionTestCase {
|
||||
public void test() throws Exception { doAllTests(); }
|
||||
|
||||
@Override
|
||||
protected boolean shouldBeAvailableAfterExecution() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getBasePath() {
|
||||
return "/codeInsight/daemonCodeAnalyzer/quickFix/introduceVariable";
|
||||
|
||||
Reference in New Issue
Block a user