use of com.intellij.codeInspection.ex.LocalInspectionToolWrapper in project intellij-community by JetBrains.
the class InspectionValidatorWrapper method runInspectionOnFile.
private static List<ProblemDescriptor> runInspectionOnFile(@NotNull PsiFile file, @NotNull LocalInspectionTool inspectionTool) {
InspectionManager inspectionManager = InspectionManager.getInstance(file.getProject());
GlobalInspectionContext context = inspectionManager.createNewGlobalContext(false);
return InspectionEngine.runInspectionOnFile(file, new LocalInspectionToolWrapper(inspectionTool), context);
}
use of com.intellij.codeInspection.ex.LocalInspectionToolWrapper in project intellij-community by JetBrains.
the class ShowIntentionsPass method collectIntentionsFromDoNotShowLeveledInspections.
/**
* Can be invoked in EDT, each inspection should be fast
*/
private static void collectIntentionsFromDoNotShowLeveledInspections(@NotNull final Project project, @NotNull final PsiFile hostFile, PsiElement psiElement, final int offset, @NotNull final IntentionsInfo intentions) {
if (psiElement != null) {
if (!psiElement.isPhysical()) {
VirtualFile virtualFile = hostFile.getVirtualFile();
String text = hostFile.getText();
LOG.error("not physical: '" + psiElement.getText() + "' @" + offset + psiElement.getTextRange() + " elem:" + psiElement + " (" + psiElement.getClass().getName() + ")" + " in:" + psiElement.getContainingFile() + " host:" + hostFile + "(" + hostFile.getClass().getName() + ")", new Attachment(virtualFile != null ? virtualFile.getPresentableUrl() : "null", text != null ? text : "null"));
}
if (DumbService.isDumb(project)) {
return;
}
final List<LocalInspectionToolWrapper> intentionTools = new ArrayList<>();
final InspectionProfile profile = InspectionProjectProfileManager.getInstance(project).getInspectionProfile();
final InspectionToolWrapper[] tools = profile.getInspectionTools(hostFile);
for (InspectionToolWrapper toolWrapper : tools) {
if (toolWrapper instanceof LocalInspectionToolWrapper && !((LocalInspectionToolWrapper) toolWrapper).isUnfair()) {
final HighlightDisplayKey key = HighlightDisplayKey.find(toolWrapper.getShortName());
if (profile.isToolEnabled(key, hostFile) && HighlightDisplayLevel.DO_NOT_SHOW.equals(profile.getErrorLevel(key, hostFile))) {
intentionTools.add((LocalInspectionToolWrapper) toolWrapper);
}
}
}
if (!intentionTools.isEmpty()) {
final List<PsiElement> elements = new ArrayList<>();
PsiElement el = psiElement;
while (el != null) {
elements.add(el);
if (el instanceof PsiFile)
break;
el = el.getParent();
}
final Set<String> dialectIds = InspectionEngine.calcElementDialectIds(elements);
final LocalInspectionToolSession session = new LocalInspectionToolSession(hostFile, 0, hostFile.getTextLength());
final Processor<LocalInspectionToolWrapper> processor = toolWrapper -> {
final LocalInspectionTool localInspectionTool = toolWrapper.getTool();
final HighlightDisplayKey key = HighlightDisplayKey.find(toolWrapper.getShortName());
final String displayName = toolWrapper.getDisplayName();
final ProblemsHolder holder = new ProblemsHolder(InspectionManager.getInstance(project), hostFile, true) {
@Override
public void registerProblem(@NotNull ProblemDescriptor problemDescriptor) {
super.registerProblem(problemDescriptor);
if (problemDescriptor instanceof ProblemDescriptorBase) {
final TextRange range = ((ProblemDescriptorBase) problemDescriptor).getTextRange();
if (range != null && range.contains(offset)) {
final QuickFix[] fixes = problemDescriptor.getFixes();
if (fixes != null) {
for (int k = 0; k < fixes.length; k++) {
final IntentionAction intentionAction = QuickFixWrapper.wrap(problemDescriptor, k);
final HighlightInfo.IntentionActionDescriptor actionDescriptor = new HighlightInfo.IntentionActionDescriptor(intentionAction, null, displayName, null, key, null, HighlightSeverity.INFORMATION);
intentions.intentionsToShow.add(actionDescriptor);
}
}
}
}
}
};
InspectionEngine.createVisitorAndAcceptElements(localInspectionTool, holder, true, session, elements, dialectIds, InspectionEngine.getDialectIdsSpecifiedForTool(toolWrapper));
localInspectionTool.inspectionFinished(session, holder);
return true;
};
JobLauncher.getInstance().invokeConcurrentlyUnderProgress(intentionTools, new DaemonProgressIndicator(), false, processor);
}
}
}
use of com.intellij.codeInspection.ex.LocalInspectionToolWrapper 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());
}
};
}
use of com.intellij.codeInspection.ex.LocalInspectionToolWrapper in project intellij-community by JetBrains.
the class JavaAPIUsagesInspectionTest method doTest.
private void doTest() {
final Java15APIUsageInspection usageInspection = new Java15APIUsageInspection();
doTest("usage1.5/" + getTestName(true), new LocalInspectionToolWrapper(usageInspection), "java 1.5");
}
use of com.intellij.codeInspection.ex.LocalInspectionToolWrapper 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() };
}
Aggregations