use of com.intellij.codeInspection.offline.OfflineProblemDescriptor 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.offline.OfflineProblemDescriptor in project intellij-community by JetBrains.
the class OfflineInspectionRVContentProvider method excludeProblem.
private static void excludeProblem(final String externalName, final Map<String, Set<OfflineProblemDescriptor>> content) {
for (Iterator<String> iter = content.keySet().iterator(); iter.hasNext(); ) {
final String packageName = iter.next();
final Set<OfflineProblemDescriptor> excluded = new HashSet<>(content.get(packageName));
for (Iterator<OfflineProblemDescriptor> it = excluded.iterator(); it.hasNext(); ) {
final OfflineProblemDescriptor ex = it.next();
if (Comparing.strEqual(ex.getFQName(), externalName)) {
it.remove();
}
}
if (excluded.isEmpty()) {
iter.remove();
} else {
content.put(packageName, excluded);
}
}
}
use of com.intellij.codeInspection.offline.OfflineProblemDescriptor in project intellij-community by JetBrains.
the class ViewOfflineResultsAction method actionPerformed.
@Override
public void actionPerformed(AnActionEvent event) {
final Project project = event.getData(CommonDataKeys.PROJECT);
LOG.assertTrue(project != null);
final FileChooserDescriptor descriptor = new FileChooserDescriptor(false, true, false, false, false, false) {
@Override
public Icon getIcon(VirtualFile file) {
if (file.isDirectory()) {
if (file.findChild(InspectionApplication.DESCRIPTIONS + "." + StdFileTypes.XML.getDefaultExtension()) != null) {
return AllIcons.Nodes.InspectionResults;
}
}
return super.getIcon(file);
}
};
descriptor.setTitle("Select Path");
descriptor.setDescription("Select directory which contains exported inspections results");
final VirtualFile virtualFile = FileChooser.chooseFile(descriptor, project, null);
if (virtualFile == null || !virtualFile.isDirectory())
return;
final Map<String, Map<String, Set<OfflineProblemDescriptor>>> resMap = new HashMap<>();
final String[] profileName = new String[1];
ProgressManager.getInstance().run(new Task.Backgroundable(project, InspectionsBundle.message("parsing.inspections.dump.progress.title"), true, new PerformAnalysisInBackgroundOption(project)) {
@Override
public void run(@NotNull ProgressIndicator indicator) {
final VirtualFile[] files = virtualFile.getChildren();
try {
for (final VirtualFile inspectionFile : files) {
if (inspectionFile.isDirectory())
continue;
final String shortName = inspectionFile.getNameWithoutExtension();
final String extension = inspectionFile.getExtension();
if (shortName.equals(InspectionApplication.DESCRIPTIONS)) {
profileName[0] = ReadAction.compute(() -> OfflineViewParseUtil.parseProfileName(LoadTextUtil.loadText(inspectionFile).toString()));
} else if (XML_EXTENSION.equals(extension)) {
resMap.put(shortName, ReadAction.compute(() -> OfflineViewParseUtil.parse(LoadTextUtil.loadText(inspectionFile).toString())));
}
}
} catch (final Exception e) {
//all parse exceptions
ApplicationManager.getApplication().invokeLater(() -> Messages.showInfoMessage(e.getMessage(), InspectionsBundle.message("offline.view.parse.exception.title")));
//cancel process
throw new ProcessCanceledException();
}
}
@Override
public void onSuccess() {
ApplicationManager.getApplication().invokeLater(() -> {
final String name = profileName[0];
showOfflineView(project, name, resMap, InspectionsBundle.message("offline.view.title") + " (" + (name != null ? name : InspectionsBundle.message("offline.view.editor.settings.title")) + ")");
});
}
});
}
use of com.intellij.codeInspection.offline.OfflineProblemDescriptor in project intellij-community by JetBrains.
the class OfflineDescriptorResolveResult method runLocalTool.
private static ProblemDescriptor runLocalTool(@NotNull PsiElement psiElement, @NotNull InspectionManager inspectionManager, @NotNull OfflineProblemDescriptor offlineProblemDescriptor, @NotNull LocalInspectionToolWrapper toolWrapper) {
PsiFile containingFile = psiElement.getContainingFile();
final ProblemsHolder holder = new ProblemsHolder(inspectionManager, containingFile, false);
final LocalInspectionTool localTool = toolWrapper.getTool();
final int startOffset = psiElement.getTextRange().getStartOffset();
final int endOffset = psiElement.getTextRange().getEndOffset();
LocalInspectionToolSession session = new LocalInspectionToolSession(containingFile, startOffset, endOffset);
final PsiElementVisitor visitor = localTool.buildVisitor(holder, false, session);
localTool.inspectionStarted(session, false);
final PsiElement[] elementsInRange = getElementsIntersectingRange(containingFile, startOffset, endOffset);
for (PsiElement element : elementsInRange) {
element.accept(visitor);
}
localTool.inspectionFinished(session, holder);
if (holder.hasResults()) {
final List<ProblemDescriptor> list = holder.getResults();
final int idx = offlineProblemDescriptor.getProblemIndex();
int curIdx = 0;
for (ProblemDescriptor descriptor : list) {
final PsiNamedElement member = localTool.getProblemElement(descriptor.getPsiElement());
if (psiElement instanceof PsiFile || member != null && member.equals(psiElement)) {
if (curIdx == idx) {
return descriptor;
}
curIdx++;
}
}
}
return null;
}
use of com.intellij.codeInspection.offline.OfflineProblemDescriptor in project intellij-community by JetBrains.
the class OfflineInspectionRVContentProvider method appendDescriptor.
@Override
protected void appendDescriptor(@NotNull GlobalInspectionContextImpl context, @NotNull final InspectionToolWrapper toolWrapper, @NotNull final RefEntityContainer container, @NotNull final InspectionTreeNode packageNode, final boolean canPackageRepeat) {
InspectionToolPresentation presentation = context.getPresentation(toolWrapper);
final RefElementNode elemNode = addNodeToParent(container, presentation, packageNode);
for (OfflineProblemDescriptor descriptor : ((RefEntityContainer<OfflineProblemDescriptor>) container).getDescriptors()) {
final OfflineDescriptorResolveResult resolveResult = myResolvedDescriptor.get(toolWrapper.getShortName()).computeIfAbsent(descriptor, d -> OfflineDescriptorResolveResult.resolve(d, toolWrapper, presentation));
elemNode.insertByOrder(ReadAction.compute(() -> OfflineProblemDescriptorNode.create(descriptor, resolveResult, toolWrapper, presentation)), true);
}
}
Aggregations