Search in sources :

Example 26 with InspectionToolWrapper

use of com.intellij.codeInspection.ex.InspectionToolWrapper in project intellij-community by JetBrains.

the class ExportHTMLAction method getWorkedTools.

@NotNull
private Set<InspectionToolWrapper> getWorkedTools(@NotNull InspectionNode node) {
    final Set<InspectionToolWrapper> result = new HashSet<>();
    final InspectionToolWrapper wrapper = node.getToolWrapper();
    if (myView.getCurrentProfileName() == null) {
        result.add(wrapper);
        return result;
    }
    final String shortName = wrapper.getShortName();
    final GlobalInspectionContextImpl context = myView.getGlobalInspectionContext();
    final Tools tools = context.getTools().get(shortName);
    if (tools != null) {
        //dummy entry points tool
        for (ScopeToolState state : tools.getTools()) {
            InspectionToolWrapper toolWrapper = state.getTool();
            result.add(toolWrapper);
        }
    }
    return result;
}
Also used : GlobalInspectionContextImpl(com.intellij.codeInspection.ex.GlobalInspectionContextImpl) ScopeToolState(com.intellij.codeInspection.ex.ScopeToolState) Tools(com.intellij.codeInspection.ex.Tools) InspectionToolWrapper(com.intellij.codeInspection.ex.InspectionToolWrapper) THashSet(gnu.trove.THashSet) HashSet(java.util.HashSet) NotNull(org.jetbrains.annotations.NotNull)

Example 27 with InspectionToolWrapper

use of com.intellij.codeInspection.ex.InspectionToolWrapper in project intellij-community by JetBrains.

the class QuickFixesViewActionGroup method getChildren.

@NotNull
@Override
public AnAction[] getChildren(@Nullable AnActionEvent e) {
    final InspectionResultsView view = getView(e);
    if (view == null || InvokeQuickFixAction.cantApplyFixes(view)) {
        return AnAction.EMPTY_ARRAY;
    }
    InspectionToolWrapper toolWrapper = view.getTree().getSelectedToolWrapper(true);
    if (toolWrapper == null)
        return AnAction.EMPTY_ARRAY;
    final QuickFixAction[] quickFixes = view.getProvider().getQuickFixes(toolWrapper, view.getTree());
    if (quickFixes == null || quickFixes.length == 0) {
        return AnAction.EMPTY_ARRAY;
    }
    return quickFixes;
}
Also used : InspectionResultsView(com.intellij.codeInspection.ui.InspectionResultsView) InspectionToolWrapper(com.intellij.codeInspection.ex.InspectionToolWrapper) QuickFixAction(com.intellij.codeInspection.ex.QuickFixAction) NotNull(org.jetbrains.annotations.NotNull)

Example 28 with InspectionToolWrapper

use of com.intellij.codeInspection.ex.InspectionToolWrapper 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);
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) VirtualFile(com.intellij.openapi.vfs.VirtualFile) HighlightSeverity(com.intellij.lang.annotation.HighlightSeverity) Document(com.intellij.openapi.editor.Document) MarkupModelEx(com.intellij.openapi.editor.ex.MarkupModelEx) DocumentMarkupModel(com.intellij.openapi.editor.impl.DocumentMarkupModel) QuickFixWrapper(com.intellij.codeInspection.ex.QuickFixWrapper) RangeHighlighterEx(com.intellij.openapi.editor.ex.RangeHighlighterEx) EditorEx(com.intellij.openapi.editor.ex.EditorEx) HighlightingLevelManager(com.intellij.codeInsight.daemon.impl.analysis.HighlightingLevelManager) Logger(com.intellij.openapi.diagnostic.Logger) CommonProcessors(com.intellij.util.CommonProcessors) RangeMarker(com.intellij.openapi.editor.RangeMarker) DumbService(com.intellij.openapi.project.DumbService) HighlightDisplayKey(com.intellij.codeInsight.daemon.HighlightDisplayKey) IntentionHintComponent(com.intellij.codeInsight.intention.impl.IntentionHintComponent) Processors(com.intellij.util.Processors) Set(java.util.Set) TextRange(com.intellij.openapi.util.TextRange) LogicalPosition(com.intellij.openapi.editor.LogicalPosition) CleanupAllIntention(com.intellij.codeInspection.actions.CleanupAllIntention) Nullable(org.jetbrains.annotations.Nullable) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) List(java.util.List) TextEditorHighlightingPass(com.intellij.codeHighlighting.TextEditorHighlightingPass) Processor(com.intellij.util.Processor) ApplicationManager(com.intellij.openapi.application.ApplicationManager) IntentionManagerSettings(com.intellij.codeInsight.intention.impl.config.IntentionManagerSettings) IntentionAction(com.intellij.codeInsight.intention.IntentionAction) NotNull(org.jetbrains.annotations.NotNull) InspectionProjectProfileManager(com.intellij.profile.codeInspection.InspectionProjectProfileManager) TemplateManagerImpl(com.intellij.codeInsight.template.impl.TemplateManagerImpl) JobLauncher(com.intellij.concurrency.JobLauncher) LocalInspectionToolWrapper(com.intellij.codeInspection.ex.LocalInspectionToolWrapper) NonNls(org.jetbrains.annotations.NonNls) DaemonCodeAnalyzer(com.intellij.codeInsight.daemon.DaemonCodeAnalyzer) ContainerUtil(com.intellij.util.containers.ContainerUtil) ArrayList(java.util.ArrayList) PsiElement(com.intellij.psi.PsiElement) PsiWhiteSpace(com.intellij.psi.PsiWhiteSpace) IntentionManager(com.intellij.codeInsight.intention.IntentionManager) Project(com.intellij.openapi.project.Project) PsiFile(com.intellij.psi.PsiFile) Segment(com.intellij.openapi.util.Segment) InjectedLanguageUtil(com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil) PsiDocumentManager(com.intellij.psi.PsiDocumentManager) Iterator(java.util.Iterator) FileDocumentManager(com.intellij.openapi.fileEditor.FileDocumentManager) com.intellij.codeInspection(com.intellij.codeInspection) HighlightDisplayLevel(com.intellij.codeHighlighting.HighlightDisplayLevel) Editor(com.intellij.openapi.editor.Editor) java.awt(java.awt) ShowIntentionActionsHandler(com.intellij.codeInsight.intention.impl.ShowIntentionActionsHandler) InspectionToolWrapper(com.intellij.codeInspection.ex.InspectionToolWrapper) Pair(com.intellij.openapi.util.Pair) Attachment(com.intellij.openapi.diagnostic.Attachment) HintManager(com.intellij.codeInsight.hint.HintManager) TemplateState(com.intellij.codeInsight.template.impl.TemplateState) HighlightDisplayKey(com.intellij.codeInsight.daemon.HighlightDisplayKey) ArrayList(java.util.ArrayList) Attachment(com.intellij.openapi.diagnostic.Attachment) PsiFile(com.intellij.psi.PsiFile) LocalInspectionToolWrapper(com.intellij.codeInspection.ex.LocalInspectionToolWrapper) PsiElement(com.intellij.psi.PsiElement) TextRange(com.intellij.openapi.util.TextRange) IntentionAction(com.intellij.codeInsight.intention.IntentionAction) LocalInspectionToolWrapper(com.intellij.codeInspection.ex.LocalInspectionToolWrapper) InspectionToolWrapper(com.intellij.codeInspection.ex.InspectionToolWrapper)

Example 29 with InspectionToolWrapper

use of com.intellij.codeInspection.ex.InspectionToolWrapper in project intellij-community by JetBrains.

the class InspectionDescriptionLinkHandler method getDescription.

@Override
public String getDescription(@NotNull final String refSuffix, @NotNull final Editor editor) {
    final Project project = editor.getProject();
    if (project == null) {
        LOG.error(editor);
        return null;
    }
    if (project.isDisposed())
        return null;
    final PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());
    if (file == null) {
        return null;
    }
    final InspectionProfile profile = InspectionProfileManager.getInstance().getCurrentProfile();
    final InspectionToolWrapper toolWrapper = profile.getInspectionTool(refSuffix, file);
    if (toolWrapper == null)
        return null;
    String description = toolWrapper.loadDescription();
    if (description == null) {
        LOG.warn("No description for inspection '" + refSuffix + "'");
        description = InspectionsBundle.message("inspection.tool.description.under.construction.text");
    }
    return description;
}
Also used : Project(com.intellij.openapi.project.Project) InspectionProfile(com.intellij.codeInspection.InspectionProfile) PsiFile(com.intellij.psi.PsiFile) InspectionToolWrapper(com.intellij.codeInspection.ex.InspectionToolWrapper)

Example 30 with InspectionToolWrapper

use of com.intellij.codeInspection.ex.InspectionToolWrapper in project intellij-community by JetBrains.

the class InspectionDump method main.

@Override
public void main(String[] args) {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    try {
        DocumentBuilder builder = factory.newDocumentBuilder();
        Document document = builder.newDocument();
        Element inspections = document.createElement("Inspections");
        document.appendChild(inspections);
        List<InspectionToolWrapper> tools = InspectionToolRegistrar.getInstance().createTools();
        for (InspectionToolWrapper tool : tools) {
            Element inspection = document.createElement("Inspection");
            inspection.setAttribute("groupPath", StringUtil.join(tool.getGroupPath(), ";"));
            inspection.setAttribute("group", tool.getGroupDisplayName());
            inspection.setAttribute("name", tool.getDisplayName());
            inspection.setAttribute("level", tool.getDefaultLevel().getName());
            if (tool.getLanguage() != null) {
                inspection.setAttribute("language", tool.getLanguage());
            }
            Element description = document.createElement("description");
            CDATASection descriptionSection = document.createCDATASection(escapeCDATA(tool.loadDescription()));
            description.appendChild(descriptionSection);
            inspection.appendChild(description);
            inspections.appendChild(inspection);
        }
        Transformer transformer = TransformerFactory.newInstance().newTransformer();
        transformer.setOutputProperty(OutputKeys.INDENT, "yes");
        DOMSource source = new DOMSource(document);
        final String path = args.length == 2 ? args[1] : PathManager.getHomePath() + File.separator + "AllInspections.xml";
        StreamResult console = new StreamResult(new File(path));
        transformer.transform(source, console);
        System.exit(0);
    } catch (ParserConfigurationException | TransformerException e) {
        // noinspection CallToPrintStackTrace
        e.printStackTrace();
        System.exit(1);
    }
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) Transformer(javax.xml.transform.Transformer) StreamResult(javax.xml.transform.stream.StreamResult) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document) CDATASection(org.w3c.dom.CDATASection) DocumentBuilder(javax.xml.parsers.DocumentBuilder) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) InspectionToolWrapper(com.intellij.codeInspection.ex.InspectionToolWrapper) File(java.io.File) TransformerException(javax.xml.transform.TransformerException)

Aggregations

InspectionToolWrapper (com.intellij.codeInspection.ex.InspectionToolWrapper)34 NotNull (org.jetbrains.annotations.NotNull)10 InspectionProfile (com.intellij.codeInspection.InspectionProfile)7 LocalInspectionToolWrapper (com.intellij.codeInspection.ex.LocalInspectionToolWrapper)6 File (java.io.File)6 Project (com.intellij.openapi.project.Project)5 InspectionProfileImpl (com.intellij.codeInspection.ex.InspectionProfileImpl)4 HighlightDisplayKey (com.intellij.codeInsight.daemon.HighlightDisplayKey)3 TextRange (com.intellij.openapi.util.TextRange)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 PsiFile (com.intellij.psi.PsiFile)3 Element (org.jdom.Element)3 AnalysisScope (com.intellij.analysis.AnalysisScope)2 HighlightDisplayLevel (com.intellij.codeHighlighting.HighlightDisplayLevel)2 IntentionAction (com.intellij.codeInsight.intention.IntentionAction)2 IntentionManager (com.intellij.codeInsight.intention.IntentionManager)2 IntentionHintComponent (com.intellij.codeInsight.intention.impl.IntentionHintComponent)2 GlobalInspectionToolWrapper (com.intellij.codeInspection.ex.GlobalInspectionToolWrapper)2 InspectionManagerEx (com.intellij.codeInspection.ex.InspectionManagerEx)2 InspectionResultsView (com.intellij.codeInspection.ui.InspectionResultsView)2