mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
extract method object: do not show dialog under write action (IDEA-74057)
This commit is contained in:
@@ -576,7 +576,6 @@ public class ExtractMethodProcessor implements MatchProvider {
|
||||
myEditor.getCaretModel().moveToOffset(offset);
|
||||
myEditor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE);
|
||||
myEditor.getSelectionModel().removeSelection();
|
||||
myEditor.getSelectionModel().removeSelection();
|
||||
}
|
||||
|
||||
private void doExtract() throws IncorrectOperationException {
|
||||
|
||||
+35
-13
@@ -21,14 +21,19 @@
|
||||
package com.intellij.refactoring.extractMethodObject;
|
||||
|
||||
import com.intellij.openapi.actionSystem.DataContext;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.application.Result;
|
||||
import com.intellij.openapi.command.CommandProcessor;
|
||||
import com.intellij.openapi.command.WriteCommandAction;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.editor.LogicalPosition;
|
||||
import com.intellij.openapi.editor.RangeMarker;
|
||||
import com.intellij.openapi.editor.ScrollType;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Pass;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.refactoring.HelpID;
|
||||
import com.intellij.refactoring.RefactoringActionHandler;
|
||||
import com.intellij.refactoring.RefactoringBundle;
|
||||
@@ -36,6 +41,7 @@ import com.intellij.refactoring.extractMethod.ExtractMethodHandler;
|
||||
import com.intellij.refactoring.extractMethod.PrepareFailedException;
|
||||
import com.intellij.refactoring.util.CommonRefactoringUtil;
|
||||
import com.intellij.refactoring.util.duplicates.DuplicatesImpl;
|
||||
import com.intellij.usageView.UsageInfo;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ExtractMethodObjectHandler implements RefactoringActionHandler {
|
||||
@@ -69,24 +75,40 @@ public class ExtractMethodObjectHandler implements RefactoringActionHandler {
|
||||
}
|
||||
|
||||
if (!CommonRefactoringUtil.checkReadOnlyStatus(project, extractProcessor.getTargetClass().getContainingFile())) return;
|
||||
|
||||
final int offset = editor.getCaretModel().getOffset();
|
||||
final RangeMarker marker = editor.getDocument().createRangeMarker(new TextRange(offset, offset));
|
||||
if (extractProcessor.showDialog()) {
|
||||
new WriteCommandAction(project, ExtractMethodObjectProcessor.REFACTORING_NAME, ExtractMethodObjectProcessor.REFACTORING_NAME) {
|
||||
protected void run(final Result result) throws Throwable {
|
||||
extractProcessor.doRefactoring();
|
||||
CommandProcessor.getInstance().executeCommand(project, new Runnable() {
|
||||
public void run() {
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
extractProcessor.doRefactoring();
|
||||
}
|
||||
});
|
||||
|
||||
processor.run();
|
||||
processor.runChangeSignature();
|
||||
PsiDocumentManager.getInstance(project).commitAllDocuments();
|
||||
if (processor.isCreateInnerClass()) {
|
||||
|
||||
processor.moveUsedMethodsToInner();
|
||||
|
||||
DuplicatesImpl.processDuplicates(extractProcessor, project, editor);
|
||||
processor.changeInstanceAccess(project);
|
||||
}
|
||||
final PsiElement method = processor.getMethod();
|
||||
LOG.assertTrue(method != null);
|
||||
method.delete();
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (processor.isCreateInnerClass()) {
|
||||
processor.changeInstanceAccess(project);
|
||||
}
|
||||
final PsiElement method = processor.getMethod();
|
||||
LOG.assertTrue(method != null);
|
||||
method.delete();
|
||||
}
|
||||
});
|
||||
}
|
||||
}.execute();
|
||||
}, ExtractMethodObjectProcessor.REFACTORING_NAME, ExtractMethodObjectProcessor.REFACTORING_NAME);
|
||||
editor.getCaretModel().moveToOffset(marker.getStartOffset());
|
||||
editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+21
-6
@@ -71,7 +71,7 @@ public class ExtractMethodObjectProcessor extends BaseRefactoringProcessor {
|
||||
|
||||
private final PsiElementFactory myElementFactory;
|
||||
|
||||
private final MyExtractMethodProcessor myExtractProcessor;
|
||||
protected final MyExtractMethodProcessor myExtractProcessor;
|
||||
private boolean myCreateInnerClass = true;
|
||||
private String myInnerClassName;
|
||||
|
||||
@@ -82,6 +82,8 @@ public class ExtractMethodObjectProcessor extends BaseRefactoringProcessor {
|
||||
private boolean myMadeStatic = false;
|
||||
private final Set<MethodToMoveUsageInfo> myUsages = new HashSet<MethodToMoveUsageInfo>();
|
||||
private PsiClass myInnerClass;
|
||||
private ChangeSignatureProcessor myChangeSignatureProcessor;
|
||||
private Runnable myCopyMethodToInner;
|
||||
|
||||
public ExtractMethodObjectProcessor(Project project, Editor editor, PsiElement[] elements, final String innerClassName) {
|
||||
super(project);
|
||||
@@ -170,8 +172,12 @@ public class ExtractMethodObjectProcessor extends BaseRefactoringProcessor {
|
||||
if (myMultipleExitPoints) {
|
||||
addOutputVariableFieldsWithGetters();
|
||||
}
|
||||
copyMethodWithoutParameters();
|
||||
copyMethodTypeParameters();
|
||||
myCopyMethodToInner = new Runnable() {
|
||||
public void run() {
|
||||
copyMethodWithoutParameters();
|
||||
copyMethodTypeParameters();
|
||||
}
|
||||
};
|
||||
} else {
|
||||
for (UsageInfo usage : usages) {
|
||||
final PsiMethodCallExpression methodCallExpression = PsiTreeUtil.getParentOfType(usage.getElement(), PsiMethodCallExpression.class);
|
||||
@@ -254,9 +260,6 @@ public class ExtractMethodObjectProcessor extends BaseRefactoringProcessor {
|
||||
PsiParameter param = params[i];
|
||||
infos[i] = new ParameterInfoImpl(i, param.getName(), param.getType());
|
||||
}
|
||||
ChangeSignatureProcessor cp = new ChangeSignatureProcessor(myProject, getMethod(), false, null, getMethod().getName(),
|
||||
new PsiImmediateClassType(myInnerClass, PsiSubstitutor.EMPTY), infos);
|
||||
cp.run();
|
||||
final PsiCodeBlock body = getMethod().getBody();
|
||||
LOG.assertTrue(body != null);
|
||||
final List<PsiLocalVariable> vars = new ArrayList<PsiLocalVariable>();
|
||||
@@ -361,6 +364,18 @@ public class ExtractMethodObjectProcessor extends BaseRefactoringProcessor {
|
||||
statement.delete();
|
||||
}
|
||||
}
|
||||
|
||||
myChangeSignatureProcessor = new ChangeSignatureProcessor(myProject, getMethod(), false, null, getMethod().getName(),
|
||||
new PsiImmediateClassType(myInnerClass, PsiSubstitutor.EMPTY), infos);
|
||||
}
|
||||
|
||||
public void runChangeSignature() {
|
||||
if (myChangeSignatureProcessor != null) {
|
||||
myChangeSignatureProcessor.run();
|
||||
}
|
||||
if (myCopyMethodToInner != null) {
|
||||
ApplicationManager.getApplication().runWriteAction(myCopyMethodToInner);
|
||||
}
|
||||
}
|
||||
|
||||
private String getPureName(PsiVariable var) {
|
||||
|
||||
@@ -42,6 +42,7 @@ public class ExtractMethodObjectTest extends LightCodeInsightTestCase {
|
||||
extractProcessor.testRun();
|
||||
processor.setCreateInnerClass(createInnerClass);
|
||||
processor.run();
|
||||
processor.runChangeSignature();
|
||||
if (createInnerClass) {
|
||||
processor.moveUsedMethodsToInner();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user