Search in sources :

Example 21 with RefEntity

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

the class InspectionRVContentProvider method addNodeToParent.

@NotNull
protected static RefElementNode addNodeToParent(@NotNull RefEntityContainer container, @NotNull InspectionToolPresentation presentation, final InspectionTreeNode parentNode) {
    final RefElementNode nodeToBeAdded = container.createNode(presentation);
    final Ref<Boolean> firstLevel = new Ref<>(true);
    RefElementNode prevNode = null;
    final Ref<RefElementNode> result = new Ref<>();
    while (true) {
        final RefElementNode currentNode = firstLevel.get() ? nodeToBeAdded : container.createNode(presentation);
        final RefEntityContainer finalContainer = container;
        final RefElementNode finalPrevNode = prevNode;
        TreeUtil.traverseDepth(parentNode, node -> {
            if (node instanceof RefElementNode) {
                final RefElementNode refElementNode = (RefElementNode) node;
                final RefEntity userObject = finalContainer.getRefEntity();
                final RefEntity object = refElementNode.getElement();
                if (userObject != null && object != null && (userObject.getClass().equals(object.getClass())) && finalContainer.areEqual(object, userObject)) {
                    if (firstLevel.get()) {
                        result.set(refElementNode);
                        return false;
                    } else {
                        refElementNode.insertByOrder(finalPrevNode, false);
                        result.set(nodeToBeAdded);
                        return false;
                    }
                }
            }
            return true;
        });
        if (!result.isNull())
            return result.get();
        if (!firstLevel.get()) {
            currentNode.insertByOrder(prevNode, false);
        }
        final RefEntityContainer owner = container.getOwner();
        if (owner == null) {
            parentNode.insertByOrder(currentNode, false);
            return nodeToBeAdded;
        }
        container = owner;
        prevNode = currentNode;
        firstLevel.set(false);
    }
}
Also used : Ref(com.intellij.openapi.util.Ref) RefEntity(com.intellij.codeInspection.reference.RefEntity) NotNull(org.jetbrains.annotations.NotNull)

Example 22 with RefEntity

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

the class InspectionRVContentProviderImpl method appendDescriptor.

@Override
protected void appendDescriptor(@NotNull GlobalInspectionContextImpl context, @NotNull final InspectionToolWrapper toolWrapper, @NotNull final RefEntityContainer container, @NotNull final InspectionTreeNode pNode, final boolean canPackageRepeat) {
    final RefEntity refElement = container.getRefEntity();
    InspectionToolPresentation presentation = context.getPresentation(toolWrapper);
    final CommonProblemDescriptor[] problems = ((RefEntityContainer<CommonProblemDescriptor>) container).getDescriptors();
    if (problems != null) {
        final RefElementNode elemNode = addNodeToParent(container, presentation, pNode);
        for (CommonProblemDescriptor problem : problems) {
            assert problem != null;
            elemNode.insertByOrder(ReadAction.compute(() -> new ProblemDescriptionNode(refElement, problem, toolWrapper, presentation)), true);
            elemNode.setProblem(elemNode.getChildCount() == 1 ? problems[0] : null);
        }
    } else {
        if (canPackageRepeat && pNode instanceof InspectionPackageNode) {
            final Set<RefEntity> currentElements = presentation.getContent().get(((InspectionPackageNode) pNode).getPackageName());
            if (currentElements != null) {
                final Set<RefEntity> currentEntities = new HashSet<>(currentElements);
                if (RefUtil.contains(refElement, currentEntities))
                    return;
            }
        }
        addNodeToParent(container, presentation, pNode);
    }
}
Also used : CommonProblemDescriptor(com.intellij.codeInspection.CommonProblemDescriptor) RefEntity(com.intellij.codeInspection.reference.RefEntity) HashSet(com.intellij.util.containers.HashSet)

Example 23 with RefEntity

use of com.intellij.codeInspection.reference.RefEntity 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 24 with RefEntity

use of com.intellij.codeInspection.reference.RefEntity 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 25 with RefEntity

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

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