Search in sources :

Example 11 with LiveIssue

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

the class LiveIssueCacheTest method should_clear_store.

@Test
public void should_clear_store() {
    LiveIssue issue1 = createTestIssue("r1");
    VirtualFile file0 = createTestFile("file0");
    cache.save(file0, Collections.singleton(issue1));
    cache.clear();
    verify(store).clear();
    assertThat(cache.getLive(file0)).isNull();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LiveIssue(org.sonarlint.intellij.issue.LiveIssue) Test(org.junit.Test)

Example 12 with LiveIssue

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

the class LiveIssueCacheTest method error_flush.

@Test
public void error_flush() throws IOException {
    doThrow(new IOException()).when(store).save(anyString(), anyCollection());
    LiveIssue issue1 = createTestIssue("r1");
    VirtualFile file0 = createTestFile("file0");
    cache.save(file0, Collections.singleton(issue1));
    exception.expect(IllegalStateException.class);
    cache.flushAll();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LiveIssue(org.sonarlint.intellij.issue.LiveIssue) IOException(java.io.IOException) Test(org.junit.Test)

Example 13 with LiveIssue

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

the class LiveIssueCacheTest method should_flush_on_project_closed.

@Test
public void should_flush_on_project_closed() throws IOException {
    LiveIssue issue1 = createTestIssue("r1");
    VirtualFile file0 = createTestFile("file0");
    cache.save(file0, Collections.singleton(issue1));
    VirtualFile file1 = createTestFile("file1");
    cache.save(file1, Collections.singleton(issue1));
    cache.disposeComponent();
    verify(store).save(eq("file0"), anyCollection());
    verify(store).save(eq("file1"), anyCollection());
    verifyNoMoreInteractions(store);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LiveIssue(org.sonarlint.intellij.issue.LiveIssue) Test(org.junit.Test)

Example 14 with LiveIssue

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

the class LiveIssueCacheTest method should_save_and_read_cache_only.

@Test
public void should_save_and_read_cache_only() throws IOException {
    VirtualFile file = createTestFile("file1");
    LiveIssue issue1 = createTestIssue("will be overwritten");
    LiveIssue issue2 = createTestIssue("r1");
    cache.save(file, Collections.singleton(issue1));
    cache.save(file, Collections.singleton(issue2));
    assertThat(cache.contains(file)).isTrue();
    assertThat(cache.getLive(file)).containsOnly(issue2);
    assertThat(cache.contains(createTestFile("file2"))).isFalse();
    verifyZeroInteractions(store);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LiveIssue(org.sonarlint.intellij.issue.LiveIssue) Test(org.junit.Test)

Example 15 with LiveIssue

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

the class IssueTree method navigate.

@CheckForNull
private OpenFileDescriptor navigate() {
    DefaultMutableTreeNode node = getSelectedNode();
    if (!(node instanceof IssueNode)) {
        return null;
    }
    LiveIssue issue = ((IssueNode) node).issue();
    if (!issue.isValid()) {
        return null;
    }
    int offset;
    RangeMarker range = issue.getRange();
    if (range != null) {
        offset = range.getStartOffset();
    } else {
        offset = 0;
    }
    return new OpenFileDescriptor(project, issue.psiFile().getVirtualFile(), offset);
}
Also used : LiveIssue(org.sonarlint.intellij.issue.LiveIssue) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) IssueNode(org.sonarlint.intellij.ui.nodes.IssueNode) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) RangeMarker(com.intellij.openapi.editor.RangeMarker) CheckForNull(javax.annotation.CheckForNull)

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