Search in sources :

Example 1 with ProblemDescriptor

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

the class DomHighlightingLiteTest method testHighlightStatus_OtherInspections2.

public void testHighlightStatus_OtherInspections2() throws Throwable {
    myElement.setFileDescription(new DomFileDescription<>(DomElement.class, "a"));
    final MyDomElementsInspection inspection = new MyDomElementsInspection() {

        @Override
        public ProblemDescriptor[] checkFile(@NotNull final PsiFile file, @NotNull final InspectionManager manager, final boolean isOnTheFly) {
            myAnnotationsManager.appendProblems(myElement, createHolder(), this.getClass());
            return ProblemDescriptor.EMPTY_ARRAY;
        }

        @Override
        public void checkFileElement(final DomFileElement fileElement, final DomElementAnnotationHolder holder) {
        }
    };
    registerInspectionKey(inspection);
    LocalInspectionToolWrapper toolWrapper = new LocalInspectionToolWrapper(inspection);
    myInspectionProfile.setInspectionTools(toolWrapper);
    myInspectionProfile.setEnabled(toolWrapper, false);
    myAnnotationsManager.appendProblems(myElement, createHolder(), MockAnnotatingDomInspection.class);
    assertEquals(DomHighlightStatus.INSPECTIONS_FINISHED, myAnnotationsManager.getHighlightStatus(myElement));
}
Also used : InspectionManager(com.intellij.codeInspection.InspectionManager) ProblemDescriptor(com.intellij.codeInspection.ProblemDescriptor) PsiFile(com.intellij.psi.PsiFile) NotNull(org.jetbrains.annotations.NotNull) LocalInspectionToolWrapper(com.intellij.codeInspection.ex.LocalInspectionToolWrapper)

Example 2 with ProblemDescriptor

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

the class DomHighlightingLiteTest method testHighlightStatus_OtherInspections.

public void testHighlightStatus_OtherInspections() throws Throwable {
    myElement.setFileDescription(new DomFileDescription<>(DomElement.class, "a"));
    final MyDomElementsInspection inspection = new MyDomElementsInspection() {

        @Override
        public ProblemDescriptor[] checkFile(@NotNull final PsiFile file, @NotNull final InspectionManager manager, final boolean isOnTheFly) {
            myAnnotationsManager.appendProblems(myElement, createHolder(), this.getClass());
            return ProblemDescriptor.EMPTY_ARRAY;
        }

        @Override
        public void checkFileElement(final DomFileElement fileElement, final DomElementAnnotationHolder holder) {
        }
    };
    registerInspectionKey(inspection);
    myInspectionProfile.setInspectionTools(new LocalInspectionToolWrapper(inspection));
    myAnnotationsManager.appendProblems(myElement, createHolder(), MockAnnotatingDomInspection.class);
    assertEquals(DomHighlightStatus.ANNOTATORS_FINISHED, myAnnotationsManager.getHighlightStatus(myElement));
    myAnnotationsManager.appendProblems(myElement, createHolder(), inspection.getClass());
    assertEquals(DomHighlightStatus.INSPECTIONS_FINISHED, myAnnotationsManager.getHighlightStatus(myElement));
}
Also used : InspectionManager(com.intellij.codeInspection.InspectionManager) ProblemDescriptor(com.intellij.codeInspection.ProblemDescriptor) PsiFile(com.intellij.psi.PsiFile) NotNull(org.jetbrains.annotations.NotNull) LocalInspectionToolWrapper(com.intellij.codeInspection.ex.LocalInspectionToolWrapper)

Example 3 with ProblemDescriptor

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

the class HardwiredNamespacePrefix method createVisitor.

protected Visitor createVisitor(final InspectionManager manager, final boolean isOnTheFly) {
    return new Visitor(manager, isOnTheFly) {

        protected void checkExpression(XPathExpression expression) {
            if (!(expression instanceof XPathBinaryExpression)) {
                return;
            }
            final XPathBinaryExpression expr = (XPathBinaryExpression) expression;
            if (expr.getOperator() == XPathTokenTypes.EQ) {
                final XPathExpression lop = expr.getLOperand();
                final XPathExpression rop = expr.getROperand();
                if (isNameComparison(lop, rop)) {
                    assert rop != null;
                    final ProblemDescriptor p = manager.createProblemDescriptor(rop, "Hardwired namespace prefix", isOnTheFly, LocalQuickFix.EMPTY_ARRAY, ProblemHighlightType.GENERIC_ERROR_OR_WARNING);
                    addProblem(p);
                } else if (isNameComparison(rop, lop)) {
                    assert lop != null;
                    final ProblemDescriptor p = manager.createProblemDescriptor(lop, "Hardwired namespace prefix", isOnTheFly, LocalQuickFix.EMPTY_ARRAY, ProblemHighlightType.GENERIC_ERROR_OR_WARNING);
                    addProblem(p);
                } else if (isNameFunctionCall(lop)) {
                // TODO
                } else if (isNameFunctionCall(rop)) {
                // TODO
                }
            }
        }
    };
}
Also used : XPathExpression(org.intellij.lang.xpath.psi.XPathExpression) XPathBinaryExpression(org.intellij.lang.xpath.psi.XPathBinaryExpression) ProblemDescriptor(com.intellij.codeInspection.ProblemDescriptor)

Example 4 with ProblemDescriptor

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

the class AbstractFix method createQuickFix.

@Nullable
public LocalQuickFix createQuickFix(boolean isOnTheFly) {
    final boolean requiresEditor = requiresEditor();
    if (requiresEditor && !isOnTheFly)
        return null;
    return new LocalQuickFix() {

        @NotNull
        public String getName() {
            return AbstractFix.this.getText();
        }

        @NotNull
        public String getFamilyName() {
            return AbstractFix.this.getFamilyName();
        }

        public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
            Editor editor;
            if (requiresEditor) {
                final DataContext dataContext = DataManager.getInstance().getDataContext();
                editor = CommonDataKeys.EDITOR.getData(dataContext);
                if (editor == null) {
                    if ((editor = FileEditorManager.getInstance(project).getSelectedTextEditor()) == null) {
                        return;
                    }
                }
            } else {
                editor = null;
            }
            final PsiFile psiFile = descriptor.getPsiElement().getContainingFile();
            if (!isAvailable(project, editor, psiFile)) {
                return;
            }
            invoke(project, editor, psiFile);
        }
    };
}
Also used : Project(com.intellij.openapi.project.Project) DataContext(com.intellij.openapi.actionSystem.DataContext) ProblemDescriptor(com.intellij.codeInspection.ProblemDescriptor) LocalQuickFix(com.intellij.codeInspection.LocalQuickFix) PsiFile(com.intellij.psi.PsiFile) Editor(com.intellij.openapi.editor.Editor) NotNull(org.jetbrains.annotations.NotNull) Nullable(org.jetbrains.annotations.Nullable)

Example 5 with ProblemDescriptor

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

the class BuildoutUnresolvedPartInspection method checkFile.

@Override
public ProblemDescriptor[] checkFile(@NotNull PsiFile file, @NotNull InspectionManager manager, boolean isOnTheFly) {
    List<ProblemDescriptor> problems = Lists.newArrayList();
    if (file.getFileType().equals(BuildoutCfgFileType.INSTANCE)) {
        Visitor visitor = new Visitor();
        file.accept(visitor);
        for (BuildoutPartReference ref : visitor.getUnresolvedParts()) {
            ProblemDescriptor d = manager.createProblemDescriptor(ref.getElement(), ref.getRangeInElement(), PyBundle.message("buildout.unresolved.part.inspection.msg"), ProblemHighlightType.GENERIC_ERROR_OR_WARNING, false);
            problems.add(d);
        }
    }
    return problems.toArray(new ProblemDescriptor[problems.size()]);
}
Also used : PsiRecursiveElementVisitor(com.intellij.psi.PsiRecursiveElementVisitor) ProblemDescriptor(com.intellij.codeInspection.ProblemDescriptor) BuildoutPartReference(com.jetbrains.python.buildout.config.ref.BuildoutPartReference)

Aggregations

ProblemDescriptor (com.intellij.codeInspection.ProblemDescriptor)54 PsiElement (com.intellij.psi.PsiElement)21 LocalQuickFix (com.intellij.codeInspection.LocalQuickFix)19 Project (com.intellij.openapi.project.Project)16 Nullable (org.jetbrains.annotations.Nullable)16 LinkedList (java.util.LinkedList)14 NotNull (org.jetbrains.annotations.NotNull)14 ArrayList (java.util.ArrayList)11 PsiReference (com.intellij.psi.PsiReference)8 CommonProblemDescriptor (com.intellij.codeInspection.CommonProblemDescriptor)5 InspectionManager (com.intellij.codeInspection.InspectionManager)5 PsiFile (com.intellij.psi.PsiFile)5 PsiAnnotation (com.intellij.psi.PsiAnnotation)4 PsiClass (com.intellij.psi.PsiClass)4 PsiJavaCodeReferenceElement (com.intellij.psi.PsiJavaCodeReferenceElement)4 QuickFix (com.intellij.codeInspection.QuickFix)3 Module (com.intellij.openapi.module.Module)3 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)3 PackageNameNode (org.ballerinalang.plugins.idea.psi.PackageNameNode)3 GroovyFix (org.jetbrains.plugins.groovy.codeInspection.GroovyFix)3