Search in sources :

Example 1 with FieldConflictsResolver

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();
}
Also used : GrMethod(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod) GrStatement(org.jetbrains.plugins.groovy.lang.psi.api.statements.GrStatement) FieldConflictsResolver(org.jetbrains.plugins.groovy.refactoring.introduce.parameter.FieldConflictsResolver) GrOpenBlock(org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrOpenBlock) Editor(com.intellij.openapi.editor.Editor) UsageInfo(com.intellij.usageView.UsageInfo) NoConstructorClassUsageInfo(com.intellij.refactoring.util.usageInfo.NoConstructorClassUsageInfo) DefaultConstructorImplicitUsageInfo(com.intellij.refactoring.util.usageInfo.DefaultConstructorImplicitUsageInfo)

Aggregations

Editor (com.intellij.openapi.editor.Editor)1 DefaultConstructorImplicitUsageInfo (com.intellij.refactoring.util.usageInfo.DefaultConstructorImplicitUsageInfo)1 NoConstructorClassUsageInfo (com.intellij.refactoring.util.usageInfo.NoConstructorClassUsageInfo)1 UsageInfo (com.intellij.usageView.UsageInfo)1 GrStatement (org.jetbrains.plugins.groovy.lang.psi.api.statements.GrStatement)1 GrOpenBlock (org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrOpenBlock)1 GrMethod (org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod)1 FieldConflictsResolver (org.jetbrains.plugins.groovy.refactoring.introduce.parameter.FieldConflictsResolver)1