Search in sources :

Example 1 with RelatedUsageInfo

use of com.intellij.refactoring.util.RelatedUsageInfo in project intellij-community by JetBrains.

the class RenameProcessor method classifyUsages.

public static MultiMap<PsiElement, UsageInfo> classifyUsages(Collection<? extends PsiElement> elements, UsageInfo[] usages) {
    final MultiMap<PsiElement, UsageInfo> result = new MultiMap<>();
    for (UsageInfo usage : usages) {
        LOG.assertTrue(usage instanceof MoveRenameUsageInfo);
        if (usage.getReference() instanceof LightElement) {
            //filter out implicit references (e.g. from derived class to super class' default constructor)
            continue;
        }
        MoveRenameUsageInfo usageInfo = (MoveRenameUsageInfo) usage;
        if (usage instanceof RelatedUsageInfo) {
            final PsiElement relatedElement = ((RelatedUsageInfo) usage).getRelatedElement();
            if (elements.contains(relatedElement)) {
                result.putValue(relatedElement, usage);
            }
        } else {
            PsiElement referenced = usageInfo.getReferencedElement();
            if (elements.contains(referenced)) {
                result.putValue(referenced, usage);
            } else if (referenced != null) {
                PsiElement indirect = referenced.getNavigationElement();
                if (elements.contains(indirect)) {
                    result.putValue(indirect, usage);
                }
            }
        }
    }
    return result;
}
Also used : MultiMap(com.intellij.util.containers.MultiMap) MoveRenameUsageInfo(com.intellij.refactoring.util.MoveRenameUsageInfo) UsageInfo(com.intellij.usageView.UsageInfo) MoveRenameUsageInfo(com.intellij.refactoring.util.MoveRenameUsageInfo) NonCodeUsageInfo(com.intellij.refactoring.util.NonCodeUsageInfo) RelatedUsageInfo(com.intellij.refactoring.util.RelatedUsageInfo) LightElement(com.intellij.psi.impl.light.LightElement) RelatedUsageInfo(com.intellij.refactoring.util.RelatedUsageInfo)

Aggregations

LightElement (com.intellij.psi.impl.light.LightElement)1 MoveRenameUsageInfo (com.intellij.refactoring.util.MoveRenameUsageInfo)1 NonCodeUsageInfo (com.intellij.refactoring.util.NonCodeUsageInfo)1 RelatedUsageInfo (com.intellij.refactoring.util.RelatedUsageInfo)1 UsageInfo (com.intellij.usageView.UsageInfo)1 MultiMap (com.intellij.util.containers.MultiMap)1