Search in sources :

Example 26 with ProblemDescriptor

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

the class ProblemDescriptionNode method calculatePresentableName.

@NotNull
@Override
protected String calculatePresentableName() {
    CommonProblemDescriptor descriptor = getDescriptor();
    if (descriptor == null)
        return "";
    PsiElement element = descriptor instanceof ProblemDescriptor ? ((ProblemDescriptor) descriptor).getPsiElement() : null;
    return XmlStringUtil.stripHtml(ProblemDescriptorUtil.renderDescriptionMessage(descriptor, element, TRIM_AT_TREE_END));
}
Also used : CommonProblemDescriptor(com.intellij.codeInspection.CommonProblemDescriptor) CommonProblemDescriptor(com.intellij.codeInspection.CommonProblemDescriptor) ProblemDescriptor(com.intellij.codeInspection.ProblemDescriptor) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Example 27 with ProblemDescriptor

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

the class SuppressableInspectionTreeNode method getSuppressContent.

@NotNull
public final Pair<PsiElement, CommonProblemDescriptor> getSuppressContent() {
    RefEntity refElement = getElement();
    CommonProblemDescriptor descriptor = getDescriptor();
    PsiElement element = descriptor instanceof ProblemDescriptor ? ((ProblemDescriptor) descriptor).getPsiElement() : refElement instanceof RefElement ? ((RefElement) refElement).getElement() : null;
    return Pair.create(element, descriptor);
}
Also used : RefElement(com.intellij.codeInspection.reference.RefElement) CommonProblemDescriptor(com.intellij.codeInspection.CommonProblemDescriptor) RefEntity(com.intellij.codeInspection.reference.RefEntity) CommonProblemDescriptor(com.intellij.codeInspection.CommonProblemDescriptor) ProblemDescriptor(com.intellij.codeInspection.ProblemDescriptor) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Example 28 with ProblemDescriptor

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

the class InspectionResultsViewComparator method compare.

@Override
public int compare(InspectionTreeNode node1, InspectionTreeNode node2) {
    if (node1 instanceof InspectionSeverityGroupNode && node2 instanceof InspectionSeverityGroupNode) {
        final InspectionSeverityGroupNode groupNode1 = (InspectionSeverityGroupNode) node1;
        final InspectionSeverityGroupNode groupNode2 = (InspectionSeverityGroupNode) node2;
        return -SeverityRegistrar.getSeverityRegistrar(groupNode1.getProject()).compare(groupNode1.getSeverityLevel().getSeverity(), groupNode2.getSeverityLevel().getSeverity());
    }
    if (node1 instanceof InspectionSeverityGroupNode)
        return -1;
    if (node2 instanceof InspectionSeverityGroupNode)
        return 1;
    if (node1 instanceof InspectionGroupNode && node2 instanceof InspectionGroupNode) {
        return ((InspectionGroupNode) node1).getGroupTitle().compareToIgnoreCase(((InspectionGroupNode) node2).getGroupTitle());
    }
    if (node1 instanceof InspectionGroupNode)
        return -1;
    if (node2 instanceof InspectionGroupNode)
        return 1;
    if (node1 instanceof InspectionNode && node2 instanceof InspectionNode)
        return InspectionsConfigTreeComparator.getDisplayTextToSort(node1.toString()).compareToIgnoreCase(InspectionsConfigTreeComparator.getDisplayTextToSort(node2.toString()));
    if (node1 instanceof InspectionNode)
        return -1;
    if (node2 instanceof InspectionNode)
        return 1;
    if (node1 instanceof InspectionModuleNode && node2 instanceof InspectionModuleNode) {
        return Comparing.compare(node1.toString(), node2.toString());
    }
    if (node1 instanceof InspectionModuleNode)
        return -1;
    if (node2 instanceof InspectionModuleNode)
        return 1;
    if (node1 instanceof InspectionPackageNode && node2 instanceof InspectionPackageNode) {
        return ((InspectionPackageNode) node1).getPackageName().compareToIgnoreCase(((InspectionPackageNode) node2).getPackageName());
    }
    if (node1 instanceof InspectionPackageNode)
        return -1;
    if (node2 instanceof InspectionPackageNode)
        return 1;
    if (node1 instanceof RefElementNode && node2 instanceof RefElementNode) {
        //sort by filename and inside file by start offset
        return compareEntities(((RefElementNode) node1).getElement(), ((RefElementNode) node2).getElement());
    }
    if (node1 instanceof ProblemDescriptionNode && node2 instanceof ProblemDescriptionNode) {
        final CommonProblemDescriptor descriptor1 = ((ProblemDescriptionNode) node1).getDescriptor();
        final CommonProblemDescriptor descriptor2 = ((ProblemDescriptionNode) node2).getDescriptor();
        if (descriptor1 instanceof ProblemDescriptor && descriptor2 instanceof ProblemDescriptor) {
            int diff = ((ProblemDescriptor) descriptor1).getLineNumber() - ((ProblemDescriptor) descriptor2).getLineNumber();
            if (diff != 0) {
                return diff;
            }
            diff = ((ProblemDescriptor) descriptor1).getHighlightType().compareTo(((ProblemDescriptor) descriptor2).getHighlightType());
            if (diff != 0) {
                return diff;
            }
            diff = PsiUtilCore.compareElementsByPosition(((ProblemDescriptor) descriptor1).getStartElement(), ((ProblemDescriptor) descriptor2).getStartElement());
            if (diff != 0) {
                return diff;
            }
            diff = PsiUtilCore.compareElementsByPosition(((ProblemDescriptor) descriptor2).getEndElement(), ((ProblemDescriptor) descriptor1).getEndElement());
            if (diff != 0)
                return diff;
            final TextRange range1 = ((ProblemDescriptor) descriptor1).getTextRangeInElement();
            final TextRange range2 = ((ProblemDescriptor) descriptor2).getTextRangeInElement();
            if (range1 != null && range2 != null) {
                diff = range1.getStartOffset() - range2.getStartOffset();
                if (diff != 0)
                    return diff;
                diff = range1.getEndOffset() - range2.getEndOffset();
                if (diff != 0)
                    return diff;
            }
        }
        if (descriptor1 != null && descriptor2 != null) {
            return descriptor1.getDescriptionTemplate().compareToIgnoreCase(descriptor2.getDescriptionTemplate());
        }
        if (descriptor1 == null)
            return descriptor2 == null ? 0 : -1;
        return 1;
    }
    if (node1 instanceof RefElementNode && node2 instanceof ProblemDescriptionNode) {
        final CommonProblemDescriptor descriptor = ((ProblemDescriptionNode) node2).getDescriptor();
        if (descriptor instanceof ProblemDescriptor) {
            return compareEntity(((RefElementNode) node1).getElement(), ((ProblemDescriptor) descriptor).getPsiElement());
        }
        return compareEntities(((RefElementNode) node1).getElement(), ((ProblemDescriptionNode) node2).getElement());
    }
    if (node2 instanceof RefElementNode && node1 instanceof ProblemDescriptionNode) {
        final CommonProblemDescriptor descriptor = ((ProblemDescriptionNode) node1).getDescriptor();
        if (descriptor instanceof ProblemDescriptor) {
            return -compareEntity(((RefElementNode) node2).getElement(), ((ProblemDescriptor) descriptor).getPsiElement());
        }
        return -compareEntities(((RefElementNode) node2).getElement(), ((ProblemDescriptionNode) node1).getElement());
    }
    if (node1 instanceof InspectionRootNode && node2 instanceof InspectionRootNode) {
        //TODO Dmitry Batkovich: optimization, because only one root node is existed
        return 0;
    }
    LOG.error("node1: " + node1 + ", node2: " + node2);
    return 0;
}
Also used : CommonProblemDescriptor(com.intellij.codeInspection.CommonProblemDescriptor) CommonProblemDescriptor(com.intellij.codeInspection.CommonProblemDescriptor) ProblemDescriptor(com.intellij.codeInspection.ProblemDescriptor) TextRange(com.intellij.openapi.util.TextRange)

Example 29 with ProblemDescriptor

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

the class LocalQuickFixWrapper method ignore.

private void ignore(@NotNull Collection<PsiElement> ignoredElements, @NotNull CommonProblemDescriptor descriptor, @Nullable QuickFix fix, @NotNull GlobalInspectionContextImpl context) {
    if (fix != null) {
        InspectionToolPresentation presentation = context.getPresentation(myToolWrapper);
        presentation.ignoreProblem(descriptor, fix);
    }
    if (descriptor instanceof ProblemDescriptor) {
        PsiElement element = ((ProblemDescriptor) descriptor).getPsiElement();
        if (element != null) {
            ignoredElements.add(element);
        }
    }
}
Also used : InspectionToolPresentation(com.intellij.codeInspection.ui.InspectionToolPresentation) CommonProblemDescriptor(com.intellij.codeInspection.CommonProblemDescriptor) ProblemDescriptor(com.intellij.codeInspection.ProblemDescriptor) PsiElement(com.intellij.psi.PsiElement)

Example 30 with ProblemDescriptor

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

the class PerformFixesModalTask method iteration.

@Override
public boolean iteration() {
    final CommonProblemDescriptor descriptor = myDescriptors[myCount++];
    ProgressIndicator indicator = myTask.getIndicator();
    if (indicator != null) {
        indicator.setFraction((double) myCount / myDescriptors.length);
        String presentableText = "usages";
        if (descriptor instanceof ProblemDescriptor) {
            final PsiElement psiElement = ((ProblemDescriptor) descriptor).getPsiElement();
            if (psiElement != null) {
                presentableText = SymbolPresentationUtil.getSymbolPresentableText(psiElement);
            }
        }
        indicator.setText("Processing " + presentableText);
    }
    final boolean[] runInReadAction = { false };
    final QuickFix[] fixes = descriptor.getFixes();
    if (fixes != null) {
        for (QuickFix fix : fixes) {
            if (!fix.startInWriteAction()) {
                runInReadAction[0] = true;
            } else {
                runInReadAction[0] = false;
                break;
            }
        }
    }
    ApplicationManager.getApplication().runWriteAction(() -> {
        myDocumentManager.commitAllDocuments();
        if (!runInReadAction[0]) {
            applyFix(myProject, descriptor);
        }
    });
    if (runInReadAction[0]) {
        applyFix(myProject, descriptor);
    }
    return isDone();
}
Also used : QuickFix(com.intellij.codeInspection.QuickFix) CommonProblemDescriptor(com.intellij.codeInspection.CommonProblemDescriptor) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) ProblemDescriptor(com.intellij.codeInspection.ProblemDescriptor) CommonProblemDescriptor(com.intellij.codeInspection.CommonProblemDescriptor) PsiElement(com.intellij.psi.PsiElement)

Aggregations

ProblemDescriptor (com.intellij.codeInspection.ProblemDescriptor)40 Project (com.intellij.openapi.project.Project)15 NotNull (org.jetbrains.annotations.NotNull)13 LocalQuickFix (com.intellij.codeInspection.LocalQuickFix)11 PsiElement (com.intellij.psi.PsiElement)10 Nullable (org.jetbrains.annotations.Nullable)8 CommonProblemDescriptor (com.intellij.codeInspection.CommonProblemDescriptor)5 PsiAnnotation (com.intellij.psi.PsiAnnotation)5 LinkedList (java.util.LinkedList)5 InspectionManager (com.intellij.codeInspection.InspectionManager)4 PsiFile (com.intellij.psi.PsiFile)4 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)4 QuickFix (com.intellij.codeInspection.QuickFix)3 PsiAnnotationMemberValue (com.intellij.psi.PsiAnnotationMemberValue)3 PsiClass (com.intellij.psi.PsiClass)3 PsiJavaCodeReferenceElement (com.intellij.psi.PsiJavaCodeReferenceElement)3 GroovyFix (org.jetbrains.plugins.groovy.codeInspection.GroovyFix)3 LocalInspectionToolWrapper (com.intellij.codeInspection.ex.LocalInspectionToolWrapper)2 ASTNode (com.intellij.lang.ASTNode)2 Editor (com.intellij.openapi.editor.Editor)2