Search in sources :

Example 21 with LiveIssue

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

the class IssueTreeModelBuilder method setFileIssues.

private void setFileIssues(VirtualFile file, Iterable<LiveIssue> issues) {
    if (!accept(file)) {
        removeFile(file);
        return;
    }
    List<LiveIssue> filtered = filter(issues);
    if (filtered.isEmpty()) {
        removeFile(file);
        return;
    }
    boolean newFile = false;
    FileNode fNode = index.getFileNode(file);
    if (fNode == null) {
        newFile = true;
        fNode = new FileNode(file);
        index.setFileNode(fNode);
    }
    setIssues(fNode, filtered);
    if (newFile) {
        AbstractNode parent = getFilesParent();
        int idx = parent.getInsertIdx(fNode, new FileNodeComparator());
        int[] newIdx = { idx };
        model.nodesWereInserted(parent, newIdx);
        model.nodeChanged(parent);
    } else {
        model.nodeStructureChanged(fNode);
    }
}
Also used : LiveIssue(org.sonarlint.intellij.issue.LiveIssue) AbstractNode(org.sonarlint.intellij.ui.nodes.AbstractNode) FileNode(org.sonarlint.intellij.ui.nodes.FileNode)

Example 22 with LiveIssue

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

the class IssueTreeModelBuilderTest method mockIssuePointer.

private static LiveIssue mockIssuePointer(String path, int startOffset, String rule, String severity, @Nullable Long creationDate) {
    Issue issue = mock(Issue.class);
    PsiFile psiFile = mock(PsiFile.class);
    when(psiFile.isValid()).thenReturn(true);
    ClientInputFile f = mockFile(path);
    when(issue.getInputFile()).thenReturn(f);
    when(issue.getRuleKey()).thenReturn(rule);
    when(issue.getRuleName()).thenReturn(rule);
    when(issue.getSeverity()).thenReturn(severity);
    RangeMarker marker = mock(RangeMarker.class);
    when(marker.getStartOffset()).thenReturn(startOffset);
    LiveIssue ip = new LiveIssue(issue, psiFile);
    ip.setCreationDate(creationDate);
    return ip;
}
Also used : LiveIssue(org.sonarlint.intellij.issue.LiveIssue) Issue(org.sonarsource.sonarlint.core.client.api.common.analysis.Issue) LiveIssue(org.sonarlint.intellij.issue.LiveIssue) PsiFile(com.intellij.psi.PsiFile) RangeMarker(com.intellij.openapi.editor.RangeMarker) ClientInputFile(org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile)

Example 23 with LiveIssue

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

the class SonarLintCheckinHandlerTest method testNoUnresolvedIssues.

@Test
public void testNoUnresolvedIssues() {
    future.complete(null);
    LiveIssue issue = mock(LiveIssue.class);
    when(issue.isResolved()).thenReturn(true);
    when(issueManager.getForFile(file)).thenReturn(Collections.singleton(issue));
    handler = new SonarLintCheckinHandler(globalSettings, project, checkinProjectPanel);
    CheckinHandler.ReturnResult result = handler.beforeCheckin(null, null);
    assertThat(result).isEqualTo(CheckinHandler.ReturnResult.COMMIT);
    verify(analysisResultIssues).set(Collections.singletonMap(file, Collections.singleton(issue)), "SCM changed files");
    verify(submitter).submitFilesModal(eq(Collections.singleton(file)), eq(TriggerType.CHECK_IN), any(AnalysisCallback.class));
}
Also used : LiveIssue(org.sonarlint.intellij.issue.LiveIssue) AnalysisCallback(org.sonarlint.intellij.analysis.AnalysisCallback) CheckinHandler(com.intellij.openapi.vcs.checkin.CheckinHandler) SonarTest(org.sonarlint.intellij.SonarTest) Test(org.junit.Test)

Example 24 with LiveIssue

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

the class AnalysisResultsTest method testContainsIssues.

@Test
public void testContainsIssues() {
    VirtualFile file = mock(VirtualFile.class);
    LiveIssue issue = mock(LiveIssue.class);
    when(issues.lastAnalysisDate()).thenReturn(Instant.now());
    when(issues.wasAnalyzed()).thenReturn(true);
    when(issues.issues()).thenReturn(Collections.singletonMap(file, Collections.singleton(issue)));
    assertThat(analysisResults.getLastAnalysisDate()).isNotNull();
    assertThat(analysisResults.getEmptyText()).isEqualTo("No issues found");
    assertThat(analysisResults.issues()).hasSize(1);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LiveIssue(org.sonarlint.intellij.issue.LiveIssue) SonarTest(org.sonarlint.intellij.SonarTest) Test(org.junit.Test)

Example 25 with LiveIssue

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

the class IssueNodeTest method createIssue.

private static LiveIssue createIssue(long date, String message) {
    PsiFile file = mock(PsiFile.class);
    when(file.isValid()).thenReturn(true);
    Issue issue = mock(Issue.class);
    when(issue.getMessage()).thenReturn(message);
    when(issue.getSeverity()).thenReturn("MAJOR");
    LiveIssue issuePointer = new LiveIssue(issue, file);
    issuePointer.setCreationDate(date);
    return issuePointer;
}
Also used : LiveIssue(org.sonarlint.intellij.issue.LiveIssue) Issue(org.sonarsource.sonarlint.core.client.api.common.analysis.Issue) LiveIssue(org.sonarlint.intellij.issue.LiveIssue) PsiFile(com.intellij.psi.PsiFile)

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