Search in sources :

Example 26 with RefEntity

use of com.intellij.codeInspection.reference.RefEntity in project intellij-community by JetBrains.

the class QuickFixAction method getSelectedElements.

@NotNull
private static RefEntity[] getSelectedElements(InspectionResultsView view) {
    if (view == null)
        return new RefElement[0];
    List<RefEntity> selection = new ArrayList<>(Arrays.asList(view.getTree().getSelectedElements()));
    PsiDocumentManager.getInstance(view.getProject()).commitAllDocuments();
    Collections.sort(selection, (o1, o2) -> {
        if (o1 instanceof RefElement && o2 instanceof RefElement) {
            RefElement r1 = (RefElement) o1;
            RefElement r2 = (RefElement) o2;
            final PsiElement element1 = r1.getElement();
            final PsiElement element2 = r2.getElement();
            final PsiFile containingFile1 = element1.getContainingFile();
            final PsiFile containingFile2 = element2.getContainingFile();
            if (containingFile1 == containingFile2) {
                int i1 = element1.getTextOffset();
                int i2 = element2.getTextOffset();
                if (i1 < i2) {
                    return 1;
                }
                if (i1 > i2) {
                    return -1;
                }
                return 0;
            }
            return containingFile1.getName().compareTo(containingFile2.getName());
        }
        if (o1 instanceof RefElement) {
            return 1;
        }
        if (o2 instanceof RefElement) {
            return -1;
        }
        return o1.getName().compareTo(o2.getName());
    });
    return selection.toArray(new RefEntity[selection.size()]);
}
Also used : RefElement(com.intellij.codeInspection.reference.RefElement) RefEntity(com.intellij.codeInspection.reference.RefEntity) PsiFile(com.intellij.psi.PsiFile) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Example 27 with RefEntity

use of com.intellij.codeInspection.reference.RefEntity in project intellij-community by JetBrains.

the class QuickFixAction method removeElements.

public static void removeElements(@NotNull RefEntity[] refElements, @NotNull Project project, @NotNull InspectionToolWrapper toolWrapper) {
    refreshViews(project, refElements, toolWrapper);
    final ArrayList<RefElement> deletedRefs = new ArrayList<>(1);
    for (RefEntity refElement : refElements) {
        if (!(refElement instanceof RefElement))
            continue;
        refElement.getRefManager().removeRefElement((RefElement) refElement, deletedRefs);
    }
}
Also used : RefElement(com.intellij.codeInspection.reference.RefElement) RefEntity(com.intellij.codeInspection.reference.RefEntity)

Example 28 with RefEntity

use of com.intellij.codeInspection.reference.RefEntity in project intellij-community by JetBrains.

the class QuickFixAction method refreshViews.

protected static void refreshViews(@NotNull Project project, @NotNull RefEntity[] refElements, @NotNull InspectionToolWrapper toolWrapper) {
    final Set<PsiElement> ignoredElements = new HashSet<>();
    for (RefEntity element : refElements) {
        final PsiElement psiElement = element instanceof RefElement ? ((RefElement) element).getElement() : null;
        if (psiElement != null && psiElement.isValid()) {
            ignoredElements.add(psiElement);
        }
    }
    refreshViews(project, ignoredElements, toolWrapper);
}
Also used : RefElement(com.intellij.codeInspection.reference.RefElement) RefEntity(com.intellij.codeInspection.reference.RefEntity) PsiElement(com.intellij.psi.PsiElement) THashSet(gnu.trove.THashSet)

Example 29 with RefEntity

use of com.intellij.codeInspection.reference.RefEntity in project intellij-community by JetBrains.

the class OfflineDescriptorResolveResult method resolve.

@NotNull
static OfflineDescriptorResolveResult resolve(@NotNull OfflineProblemDescriptor descriptor, @NotNull InspectionToolWrapper wrapper, @NotNull InspectionToolPresentation presentation) {
    final RefEntity element = descriptor.getRefElement(presentation.getContext().getRefManager());
    final CommonProblemDescriptor resolvedDescriptor = ReadAction.compute(() -> createDescriptor(element, descriptor, wrapper, presentation));
    return new OfflineDescriptorResolveResult(element, resolvedDescriptor);
}
Also used : RefEntity(com.intellij.codeInspection.reference.RefEntity) NotNull(org.jetbrains.annotations.NotNull)

Example 30 with RefEntity

use of com.intellij.codeInspection.reference.RefEntity in project intellij-community by JetBrains.

the class OfflineInspectionRVContentProvider method getFilteredContent.

@Nullable
@SuppressWarnings({ "UnusedAssignment" })
private Map<String, Set<OfflineProblemDescriptor>> getFilteredContent(@NotNull GlobalInspectionContextImpl context, @NotNull InspectionToolWrapper toolWrapper) {
    Map<String, Set<OfflineProblemDescriptor>> content = myContent.get(toolWrapper.getShortName());
    if (content == null)
        return null;
    if (context.getUIOptions().FILTER_RESOLVED_ITEMS) {
        final Map<String, Set<OfflineProblemDescriptor>> current = new HashMap<>(content);
        //GC it
        content = null;
        InspectionToolPresentation presentation = context.getPresentation(toolWrapper);
        for (RefEntity refEntity : presentation.getIgnoredRefElements()) {
            if (refEntity instanceof RefElement) {
                excludeProblem(refEntity.getExternalName(), current);
            }
        }
        return current;
    }
    return content;
}
Also used : RefElement(com.intellij.codeInspection.reference.RefElement) HashSet(com.intellij.util.containers.HashSet) THashMap(gnu.trove.THashMap) RefEntity(com.intellij.codeInspection.reference.RefEntity) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

RefEntity (com.intellij.codeInspection.reference.RefEntity)38 RefElement (com.intellij.codeInspection.reference.RefElement)17 Nullable (org.jetbrains.annotations.Nullable)15 CommonProblemDescriptor (com.intellij.codeInspection.CommonProblemDescriptor)12 RefClass (com.intellij.codeInspection.reference.RefClass)11 NotNull (org.jetbrains.annotations.NotNull)9 PsiElement (com.intellij.psi.PsiElement)8 RefPackage (com.intellij.codeInspection.reference.RefPackage)7 HashSet (com.intellij.util.containers.HashSet)5 RefModule (com.intellij.codeInspection.reference.RefModule)4 Project (com.intellij.openapi.project.Project)4 DefaultInspectionToolPresentation (com.intellij.codeInspection.ui.DefaultInspectionToolPresentation)3 InspectionToolPresentation (com.intellij.codeInspection.ui.InspectionToolPresentation)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 THashSet (gnu.trove.THashSet)3 AnalysisScope (com.intellij.analysis.AnalysisScope)2 RefJavaUtil (com.intellij.codeInspection.reference.RefJavaUtil)2 RefManagerImpl (com.intellij.codeInspection.reference.RefManagerImpl)2 RefVisitor (com.intellij.codeInspection.reference.RefVisitor)2 ProblemGroup (com.intellij.lang.annotation.ProblemGroup)2