mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
run refactoring tests outside the write action and get rid of testRun()
This commit is contained in:
+16
-6
@@ -15,6 +15,8 @@
|
||||
*/
|
||||
package com.intellij.codeInsight.daemon.impl.quickfix;
|
||||
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.util.Computable;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.controlFlow.ReturnStatementsVisitor;
|
||||
import com.intellij.psi.util.PsiTypesUtil;
|
||||
@@ -23,7 +25,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ConvertReturnStatementsVisitor implements ReturnStatementsVisitor {
|
||||
class ConvertReturnStatementsVisitor implements ReturnStatementsVisitor {
|
||||
private final PsiElementFactory myFactory;
|
||||
private final PsiMethod myMethod;
|
||||
private final DeclarationSearcher mySearcher;
|
||||
@@ -39,7 +41,11 @@ public class ConvertReturnStatementsVisitor implements ReturnStatementsVisitor {
|
||||
|
||||
@Override
|
||||
public void visit(final List<PsiReturnStatement> returnStatements) throws IncorrectOperationException {
|
||||
final PsiReturnStatement statement = replaceReturnStatements(returnStatements);
|
||||
final PsiReturnStatement statement = ApplicationManager.getApplication().runWriteAction(new Computable<PsiReturnStatement>() {
|
||||
public PsiReturnStatement compute() {
|
||||
return replaceReturnStatements(returnStatements);
|
||||
}
|
||||
});
|
||||
if (statement != null) {
|
||||
myLatestReturn = statement;
|
||||
}
|
||||
@@ -55,10 +61,14 @@ public class ConvertReturnStatementsVisitor implements ReturnStatementsVisitor {
|
||||
}
|
||||
|
||||
public PsiReturnStatement createReturnInLastStatement() throws IncorrectOperationException {
|
||||
PsiCodeBlock body = myMethod.getBody();
|
||||
final String value = generateValue(body.getRBrace());
|
||||
PsiReturnStatement returnStatement = (PsiReturnStatement) myFactory.createStatementFromText("return " + value+";", myMethod);
|
||||
return (PsiReturnStatement) body.addBefore(returnStatement, body.getRBrace());
|
||||
return ApplicationManager.getApplication().runWriteAction(new Computable<PsiReturnStatement>() {
|
||||
public PsiReturnStatement compute() {
|
||||
PsiCodeBlock body = myMethod.getBody();
|
||||
final String value = generateValue(body.getRBrace());
|
||||
PsiReturnStatement returnStatement = (PsiReturnStatement) myFactory.createStatementFromText("return " + value+";", myMethod);
|
||||
return (PsiReturnStatement) body.addBefore(returnStatement, body.getRBrace());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
+22
-36
@@ -122,60 +122,40 @@ public class MethodReturnTypeFix extends LocalQuickFixAndIntentionActionOnPsiEle
|
||||
final List<PsiMethod> affectedMethods = changeReturnType(myMethod, myReturnType);
|
||||
|
||||
PsiElementFactory factory = JavaPsiFacade.getInstance(project).getElementFactory();
|
||||
final SourceMethodSelector returnSelector = new SourceMethodSelector(myMethod);
|
||||
PsiReturnStatement statementToSelect = null;
|
||||
if (!PsiType.VOID.equals(myReturnType)) {
|
||||
final ReturnStatementAdder adder = new ReturnStatementAdder(factory, myReturnType, returnSelector);
|
||||
final ReturnStatementAdder adder = new ReturnStatementAdder(factory, myReturnType);
|
||||
|
||||
for (PsiMethod affectedMethod : affectedMethods) {
|
||||
adder.addReturnForMethod(file, affectedMethod);
|
||||
PsiReturnStatement statement = adder.addReturnForMethod(file, affectedMethod);
|
||||
if (statement != null && affectedMethod == myMethod) {
|
||||
statementToSelect = statement;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
final PsiReturnStatement latestReturn = returnSelector.getReturnStatement();
|
||||
if (latestReturn != null) {
|
||||
Editor editorForMethod = getEditorForMethod(myMethod, project, editor, latestReturn.getContainingFile());
|
||||
if (statementToSelect != null) {
|
||||
Editor editorForMethod = getEditorForMethod(myMethod, project, editor, statementToSelect.getContainingFile());
|
||||
if (editorForMethod != null) {
|
||||
selectReturnValueInEditor(latestReturn, editorForMethod);
|
||||
selectReturnValueInEditor(statementToSelect, editorForMethod);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static class SourceMethodSelector {
|
||||
private final PsiMethod mySourceMethod;
|
||||
private PsiReturnStatement myReturnStatement;
|
||||
|
||||
private SourceMethodSelector(final PsiMethod sourceMethod) {
|
||||
mySourceMethod = sourceMethod;
|
||||
}
|
||||
|
||||
public void accept(final PsiReturnStatement statement, final PsiMethod method) {
|
||||
if (mySourceMethod.equals(method) && statement != null) {
|
||||
myReturnStatement = statement;
|
||||
}
|
||||
}
|
||||
|
||||
public PsiReturnStatement getReturnStatement() {
|
||||
return myReturnStatement;
|
||||
}
|
||||
}
|
||||
|
||||
// to clearly separate data
|
||||
private static class ReturnStatementAdder {
|
||||
private final PsiElementFactory factory;
|
||||
private final PsiType myTargetType;
|
||||
private final SourceMethodSelector mySelector;
|
||||
|
||||
private ReturnStatementAdder(@NotNull final PsiElementFactory factory, @NotNull final PsiType targetType,
|
||||
@NotNull final SourceMethodSelector selector) {
|
||||
private ReturnStatementAdder(@NotNull final PsiElementFactory factory, @NotNull final PsiType targetType) {
|
||||
this.factory = factory;
|
||||
myTargetType = targetType;
|
||||
mySelector = selector;
|
||||
}
|
||||
|
||||
public void addReturnForMethod(final PsiFile file, final PsiMethod method) {
|
||||
public PsiReturnStatement addReturnForMethod(final PsiFile file, final PsiMethod method) {
|
||||
final PsiModifierList modifiers = method.getModifierList();
|
||||
if (modifiers.hasModifierProperty(PsiModifier.ABSTRACT) || method.getBody() == null) {
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -197,15 +177,16 @@ public class MethodReturnTypeFix extends LocalQuickFixAndIntentionActionOnPsiEle
|
||||
else {
|
||||
returnStatement = visitor.createReturnInLastStatement();
|
||||
}
|
||||
mySelector.accept(returnStatement, method);
|
||||
if (method.getContainingFile() != file) {
|
||||
UndoUtil.markPsiFileForUndo(file);
|
||||
}
|
||||
return returnStatement;
|
||||
}
|
||||
catch (IncorrectOperationException e) {
|
||||
LOG.error(e);
|
||||
}
|
||||
|
||||
if (method.getContainingFile() != file) {
|
||||
UndoUtil.markPsiFileForUndo(file);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -401,4 +382,9 @@ public class MethodReturnTypeFix extends LocalQuickFixAndIntentionActionOnPsiEle
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean startInWriteAction() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
+5
-1
@@ -18,7 +18,6 @@ package com.intellij.codeInsight.daemon.impl.quickfix;
|
||||
import com.intellij.codeInsight.CodeInsightUtilBase;
|
||||
import com.intellij.codeInsight.daemon.QuickFixBundle;
|
||||
import com.intellij.codeInspection.LocalQuickFixAndIntentionActionOnPsiElement;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
@@ -100,4 +99,9 @@ public class RemoveUnusedParameterFix extends LocalQuickFixAndIntentionActionOnP
|
||||
}
|
||||
return result.toArray(new ParameterInfoImpl[result.size()]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean startInWriteAction() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
+28
-17
@@ -65,28 +65,36 @@ public class ImplementAbstractMethodHandler {
|
||||
|
||||
final PsiElement[][] result = new PsiElement[1][];
|
||||
ProgressManager.getInstance().runProcessWithProgressSynchronously(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
final PsiClass psiClass = myMethod.getContainingClass();
|
||||
if (!psiClass.isValid()) return;
|
||||
if (!psiClass.isEnum()) {
|
||||
result[0] = getClassImplementations(psiClass);
|
||||
} else {
|
||||
final List<PsiElement> enumConstants = new ArrayList<PsiElement>();
|
||||
for (PsiField field : psiClass.getFields()) {
|
||||
if (field instanceof PsiEnumConstant) {
|
||||
final PsiEnumConstantInitializer initializingClass = ((PsiEnumConstant)field).getInitializingClass();
|
||||
if (initializingClass != null) {
|
||||
PsiMethod method = initializingClass.findMethodBySignature(myMethod, true);
|
||||
if (method == null || !method.getContainingClass().equals(initializingClass)) {
|
||||
enumConstants.add(initializingClass);
|
||||
ApplicationManager.getApplication().runReadAction(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
final PsiClass psiClass = myMethod.getContainingClass();
|
||||
if (!psiClass.isValid()) return;
|
||||
if (!psiClass.isEnum()) {
|
||||
result[0] = getClassImplementations(psiClass);
|
||||
}
|
||||
else {
|
||||
final List<PsiElement> enumConstants = new ArrayList<PsiElement>();
|
||||
for (PsiField field : psiClass.getFields()) {
|
||||
if (field instanceof PsiEnumConstant) {
|
||||
final PsiEnumConstantInitializer initializingClass = ((PsiEnumConstant)field).getInitializingClass();
|
||||
if (initializingClass != null) {
|
||||
PsiMethod method = initializingClass.findMethodBySignature(myMethod, true);
|
||||
if (method == null || !method.getContainingClass().equals(initializingClass)) {
|
||||
enumConstants.add(initializingClass);
|
||||
}
|
||||
}
|
||||
else {
|
||||
enumConstants.add(field);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
enumConstants.add(field);
|
||||
}
|
||||
result[0] = PsiUtilBase.toPsiElementArray(enumConstants);
|
||||
}
|
||||
}
|
||||
result[0] = PsiUtilBase.toPsiElementArray(enumConstants);
|
||||
}
|
||||
});
|
||||
}
|
||||
}, CodeInsightBundle.message("intention.implement.abstract.method.searching.for.descendants.progress"), true, myProject);
|
||||
|
||||
@@ -108,6 +116,7 @@ public class ImplementAbstractMethodHandler {
|
||||
myList = new JBList(result[0]);
|
||||
myList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
|
||||
final Runnable runnable = new Runnable(){
|
||||
@Override
|
||||
public void run() {
|
||||
int index = myList.getSelectedIndex();
|
||||
if (index < 0) return;
|
||||
@@ -131,6 +140,7 @@ public class ImplementAbstractMethodHandler {
|
||||
if (!((PsiElement)o).isValid()) return;
|
||||
}
|
||||
CommandProcessor.getInstance().executeCommand(myProject, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
final LinkedHashSet<PsiClass> classes = new LinkedHashSet<PsiClass>();
|
||||
for (Object o : selection) {
|
||||
@@ -143,6 +153,7 @@ public class ImplementAbstractMethodHandler {
|
||||
}
|
||||
if (!CodeInsightUtilBase.preparePsiElementsForWrite(classes)) return;
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
for (PsiClass psiClass : classes) {
|
||||
try {
|
||||
|
||||
+20
-16
@@ -76,7 +76,7 @@ public class ExtractMethodHandler implements RefactoringActionHandler {
|
||||
selectAndPass(project, editor, file, callback);
|
||||
}
|
||||
|
||||
public static void selectAndPass(final Project project, final Editor editor, final PsiFile file, final Pass<PsiElement[]> callback) {
|
||||
public static void selectAndPass(@NotNull final Project project, @NotNull final Editor editor, @NotNull final PsiFile file, @NotNull final Pass<PsiElement[]> callback) {
|
||||
editor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE);
|
||||
if (!editor.getSelectionModel().hasSelection()) {
|
||||
final int offset = editor.getCaretModel().getOffset();
|
||||
@@ -133,26 +133,30 @@ public class ExtractMethodHandler implements RefactoringActionHandler {
|
||||
private static boolean invokeOnElements(final Project project, final Editor editor, @NotNull final ExtractMethodProcessor processor, final boolean directTypes) {
|
||||
if (!CommonRefactoringUtil.checkReadOnlyStatus(project, processor.getTargetClass().getContainingFile())) return false;
|
||||
if (processor.showDialog(directTypes)) {
|
||||
CommandProcessor.getInstance().executeCommand(project, new Runnable() {
|
||||
public void run() {
|
||||
PostprocessReformattingAspect.getInstance(project).postponeFormattingInside(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
processor.doRefactoring();
|
||||
}
|
||||
catch (IncorrectOperationException e) {
|
||||
LOG.error(e);
|
||||
}
|
||||
DuplicatesImpl.processDuplicates(processor, project, editor);
|
||||
}
|
||||
});
|
||||
}
|
||||
}, REFACTORING_NAME, null);
|
||||
run(project, editor, processor);
|
||||
DuplicatesImpl.processDuplicates(processor, project, editor);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void run(@NotNull final Project project, final Editor editor, final ExtractMethodProcessor processor) {
|
||||
CommandProcessor.getInstance().executeCommand(project, new Runnable() {
|
||||
public void run() {
|
||||
PostprocessReformattingAspect.getInstance(project).postponeFormattingInside(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
processor.doRefactoring();
|
||||
}
|
||||
catch (IncorrectOperationException e) {
|
||||
LOG.error(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}, REFACTORING_NAME, null);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static ExtractMethodProcessor getProcessor(final PsiElement[] elements,
|
||||
final Project project,
|
||||
|
||||
+16
-3
@@ -77,6 +77,7 @@ import com.intellij.util.VisibilityUtil;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.annotations.TestOnly;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@@ -495,15 +496,21 @@ public class ExtractMethodProcessor implements MatchProvider {
|
||||
return showDialog(true);
|
||||
}
|
||||
|
||||
@TestOnly
|
||||
public void testRun() throws IncorrectOperationException {
|
||||
testPrepare();
|
||||
|
||||
ExtractMethodHandler.run(myProject, myEditor, this);
|
||||
}
|
||||
|
||||
@TestOnly
|
||||
public void testPrepare() {
|
||||
myInputVariables.setFoldingAvailable(myInputVariables.isFoldingSelectedByDefault());
|
||||
myMethodName = myInitialMethodName;
|
||||
myVariableDatum = new ParameterTablePanel.VariableData[myInputVariables.getInputVariables().size()];
|
||||
for (int i = 0; i < myInputVariables.getInputVariables().size(); i++) {
|
||||
myVariableDatum[i] = myInputVariables.getInputVariables().get(i);
|
||||
}
|
||||
|
||||
doRefactoring();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -544,7 +551,13 @@ public class ExtractMethodProcessor implements MatchProvider {
|
||||
final Map<PsiMethodCallExpression, PsiMethod> overloadsResolveMap = new HashMap<PsiMethodCallExpression, PsiMethod>();
|
||||
final Runnable collectOverloads = new Runnable() {
|
||||
public void run() {
|
||||
overloadsResolveMap.putAll(ExtractMethodUtil.encodeOverloadTargets(myTargetClass, processConflictsScope, myMethodName, myCodeFragmentMember));
|
||||
ApplicationManager.getApplication().runReadAction(new Runnable() {
|
||||
public void run() {
|
||||
Map<PsiMethodCallExpression, PsiMethod> overloads =
|
||||
ExtractMethodUtil.encodeOverloadTargets(myTargetClass, processConflictsScope, myMethodName, myCodeFragmentMember);
|
||||
overloadsResolveMap.putAll(overloads);
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
final Runnable extract = new Runnable() {
|
||||
|
||||
+43
-37
@@ -22,18 +22,17 @@ 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.openapi.util.TextRange;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.PsiDocumentManager;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.refactoring.HelpID;
|
||||
import com.intellij.refactoring.RefactoringActionHandler;
|
||||
import com.intellij.refactoring.RefactoringBundle;
|
||||
@@ -41,7 +40,6 @@ 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 {
|
||||
@@ -55,7 +53,7 @@ public class ExtractMethodObjectHandler implements RefactoringActionHandler {
|
||||
});
|
||||
}
|
||||
|
||||
private void invokeOnElements(final Project project, final Editor editor, PsiFile file, PsiElement[] elements) {
|
||||
private void invokeOnElements(@NotNull final Project project, @NotNull final Editor editor, @NotNull PsiFile file, @NotNull PsiElement[] elements) {
|
||||
if (elements.length == 0) {
|
||||
String message = RefactoringBundle
|
||||
.getCannotRefactorMessage(RefactoringBundle.message("selected.block.should.represent.a.set.of.statements.or.an.expression"));
|
||||
@@ -75,41 +73,49 @@ public class ExtractMethodObjectHandler implements RefactoringActionHandler {
|
||||
}
|
||||
|
||||
if (!CommonRefactoringUtil.checkReadOnlyStatus(project, extractProcessor.getTargetClass().getContainingFile())) return;
|
||||
if (extractProcessor.showDialog()) {
|
||||
run(project, editor, processor, extractProcessor);
|
||||
}
|
||||
}
|
||||
|
||||
public static void run(@NotNull final Project project,
|
||||
@NotNull final Editor editor,
|
||||
@NotNull final ExtractMethodObjectProcessor processor,
|
||||
@NotNull final ExtractMethodObjectProcessor.MyExtractMethodProcessor extractProcessor) {
|
||||
final int offset = editor.getCaretModel().getOffset();
|
||||
final RangeMarker marker = editor.getDocument().createRangeMarker(new TextRange(offset, offset));
|
||||
if (extractProcessor.showDialog()) {
|
||||
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);
|
||||
CommandProcessor.getInstance().executeCommand(project, new Runnable() {
|
||||
public void run() {
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
extractProcessor.doRefactoring();
|
||||
}
|
||||
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();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
processor.run();
|
||||
processor.runChangeSignature();
|
||||
PsiDocumentManager.getInstance(project).commitAllDocuments();
|
||||
if (processor.isCreateInnerClass()) {
|
||||
processor.moveUsedMethodsToInner();
|
||||
DuplicatesImpl.processDuplicates(extractProcessor, project, editor);
|
||||
}
|
||||
}, ExtractMethodObjectProcessor.REFACTORING_NAME, ExtractMethodObjectProcessor.REFACTORING_NAME);
|
||||
editor.getCaretModel().moveToOffset(marker.getStartOffset());
|
||||
editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE);
|
||||
}
|
||||
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();
|
||||
}
|
||||
});
|
||||
}
|
||||
}, ExtractMethodObjectProcessor.REFACTORING_NAME, ExtractMethodObjectProcessor.REFACTORING_NAME);
|
||||
editor.getCaretModel().moveToOffset(marker.getStartOffset());
|
||||
marker.dispose();
|
||||
editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE);
|
||||
}
|
||||
|
||||
public void invoke(@NotNull final Project project, @NotNull final PsiElement[] elements, final DataContext dataContext) {
|
||||
|
||||
+2
-2
@@ -193,7 +193,7 @@ public class ExtractMethodObjectProcessor extends BaseRefactoringProcessor {
|
||||
}
|
||||
}
|
||||
|
||||
public void moveUsedMethodsToInner() {
|
||||
void moveUsedMethodsToInner() {
|
||||
if (!myUsages.isEmpty()) {
|
||||
if (ApplicationManager.getApplication().isUnitTestMode()) {
|
||||
for (MethodToMoveUsageInfo usage : myUsages) {
|
||||
@@ -370,7 +370,7 @@ public class ExtractMethodObjectProcessor extends BaseRefactoringProcessor {
|
||||
new PsiImmediateClassType(myInnerClass, PsiSubstitutor.EMPTY), infos);
|
||||
}
|
||||
|
||||
public void runChangeSignature() {
|
||||
void runChangeSignature() {
|
||||
if (myChangeSignatureProcessor != null) {
|
||||
myChangeSignatureProcessor.run();
|
||||
}
|
||||
|
||||
+6
-1
@@ -17,6 +17,7 @@ package com.intellij.refactoring.inline;
|
||||
|
||||
import com.intellij.codeInsight.TargetElementUtilBase;
|
||||
import com.intellij.lang.StdLanguages;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.progress.ProgressManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
@@ -72,7 +73,11 @@ public class InlineToAnonymousClassHandler extends JavaInlineActionHandler {
|
||||
if (!ProgressManager.getInstance().runProcessWithProgressSynchronously(new Runnable(){
|
||||
@Override
|
||||
public void run() {
|
||||
inheritors.addAll(ClassInheritorsSearch.search(element).findAll());
|
||||
ApplicationManager.getApplication().runReadAction(new Runnable() {
|
||||
public void run() {
|
||||
inheritors.addAll(ClassInheritorsSearch.search(element).findAll());
|
||||
}
|
||||
});
|
||||
}
|
||||
}, "Searching for class \"" + element.getQualifiedName() + "\" inheritors ...", true, element.getProject())) return false;
|
||||
return inheritors.size() == 0;
|
||||
|
||||
@@ -30,6 +30,7 @@ import com.intellij.codeInsight.ChangeContextUtil;
|
||||
import com.intellij.codeInsight.PsiEquivalenceUtil;
|
||||
import com.intellij.codeInsight.intention.AddAnnotationFix;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.application.ModalityState;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.progress.ProgressManager;
|
||||
import com.intellij.openapi.util.Condition;
|
||||
@@ -89,6 +90,7 @@ public class PullUpHelper extends BaseRefactoringProcessor{
|
||||
myManager = mySourceClass.getManager();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected UsageViewDescriptor createUsageViewDescriptor(UsageInfo[] usages) {
|
||||
return new PullUpUsageViewDescriptor();
|
||||
}
|
||||
@@ -119,17 +121,12 @@ public class PullUpHelper extends BaseRefactoringProcessor{
|
||||
}
|
||||
}
|
||||
}
|
||||
final Runnable replaceMethodDuplicatesRunnable = new Runnable() {
|
||||
ApplicationManager.getApplication().invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
processMethodsDuplicates();
|
||||
}
|
||||
};
|
||||
if (ApplicationManager.getApplication().isUnitTestMode()) {
|
||||
replaceMethodDuplicatesRunnable.run();
|
||||
} else {
|
||||
ApplicationManager.getApplication().invokeLater(replaceMethodDuplicatesRunnable);
|
||||
}
|
||||
}, ModalityState.NON_MODAL, myProject.getDisposed());
|
||||
}
|
||||
|
||||
private void processMethodsDuplicates() {
|
||||
|
||||
@@ -43,6 +43,7 @@ import com.intellij.refactoring.RefactoringBundle;
|
||||
import com.intellij.refactoring.util.CommonRefactoringUtil;
|
||||
import com.intellij.ui.ReplacePromptDialog;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -56,7 +57,7 @@ public class DuplicatesImpl {
|
||||
|
||||
private DuplicatesImpl() {}
|
||||
|
||||
public static void invoke(final Project project, Editor editor, final MatchProvider provider) {
|
||||
public static void invoke(@NotNull final Project project, @NotNull Editor editor, @NotNull MatchProvider provider) {
|
||||
final List<Match> duplicates = provider.getDuplicates();
|
||||
int idx = 0;
|
||||
final Ref<Boolean> showAll = new Ref<Boolean>();
|
||||
@@ -96,7 +97,7 @@ public class DuplicatesImpl {
|
||||
return confirmDuplicatePrompt;
|
||||
}
|
||||
|
||||
private static boolean replaceMatch(final Project project, final MatchProvider provider, final Match match, final Editor editor,
|
||||
private static boolean replaceMatch(final Project project, final MatchProvider provider, final Match match, @NotNull final Editor editor,
|
||||
final int idx, final int size, Ref<Boolean> showAll, final String confirmDuplicatePrompt) {
|
||||
final ArrayList<RangeHighlighter> highlighters = new ArrayList<RangeHighlighter>();
|
||||
highlightMatch(project, editor, match, highlighters);
|
||||
@@ -172,7 +173,7 @@ public class DuplicatesImpl {
|
||||
attributes, true, highlighters);
|
||||
}
|
||||
|
||||
public static void processDuplicates(final MatchProvider provider, final Project project, Editor editor) {
|
||||
public static void processDuplicates(@NotNull MatchProvider provider, @NotNull Project project, @NotNull Editor editor) {
|
||||
boolean hasDuplicates = provider.hasDuplicates();
|
||||
if (hasDuplicates) {
|
||||
final int answer = Messages.showYesNoDialog(project,
|
||||
|
||||
+12
-6
@@ -63,6 +63,7 @@ public class MethodDuplicatesHandler implements RefactoringActionHandler {
|
||||
public static final String REFACTORING_NAME = RefactoringBundle.message("replace.method.code.duplicates.title");
|
||||
private static final Logger LOG = Logger.getInstance("#" + MethodDuplicatesHandler.class.getName());
|
||||
|
||||
@Override
|
||||
public void invoke(@NotNull final Project project, final Editor editor, PsiFile file, DataContext dataContext) {
|
||||
final int offset = editor.getCaretModel().getOffset();
|
||||
final PsiElement element = file.findElementAt(offset);
|
||||
@@ -98,6 +99,7 @@ public class MethodDuplicatesHandler implements RefactoringActionHandler {
|
||||
dlg.show();
|
||||
if (dlg.isOK()) {
|
||||
ProgressManager.getInstance().runProcessWithProgressSynchronously(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ProgressManager.getInstance().getProgressIndicator().setIndeterminate(true);
|
||||
invokeOnScope(project, method, dlg.getScope(AnalysisUIOptions.getInstance(project), scope, project, module));
|
||||
@@ -144,6 +146,7 @@ public class MethodDuplicatesHandler implements RefactoringActionHandler {
|
||||
replaceDuplicate(project, duplicates, methods);
|
||||
if (!silent) {
|
||||
final Runnable nothingFoundRunnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (duplicates.isEmpty()) {
|
||||
final String message = RefactoringBundle.message("idea.has.not.found.any.code.that.can.be.replaced.with.method.call",
|
||||
@@ -167,6 +170,7 @@ public class MethodDuplicatesHandler implements RefactoringActionHandler {
|
||||
if (progressIndicator != null && progressIndicator.isCanceled()) return;
|
||||
|
||||
final Runnable replaceRunnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
for (final PsiMethod method : methods) {
|
||||
final List<Match> matches = duplicates.get(method);
|
||||
@@ -174,8 +178,10 @@ public class MethodDuplicatesHandler implements RefactoringActionHandler {
|
||||
final int duplicatesNo = matches.size();
|
||||
WindowManager.getInstance().getStatusBar(project).setInfo(getStatusMessage(duplicatesNo));
|
||||
CommandProcessor.getInstance().executeCommand(project, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
PostprocessReformattingAspect.getInstance(project).postponeFormattingInside(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
DuplicatesImpl.invoke(project, new MethodDuplicatesMatchProvider(method, matches));
|
||||
}
|
||||
@@ -187,12 +193,7 @@ public class MethodDuplicatesHandler implements RefactoringActionHandler {
|
||||
}
|
||||
}
|
||||
};
|
||||
if (ApplicationManager.getApplication().isUnitTestMode()) {
|
||||
replaceRunnable.run();
|
||||
}
|
||||
else {
|
||||
ApplicationManager.getApplication().invokeLater(replaceRunnable, ModalityState.NON_MODAL);
|
||||
}
|
||||
ApplicationManager.getApplication().invokeLater(replaceRunnable, ModalityState.NON_MODAL);
|
||||
}
|
||||
finally {
|
||||
a.finish();
|
||||
@@ -243,6 +244,7 @@ public class MethodDuplicatesHandler implements RefactoringActionHandler {
|
||||
CommonRefactoringUtil.showErrorHint(project, editor, message, REFACTORING_NAME, HelpID.METHOD_DUPLICATES);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invoke(@NotNull Project project, @NotNull PsiElement[] elements, DataContext dataContext) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
@@ -256,6 +258,7 @@ public class MethodDuplicatesHandler implements RefactoringActionHandler {
|
||||
myDuplicates = duplicates;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PsiElement processMatch(Match match) throws IncorrectOperationException {
|
||||
match.changeSignature(myMethod);
|
||||
final PsiClass containingClass = myMethod.getContainingClass();
|
||||
@@ -352,14 +355,17 @@ public class MethodDuplicatesHandler implements RefactoringActionHandler {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Match> getDuplicates() {
|
||||
return myDuplicates;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasDuplicates() {
|
||||
return myDuplicates.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public String getConfirmDuplicatePrompt(final Match match) {
|
||||
final PsiElement matchStart = match.getMatchStart();
|
||||
|
||||
Reference in New Issue
Block a user