use of com.intellij.refactoring.rename.UnresolvableCollisionUsageInfo in project intellij-community by JetBrains.
the class RenameGrFieldProcessor method findCollisions.
@Override
public void findCollisions(PsiElement element, String newName, Map<? extends PsiElement, String> allRenames, List<UsageInfo> result) {
List<UsageInfo> collisions = new ArrayList<>();
for (UsageInfo info : result) {
if (!(info instanceof MoveRenameUsageInfo))
continue;
final PsiElement infoElement = info.getElement();
final PsiElement referencedElement = ((MoveRenameUsageInfo) info).getReferencedElement();
if (!(infoElement instanceof GrReferenceExpression))
continue;
final GrReferenceExpression refExpr = (GrReferenceExpression) infoElement;
if (!(referencedElement instanceof GrField || refExpr.advancedResolve().isInvokedOnProperty()))
continue;
if (!(refExpr.getParent() instanceof GrCall))
continue;
final PsiType[] argTypes = PsiUtil.getArgumentTypes(refExpr, false);
final PsiType[] typeArguments = refExpr.getTypeArguments();
final MethodResolverProcessor processor = new MethodResolverProcessor(newName, refExpr, false, null, argTypes, typeArguments);
final PsiMethod resolved = ResolveUtil.resolveExistingElement(refExpr, processor, PsiMethod.class);
if (resolved == null)
continue;
collisions.add(new UnresolvableCollisionUsageInfo(resolved, refExpr) {
@Override
public String getDescription() {
return GroovyRefactoringBundle.message("usage.will.be.overriden.by.method", refExpr.getParent().getText(), PsiFormatUtil.formatMethod(resolved, PsiSubstitutor.EMPTY, PsiFormatUtilBase.SHOW_NAME, PsiFormatUtilBase.SHOW_TYPE));
}
});
}
result.addAll(collisions);
super.findCollisions(element, newName, allRenames, result);
}
use of com.intellij.refactoring.rename.UnresolvableCollisionUsageInfo in project intellij-community by JetBrains.
the class AutomaticRenamer method findUsagesForElement.
private boolean findUsagesForElement(PsiNamedElement element, List<UsageInfo> result, final boolean searchInStringsAndComments, final boolean searchInNonJavaFiles, List<UnresolvableCollisionUsageInfo> unresolvedUsages, Map<PsiElement, String> allRenames) {
final String newName = getNewName(element);
if (newName != null) {
final LinkedHashMap<PsiNamedElement, String> renames = new LinkedHashMap<>();
renames.putAll(myRenames);
if (allRenames != null) {
for (PsiElement psiElement : allRenames.keySet()) {
if (psiElement instanceof PsiNamedElement) {
renames.put((PsiNamedElement) psiElement, allRenames.get(psiElement));
}
}
}
final UsageInfo[] usages = RenameUtil.findUsages(element, newName, searchInStringsAndComments, searchInNonJavaFiles, renames);
for (final UsageInfo usage : usages) {
if (usage instanceof UnresolvableCollisionUsageInfo) {
if (unresolvedUsages != null) {
unresolvedUsages.add((UnresolvableCollisionUsageInfo) usage);
}
return false;
}
}
ContainerUtil.addAll(result, usages);
}
return true;
}
use of com.intellij.refactoring.rename.UnresolvableCollisionUsageInfo in project intellij-community by JetBrains.
the class RenameAliasImportedMethodProcessor method findCollisions.
@Override
public void findCollisions(PsiElement element, final String newName, final Map<? extends PsiElement, String> allRenames, final List<UsageInfo> result) {
if (element instanceof PsiMethod) {
final PsiMethod method = (PsiMethod) element;
OverridingMethodsSearch.search(method).forEach(overrider -> {
PsiElement original = overrider;
if (overrider instanceof PsiMirrorElement) {
original = ((PsiMirrorElement) overrider).getPrototype();
}
if (original instanceof SyntheticElement)
return true;
if (original instanceof GrField) {
result.add(new FieldNameCollisionInfo((GrField) original, method));
}
return true;
});
}
final ListIterator<UsageInfo> iterator = result.listIterator();
while (iterator.hasNext()) {
final UsageInfo info = iterator.next();
final PsiElement ref = info.getElement();
if (ref instanceof GrReferenceExpression || ref == null)
continue;
if (!RenameUtil.isValidName(element.getProject(), ref, newName)) {
iterator.add(new UnresolvableCollisionUsageInfo(ref, element) {
@Override
public String getDescription() {
return RefactoringBundle.message("0.is.not.an.identifier", newName, ref.getText());
}
});
}
}
}
Aggregations