Search in sources :

Example 1 with ChangedMethodCallInfo

use of com.intellij.refactoring.introduceParameter.ChangedMethodCallInfo in project intellij-community by JetBrains.

the class GrIntroduceClosureParameterProcessor method processInternalUsages.

private static void processInternalUsages(UsageInfo[] usages, GrIntroduceParameterSettings settings) {
    final GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(settings.getProject());
    // Replacing expression occurrences
    for (UsageInfo usage : usages) {
        if (usage instanceof ChangedMethodCallInfo) {
            PsiElement element = usage.getElement();
            processChangedMethodCall(element, settings);
        } else if (usage instanceof InternalUsageInfo) {
            PsiElement element = usage.getElement();
            if (element == null)
                continue;
            GrExpression newExpr = factory.createExpressionFromText(settings.getName());
            if (element instanceof GrExpression) {
                ((GrExpression) element).replaceWithExpression(newExpr, true);
            } else {
                element.replace(newExpr);
            }
        }
    }
    final StringPartInfo info = settings.getStringPartInfo();
    if (info != null) {
        final GrExpression expr = info.replaceLiteralWithConcatenation(settings.getName());
        final Editor editor = PsiUtilBase.findEditor(expr);
        if (editor != null) {
            editor.getSelectionModel().removeSelection();
            editor.getCaretModel().moveToOffset(expr.getTextRange().getEndOffset());
        }
    }
}
Also used : GroovyPsiElementFactory(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory) ChangedMethodCallInfo(com.intellij.refactoring.introduceParameter.ChangedMethodCallInfo) Editor(com.intellij.openapi.editor.Editor) StringPartInfo(org.jetbrains.plugins.groovy.refactoring.introduce.StringPartInfo) ExternalUsageInfo(com.intellij.refactoring.introduceParameter.ExternalUsageInfo) UsageInfo(com.intellij.usageView.UsageInfo) InternalUsageInfo(com.intellij.refactoring.introduceParameter.InternalUsageInfo) InternalUsageInfo(com.intellij.refactoring.introduceParameter.InternalUsageInfo)

Example 2 with ChangedMethodCallInfo

use of com.intellij.refactoring.introduceParameter.ChangedMethodCallInfo in project intellij-community by JetBrains.

the class GrIntroduceClosureParameterProcessor method findUsages.

@NotNull
@Override
protected UsageInfo[] findUsages() {
    ArrayList<UsageInfo> result = new ArrayList<>();
    if (!mySettings.generateDelegate() && toSearchFor != null) {
        Collection<PsiReference> refs;
        if (toSearchFor instanceof GrField) {
            refs = ReferencesSearch.search(toSearchFor).findAll();
            final GrAccessorMethod[] getters = ((GrField) toSearchFor).getGetters();
            for (GrAccessorMethod getter : getters) {
                refs.addAll(MethodReferencesSearch.search(getter, getter.getResolveScope(), true).findAll());
            }
        } else if (toSearchFor instanceof GrVariable) {
            refs = findUsagesForLocal(toReplaceIn, ((GrVariable) toSearchFor));
        } else {
            refs = ReferencesSearch.search(toSearchFor).findAll();
        }
        for (PsiReference ref1 : refs) {
            PsiElement ref = ref1.getElement();
            if (!PsiTreeUtil.isAncestor(toReplaceIn, ref, false)) {
                result.add(new ExternalUsageInfo(ref));
            } else {
                result.add(new ChangedMethodCallInfo(ref));
            }
        }
        if (toSearchFor instanceof GrVariable && !((GrVariable) toSearchFor).hasModifierProperty(PsiModifier.FINAL)) {
            setPreviewUsages(true);
        }
    }
    if (mySettings.replaceAllOccurrences()) {
        PsiElement[] exprs = GroovyIntroduceParameterUtil.getOccurrences(mySettings);
        for (PsiElement expr : exprs) {
            result.add(new InternalUsageInfo(expr));
        }
    } else {
        if (mySettings.getExpression() != null) {
            result.add(new InternalUsageInfo(mySettings.getExpression()));
        }
    }
    final UsageInfo[] usageInfos = result.toArray(new UsageInfo[result.size()]);
    return UsageViewUtil.removeDuplicatedUsages(usageInfos);
}
Also used : ArrayList(java.util.ArrayList) ChangedMethodCallInfo(com.intellij.refactoring.introduceParameter.ChangedMethodCallInfo) GrAccessorMethod(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrAccessorMethod) ExternalUsageInfo(com.intellij.refactoring.introduceParameter.ExternalUsageInfo) ExternalUsageInfo(com.intellij.refactoring.introduceParameter.ExternalUsageInfo) UsageInfo(com.intellij.usageView.UsageInfo) InternalUsageInfo(com.intellij.refactoring.introduceParameter.InternalUsageInfo) InternalUsageInfo(com.intellij.refactoring.introduceParameter.InternalUsageInfo) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

ChangedMethodCallInfo (com.intellij.refactoring.introduceParameter.ChangedMethodCallInfo)2 ExternalUsageInfo (com.intellij.refactoring.introduceParameter.ExternalUsageInfo)2 InternalUsageInfo (com.intellij.refactoring.introduceParameter.InternalUsageInfo)2 UsageInfo (com.intellij.usageView.UsageInfo)2 Editor (com.intellij.openapi.editor.Editor)1 ArrayList (java.util.ArrayList)1 NotNull (org.jetbrains.annotations.NotNull)1 GroovyPsiElementFactory (org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory)1 GrAccessorMethod (org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrAccessorMethod)1 StringPartInfo (org.jetbrains.plugins.groovy.refactoring.introduce.StringPartInfo)1