replace code duplicates: move change signature out of write action

This commit is contained in:
Anna.Kozlova
2016-05-04 13:47:03 +02:00
parent 9b9a8d4051
commit 0da5a0cefd
5 changed files with 22 additions and 3 deletions
@@ -1229,8 +1229,12 @@ public class ExtractMethodProcessor implements MatchProvider {
return result;
}
public PsiElement processMatch(Match match) throws IncorrectOperationException {
@Override
public void prepareSignature(Match match) {
MatchUtil.changeSignature(match, myExtractedMethod);
}
public PsiElement processMatch(Match match) throws IncorrectOperationException {
if (RefactoringUtil.isInStaticContext(match.getMatchStart(), myExtractedMethod.getContainingClass())) {
PsiUtil.setModifierProperty(myExtractedMethod, PsiModifier.STATIC, true);
}
@@ -40,6 +40,9 @@ class ConstantMatchProvider implements MatchProvider {
myMatches = matches;
}
@Override
public void prepareSignature(Match match) {}
@Override
public PsiElement processMatch(Match match) throws IncorrectOperationException {
final PsiClass containingClass = myField.getContainingClass();
@@ -140,6 +140,9 @@ public class DuplicatesImpl {
HighlightManager.getInstance(project).removeSegmentHighlighter(editor, highlighters.get(0));
}
// call change signature when needed
provider.prepareSignature(match);
new WriteCommandAction(project, MethodDuplicatesHandler.REFACTORING_NAME, MethodDuplicatesHandler.REFACTORING_NAME) {
@Override
protected void run(@NotNull Result result) throws Throwable {
@@ -17,7 +17,6 @@ package com.intellij.refactoring.util.duplicates;
import com.intellij.psi.PsiElement;
import com.intellij.util.IncorrectOperationException;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List;
@@ -26,6 +25,12 @@ import java.util.List;
* @author dsl
*/
public interface MatchProvider {
/**
* Call change signature here to avoid refactoring under write action
* @param match match which requires signature to be changed e.g. due to stronger expected type, etc
*/
void prepareSignature(Match match);
PsiElement processMatch(Match match) throws IncorrectOperationException;
List<Match> getDuplicates();
@@ -47,8 +47,12 @@ class MethodDuplicatesMatchProvider implements MatchProvider {
}
@Override
public PsiElement processMatch(Match match) throws IncorrectOperationException {
public void prepareSignature(Match match) {
MatchUtil.changeSignature(match, myMethod);
}
@Override
public PsiElement processMatch(Match match) throws IncorrectOperationException {
final PsiClass containingClass = myMethod.getContainingClass();
if (isEssentialStaticContextAbsent(match)) {
PsiUtil.setModifierProperty(myMethod, PsiModifier.STATIC, true);