use of com.intellij.refactoring.introduceParameter.InternalUsageInfo 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.InternalUsageInfo in project intellij-community by JetBrains.
the class GrIntroduceClosureParameterProcessor method preprocessUsages.
@Override
protected boolean preprocessUsages(@NotNull Ref<UsageInfo[]> refUsages) {
UsageInfo[] usagesIn = refUsages.get();
MultiMap<PsiElement, String> conflicts = new MultiMap<>();
if (!mySettings.generateDelegate()) {
detectAccessibilityConflicts(usagesIn, conflicts);
}
final GrExpression expression = mySettings.getExpression();
if (expression != null && toSearchFor instanceof PsiMember) {
final AnySupers anySupers = new AnySupers();
expression.accept(anySupers);
if (anySupers.containsSupers()) {
final PsiElement containingClass = PsiUtil.getFileOrClassContext(toReplaceIn);
for (UsageInfo usageInfo : usagesIn) {
if (!(usageInfo.getElement() instanceof PsiMethod) && !(usageInfo instanceof InternalUsageInfo)) {
if (!PsiTreeUtil.isAncestor(containingClass, usageInfo.getElement(), false)) {
conflicts.putValue(expression, RefactoringBundle.message("parameter.initializer.contains.0.but.not.all.calls.to.method.are.in.its.class", CommonRefactoringUtil.htmlEmphasize(PsiKeyword.SUPER)));
break;
}
}
}
}
}
return showConflicts(conflicts, usagesIn);
}
use of com.intellij.refactoring.introduceParameter.InternalUsageInfo 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