Search in sources :

Example 1 with UnresolvableCollisionUsageInfo

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);
}
Also used : GrField(org.jetbrains.plugins.groovy.lang.psi.api.statements.GrField) GrCall(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrCall) ArrayList(java.util.ArrayList) MoveRenameUsageInfo(com.intellij.refactoring.util.MoveRenameUsageInfo) GrReferenceExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression) MethodResolverProcessor(org.jetbrains.plugins.groovy.lang.resolve.processors.MethodResolverProcessor) UnresolvableCollisionUsageInfo(com.intellij.refactoring.rename.UnresolvableCollisionUsageInfo) UsageInfo(com.intellij.usageView.UsageInfo) UnresolvableCollisionUsageInfo(com.intellij.refactoring.rename.UnresolvableCollisionUsageInfo) MoveRenameUsageInfo(com.intellij.refactoring.util.MoveRenameUsageInfo)

Example 2 with UnresolvableCollisionUsageInfo

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;
}
Also used : PsiNamedElement(com.intellij.psi.PsiNamedElement) UnresolvableCollisionUsageInfo(com.intellij.refactoring.rename.UnresolvableCollisionUsageInfo) PsiElement(com.intellij.psi.PsiElement) UnresolvableCollisionUsageInfo(com.intellij.refactoring.rename.UnresolvableCollisionUsageInfo) UsageInfo(com.intellij.usageView.UsageInfo)

Example 3 with UnresolvableCollisionUsageInfo

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());
                }
            });
        }
    }
}
Also used : GrField(org.jetbrains.plugins.groovy.lang.psi.api.statements.GrField) UnresolvableCollisionUsageInfo(com.intellij.refactoring.rename.UnresolvableCollisionUsageInfo) GroovyPsiElement(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement) UsageInfo(com.intellij.usageView.UsageInfo) UnresolvableCollisionUsageInfo(com.intellij.refactoring.rename.UnresolvableCollisionUsageInfo) GrReferenceExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression)

Aggregations

UnresolvableCollisionUsageInfo (com.intellij.refactoring.rename.UnresolvableCollisionUsageInfo)3 UsageInfo (com.intellij.usageView.UsageInfo)3 GrField (org.jetbrains.plugins.groovy.lang.psi.api.statements.GrField)2 GrReferenceExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression)2 PsiElement (com.intellij.psi.PsiElement)1 PsiNamedElement (com.intellij.psi.PsiNamedElement)1 MoveRenameUsageInfo (com.intellij.refactoring.util.MoveRenameUsageInfo)1 ArrayList (java.util.ArrayList)1 GroovyPsiElement (org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement)1 GrCall (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrCall)1 MethodResolverProcessor (org.jetbrains.plugins.groovy.lang.resolve.processors.MethodResolverProcessor)1