Search in sources :

Example 21 with LocalInspectionTool

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

the class InspectionLIfeCycleTest method testInspectionFinishedCalledOnce.

public void testInspectionFinishedCalledOnce() throws Exception {
    String text = "class LQF {\n" + "    int f;\n" + "    public void me() {\n" + "        <caret>\n" + "    }\n" + "}";
    configureFromFileText("x.java", text);
    final AtomicInteger startedCount = new AtomicInteger();
    final AtomicInteger finishedCount = new AtomicInteger();
    final Key<Object> KEY = Key.create("just key");
    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 PsiElementVisitor() {
            };
        }

        @Override
        public void inspectionStarted(@NotNull LocalInspectionToolSession session, boolean isOnTheFly) {
            startedCount.incrementAndGet();
            session.putUserData(KEY, session);
        }

        @Override
        public void inspectionFinished(@NotNull LocalInspectionToolSession session, @NotNull ProblemsHolder problemsHolder) {
            finishedCount.incrementAndGet();
            assertEmpty(problemsHolder.getResults());
            assertSame(session, session.getUserData(KEY));
        }
    };
    enableInspectionTool(tool);
    List<HighlightInfo> infos = highlightErrors();
    assertEmpty(infos);
    assertEquals(1, startedCount.get());
    assertEquals(1, finishedCount.get());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) LocalInspectionToolSession(com.intellij.codeInspection.LocalInspectionToolSession) HighlightInfo(com.intellij.codeInsight.daemon.impl.HighlightInfo) PsiElementVisitor(com.intellij.psi.PsiElementVisitor) LocalInspectionTool(com.intellij.codeInspection.LocalInspectionTool) NotNull(org.jetbrains.annotations.NotNull) ProblemsHolder(com.intellij.codeInspection.ProblemsHolder)

Example 22 with LocalInspectionTool

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

the class DaemonAnalyzerTestCase method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    final LocalInspectionTool[] tools = configureLocalInspectionTools();
    InspectionsKt.configureInspections(tools, getProject(), getTestRootDisposable());
    DaemonCodeAnalyzerImpl daemonCodeAnalyzer = (DaemonCodeAnalyzerImpl) DaemonCodeAnalyzer.getInstance(getProject());
    daemonCodeAnalyzer.prepareForTest();
    final StartupManagerImpl startupManager = (StartupManagerImpl) StartupManagerEx.getInstanceEx(getProject());
    startupManager.runStartupActivities();
    startupManager.startCacheUpdate();
    startupManager.runPostStartupActivities();
    DaemonCodeAnalyzerSettings.getInstance().setImportHintEnabled(false);
    if (isStressTest()) {
        // hack to avoid slowdowns in PyExtensionFactory
        IntentionManager.getInstance().getAvailableIntentionActions();
        // to cache stuff
        PathManagerEx.getTestDataPath();
        // pre-load tons of classes
        ReferenceProvidersRegistry.getInstance();
        // zillion of Dom Sem classes
        InjectedLanguageManager.getInstance(getProject());
        // pile of annotator classes loads
        LanguageAnnotators.INSTANCE.allForLanguage(JavaLanguage.INSTANCE);
        LanguageAnnotators.INSTANCE.allForLanguage(StdLanguages.XML);
        ProblemHighlightFilter.EP_NAME.getExtensions();
        Extensions.getExtensions(ImplicitUsageProvider.EP_NAME);
        Extensions.getExtensions(XmlSchemaProvider.EP_NAME);
        Extensions.getExtensions(XmlFileNSInfoProvider.EP_NAME);
        Extensions.getExtensions(ExternalAnnotatorsFilter.EXTENSION_POINT_NAME);
        Extensions.getExtensions(IndexPatternBuilder.EP_NAME);
    }
}
Also used : StartupManagerImpl(com.intellij.ide.startup.impl.StartupManagerImpl) DaemonCodeAnalyzerImpl(com.intellij.codeInsight.daemon.impl.DaemonCodeAnalyzerImpl) LocalInspectionTool(com.intellij.codeInspection.LocalInspectionTool)

Example 23 with LocalInspectionTool

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

the class DaemonAnalyzerTestCase method createLocalInspectionTools.

protected static LocalInspectionTool[] createLocalInspectionTools(final InspectionToolProvider... provider) {
    final ArrayList<LocalInspectionTool> result = new ArrayList<>();
    for (InspectionToolProvider toolProvider : provider) {
        for (Class aClass : toolProvider.getInspectionClasses()) {
            try {
                final Object tool = aClass.newInstance();
                assertTrue(tool instanceof LocalInspectionTool);
                result.add((LocalInspectionTool) tool);
            } catch (Exception e) {
                LOG.error(e);
            }
        }
    }
    return result.toArray(new LocalInspectionTool[result.size()]);
}
Also used : TIntArrayList(gnu.trove.TIntArrayList) ArrayList(java.util.ArrayList) LocalInspectionTool(com.intellij.codeInspection.LocalInspectionTool) InspectionToolProvider(com.intellij.codeInspection.InspectionToolProvider) IOException(java.io.IOException)

Example 24 with LocalInspectionTool

use of com.intellij.codeInspection.LocalInspectionTool in project kotlin by JetBrains.

the class AbstractQuickFixTest method configureLocalInspectionTools.

@NotNull
@Override
protected LocalInspectionTool[] configureLocalInspectionTools() {
    if (KotlinTestUtils.isAllFilesPresentTest(getTestName(false)))
        return super.configureLocalInspectionTools();
    String testRoot = KotlinTestUtils.getTestsRoot(this.getClass());
    String configFileText = FilesKt.readText(new File(testRoot, getTestName(true) + ".kt"), Charset.defaultCharset());
    List<String> toolsStrings = InTextDirectivesUtils.findListWithPrefixes(configFileText, "TOOL:");
    if (toolsStrings.isEmpty())
        return super.configureLocalInspectionTools();
    return ArrayUtil.toObjectArray(CollectionsKt.map(toolsStrings, new Function1<String, LocalInspectionTool>() {

        @Override
        public LocalInspectionTool invoke(String toolFqName) {
            try {
                Class<?> aClass = Class.forName(toolFqName);
                return (LocalInspectionTool) aClass.newInstance();
            } catch (Exception e) {
                throw new IllegalArgumentException("Failed to create inspection for key '" + toolFqName + "'", e);
            }
        }
    }), LocalInspectionTool.class);
}
Also used : Function1(kotlin.jvm.functions.Function1) KtFile(org.jetbrains.kotlin.psi.KtFile) File(java.io.File) LocalInspectionTool(com.intellij.codeInspection.LocalInspectionTool) IOException(java.io.IOException) NotNull(org.jetbrains.annotations.NotNull)

Example 25 with LocalInspectionTool

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

the class PythonInspectionsTest method testPyDefaultArgumentInspection.

public void testPyDefaultArgumentInspection() {
    LocalInspectionTool inspection = new PyDefaultArgumentInspection();
    doTest(getTestName(false), inspection);
}
Also used : LocalInspectionTool(com.intellij.codeInspection.LocalInspectionTool)

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