Search in sources :

Example 16 with LocalInspectionTool

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

the class StreamApiMigrationInspectionTest method configureLocalInspectionTools.

@NotNull
@Override
protected LocalInspectionTool[] configureLocalInspectionTools() {
    StreamApiMigrationInspection inspection = new StreamApiMigrationInspection();
    inspection.SUGGEST_FOREACH = true;
    return new LocalInspectionTool[] { inspection };
}
Also used : LocalInspectionTool(com.intellij.codeInspection.LocalInspectionTool) StreamApiMigrationInspection(com.intellij.codeInspection.streamMigration.StreamApiMigrationInspection) NotNull(org.jetbrains.annotations.NotNull)

Example 17 with LocalInspectionTool

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

the class StreamToLoopInspectionTest method configureLocalInspectionTools.

@NotNull
@Override
protected LocalInspectionTool[] configureLocalInspectionTools() {
    StreamToLoopInspection inspection = new StreamToLoopInspection();
    inspection.SUPPORT_UNKNOWN_SOURCES = true;
    return new LocalInspectionTool[] { inspection };
}
Also used : StreamToLoopInspection(com.intellij.codeInspection.streamToLoop.StreamToLoopInspection) LocalInspectionTool(com.intellij.codeInspection.LocalInspectionTool) NotNull(org.jetbrains.annotations.NotNull)

Example 18 with LocalInspectionTool

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

the class DaemonRespondToChangesTest method configureLocalInspectionTools.

@Override
protected LocalInspectionTool[] configureLocalInspectionTools() {
    if (isStressTest() && !getTestName(false).equals("TypingCurliesClearsEndOfFileErrorsInPhp_ItIsPerformanceTestBecauseItRunsTooLong")) {
        // all possible inspections
        List<InspectionToolWrapper> all = InspectionToolRegistrar.getInstance().createTools();
        List<LocalInspectionTool> locals = new ArrayList<>();
        all.stream().filter(tool -> tool instanceof LocalInspectionToolWrapper).forEach(tool -> {
            LocalInspectionTool e = ((LocalInspectionToolWrapper) tool).getTool();
            locals.add(e);
        });
        return locals.toArray(new LocalInspectionTool[locals.size()]);
    }
    return new LocalInspectionTool[] { new FieldCanBeLocalInspection(), new RequiredAttributesInspectionBase(), new CheckDtdReferencesInspection(), new AccessStaticViaInstance() };
}
Also used : TypedAction(com.intellij.openapi.editor.actionSystem.TypedAction) UIUtil(com.intellij.util.ui.UIUtil) com.intellij.testFramework(com.intellij.testFramework) VirtualFile(com.intellij.openapi.vfs.VirtualFile) THashSet(gnu.trove.THashSet) DocumentMarkupModel(com.intellij.openapi.editor.impl.DocumentMarkupModel) ApplicationEx(com.intellij.openapi.application.ex.ApplicationEx) AccessToken(com.intellij.openapi.application.AccessToken) CompletionContributor(com.intellij.codeInsight.completion.CompletionContributor) com.intellij.lang(com.intellij.lang) PerformanceWatcher(com.intellij.diagnostic.PerformanceWatcher) EditorImpl(com.intellij.openapi.editor.impl.EditorImpl) CodeFoldingManager(com.intellij.codeInsight.folding.CodeFoldingManager) RangeHighlighter(com.intellij.openapi.editor.markup.RangeHighlighter) WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) EditorActionManager(com.intellij.openapi.editor.actionSystem.EditorActionManager) Module(com.intellij.openapi.module.Module) TextEditor(com.intellij.openapi.fileEditor.TextEditor) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) PlainTextFileType(com.intellij.openapi.fileTypes.PlainTextFileType) TextRange(com.intellij.openapi.util.TextRange) HighlighterTargetArea(com.intellij.openapi.editor.markup.HighlighterTargetArea) MarkupModel(com.intellij.openapi.editor.markup.MarkupModel) ConsoleView(com.intellij.execution.ui.ConsoleView) DeleteCatchFix(com.intellij.codeInsight.daemon.impl.quickfix.DeleteCatchFix) com.intellij.util(com.intellij.util) LightweightHint(com.intellij.ui.LightweightHint) ProjectManagerImpl(com.intellij.openapi.project.impl.ProjectManagerImpl) InspectionProjectProfileManager(com.intellij.profile.codeInspection.InspectionProjectProfileManager) ProperTextRange(com.intellij.openapi.util.ProperTextRange) java.util(java.util) ExternalResourceManagerExImpl(com.intellij.javaee.ExternalResourceManagerExImpl) com.intellij.openapi.editor(com.intellij.openapi.editor) LocalInspectionToolWrapper(com.intellij.codeInspection.ex.LocalInspectionToolWrapper) EditorInfo(com.intellij.codeInsight.EditorInfo) Annotator(com.intellij.lang.annotation.Annotator) ThreadDumper(com.intellij.diagnostic.ThreadDumper) InspectionToolRegistrar(com.intellij.codeInspection.ex.InspectionToolRegistrar) CoreProgressManager(com.intellij.openapi.progress.impl.CoreProgressManager) Segment(com.intellij.openapi.util.Segment) TextConsoleBuilderFactory(com.intellij.execution.filters.TextConsoleBuilderFactory) AccessStaticViaInstance(com.intellij.codeInspection.accessStaticViaInstance.AccessStaticViaInstance) JavaLanguage(com.intellij.lang.java.JavaLanguage) DebugUtil(com.intellij.psi.impl.DebugUtil) StdFileTypes(com.intellij.openapi.fileTypes.StdFileTypes) Language(org.intellij.lang.annotations.Language) StringUtil(com.intellij.openapi.util.text.StringUtil) UnusedDeclarationInspectionBase(com.intellij.codeInspection.deadCode.UnusedDeclarationInspectionBase) ProjectManagerEx(com.intellij.openapi.project.ex.ProjectManagerEx) IOException(java.io.IOException) StorageUtilKt(com.intellij.configurationStore.StorageUtilKt) AbstractIntentionAction(com.intellij.codeInsight.intention.AbstractIntentionAction) Disposable(com.intellij.openapi.Disposable) InlineRefactoringActionHandler(com.intellij.refactoring.inline.InlineRefactoringActionHandler) File(java.io.File) java.awt(java.awt) AtomicLong(java.util.concurrent.atomic.AtomicLong) RequiredAttributesInspectionBase(com.intellij.codeInspection.htmlInspections.RequiredAttributesInspectionBase) Result(com.intellij.openapi.application.Result) InspectionToolWrapper(com.intellij.codeInspection.ex.InspectionToolWrapper) UndoManager(com.intellij.openapi.command.undo.UndoManager) LocalInspectionTool(com.intellij.codeInspection.LocalInspectionTool) ApplicationManagerEx(com.intellij.openapi.application.ex.ApplicationManagerEx) SimpleDataContext(com.intellij.openapi.actionSystem.impl.SimpleDataContext) HeavyProcessLatch(com.intellij.util.io.storage.HeavyProcessLatch) CheckDtdReferencesInspection(com.intellij.xml.util.CheckDtdReferencesInspection) GutterIconRenderer(com.intellij.openapi.editor.markup.GutterIconRenderer) ExternalAnnotator(com.intellij.lang.annotation.ExternalAnnotator) HighlightSeverity(com.intellij.lang.annotation.HighlightSeverity) PsiAwareTextEditorProvider(com.intellij.openapi.fileEditor.impl.text.PsiAwareTextEditorProvider) MarkupModelEx(com.intellij.openapi.editor.ex.MarkupModelEx) AnnotationHolder(com.intellij.lang.annotation.AnnotationHolder) IdeActions(com.intellij.openapi.actionSystem.IdeActions) Nls(org.jetbrains.annotations.Nls) ConsoleViewContentType(com.intellij.execution.ui.ConsoleViewContentType) ProjectManager(com.intellij.openapi.project.ProjectManager) RangeHighlighterEx(com.intellij.openapi.editor.ex.RangeHighlighterEx) SaveAndSyncHandlerImpl(com.intellij.ide.SaveAndSyncHandlerImpl) Disposer(com.intellij.openapi.util.Disposer) EditorHintListener(com.intellij.codeInsight.hint.EditorHintListener) EditorEx(com.intellij.openapi.editor.ex.EditorEx) CommonDataKeys(com.intellij.openapi.actionSystem.CommonDataKeys) Method(java.lang.reflect.Method) LightQuickFixTestCase(com.intellij.codeInsight.daemon.quickFix.LightQuickFixTestCase) ProblemsHolder(com.intellij.codeInspection.ProblemsHolder) IntentionHintComponent(com.intellij.codeInsight.intention.impl.IntentionHintComponent) JavaFileType(com.intellij.ide.highlighter.JavaFileType) com.intellij.codeInsight.daemon(com.intellij.codeInsight.daemon) Collectors(java.util.stream.Collectors) com.intellij.codeHighlighting(com.intellij.codeHighlighting) Nullable(org.jetbrains.annotations.Nullable) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) List(java.util.List) ApplicationManager(com.intellij.openapi.application.ApplicationManager) GeneralSettings(com.intellij.ide.GeneralSettings) IntentionAction(com.intellij.codeInsight.intention.IntentionAction) com.intellij.psi(com.intellij.psi) NotNull(org.jetbrains.annotations.NotNull) HintListener(com.intellij.ui.HintListener) WriteAction(com.intellij.openapi.application.WriteAction) DataContext(com.intellij.openapi.actionSystem.DataContext) NonNls(org.jetbrains.annotations.NonNls) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ContainerUtil(com.intellij.util.containers.ContainerUtil) AtomicReference(java.util.concurrent.atomic.AtomicReference) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) RenameProcessor(com.intellij.refactoring.rename.RenameProcessor) InspectionProfile(com.intellij.codeInspection.InspectionProfile) IntentionManager(com.intellij.codeInsight.intention.IntentionManager) Project(com.intellij.openapi.project.Project) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) CodeInsightTestFixtureImpl(com.intellij.testFramework.fixtures.impl.CodeInsightTestFixtureImpl) FieldCanBeLocalInspection(com.intellij.codeInspection.varScopeCanBeNarrowed.FieldCanBeLocalInspection) TextEditorProvider(com.intellij.openapi.fileEditor.impl.text.TextEditorProvider) MarkupModelListener(com.intellij.openapi.editor.impl.event.MarkupModelListener) AbstractProjectComponent(com.intellij.openapi.components.AbstractProjectComponent) CommandProcessor(com.intellij.openapi.command.CommandProcessor) UnusedDeclarationInspection(com.intellij.codeInspection.deadCode.UnusedDeclarationInspection) FieldCanBeLocalInspection(com.intellij.codeInspection.varScopeCanBeNarrowed.FieldCanBeLocalInspection) AccessStaticViaInstance(com.intellij.codeInspection.accessStaticViaInstance.AccessStaticViaInstance) CheckDtdReferencesInspection(com.intellij.xml.util.CheckDtdReferencesInspection) RequiredAttributesInspectionBase(com.intellij.codeInspection.htmlInspections.RequiredAttributesInspectionBase) LocalInspectionToolWrapper(com.intellij.codeInspection.ex.LocalInspectionToolWrapper) InspectionToolWrapper(com.intellij.codeInspection.ex.InspectionToolWrapper) LocalInspectionTool(com.intellij.codeInspection.LocalInspectionTool) LocalInspectionToolWrapper(com.intellij.codeInspection.ex.LocalInspectionToolWrapper)

Example 19 with LocalInspectionTool

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

the class DaemonRespondToChangesTest method testLIPGetAllParentsAfterCodeBlockModification.

public void testLIPGetAllParentsAfterCodeBlockModification() throws Throwable {
    @Language("JAVA") String text = "class LQF {\n" + "    int f;\n" + "    public void me() {\n" + "        //<caret>\n" + "    }\n" + "}";
    configureByText(StdFileTypes.JAVA, text);
    final List<PsiElement> visitedElements = Collections.synchronizedList(new ArrayList<>());
    class MyVisitor extends PsiElementVisitor {

        @Override
        public void visitElement(PsiElement element) {
            visitedElements.add(element);
        }
    }
    final LocalInspectionTool tool = new LocalInspectionTool() {

        @Nls
        @NotNull
        @Override
        public String getGroupDisplayName() {
            return "fegna";
        }

        @Nls
        @NotNull
        @Override
        public String getDisplayName() {
            return getGroupDisplayName();
        }

        @NotNull
        @Override
        public String getShortName() {
            return getGroupDisplayName();
        }

        @NotNull
        @Override
        public PsiElementVisitor buildVisitor(@NotNull ProblemsHolder holder, boolean isOnTheFly) {
            return new MyVisitor();
        }
    };
    disposeOnTearDown(() -> disableInspectionTool(tool.getShortName()));
    enableInspectionTool(tool);
    List<HighlightInfo> infos = highlightErrors();
    assertEmpty(infos);
    List<PsiElement> allPsi = CollectHighlightsUtil.getElementsInRange(myFile, 0, myFile.getTextLength());
    assertEquals(new HashSet<>(allPsi), new HashSet<>(visitedElements));
    // inside code block modification
    visitedElements.clear();
    backspace();
    backspace();
    infos = highlightErrors();
    assertEmpty(infos);
    PsiMethod method = ((PsiJavaFile) myFile).getClasses()[0].getMethods()[0];
    List<PsiElement> methodAndParents = CollectHighlightsUtil.getElementsInRange(myFile, method.getTextRange().getStartOffset(), method.getTextRange().getEndOffset(), true);
    assertEquals(new HashSet<>(methodAndParents), new HashSet<>(visitedElements));
}
Also used : NotNull(org.jetbrains.annotations.NotNull) ProblemsHolder(com.intellij.codeInspection.ProblemsHolder) JavaLanguage(com.intellij.lang.java.JavaLanguage) Language(org.intellij.lang.annotations.Language) LocalInspectionTool(com.intellij.codeInspection.LocalInspectionTool)

Example 20 with LocalInspectionTool

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

the class HighlightSeverityTest method testErrorLikeUnusedSymbol.

public void testErrorLikeUnusedSymbol() throws Exception {
    enableInspectionTool(new LocalInspectionTool() {

        @NotNull
        @Override
        public String getShortName() {
            return getDisplayName();
        }

        @NotNull
        @Override
        public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, boolean isOnTheFly, @NotNull LocalInspectionToolSession session) {
            return new JavaElementVisitor() {

                @Override
                public void visitIdentifier(PsiIdentifier identifier) {
                    if (identifier.getText().equals("k")) {
                        holder.registerProblem(identifier, "Variable 'k' is never used");
                    }
                }
            };
        }

        @NotNull
        @Override
        public HighlightDisplayLevel getDefaultLevel() {
            return HighlightDisplayLevel.ERROR;
        }

        @Nls
        @NotNull
        @Override
        public String getDisplayName() {
            return "x";
        }

        @Nls
        @NotNull
        @Override
        public String getGroupDisplayName() {
            return getDisplayName();
        }
    });
    doTest(BASE_PATH + "/" + getTestName(false) + ".java", true, false);
}
Also used : HighlightDisplayLevel(com.intellij.codeHighlighting.HighlightDisplayLevel) JavaElementVisitor(com.intellij.psi.JavaElementVisitor) Nls(org.jetbrains.annotations.Nls) NonNls(org.jetbrains.annotations.NonNls) LocalInspectionToolSession(com.intellij.codeInspection.LocalInspectionToolSession) PsiIdentifier(com.intellij.psi.PsiIdentifier) PsiElementVisitor(com.intellij.psi.PsiElementVisitor) LocalInspectionTool(com.intellij.codeInspection.LocalInspectionTool) NotNull(org.jetbrains.annotations.NotNull) ProblemsHolder(com.intellij.codeInspection.ProblemsHolder)

Aggregations

LocalInspectionTool (com.intellij.codeInspection.LocalInspectionTool)29 NotNull (org.jetbrains.annotations.NotNull)11 ProblemsHolder (com.intellij.codeInspection.ProblemsHolder)4 HighlightDisplayLevel (com.intellij.codeHighlighting.HighlightDisplayLevel)3 LocalInspectionToolWrapper (com.intellij.codeInspection.ex.LocalInspectionToolWrapper)3 Project (com.intellij.openapi.project.Project)3 IOException (java.io.IOException)3 HighlightDisplayKey (com.intellij.codeInsight.daemon.HighlightDisplayKey)2 LocalInspectionToolSession (com.intellij.codeInspection.LocalInspectionToolSession)2 InspectionProfileImpl (com.intellij.codeInspection.ex.InspectionProfileImpl)2 InspectionToolWrapper (com.intellij.codeInspection.ex.InspectionToolWrapper)2 JavaLanguage (com.intellij.lang.java.JavaLanguage)2 PsiElementVisitor (com.intellij.psi.PsiElementVisitor)2 File (java.io.File)2 Language (org.intellij.lang.annotations.Language)2 Nls (org.jetbrains.annotations.Nls)2 NonNls (org.jetbrains.annotations.NonNls)2 com.intellij.codeHighlighting (com.intellij.codeHighlighting)1 EditorInfo (com.intellij.codeInsight.EditorInfo)1 CompletionContributor (com.intellij.codeInsight.completion.CompletionContributor)1