use of org.jetbrains.plugins.groovy.refactoring.introduce.parameter.FieldConflictsResolver in project intellij-community by JetBrains.
the class ExtractClosureFromMethodProcessor method performRefactoring.
@Override
protected void performRefactoring(@NotNull UsageInfo[] usages) {
final IntroduceParameterData data = new IntroduceParameterDataAdapter();
IntroduceParameterUtil.processUsages(usages, data);
final PsiMethod toSearchFor = (PsiMethod) myHelper.getToSearchFor();
final boolean methodsToProcessAreDifferent = myMethod != toSearchFor;
if (myHelper.generateDelegate()) {
GroovyIntroduceParameterUtil.generateDelegate(myMethod, data.getParameterInitializer(), myProject);
if (methodsToProcessAreDifferent) {
final GrMethod method = GroovyIntroduceParameterUtil.generateDelegate(toSearchFor, data.getParameterInitializer(), myProject);
final PsiClass containingClass = method.getContainingClass();
if (containingClass != null && containingClass.isInterface()) {
final GrOpenBlock block = method.getBlock();
if (block != null) {
block.delete();
}
}
}
}
// Changing signature of initial method
// (signature of myMethodToReplaceIn will be either changed now or have already been changed)
final FieldConflictsResolver fieldConflictsResolver = new FieldConflictsResolver(myHelper.getName(), myMethod.getBlock());
IntroduceParameterUtil.changeMethodSignatureAndResolveFieldConflicts(new UsageInfo(myMethod), usages, data);
if (methodsToProcessAreDifferent) {
IntroduceParameterUtil.changeMethodSignatureAndResolveFieldConflicts(new UsageInfo(toSearchFor), usages, data);
}
// Replacing expression occurrences
for (UsageInfo usage : usages) {
if (usage instanceof ChangedMethodCallInfo) {
PsiElement element = usage.getElement();
GroovyIntroduceParameterUtil.processChangedMethodCall(element, myHelper, myProject);
}
}
final GrStatement newStatement = ExtractUtil.replaceStatement(myDeclarationOwner, myHelper);
final Editor editor = PsiUtilBase.findEditor(newStatement);
if (editor != null) {
PsiDocumentManager.getInstance(myProject).commitDocument(editor.getDocument());
editor.getSelectionModel().removeSelection();
editor.getCaretModel().moveToOffset(newStatement.getTextRange().getEndOffset());
}
fieldConflictsResolver.fix();
}
Aggregations