Search in sources :

Example 16 with LiveIssue

use of org.sonarlint.intellij.issue.LiveIssue in project sonarlint-intellij by SonarSource.

the class IssueTreeModelBuilder method setIssues.

private static void setIssues(FileNode node, Iterable<LiveIssue> issuePointers) {
    node.removeAllChildren();
    // 15ms for 500 issues -> to improve?
    TreeSet<LiveIssue> set = new TreeSet<>(ISSUE_COMPARATOR);
    for (LiveIssue issue : issuePointers) {
        set.add(issue);
    }
    for (LiveIssue issue : set) {
        IssueNode iNode = new IssueNode(issue);
        node.add(iNode);
    }
}
Also used : LiveIssue(org.sonarlint.intellij.issue.LiveIssue) TreeSet(java.util.TreeSet) IssueNode(org.sonarlint.intellij.ui.nodes.IssueNode)

Example 17 with LiveIssue

use of org.sonarlint.intellij.issue.LiveIssue in project sonarlint-intellij by SonarSource.

the class SonarExternalAnnotator method apply.

@Override
public void apply(@NotNull PsiFile file, AnnotationContext annotationResult, @NotNull AnnotationHolder holder) {
    // In PHPStorm the same PHP file is analyzed twice (once as PHP file and once as HTML file)
    if ("html".equalsIgnoreCase(file.getFileType().getName())) {
        return;
    }
    Collection<LiveIssue> issues = annotationResult.store.getForFile(file.getVirtualFile());
    issues.stream().filter(issue -> !issue.isResolved()).forEach(issue -> {
        // reject non-null ranges that are no longer valid. It probably means that they were deleted from the file.
        RangeMarker range = issue.getRange();
        if (range == null || range.isValid()) {
            addAnnotation(issue, holder);
        }
    });
}
Also used : UIUtil(com.intellij.util.ui.UIUtil) SonarLintTextAttributes(org.sonarlint.intellij.config.SonarLintTextAttributes) ExternalAnnotator(com.intellij.lang.annotation.ExternalAnnotator) KeymapManager(com.intellij.openapi.keymap.KeymapManager) HighlightSeverity(com.intellij.lang.annotation.HighlightSeverity) NonNls(org.jetbrains.annotations.NonNls) Keymap(com.intellij.openapi.keymap.Keymap) AnnotationHolder(com.intellij.lang.annotation.AnnotationHolder) IdeActions(com.intellij.openapi.actionSystem.IdeActions) InspectionDescriptionLinkHandler(com.intellij.codeInsight.hint.InspectionDescriptionLinkHandler) SonarLintSeverity(org.sonarlint.intellij.util.SonarLintSeverity) Project(com.intellij.openapi.project.Project) PsiFile(com.intellij.psi.PsiFile) Nullable(javax.annotation.Nullable) RangeMarker(com.intellij.openapi.editor.RangeMarker) IssueManager(org.sonarlint.intellij.issue.IssueManager) SonarLintUtils(org.sonarlint.intellij.util.SonarLintUtils) Collection(java.util.Collection) TextRange(com.intellij.openapi.util.TextRange) Editor(com.intellij.openapi.editor.Editor) KeymapUtil(com.intellij.openapi.keymap.KeymapUtil) TextAttributesKey(com.intellij.openapi.editor.colors.TextAttributesKey) ApplicationManager(com.intellij.openapi.application.ApplicationManager) XmlStringUtil(com.intellij.xml.util.XmlStringUtil) ProblemHighlightType(com.intellij.codeInspection.ProblemHighlightType) Annotation(com.intellij.lang.annotation.Annotation) LiveIssue(org.sonarlint.intellij.issue.LiveIssue) NotNull(org.jetbrains.annotations.NotNull) LiveIssue(org.sonarlint.intellij.issue.LiveIssue) RangeMarker(com.intellij.openapi.editor.RangeMarker)

Example 18 with LiveIssue

use of org.sonarlint.intellij.issue.LiveIssue in project sonarlint-intellij by SonarSource.

the class SonarLintCheckinHandler method processResult.

private ReturnResult processResult(Collection<VirtualFile> affectedFiles) {
    AnalysisResultIssues analysisResultIssues = SonarLintUtils.get(project, AnalysisResultIssues.class);
    IssueManager issueManager = SonarLintUtils.get(project, IssueManager.class);
    Map<VirtualFile, Collection<LiveIssue>> map = affectedFiles.stream().collect(Collectors.toMap(Function.identity(), issueManager::getForFile));
    long numIssues = map.entrySet().stream().flatMap(e -> e.getValue().stream()).filter(i -> !i.isResolved()).count();
    analysisResultIssues.set(map, "SCM changed files");
    long numBlockerIssues = map.entrySet().stream().flatMap(e -> e.getValue().stream()).filter(i -> !i.isResolved()).filter(i -> "BLOCKER".equals(i.getSeverity())).count();
    if (numIssues == 0) {
        return ReturnResult.COMMIT;
    }
    long numFiles = map.keySet().size();
    String msg = createMessage(numFiles, numIssues, numBlockerIssues);
    if (ApplicationManager.getApplication().isHeadlessEnvironment()) {
        LOGGER.info(msg);
        return ReturnResult.CANCEL;
    }
    return showYesNoCancel(msg);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) UIUtil(com.intellij.util.ui.UIUtil) VirtualFile(com.intellij.openapi.vfs.VirtualFile) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) PairConsumer(com.intellij.util.PairConsumer) Function(java.util.function.Function) IssuesViewTabOpener(org.sonarlint.intellij.actions.IssuesViewTabOpener) CheckinHandler(com.intellij.openapi.vcs.checkin.CheckinHandler) Map(java.util.Map) SonarLintGlobalSettings(org.sonarlint.intellij.config.global.SonarLintGlobalSettings) Project(com.intellij.openapi.project.Project) Messages(com.intellij.openapi.ui.Messages) Logger(com.intellij.openapi.diagnostic.Logger) BorderLayout(java.awt.BorderLayout) CommitExecutor(com.intellij.openapi.vcs.changes.CommitExecutor) JComponent(javax.swing.JComponent) IssueManager(org.sonarlint.intellij.issue.IssueManager) SonarLintUtils(org.sonarlint.intellij.util.SonarLintUtils) PropertiesComponent(com.intellij.ide.util.PropertiesComponent) DumbService(com.intellij.openapi.project.DumbService) CheckinProjectPanel(com.intellij.openapi.vcs.CheckinProjectPanel) AnalysisCallback(org.sonarlint.intellij.analysis.AnalysisCallback) Collection(java.util.Collection) Set(java.util.Set) Collectors(java.util.stream.Collectors) RefreshableOnComponent(com.intellij.openapi.vcs.ui.RefreshableOnComponent) NonFocusableCheckBox(com.intellij.ui.NonFocusableCheckBox) Nullable(org.jetbrains.annotations.Nullable) ServiceManager(com.intellij.openapi.components.ServiceManager) AnalysisResultIssues(org.sonarlint.intellij.issue.AnalysisResultIssues) JCheckBox(javax.swing.JCheckBox) ApplicationManager(com.intellij.openapi.application.ApplicationManager) LiveIssue(org.sonarlint.intellij.issue.LiveIssue) JPanel(javax.swing.JPanel) IssueManager(org.sonarlint.intellij.issue.IssueManager) Collection(java.util.Collection) AnalysisResultIssues(org.sonarlint.intellij.issue.AnalysisResultIssues)

Example 19 with LiveIssue

use of org.sonarlint.intellij.issue.LiveIssue in project sonarlint-intellij by SonarSource.

the class IssueTreeModelBuilderTest method addFile.

private void addFile(Map<VirtualFile, Collection<LiveIssue>> data, String fileName, int numIssues) {
    VirtualFile file = mock(VirtualFile.class);
    when(file.getName()).thenReturn(fileName);
    when(file.isValid()).thenReturn(true);
    PsiFile psiFile = mock(PsiFile.class);
    when(psiFile.isValid()).thenReturn(true);
    List<LiveIssue> issueList = new LinkedList<>();
    for (int i = 0; i < numIssues; i++) {
        issueList.add(mockIssuePointer(fileName, i, "rule" + i, "MAJOR", (long) i));
    }
    data.put(file, issueList);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LiveIssue(org.sonarlint.intellij.issue.LiveIssue) PsiFile(com.intellij.psi.PsiFile) LinkedList(java.util.LinkedList)

Example 20 with LiveIssue

use of org.sonarlint.intellij.issue.LiveIssue in project sonarlint-intellij by SonarSource.

the class AbstractIssuesPanel method issueTreeSelectionChanged.

protected void issueTreeSelectionChanged() {
    IssueNode[] selectedNodes = tree.getSelectedNodes(IssueNode.class, null);
    if (selectedNodes.length > 0) {
        LiveIssue issue = selectedNodes[0].issue();
        rulePanel.setRuleKey(issue);
        if (issue.getRange() != null) {
            highlighting.highlightFlowsWithHighlightersUtil(issue.getRange(), issue.getMessage(), issue.flows());
        }
        flowsTree.getEmptyText().setText("Selected issue doesn't have flows");
        flowsTreeBuilder.setFlows(issue.flows(), issue.getRange(), issue.getMessage());
        flowsTree.expandAll();
    } else {
        flowsTreeBuilder.clearFlows();
        flowsTree.getEmptyText().setText("No issue selected");
        rulePanel.setRuleKey(null);
        highlighting.removeHighlightingFlows();
    }
}
Also used : LiveIssue(org.sonarlint.intellij.issue.LiveIssue) IssueNode(org.sonarlint.intellij.ui.nodes.IssueNode)

Aggregations

LiveIssue (org.sonarlint.intellij.issue.LiveIssue)26 Test (org.junit.Test)15 VirtualFile (com.intellij.openapi.vfs.VirtualFile)11 RangeMarker (com.intellij.openapi.editor.RangeMarker)4 PsiFile (com.intellij.psi.PsiFile)4 CheckinHandler (com.intellij.openapi.vcs.checkin.CheckinHandler)3 AnalysisCallback (org.sonarlint.intellij.analysis.AnalysisCallback)3 IssueNode (org.sonarlint.intellij.ui.nodes.IssueNode)3 ApplicationManager (com.intellij.openapi.application.ApplicationManager)2 Project (com.intellij.openapi.project.Project)2 TextRange (com.intellij.openapi.util.TextRange)2 UIUtil (com.intellij.util.ui.UIUtil)2 IOException (java.io.IOException)2 Collection (java.util.Collection)2 SonarTest (org.sonarlint.intellij.SonarTest)2 IssueManager (org.sonarlint.intellij.issue.IssueManager)2 SonarLintUtils (org.sonarlint.intellij.util.SonarLintUtils)2 Issue (org.sonarsource.sonarlint.core.client.api.common.analysis.Issue)2 InspectionDescriptionLinkHandler (com.intellij.codeInsight.hint.InspectionDescriptionLinkHandler)1 ProblemHighlightType (com.intellij.codeInspection.ProblemHighlightType)1