Search in sources :

Example 1 with InspectionManager

use of com.intellij.codeInspection.InspectionManager 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 InspectionManager

use of com.intellij.codeInspection.InspectionManager 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 InspectionManager

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

the class CleanupIntention method invoke.

@Override
public void invoke(@NotNull final Project project, final Editor editor, final PsiFile file) throws IncorrectOperationException {
    if (!FileModificationService.getInstance().preparePsiElementForWrite(file))
        return;
    final InspectionManager managerEx = InspectionManager.getInstance(project);
    final GlobalInspectionContextBase globalContext = (GlobalInspectionContextBase) managerEx.createNewGlobalContext(false);
    final AnalysisScope scope = getScope(project, file);
    if (scope != null) {
        globalContext.codeCleanup(scope, InspectionProjectProfileManager.getInstance(project).getCurrentProfile(), getText(), null, false);
    }
}
Also used : AnalysisScope(com.intellij.analysis.AnalysisScope) InspectionManager(com.intellij.codeInspection.InspectionManager) GlobalInspectionContextBase(com.intellij.codeInspection.ex.GlobalInspectionContextBase)

Example 4 with InspectionManager

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

the class JavaDocCommentFixer method fixComment.

@Override
public void fixComment(@NotNull Project project, @NotNull Editor editor, @NotNull PsiComment comment) {
    if (!(comment instanceof PsiDocComment)) {
        return;
    }
    PsiDocComment docComment = (PsiDocComment) comment;
    PsiJavaDocumentedElement owner = docComment.getOwner();
    if (owner == null) {
        return;
    }
    PsiFile file = comment.getContainingFile();
    if (file == null) {
        return;
    }
    JavaDocReferenceInspection referenceInspection = new JavaDocReferenceInspection();
    JavaDocLocalInspection localInspection = getDocLocalInspection();
    InspectionManager inspectionManager = InspectionManager.getInstance(project);
    ProblemDescriptor[] referenceProblems = null;
    ProblemDescriptor[] otherProblems = null;
    if (owner instanceof PsiClass) {
        referenceProblems = referenceInspection.checkClass(((PsiClass) owner), inspectionManager, false);
        otherProblems = localInspection.checkClass(((PsiClass) owner), inspectionManager, false);
    } else if (owner instanceof PsiField) {
        referenceProblems = referenceInspection.checkField(((PsiField) owner), inspectionManager, false);
        otherProblems = localInspection.checkField(((PsiField) owner), inspectionManager, false);
    } else if (owner instanceof PsiMethod) {
        referenceProblems = referenceInspection.checkMethod((PsiMethod) owner, inspectionManager, false);
        otherProblems = localInspection.checkMethod((PsiMethod) owner, inspectionManager, false);
    }
    if (referenceProblems != null) {
        fixReferenceProblems(referenceProblems, project);
    }
    if (otherProblems != null) {
        fixCommonProblems(otherProblems, comment, editor.getDocument(), project);
    }
    PsiDocumentManager.getInstance(project).doPostponedOperationsAndUnblockDocument(editor.getDocument());
    ensureContentOrdered(docComment, editor.getDocument());
    locateCaret(docComment, editor, file);
}
Also used : PsiDocComment(com.intellij.psi.javadoc.PsiDocComment) JavaDocReferenceInspection(com.intellij.codeInspection.javaDoc.JavaDocReferenceInspection) InspectionManager(com.intellij.codeInspection.InspectionManager) ProblemDescriptor(com.intellij.codeInspection.ProblemDescriptor) JavaDocLocalInspection(com.intellij.codeInspection.javaDoc.JavaDocLocalInspection)

Example 5 with InspectionManager

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

the class WholeFileLocalInspectionsPassFactory method createHighlightingPass.

@Override
@Nullable
public TextEditorHighlightingPass createHighlightingPass(@NotNull final PsiFile file, @NotNull final Editor editor) {
    final Long appliedModificationCount = myPsiModificationCount.get(file);
    if (appliedModificationCount != null && appliedModificationCount == PsiManager.getInstance(myProject).getModificationTracker().getModificationCount()) {
        //optimization
        return null;
    }
    if (!ProblemHighlightFilter.shouldHighlightFile(file)) {
        return null;
    }
    if (myFileToolsCache.containsKey(file) && !myFileToolsCache.get(file)) {
        return null;
    }
    ProperTextRange visibleRange = VisibleHighlightingPassFactory.calculateVisibleRange(editor);
    return new LocalInspectionsPass(file, editor.getDocument(), 0, file.getTextLength(), visibleRange, true, new DefaultHighlightInfoProcessor()) {

        @NotNull
        @Override
        List<LocalInspectionToolWrapper> getInspectionTools(@NotNull InspectionProfileWrapper profile) {
            List<LocalInspectionToolWrapper> tools = super.getInspectionTools(profile);
            List<LocalInspectionToolWrapper> result = tools.stream().filter(LocalInspectionToolWrapper::runForWholeFile).collect(Collectors.toList());
            myFileToolsCache.put(file, !result.isEmpty());
            return result;
        }

        @Override
        protected String getPresentableName() {
            return DaemonBundle.message("pass.whole.inspections");
        }

        @Override
        void inspectInjectedPsi(@NotNull List<PsiElement> elements, boolean onTheFly, @NotNull ProgressIndicator indicator, @NotNull InspectionManager iManager, boolean inVisibleRange, @NotNull List<LocalInspectionToolWrapper> wrappers) {
        // already inspected in LIP
        }

        @Override
        protected void applyInformationWithProgress() {
            super.applyInformationWithProgress();
            myPsiModificationCount.put(file, PsiManager.getInstance(myProject).getModificationTracker().getModificationCount());
        }
    };
}
Also used : InspectionProfileWrapper(com.intellij.codeInspection.ex.InspectionProfileWrapper) InspectionManager(com.intellij.codeInspection.InspectionManager) ProperTextRange(com.intellij.openapi.util.ProperTextRange) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) List(java.util.List) NotNull(org.jetbrains.annotations.NotNull) LocalInspectionToolWrapper(com.intellij.codeInspection.ex.LocalInspectionToolWrapper) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

InspectionManager (com.intellij.codeInspection.InspectionManager)8 ProblemDescriptor (com.intellij.codeInspection.ProblemDescriptor)4 NotNull (org.jetbrains.annotations.NotNull)4 LocalInspectionToolWrapper (com.intellij.codeInspection.ex.LocalInspectionToolWrapper)3 PsiFile (com.intellij.psi.PsiFile)3 GlobalInspectionContextBase (com.intellij.codeInspection.ex.GlobalInspectionContextBase)2 AnalysisScope (com.intellij.analysis.AnalysisScope)1 IntentionAction (com.intellij.codeInsight.intention.IntentionAction)1 InspectionProfile (com.intellij.codeInspection.InspectionProfile)1 LocalQuickFix (com.intellij.codeInspection.LocalQuickFix)1 InspectionProfileWrapper (com.intellij.codeInspection.ex.InspectionProfileWrapper)1 JavaDocLocalInspection (com.intellij.codeInspection.javaDoc.JavaDocLocalInspection)1 JavaDocReferenceInspection (com.intellij.codeInspection.javaDoc.JavaDocReferenceInspection)1 InspectionToolPresentation (com.intellij.codeInspection.ui.InspectionToolPresentation)1 Editor (com.intellij.openapi.editor.Editor)1 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)1 Project (com.intellij.openapi.project.Project)1 ProperTextRange (com.intellij.openapi.util.ProperTextRange)1 PsiDocComment (com.intellij.psi.javadoc.PsiDocComment)1 IncorrectOperationException (com.intellij.util.IncorrectOperationException)1