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());
}
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);
}
}
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()]);
}
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);
}
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);
}
Aggregations