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);
}
}
}
});
}
}
use of com.intellij.usageView.UsageInfo in project intellij-community by JetBrains.
the class MoveGroovyClassHandler method preprocessUsages.
@Override
public void preprocessUsages(Collection<UsageInfo> results) {
//remove all alias-imported usages from collection
for (Iterator<UsageInfo> iterator = results.iterator(); iterator.hasNext(); ) {
UsageInfo info = iterator.next();
if (info == null) {
LOG.debug("info==null");
continue;
}
final PsiReference ref = info.getReference();
if (ref == null)
continue;
final PsiElement element = ref.getElement();
if (!(element instanceof GrReferenceElement))
continue;
final GroovyResolveResult resolveResult = ((GrReferenceElement) element).advancedResolve();
final PsiElement context = resolveResult.getCurrentFileResolveContext();
if (!(context instanceof GrImportStatement))
continue;
if (!((GrImportStatement) context).isAliasedImport())
continue;
iterator.remove();
}
}
use of com.intellij.usageView.UsageInfo 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.usageView.UsageInfo 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.usageView.UsageInfo in project intellij-community by JetBrains.
the class RenameGrFieldProcessor method renameElement.
@Override
public void renameElement(final PsiElement psiElement, String newName, final UsageInfo[] usages, @Nullable RefactoringElementListener listener) throws IncorrectOperationException {
GrField field = (GrField) psiElement;
Map<GrReferenceExpression, PsiElement> handled = ContainerUtil.newHashMap();
for (UsageInfo usage : usages) {
final PsiReference ref = usage.getReference();
if (ref instanceof GrReferenceExpression) {
PsiElement resolved = ref.resolve();
ref.handleElementRename(getNewNameFromTransformations(resolved, newName));
handled.put((GrReferenceExpression) ref, resolved);
} else if (ref != null) {
handleElementRename(newName, ref, field.getName());
}
}
field.setName(newName);
PsiManager manager = psiElement.getManager();
for (GrReferenceExpression expression : handled.keySet()) {
PsiElement oldResolved = handled.get(expression);
if (oldResolved == null)
continue;
PsiElement resolved = expression.resolve();
if (resolved == null)
continue;
if (manager.areElementsEquivalent(oldResolved, resolved))
continue;
if (oldResolved.equals(field) || isQualificationNeeded(manager, oldResolved, resolved)) {
qualify(field, expression);
}
}
if (listener != null) {
listener.elementRenamed(psiElement);
}
}
Aggregations