use of com.intellij.usageView.UsageInfo 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.usageView.UsageInfo in project intellij-community by JetBrains.
the class ExtractClosureFromMethodProcessor method preprocessUsages.
@Override
protected boolean preprocessUsages(@NotNull Ref<UsageInfo[]> refUsages) {
UsageInfo[] usagesIn = refUsages.get();
MultiMap<PsiElement, String> conflicts = new MultiMap<>();
final GrStatement[] statements = myHelper.getStatements();
for (GrStatement statement : statements) {
GroovyIntroduceParameterUtil.detectAccessibilityConflicts(statement, usagesIn, conflicts, false, myProject);
}
for (UsageInfo info : usagesIn) {
if (info instanceof OtherLanguageUsageInfo) {
final String lang = CommonRefactoringUtil.htmlEmphasize(info.getElement().getLanguage().getDisplayName());
conflicts.putValue(info.getElement(), GroovyRefactoringBundle.message("cannot.process.usage.in.language.{0}", lang));
}
}
if (!myMethod.hasModifierProperty(PsiModifier.PRIVATE)) {
final AnySupers anySupers = new AnySupers();
for (GrStatement statement : statements) {
statement.accept(anySupers);
}
if (anySupers.containsSupers()) {
for (UsageInfo usageInfo : usagesIn) {
if (!(usageInfo.getElement() instanceof PsiMethod) && !(usageInfo instanceof InternalUsageInfo)) {
if (!PsiTreeUtil.isAncestor(myMethod.getContainingClass(), usageInfo.getElement(), false)) {
conflicts.putValue(statements[0], RefactoringBundle.message("parameter.initializer.contains.0.but.not.all.calls.to.method.are.in.its.class", CommonRefactoringUtil.htmlEmphasize(PsiKeyword.SUPER)));
break;
}
}
}
}
}
if (!conflicts.isEmpty() && ApplicationManager.getApplication().isUnitTestMode()) {
throw new ConflictsInTestsException(conflicts.values());
}
if (!conflicts.isEmpty()) {
final ConflictsDialog conflictsDialog = prepareConflictsDialog(conflicts, usagesIn);
if (!conflictsDialog.showAndGet()) {
if (conflictsDialog.isShowConflicts())
prepareSuccessful();
return false;
}
}
prepareSuccessful();
return true;
}
use of com.intellij.usageView.UsageInfo in project intellij-community by JetBrains.
the class GroovyInlineLocalProcessor method preprocessUsages.
@Override
protected boolean preprocessUsages(@NotNull Ref<UsageInfo[]> refUsages) {
final MultiMap<PsiElement, String> conflicts = new MultiMap<>();
final UsageInfo[] usages = refUsages.get();
for (UsageInfo usage : usages) {
collectConflicts(usage.getReference(), conflicts);
}
return showConflicts(conflicts, usages);
}
use of com.intellij.usageView.UsageInfo in project intellij-community by JetBrains.
the class GrAliasImportIntention method findUsages.
private static List<UsageInfo> findUsages(PsiMember member, GroovyFileBase file) {
LocalSearchScope scope = new LocalSearchScope(file);
final ArrayList<UsageInfo> infos = new ArrayList<>();
final HashSet<Object> usedRefs = ContainerUtil.newHashSet();
final Processor<PsiReference> consumer = reference -> {
if (usedRefs.add(reference)) {
infos.add(new UsageInfo(reference));
}
return true;
};
if (member instanceof PsiMethod) {
MethodReferencesSearch.search((PsiMethod) member, scope, false).forEach(consumer);
} else {
ReferencesSearch.search(member, scope).forEach(consumer);
if (member instanceof PsiField) {
final PsiMethod getter = GroovyPropertyUtils.findGetterForField((PsiField) member);
if (getter != null) {
MethodReferencesSearch.search(getter, scope, false).forEach(consumer);
}
final PsiMethod setter = GroovyPropertyUtils.findSetterForField((PsiField) member);
if (setter != null) {
MethodReferencesSearch.search(setter, scope, false).forEach(consumer);
}
}
}
return infos;
}
use of com.intellij.usageView.UsageInfo in project intellij-community by JetBrains.
the class GrAliasImportIntention method updateRefs.
private static void updateRefs(List<UsageInfo> usages, final String memberName, final GrImportStatement updatedImport) {
if (updatedImport == null)
return;
final String name = ApplicationManager.getApplication().runReadAction(new Computable<String>() {
@Nullable
@Override
public String compute() {
return updatedImport.getImportedName();
}
});
for (final UsageInfo usage : usages) {
ApplicationManager.getApplication().runWriteAction(() -> {
final PsiElement usageElement = usage.getElement();
if (usageElement == null)
return;
if (usageElement.getParent() instanceof GrImportStatement)
return;
if (usageElement instanceof GrReferenceElement) {
final GrReferenceElement ref = (GrReferenceElement) usageElement;
final PsiElement qualifier = ref.getQualifier();
if (qualifier == null) {
final String refName = ref.getReferenceName();
if (refName == null)
return;
if (memberName.equals(refName)) {
ref.handleElementRename(name);
} else if (refName.equals(GroovyPropertyUtils.getPropertyNameByAccessorName(memberName))) {
final String newPropName = GroovyPropertyUtils.getPropertyNameByAccessorName(name);
if (newPropName != null) {
ref.handleElementRename(newPropName);
} else {
ref.handleElementRename(name);
}
} else if (refName.equals(GroovyPropertyUtils.getGetterNameBoolean(memberName))) {
final String getterName = GroovyPropertyUtils.getGetterNameBoolean(name);
ref.handleElementRename(getterName);
} else if (refName.equals(GroovyPropertyUtils.getGetterNameNonBoolean(memberName))) {
final String getterName = GroovyPropertyUtils.getGetterNameNonBoolean(name);
ref.handleElementRename(getterName);
} else if (refName.equals(GroovyPropertyUtils.getSetterName(memberName))) {
final String getterName = GroovyPropertyUtils.getSetterName(name);
ref.handleElementRename(getterName);
}
}
}
});
}
}
Aggregations