use of com.intellij.codeInspection.ex.LocalInspectionToolWrapper in project intellij-community by JetBrains.
the class SpellCheckingEditorCustomization method init.
@SuppressWarnings({ "unchecked" })
private static boolean init() {
// It's assumed that default spell checking inspection settings are just fine for processing all types of data.
// Please perform corresponding settings tuning if that assumption is broken at future.
Class<LocalInspectionTool>[] inspectionClasses = (Class<LocalInspectionTool>[]) new Class<?>[] { SpellCheckingInspection.class };
for (Class<LocalInspectionTool> inspectionClass : inspectionClasses) {
try {
LocalInspectionTool tool = inspectionClass.newInstance();
SPELL_CHECK_TOOLS.put(tool.getShortName(), new LocalInspectionToolWrapper(tool));
} catch (Throwable e) {
return false;
}
}
return true;
}
use of com.intellij.codeInspection.ex.LocalInspectionToolWrapper in project intellij-community by JetBrains.
the class DomHighlightingLiteTest method testHighlightStatus_OtherInspections2.
public void testHighlightStatus_OtherInspections2() throws Throwable {
myElement.setFileDescription(new DomFileDescription<>(DomElement.class, "a"));
final MyDomElementsInspection inspection = new MyDomElementsInspection() {
@Override
public ProblemDescriptor[] checkFile(@NotNull final PsiFile file, @NotNull final InspectionManager manager, final boolean isOnTheFly) {
myAnnotationsManager.appendProblems(myElement, createHolder(), this.getClass());
return ProblemDescriptor.EMPTY_ARRAY;
}
@Override
public void checkFileElement(final DomFileElement fileElement, final DomElementAnnotationHolder holder) {
}
};
registerInspectionKey(inspection);
LocalInspectionToolWrapper toolWrapper = new LocalInspectionToolWrapper(inspection);
myInspectionProfile.setInspectionTools(toolWrapper);
myInspectionProfile.setEnabled(toolWrapper, false);
myAnnotationsManager.appendProblems(myElement, createHolder(), MockAnnotatingDomInspection.class);
assertEquals(DomHighlightStatus.INSPECTIONS_FINISHED, myAnnotationsManager.getHighlightStatus(myElement));
}
use of com.intellij.codeInspection.ex.LocalInspectionToolWrapper in project intellij-community by JetBrains.
the class DomHighlightingLiteTest method testHighlightStatus_OtherInspections.
public void testHighlightStatus_OtherInspections() throws Throwable {
myElement.setFileDescription(new DomFileDescription<>(DomElement.class, "a"));
final MyDomElementsInspection inspection = new MyDomElementsInspection() {
@Override
public ProblemDescriptor[] checkFile(@NotNull final PsiFile file, @NotNull final InspectionManager manager, final boolean isOnTheFly) {
myAnnotationsManager.appendProblems(myElement, createHolder(), this.getClass());
return ProblemDescriptor.EMPTY_ARRAY;
}
@Override
public void checkFileElement(final DomFileElement fileElement, final DomElementAnnotationHolder holder) {
}
};
registerInspectionKey(inspection);
myInspectionProfile.setInspectionTools(new LocalInspectionToolWrapper(inspection));
myAnnotationsManager.appendProblems(myElement, createHolder(), MockAnnotatingDomInspection.class);
assertEquals(DomHighlightStatus.ANNOTATORS_FINISHED, myAnnotationsManager.getHighlightStatus(myElement));
myAnnotationsManager.appendProblems(myElement, createHolder(), inspection.getClass());
assertEquals(DomHighlightStatus.INSPECTIONS_FINISHED, myAnnotationsManager.getHighlightStatus(myElement));
}
use of com.intellij.codeInspection.ex.LocalInspectionToolWrapper in project intellij-community by JetBrains.
the class OfflineDescriptorResolveResult method createDescriptor.
@Nullable
private static CommonProblemDescriptor createDescriptor(@Nullable RefEntity element, @NotNull OfflineProblemDescriptor offlineDescriptor, @NotNull InspectionToolWrapper toolWrapper, @NotNull InspectionToolPresentation presentation) {
if (toolWrapper instanceof GlobalInspectionToolWrapper) {
final LocalInspectionToolWrapper localTool = ((GlobalInspectionToolWrapper) toolWrapper).getSharedLocalInspectionToolWrapper();
if (localTool != null) {
final CommonProblemDescriptor descriptor = createDescriptor(element, offlineDescriptor, localTool, presentation);
if (descriptor != null) {
return descriptor;
}
}
return createRerunGlobalToolDescriptor((GlobalInspectionToolWrapper) toolWrapper, element);
}
if (!(toolWrapper instanceof LocalInspectionToolWrapper))
return null;
final InspectionManager inspectionManager = InspectionManager.getInstance(presentation.getContext().getProject());
final OfflineProblemDescriptor offlineProblemDescriptor = offlineDescriptor;
if (element instanceof RefElement) {
final PsiElement psiElement = ((RefElement) element).getElement();
if (psiElement != null) {
ProblemDescriptor descriptor = ProgressManager.getInstance().runProcess(() -> runLocalTool(psiElement, inspectionManager, offlineProblemDescriptor, (LocalInspectionToolWrapper) toolWrapper), new DaemonProgressIndicator());
if (descriptor != null)
return descriptor;
}
return null;
}
final List<String> hints = offlineProblemDescriptor.getHints();
CommonProblemDescriptor descriptor = inspectionManager.createProblemDescriptor(offlineProblemDescriptor.getDescription(), (QuickFix) null);
final QuickFix[] quickFixes = getFixes(descriptor, hints, presentation);
if (quickFixes != null) {
descriptor = inspectionManager.createProblemDescriptor(offlineProblemDescriptor.getDescription(), quickFixes);
}
return descriptor;
}
use of com.intellij.codeInspection.ex.LocalInspectionToolWrapper in project intellij-community by JetBrains.
the class InspectionEngine method inspectElements.
// returns map tool.shortName -> list of descriptors found
@NotNull
static Map<String, List<ProblemDescriptor>> inspectElements(@NotNull List<LocalInspectionToolWrapper> toolWrappers, @NotNull final PsiFile file, @NotNull final InspectionManager iManager, final boolean isOnTheFly, boolean failFastOnAcquireReadAction, @NotNull ProgressIndicator indicator, @NotNull final List<PsiElement> elements, @NotNull final Set<String> elementDialectIds) {
TextRange range = file.getTextRange();
final LocalInspectionToolSession session = new LocalInspectionToolSession(file, range.getStartOffset(), range.getEndOffset());
Map<LocalInspectionToolWrapper, Set<String>> toolToSpecifiedDialectIds = getToolsToSpecifiedLanguages(toolWrappers);
List<Entry<LocalInspectionToolWrapper, Set<String>>> entries = new ArrayList<>(toolToSpecifiedDialectIds.entrySet());
final Map<String, List<ProblemDescriptor>> resultDescriptors = new ConcurrentHashMap<>();
Processor<Entry<LocalInspectionToolWrapper, Set<String>>> processor = entry -> {
ProblemsHolder holder = new ProblemsHolder(iManager, file, isOnTheFly);
final LocalInspectionTool tool = entry.getKey().getTool();
Set<String> dialectIdsSpecifiedForTool = entry.getValue();
createVisitorAndAcceptElements(tool, holder, isOnTheFly, session, elements, elementDialectIds, dialectIdsSpecifiedForTool);
tool.inspectionFinished(session, holder);
if (holder.hasResults()) {
resultDescriptors.put(tool.getShortName(), ContainerUtil.filter(holder.getResults(), descriptor -> {
PsiElement element = descriptor.getPsiElement();
return element == null || !SuppressionUtil.inspectionResultSuppressed(element, tool);
}));
}
return true;
};
JobLauncher.getInstance().invokeConcurrentlyUnderProgress(entries, indicator, failFastOnAcquireReadAction, processor);
return resultDescriptors;
}
Aggregations