Search in sources :

Example 16 with RefElement

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

the class GlobalInspectionContextImpl method ignoreElement.

public void ignoreElement(@NotNull InspectionProfileEntry tool, @NotNull PsiElement element) {
    final RefElement refElement = getRefManager().getReference(element);
    final Tools tools = getTools().get(tool.getShortName());
    if (tools != null) {
        for (ScopeToolState state : tools.getTools()) {
            InspectionToolWrapper toolWrapper = state.getTool();
            ignoreElementRecursively(toolWrapper, refElement);
        }
    }
}
Also used : RefElement(com.intellij.codeInspection.reference.RefElement)

Example 17 with RefElement

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

the class InspectionRVContentProviderImpl method checkReportedProblems.

@Override
public boolean checkReportedProblems(@NotNull GlobalInspectionContextImpl context, @NotNull final InspectionToolWrapper toolWrapper) {
    InspectionToolPresentation presentation = context.getPresentation(toolWrapper);
    presentation.updateContent();
    final SearchScope searchScope = context.getCurrentScope().toSearchScope();
    if (searchScope instanceof LocalSearchScope) {
        final Map<String, Set<RefEntity>> contents = presentation.getContent();
        final Map<RefEntity, CommonProblemDescriptor[]> problemElements = presentation.getProblemElements();
        for (Set<RefEntity> entities : contents.values()) {
            for (Iterator<RefEntity> iterator = entities.iterator(); iterator.hasNext(); ) {
                RefEntity entity = iterator.next();
                if (entity instanceof RefElement) {
                    final PsiElement element = ((RefElement) entity).getElement();
                    if (element != null) {
                        final TextRange range = element.getTextRange();
                        if (range != null && ((LocalSearchScope) searchScope).containsRange(element.getContainingFile(), range)) {
                            continue;
                        }
                    }
                }
                problemElements.remove(entity);
                iterator.remove();
            }
        }
    }
    return presentation.hasReportedProblems();
}
Also used : LocalSearchScope(com.intellij.psi.search.LocalSearchScope) HashSet(com.intellij.util.containers.HashSet) Set(java.util.Set) TextRange(com.intellij.openapi.util.TextRange) RefElement(com.intellij.codeInspection.reference.RefElement) RefEntity(com.intellij.codeInspection.reference.RefEntity) SearchScope(com.intellij.psi.search.SearchScope) LocalSearchScope(com.intellij.psi.search.LocalSearchScope) PsiElement(com.intellij.psi.PsiElement)

Example 18 with RefElement

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

the class InspectionResultsView method collectPsiElements.

@NotNull
private PsiElement[] collectPsiElements() {
    RefEntity[] refElements = myTree.getSelectedElements();
    List<PsiElement> psiElements = new ArrayList<>();
    for (RefEntity refElement : refElements) {
        PsiElement psiElement = refElement instanceof RefElement ? ((RefElement) refElement).getElement() : null;
        if (psiElement != null && psiElement.isValid()) {
            psiElements.add(psiElement);
        }
    }
    return PsiUtilCore.toPsiElementArray(psiElements);
}
Also used : RefElement(com.intellij.codeInspection.reference.RefElement) RefEntity(com.intellij.codeInspection.reference.RefEntity) NotNull(org.jetbrains.annotations.NotNull)

Example 19 with RefElement

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

the class InspectionResultsView method getData.

@Override
public Object getData(String dataId) {
    if (PlatformDataKeys.HELP_ID.is(dataId))
        return HELP_ID;
    if (DATA_KEY.is(dataId))
        return this;
    if (ExclusionHandler.EXCLUSION_HANDLER.is(dataId))
        return myExclusionHandler;
    if (myTree == null)
        return null;
    TreePath[] paths = myTree.getSelectionPaths();
    if (paths == null || paths.length == 0)
        return null;
    if (paths.length > 1) {
        if (LangDataKeys.PSI_ELEMENT_ARRAY.is(dataId)) {
            return collectPsiElements();
        }
        return null;
    }
    TreePath path = paths[0];
    InspectionTreeNode selectedNode = (InspectionTreeNode) path.getLastPathComponent();
    if (!CommonDataKeys.NAVIGATABLE.is(dataId) && !CommonDataKeys.PSI_ELEMENT.is(dataId)) {
        return null;
    }
    if (selectedNode instanceof RefElementNode) {
        final RefElementNode refElementNode = (RefElementNode) selectedNode;
        RefEntity refElement = refElementNode.getElement();
        if (refElement == null)
            return null;
        final RefEntity item = refElement.getRefManager().getRefinedElement(refElement);
        if (!item.isValid())
            return null;
        PsiElement psiElement = item instanceof RefElement ? ((RefElement) item).getElement() : null;
        if (psiElement == null)
            return null;
        final CommonProblemDescriptor problem = refElementNode.getDescriptor();
        if (problem instanceof ProblemDescriptor) {
            PsiElement elementFromDescriptor = ((ProblemDescriptor) problem).getPsiElement();
            if (elementFromDescriptor == null && CommonDataKeys.NAVIGATABLE.is(dataId)) {
                final InspectionTreeNode node = (InspectionTreeNode) refElementNode.getChildAt(0);
                if (node.isValid()) {
                    return InspectionResultsViewUtil.getNavigatableForInvalidNode((ProblemDescriptionNode) node);
                }
            } else {
                psiElement = elementFromDescriptor;
            }
        }
        if (CommonDataKeys.NAVIGATABLE.is(dataId)) {
            return getSelectedNavigatable(problem, psiElement);
        } else if (CommonDataKeys.PSI_ELEMENT.is(dataId)) {
            return psiElement != null && psiElement.isValid() ? psiElement : null;
        }
    } else if (selectedNode instanceof ProblemDescriptionNode && CommonDataKeys.NAVIGATABLE.is(dataId)) {
        Navigatable navigatable = getSelectedNavigatable(((ProblemDescriptionNode) selectedNode).getDescriptor());
        return navigatable == null ? InspectionResultsViewUtil.getNavigatableForInvalidNode((ProblemDescriptionNode) selectedNode) : navigatable;
    }
    return null;
}
Also used : RefElement(com.intellij.codeInspection.reference.RefElement) TreePath(javax.swing.tree.TreePath) RefEntity(com.intellij.codeInspection.reference.RefEntity) Navigatable(com.intellij.pom.Navigatable)

Example 20 with RefElement

use of com.intellij.codeInspection.reference.RefElement 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)

Aggregations

RefElement (com.intellij.codeInspection.reference.RefElement)25 RefEntity (com.intellij.codeInspection.reference.RefEntity)16 PsiElement (com.intellij.psi.PsiElement)11 NotNull (org.jetbrains.annotations.NotNull)7 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 Nullable (org.jetbrains.annotations.Nullable)4 EntryPoint (com.intellij.codeInspection.reference.EntryPoint)3 PsiFile (com.intellij.psi.PsiFile)3 Element (org.jdom.Element)3 UnusedDeclarationInspectionBase (com.intellij.codeInspection.deadCode.UnusedDeclarationInspectionBase)2 GlobalInspectionToolWrapper (com.intellij.codeInspection.ex.GlobalInspectionToolWrapper)2 LocalInspectionToolWrapper (com.intellij.codeInspection.ex.LocalInspectionToolWrapper)2 RefClass (com.intellij.codeInspection.reference.RefClass)2 RefJavaUtil (com.intellij.codeInspection.reference.RefJavaUtil)2 RefManagerImpl (com.intellij.codeInspection.reference.RefManagerImpl)2 Project (com.intellij.openapi.project.Project)2 Navigatable (com.intellij.pom.Navigatable)2 SearchScope (com.intellij.psi.search.SearchScope)2 HashSet (com.intellij.util.containers.HashSet)2 THashSet (gnu.trove.THashSet)2