Search in sources :

Example 66 with UsageInfo

use of com.intellij.usageView.UsageInfo in project android by JetBrains.

the class AndroidInferNullityAnnotationAction method findModulesFromUsage.

private static Map<Module, PsiFile> findModulesFromUsage(UsageInfo[] infos) {
    // We need 1 file from each module that requires changes (the file may be overwritten below):
    Map<Module, PsiFile> modules = new HashMap<>();
    for (UsageInfo info : infos) {
        PsiElement element = info.getElement();
        assert element != null;
        Module module = ModuleUtilCore.findModuleForPsiElement(element);
        PsiFile file = element.getContainingFile();
        modules.put(module, file);
    }
    return modules;
}
Also used : PsiFile(com.intellij.psi.PsiFile) Module(com.intellij.openapi.module.Module) UsageInfo(com.intellij.usageView.UsageInfo) PsiElement(com.intellij.psi.PsiElement)

Example 67 with UsageInfo

use of com.intellij.usageView.UsageInfo in project android by JetBrains.

the class AndroidComponentSafeDeleteProcessor method findUsages.

@Override
public NonCodeUsageSearchInfo findUsages(@NotNull PsiElement element, @NotNull PsiElement[] allElementsToDelete, @NotNull List<UsageInfo> result) {
    final ArrayList<UsageInfo> usages = new ArrayList<UsageInfo>();
    final NonCodeUsageSearchInfo info = getBaseHandler().findUsages(element, allElementsToDelete, usages);
    if (info == null) {
        return info;
    }
    assert element instanceof PsiClass;
    final PsiClass componentClass = (PsiClass) element;
    final AndroidAttributeValue<PsiClass> declaration = AndroidDomUtil.findComponentDeclarationInManifest(componentClass);
    if (declaration == null) {
        return info;
    }
    final XmlAttributeValue declarationAttributeValue = declaration.getXmlAttributeValue();
    for (UsageInfo usage : usages) {
        if (declarationAttributeValue != usage.getElement()) {
            result.add(usage);
        }
    }
    return info;
}
Also used : ArrayList(java.util.ArrayList) PsiClass(com.intellij.psi.PsiClass) NonCodeUsageSearchInfo(com.intellij.refactoring.safeDelete.NonCodeUsageSearchInfo) XmlAttributeValue(com.intellij.psi.xml.XmlAttributeValue) UsageInfo(com.intellij.usageView.UsageInfo)

Example 68 with UsageInfo

use of com.intellij.usageView.UsageInfo in project android by JetBrains.

the class UnusedResourcesProcessor method findUsages.

@Override
@NotNull
protected UsageInfo[] findUsages() {
    Map<Issue, Map<File, List<ProblemData>>> map = computeUnusedMap();
    List<PsiElement> elements = computeUnusedDeclarationElements(map);
    myElements = elements.toArray(new PsiElement[elements.size()]);
    UsageInfo[] result = new UsageInfo[myElements.length];
    for (int i = 0, n = myElements.length; i < n; i++) {
        PsiElement element = myElements[i];
        if (element instanceof PsiBinaryFile) {
            // The usage view doesn't handle binaries at all. Work around this (for example,
            // the UsageInfo class asserts in the constructor if the element doesn't have
            // a text range.)
            SmartPointerManager smartPointerManager = SmartPointerManager.getInstance(myProject);
            SmartPsiElementPointer<PsiElement> smartPointer = smartPointerManager.createSmartPsiElementPointer(element);
            SmartPsiFileRange smartFileRange = smartPointerManager.createSmartPsiFileRangePointer((PsiBinaryFile) element, TextRange.EMPTY_RANGE);
            result[i] = new UsageInfo(smartPointer, smartFileRange, false, false) {

                @Override
                public boolean isValid() {
                    return true;
                }

                @Override
                @Nullable
                public Segment getSegment() {
                    return null;
                }
            };
        } else {
            result[i] = new UsageInfo(element);
        }
    }
    return UsageViewUtil.removeDuplicatedUsages(result);
}
Also used : Issue(com.android.tools.lint.detector.api.Issue) Segment(com.intellij.openapi.util.Segment) ProblemData(org.jetbrains.android.inspections.lint.ProblemData) Map(java.util.Map) UsageInfo(com.intellij.usageView.UsageInfo) Nullable(org.jetbrains.annotations.Nullable) NotNull(org.jetbrains.annotations.NotNull)

Example 69 with UsageInfo

use of com.intellij.usageView.UsageInfo in project android by JetBrains.

the class AndroidInlineAllStyleUsagesProcessor method performRefactoring.

@Override
protected void performRefactoring(@NotNull UsageInfo[] usages) {
    final List<StyleUsageData> inlineInfos = new ArrayList<StyleUsageData>();
    for (UsageInfo usage : usages) {
        final PsiElement element = usage.getElement();
        if (element == null)
            continue;
        final XmlTag tag = PsiTreeUtil.getParentOfType(element, XmlTag.class);
        StyleUsageData usageData = tag != null ? AndroidInlineUtil.getStyleUsageData(tag) : null;
        if (usageData != null && usageData.getReference().computeTargetElements().length == 1) {
            inlineInfos.add(usageData);
        }
    }
    for (StyleUsageData info : inlineInfos) {
        info.inline(myAttributeValues, myParentStyleRef);
    }
    myStyleTag.delete();
}
Also used : ArrayList(java.util.ArrayList) UsageInfo(com.intellij.usageView.UsageInfo) PsiElement(com.intellij.psi.PsiElement) XmlTag(com.intellij.psi.xml.XmlTag)

Example 70 with UsageInfo

use of com.intellij.usageView.UsageInfo in project android by JetBrains.

the class AndroidInlineAllStyleUsagesProcessor method findUsages.

@NotNull
@Override
protected UsageInfo[] findUsages() {
    final Set<UsageInfo> usages = new HashSet<UsageInfo>();
    AndroidInlineUtil.addReferences(myStyleElement, usages);
    for (PsiField field : AndroidResourceUtil.findResourceFieldsForValueResource(myStyleTag, false)) {
        AndroidInlineUtil.addReferences(field, usages);
    }
    return usages.toArray(new UsageInfo[usages.size()]);
}
Also used : PsiField(com.intellij.psi.PsiField) UsageInfo(com.intellij.usageView.UsageInfo) HashSet(com.intellij.util.containers.HashSet) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

UsageInfo (com.intellij.usageView.UsageInfo)283 PsiElement (com.intellij.psi.PsiElement)70 NotNull (org.jetbrains.annotations.NotNull)57 ArrayList (java.util.ArrayList)41 MoveRenameUsageInfo (com.intellij.refactoring.util.MoveRenameUsageInfo)38 IncorrectOperationException (com.intellij.util.IncorrectOperationException)34 PsiFile (com.intellij.psi.PsiFile)33 MultiMap (com.intellij.util.containers.MultiMap)30 VirtualFile (com.intellij.openapi.vfs.VirtualFile)29 Nullable (org.jetbrains.annotations.Nullable)20 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)19 DefaultConstructorImplicitUsageInfo (com.intellij.refactoring.util.usageInfo.DefaultConstructorImplicitUsageInfo)17 NoConstructorClassUsageInfo (com.intellij.refactoring.util.usageInfo.NoConstructorClassUsageInfo)17 Project (com.intellij.openapi.project.Project)16 HashSet (com.intellij.util.containers.HashSet)15 TextRange (com.intellij.openapi.util.TextRange)12 PsiReference (com.intellij.psi.PsiReference)12 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)11 PsiClass (com.intellij.psi.PsiClass)11 LocalSearchScope (com.intellij.psi.search.LocalSearchScope)11