void () { AtomicBoolean inspectionStarted = new AtomicBoolean(); AtomicBoolean doRunInspection = new AtomicBoolean(true); GlobalSimpleInspectionTool myTool = new GlobalSimpleInspectionTool() { @Override public void checkFile(@NotNull PsiFile file, @NotNull InspectionManager manager, @NotNull ProblemsHolder problemsHolder, @NotNull GlobalInspectionContext globalContext, @NotNull ProblemDescriptionsProcessor problemDescriptionsProcessor) { inspectionStarted.set(true); while (doRunInspection.get()) { ProgressManager.checkCanceled(); } problemsHolder.registerProblem(manager.createProblemDescriptor(file, "Finished: "+getShortName(), (LocalQuickFix)null, ProblemHighlightType.GENERIC_ERROR_OR_WARNING, true)); } @NotNull @Override public String getShortName() { return "myTool"; } @NotNull @Override public String getDisplayName() { return "A"+getShortName(); } }; String shortName = myTool.getShortName(); InspectionProfileImpl profile = new InspectionProfileImpl("myTestProfile:"+getTestName(false)); InspectionsKt.disableAllTools(profile); profile.addTool(getProject(), new GlobalInspectionToolWrapper(myTool), null); profile.enableTool(shortName, getProject()); GlobalInspectionContextImpl context = ((InspectionManagerEx)InspectionManager.getInstance(getProject())).createNewGlobalContext(); context.setExternalProfile(profile); @Language("JAVA") String text = "class Foo {}"; configureByText(JavaFileType.INSTANCE, text); AnalysisScope scope = new AnalysisScope(getFile()); //noinspection SSBasedInspection SwingUtilities.invokeLater(new Runnable() { @Override public void run() { if (!inspectionStarted.get()) { SwingUtilities.invokeLater(this); return; } inspectionStarted.set(false); WriteAction.run(() -> { }); // have to restart while (!inspectionStarted.get()) { UIUtil.dispatchAllInvocationEvents(); } doRunInspection.set(false); } }); context.doInspections(scope); UIUtil.dispatchAllInvocationEvents(); Tools tools = context.getTools().get(shortName); GlobalInspectionToolWrapper toolWrapper = (GlobalInspectionToolWrapper)tools.getTool(); InspectionToolPresentation presentation = context.getPresentation(toolWrapper); CommonProblemDescriptor descriptor = assertOneElement(presentation.getProblemDescriptors()); assertEquals("Finished: "+shortName, descriptor.getDescriptionTemplate()); }