Search in sources :

Example 1 with InspectionProfileWrapper

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

the class SpellCheckingEditorCustomization method customize.

@Override
public void customize(@NotNull EditorEx editor) {
    boolean apply = isEnabled();
    if (!READY) {
        return;
    }
    Project project = editor.getProject();
    if (project == null) {
        return;
    }
    PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());
    if (file == null) {
        return;
    }
    Function<InspectionProfileImpl, InspectionProfileWrapper> strategy = file.getUserData(InspectionProfileWrapper.CUSTOMIZATION_KEY);
    if (strategy == null) {
        file.putUserData(InspectionProfileWrapper.CUSTOMIZATION_KEY, strategy = new MyInspectionProfileStrategy());
    }
    if (!(strategy instanceof MyInspectionProfileStrategy)) {
        return;
    }
    ((MyInspectionProfileStrategy) strategy).setUseSpellCheck(apply);
    if (apply) {
        editor.putUserData(IntentionManager.SHOW_INTENTION_OPTIONS_KEY, false);
    }
    // Update representation.
    DaemonCodeAnalyzer analyzer = DaemonCodeAnalyzer.getInstance(project);
    if (analyzer != null) {
        analyzer.restart(file);
    }
}
Also used : Project(com.intellij.openapi.project.Project) InspectionProfileWrapper(com.intellij.codeInspection.ex.InspectionProfileWrapper) InspectionProfileImpl(com.intellij.codeInspection.ex.InspectionProfileImpl) DaemonCodeAnalyzer(com.intellij.codeInsight.daemon.DaemonCodeAnalyzer) PsiFile(com.intellij.psi.PsiFile)

Example 2 with InspectionProfileWrapper

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

InspectionProfileWrapper (com.intellij.codeInspection.ex.InspectionProfileWrapper)2 DaemonCodeAnalyzer (com.intellij.codeInsight.daemon.DaemonCodeAnalyzer)1 InspectionManager (com.intellij.codeInspection.InspectionManager)1 InspectionProfileImpl (com.intellij.codeInspection.ex.InspectionProfileImpl)1 LocalInspectionToolWrapper (com.intellij.codeInspection.ex.LocalInspectionToolWrapper)1 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)1 Project (com.intellij.openapi.project.Project)1 ProperTextRange (com.intellij.openapi.util.ProperTextRange)1 PsiFile (com.intellij.psi.PsiFile)1 List (java.util.List)1 NotNull (org.jetbrains.annotations.NotNull)1 Nullable (org.jetbrains.annotations.Nullable)1