Search in sources :

Example 1 with OfflineProblemDescriptor

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;
}
Also used : GlobalInspectionToolWrapper(com.intellij.codeInspection.ex.GlobalInspectionToolWrapper) DaemonProgressIndicator(com.intellij.codeInsight.daemon.impl.DaemonProgressIndicator) OfflineProblemDescriptor(com.intellij.codeInspection.offline.OfflineProblemDescriptor) OfflineProblemDescriptor(com.intellij.codeInspection.offline.OfflineProblemDescriptor) RefElement(com.intellij.codeInspection.reference.RefElement) LocalInspectionToolWrapper(com.intellij.codeInspection.ex.LocalInspectionToolWrapper) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with OfflineProblemDescriptor

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);
        }
    }
}
Also used : OfflineProblemDescriptor(com.intellij.codeInspection.offline.OfflineProblemDescriptor) HashSet(com.intellij.util.containers.HashSet)

Example 3 with OfflineProblemDescriptor

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")) + ")");
            });
        }
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Task(com.intellij.openapi.progress.Task) HashMap(java.util.HashMap) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) OfflineProblemDescriptor(com.intellij.codeInspection.offline.OfflineProblemDescriptor) Project(com.intellij.openapi.project.Project) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) PerformAnalysisInBackgroundOption(com.intellij.analysis.PerformAnalysisInBackgroundOption) HashMap(java.util.HashMap) Map(java.util.Map) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException)

Example 4 with OfflineProblemDescriptor

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;
}
Also used : OfflineProblemDescriptor(com.intellij.codeInspection.offline.OfflineProblemDescriptor)

Example 5 with OfflineProblemDescriptor

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);
    }
}
Also used : OfflineProblemDescriptor(com.intellij.codeInspection.offline.OfflineProblemDescriptor)

Aggregations

OfflineProblemDescriptor (com.intellij.codeInspection.offline.OfflineProblemDescriptor)7 THashMap (gnu.trove.THashMap)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Set (java.util.Set)2 PerformAnalysisInBackgroundOption (com.intellij.analysis.PerformAnalysisInBackgroundOption)1 DaemonProgressIndicator (com.intellij.codeInsight.daemon.impl.DaemonProgressIndicator)1 GlobalInspectionToolWrapper (com.intellij.codeInspection.ex.GlobalInspectionToolWrapper)1 LocalInspectionToolWrapper (com.intellij.codeInspection.ex.LocalInspectionToolWrapper)1 RefElement (com.intellij.codeInspection.reference.RefElement)1 FileChooserDescriptor (com.intellij.openapi.fileChooser.FileChooserDescriptor)1 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)1 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)1 Task (com.intellij.openapi.progress.Task)1 Project (com.intellij.openapi.project.Project)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 HashSet (com.intellij.util.containers.HashSet)1 XppReader (com.thoughtworks.xstream.io.xml.XppReader)1 THashSet (gnu.trove.THashSet)1 TObjectIntHashMap (gnu.trove.TObjectIntHashMap)1