mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
Introduce variable intention fixed
This commit is contained in:
@@ -21,6 +21,7 @@ import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.SyntheticElement;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.*;
|
||||
@@ -34,6 +35,11 @@ public abstract class BaseRefactoringAction extends PsiElementBaseIntentionActio
|
||||
return super.isAvailable(project, editor, file);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
|
||||
super.invoke(project, editor, file);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean isAvailable(@NotNull Project project, Editor editor, @NotNull PsiElement element) {
|
||||
return !(element instanceof SyntheticElement) && isAvailableOverride(project, editor, element);
|
||||
|
||||
+11
-13
@@ -43,25 +43,23 @@ public class IntroduceVariableIntentionAction extends BaseRefactoringAction {
|
||||
|
||||
@Override
|
||||
protected boolean isAvailableOverride(@NotNull Project project, Editor editor, @NotNull PsiElement element) {
|
||||
final PsiExpression expression = getExpression(element);
|
||||
if (expression == null || !(expression.getParent() instanceof PsiExpressionStatement)) {
|
||||
final PsiExpressionStatement statement = PsiTreeUtil.getParentOfType(element,PsiExpressionStatement.class);
|
||||
if (statement == null){
|
||||
return false;
|
||||
}
|
||||
|
||||
final PsiExpression expression = statement.getExpression();
|
||||
|
||||
return expression.getType() != PsiType.VOID && !(expression instanceof PsiAssignmentExpression);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static PsiExpression getExpression(@NotNull PsiElement element) {
|
||||
PsiExpression expression = PsiTreeUtil.getParentOfType(element, PsiExpression.class, false);
|
||||
while (expression != null && expression instanceof PsiReferenceExpression) {
|
||||
expression = PsiTreeUtil.getParentOfType(expression, PsiExpression.class, true);
|
||||
}
|
||||
return expression;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
|
||||
new IntroduceVariableHandler().invoke(project, editor, file, null);
|
||||
public void invoke(@NotNull Project project, Editor editor, @NotNull PsiElement element) throws IncorrectOperationException {
|
||||
final PsiExpressionStatement statement = PsiTreeUtil.getParentOfType(element,PsiExpressionStatement.class);
|
||||
if (statement == null){
|
||||
return;
|
||||
}
|
||||
|
||||
new IntroduceVariableHandler().invoke(project, editor, statement.getExpression());
|
||||
}
|
||||
}
|
||||
|
||||
+4
@@ -33,11 +33,15 @@ import com.intellij.refactoring.ui.ConflictsDialog;
|
||||
import com.intellij.refactoring.ui.TypeSelectorManagerImpl;
|
||||
import com.intellij.refactoring.util.CommonRefactoringUtil;
|
||||
import com.intellij.util.containers.MultiMap;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class IntroduceVariableHandler extends IntroduceVariableBase {
|
||||
|
||||
public void invoke(@NotNull final Project project, final Editor editor, final PsiExpression expression) {
|
||||
invokeImpl(project, expression, editor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IntroduceVariableSettings getSettings(Project project, Editor editor,
|
||||
|
||||
Reference in New Issue
Block a user