mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
replace code duplicates: move change signature out of write action
This commit is contained in:
+5
-1
@@ -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();
|
||||
|
||||
+5
-1
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user