use of com.intellij.refactoring.introduceParameter.ExternalUsageInfo in project intellij-community by JetBrains.
the class ExtractClosureFromClosureProcessor method findUsages.
@NotNull
@Override
protected UsageInfo[] findUsages() {
final GrVariable var = (GrVariable) myHelper.getToSearchFor();
if (var != null) {
final List<UsageInfo> result = new ArrayList<>();
for (PsiReference ref : ReferencesSearch.search(var)) {
final PsiElement element = ref.getElement();
if (element.getLanguage() != GroovyLanguage.INSTANCE) {
result.add(new OtherLanguageUsageInfo(ref));
continue;
}
final GrCall call = GroovyRefactoringUtil.getCallExpressionByMethodReference(element);
if (call == null)
continue;
result.add(new ExternalUsageInfo(element));
}
return result.toArray(new UsageInfo[result.size()]);
}
return UsageInfo.EMPTY_ARRAY;
}
use of com.intellij.refactoring.introduceParameter.ExternalUsageInfo 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);
}
use of com.intellij.refactoring.introduceParameter.ExternalUsageInfo in project intellij-community by JetBrains.
the class GroovyIntroduceParameterUtil method detectAccessibilityConflicts.
public static void detectAccessibilityConflicts(@Nullable GroovyPsiElement elementToProcess, final UsageInfo[] usages, MultiMap<PsiElement, String> conflicts, boolean replaceFieldsWithGetters, Project project) {
if (elementToProcess == null)
return;
final ReferencedElementsCollector collector = new ReferencedElementsCollector();
elementToProcess.accept(collector);
final List<PsiElement> result = collector.getResult();
if (result.isEmpty())
return;
for (final UsageInfo usageInfo : usages) {
if (!(usageInfo instanceof ExternalUsageInfo) || !IntroduceParameterUtil.isMethodUsage(usageInfo))
continue;
final PsiElement place = usageInfo.getElement();
for (PsiElement element : result) {
if (element instanceof PsiField && replaceFieldsWithGetters) {
//check getter access instead
final PsiClass psiClass = ((PsiField) element).getContainingClass();
LOG.assertTrue(psiClass != null);
final PsiMethod method = GroovyPropertyUtils.findGetterForField((PsiField) element);
if (method != null) {
element = method;
}
}
if (element instanceof PsiMember && !JavaPsiFacade.getInstance(project).getResolveHelper().isAccessible((PsiMember) element, place, null)) {
String message = RefactoringBundle.message("0.is.not.accessible.from.1.value.for.introduced.parameter.in.that.method.call.will.be.incorrect", RefactoringUIUtil.getDescription(element, true), RefactoringUIUtil.getDescription(ConflictsUtil.getContainer(place), true));
conflicts.putValue(element, message);
}
}
}
}
Aggregations