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());
}
}
}
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);
}
Aggregations