use of com.intellij.codeInspection.ex.GlobalInspectionToolWrapper in project intellij-community by JetBrains.
the class RedundantSuppressTest method setUp.
@Override
protected void setUp() throws Exception {
super.setUp();
myInspectionToolWrappers = new InspectionToolWrapper[] { new LocalInspectionToolWrapper(new JavaDocReferenceInspection()), new LocalInspectionToolWrapper(new I18nInspection()), new LocalInspectionToolWrapper(new RawUseOfParameterizedTypeInspection()), new GlobalInspectionToolWrapper(new EmptyMethodInspection()), new GlobalInspectionToolWrapper(new UnusedDeclarationInspection()) };
myWrapper = new GlobalInspectionToolWrapper(new RedundantSuppressInspection() {
@NotNull
@Override
protected InspectionToolWrapper[] getInspectionTools(PsiElement psiElement, @NotNull InspectionManager manager) {
return myInspectionToolWrappers;
}
});
}
use of com.intellij.codeInspection.ex.GlobalInspectionToolWrapper 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.GlobalInspectionToolWrapper in project intellij-community by JetBrains.
the class InspectionEngine method runInspectionOnFile.
@NotNull
public static List<ProblemDescriptor> runInspectionOnFile(@NotNull final PsiFile file, @NotNull InspectionToolWrapper toolWrapper, @NotNull final GlobalInspectionContext inspectionContext) {
final InspectionManager inspectionManager = InspectionManager.getInstance(file.getProject());
toolWrapper.initialize(inspectionContext);
RefManagerImpl refManager = (RefManagerImpl) inspectionContext.getRefManager();
refManager.inspectionReadActionStarted();
try {
if (toolWrapper instanceof LocalInspectionToolWrapper) {
return inspect(Collections.singletonList((LocalInspectionToolWrapper) toolWrapper), file, inspectionManager, new EmptyProgressIndicator());
}
if (toolWrapper instanceof GlobalInspectionToolWrapper) {
final GlobalInspectionTool globalTool = ((GlobalInspectionToolWrapper) toolWrapper).getTool();
final List<ProblemDescriptor> descriptors = new ArrayList<>();
if (globalTool instanceof GlobalSimpleInspectionTool) {
GlobalSimpleInspectionTool simpleTool = (GlobalSimpleInspectionTool) globalTool;
ProblemsHolder problemsHolder = new ProblemsHolder(inspectionManager, file, false);
ProblemDescriptionsProcessor collectProcessor = new ProblemDescriptionsProcessor() {
@Nullable
@Override
public CommonProblemDescriptor[] getDescriptions(@NotNull RefEntity refEntity) {
return descriptors.toArray(new CommonProblemDescriptor[descriptors.size()]);
}
@Override
public void ignoreElement(@NotNull RefEntity refEntity) {
throw new RuntimeException();
}
@Override
public void addProblemElement(@Nullable RefEntity refEntity, @NotNull CommonProblemDescriptor... commonProblemDescriptors) {
if (!(refEntity instanceof RefElement))
return;
PsiElement element = ((RefElement) refEntity).getElement();
convertToProblemDescriptors(element, commonProblemDescriptors, descriptors);
}
@Override
public RefEntity getElement(@NotNull CommonProblemDescriptor descriptor) {
throw new RuntimeException();
}
};
simpleTool.checkFile(file, inspectionManager, problemsHolder, inspectionContext, collectProcessor);
return descriptors;
}
RefElement fileRef = refManager.getReference(file);
final AnalysisScope scope = new AnalysisScope(file);
assert fileRef != null;
fileRef.accept(new RefVisitor() {
@Override
public void visitElement(@NotNull RefEntity elem) {
CommonProblemDescriptor[] elemDescriptors = globalTool.checkElement(elem, scope, inspectionManager, inspectionContext);
if (elemDescriptors != null) {
convertToProblemDescriptors(file, elemDescriptors, descriptors);
}
for (RefEntity child : elem.getChildren()) {
child.accept(this);
}
}
});
return descriptors;
}
} finally {
refManager.inspectionReadActionFinished();
toolWrapper.cleanup(file.getProject());
inspectionContext.cleanup();
}
return Collections.emptyList();
}
use of com.intellij.codeInspection.ex.GlobalInspectionToolWrapper in project intellij-community by JetBrains.
the class EntryPointsNode method createDummyWrapper.
private static InspectionToolWrapper createDummyWrapper(@NotNull GlobalInspectionContextImpl context) {
InspectionToolWrapper toolWrapper = new GlobalInspectionToolWrapper(new DummyEntryPointsEP());
toolWrapper.initialize(context);
return toolWrapper;
}
use of com.intellij.codeInspection.ex.GlobalInspectionToolWrapper in project android by JetBrains.
the class AndroidInspectionsTest method getUnusedDeclarationWrapper.
private static GlobalInspectionToolWrapper getUnusedDeclarationWrapper() {
final InspectionEP ep = new InspectionEP();
ep.presentation = UnusedDeclarationPresentation.class.getName();
ep.implementationClass = UnusedDeclarationInspection.class.getName();
ep.shortName = UnusedDeclarationInspectionBase.SHORT_NAME;
UnusedDeclarationInspection tool = new UnusedDeclarationInspection(true);
return new GlobalInspectionToolWrapper(tool, ep);
}
Aggregations