Search in sources :

Example 1 with FileWarningSnapshotEvent

use of nl.tudelft.watchdog.core.logic.event.eventtypes.staticanalysis.FileWarningSnapshotEvent in project watchdog by TestRoots.

the class MarkupModelListenerTest method generates_file_warning_snapshot_with_correct_line_numbers_when_opening_a_file.

@Test
public void generates_file_warning_snapshot_with_correct_line_numbers_when_opening_a_file() throws Exception {
    runForActivePage((page) -> {
        IEditorPart editor;
        try {
            editor = IDE.openEditor(page, this.preExistingTestFile);
        } catch (PartInitException e) {
            throw new RuntimeException(e);
        }
        ArgumentCaptor<FileWarningSnapshotEvent> captor = ArgumentCaptor.forClass(FileWarningSnapshotEvent.class);
        Mockito.verify(this.trackingEventManager).addEvent(captor.capture());
        try {
            int[] lineNumbers = captor.getValue().warnings.stream().map(warning -> warning.lineNumber).mapToInt(Integer::intValue).toArray();
            assertArrayEquals(lineNumbers, new int[] { 2, 5 });
        } finally {
            page.closeEditor(editor, false);
        }
    });
}
Also used : FileWarningSnapshotEvent(nl.tudelft.watchdog.core.logic.event.eventtypes.staticanalysis.FileWarningSnapshotEvent) IEditorPart(org.eclipse.ui.IEditorPart) PartInitException(org.eclipse.ui.PartInitException) Test(org.junit.Test)

Example 2 with FileWarningSnapshotEvent

use of nl.tudelft.watchdog.core.logic.event.eventtypes.staticanalysis.FileWarningSnapshotEvent in project watchdog by TestRoots.

the class MarkupModelListenerTest method generates_file_warning_snapshot_with_correct_classification_when_opening_a_file.

@Test
public void generates_file_warning_snapshot_with_correct_classification_when_opening_a_file() throws Exception {
    runForActivePage((page) -> {
        IEditorPart editor;
        try {
            editor = IDE.openEditor(page, this.preExistingTestFile);
        } catch (PartInitException e) {
            throw new RuntimeException(e);
        }
        ArgumentCaptor<FileWarningSnapshotEvent> captor = ArgumentCaptor.forClass(FileWarningSnapshotEvent.class);
        Mockito.verify(this.trackingEventManager).addEvent(captor.capture());
        try {
            String[] classifications = captor.getValue().warnings.stream().map(warning -> warning.type).toArray(String[]::new);
            assertArrayEquals(classifications, new String[] { PRE_EXISTING_MARKER_CLASSIFICATION_TYPE, "unknown" });
        } finally {
            page.closeEditor(editor, false);
        }
    });
}
Also used : IntervalManager(nl.tudelft.watchdog.eclipse.logic.interval.IntervalManager) IFolder(org.eclipse.core.resources.IFolder) ResourcesPlugin(org.eclipse.core.resources.ResourcesPlugin) IDE(org.eclipse.ui.ide.IDE) TransferManager(nl.tudelft.watchdog.eclipse.logic.network.TransferManager) CoreException(org.eclipse.core.runtime.CoreException) TrackingEventType(nl.tudelft.watchdog.core.logic.event.eventtypes.TrackingEventType) WorkbenchListener(nl.tudelft.watchdog.eclipse.logic.ui.listeners.WorkbenchListener) ArrayList(java.util.ArrayList) Answer(org.mockito.stubbing.Answer) EclipseMarkupModelListener(nl.tudelft.watchdog.eclipse.logic.ui.listeners.staticanalysis.EclipseMarkupModelListener) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ArgumentCaptor(org.mockito.ArgumentCaptor) ByteArrayInputStream(java.io.ByteArrayInputStream) IProject(org.eclipse.core.resources.IProject) Document(nl.tudelft.watchdog.core.logic.document.Document) IWorkspace(org.eclipse.core.resources.IWorkspace) PartInitException(org.eclipse.ui.PartInitException) After(org.junit.After) Assert.assertArrayEquals(org.junit.Assert.assertArrayEquals) WatchDogEventType(nl.tudelft.watchdog.core.logic.ui.events.WatchDogEventType) IFile(org.eclipse.core.resources.IFile) IEditorPart(org.eclipse.ui.IEditorPart) IMarker(org.eclipse.core.resources.IMarker) Before(org.junit.Before) Job(org.eclipse.core.runtime.jobs.Job) PlatformUI(org.eclipse.ui.PlatformUI) FileWarningSnapshotEvent(nl.tudelft.watchdog.core.logic.event.eventtypes.staticanalysis.FileWarningSnapshotEvent) WatchDogEventEditorSpecificImplementation(nl.tudelft.watchdog.core.logic.ui.events.WatchDogEventType.WatchDogEventEditorSpecificImplementation) TrackingEventManager(nl.tudelft.watchdog.core.logic.event.TrackingEventManager) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Display(org.eclipse.swt.widgets.Display) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) Assert.assertNotEquals(org.junit.Assert.assertNotEquals) Consumer(java.util.function.Consumer) Mockito(org.mockito.Mockito) List(java.util.List) Stream(java.util.stream.Stream) IWorkspaceDescription(org.eclipse.core.resources.IWorkspaceDescription) Assert(org.junit.Assert) StaticAnalysisWarningEvent(nl.tudelft.watchdog.core.logic.event.eventtypes.staticanalysis.StaticAnalysisWarningEvent) Assert.assertEquals(org.junit.Assert.assertEquals) InputStream(java.io.InputStream) FileWarningSnapshotEvent(nl.tudelft.watchdog.core.logic.event.eventtypes.staticanalysis.FileWarningSnapshotEvent) IEditorPart(org.eclipse.ui.IEditorPart) PartInitException(org.eclipse.ui.PartInitException) Test(org.junit.Test)

Example 3 with FileWarningSnapshotEvent

use of nl.tudelft.watchdog.core.logic.event.eventtypes.staticanalysis.FileWarningSnapshotEvent in project watchdog by TestRoots.

the class ResourceAndResourceDeltaVisitor method createWarningSnapshotForMarkers.

private void createWarningSnapshotForMarkers(List<MarkerHolder> currentMarkers, Document document) {
    List<Warning<String>> warnings = currentMarkers.stream().map(holder -> new Warning<>(StaticAnalysisMessageClassifier.classify(holder.message), holder.lineNumber, DateTime.now().toDate())).collect(Collectors.toList());
    this.trackingEventManager.addEvent(new FileWarningSnapshotEvent(document, warnings));
}
Also used : Arrays(java.util.Arrays) DocumentCreator(nl.tudelft.watchdog.eclipse.logic.document.DocumentCreator) FileWarningSnapshotEvent(nl.tudelft.watchdog.core.logic.event.eventtypes.staticanalysis.FileWarningSnapshotEvent) TrackingEventManager(nl.tudelft.watchdog.core.logic.event.TrackingEventManager) DateTime(org.joda.time.DateTime) IResourceDeltaVisitor(org.eclipse.core.resources.IResourceDeltaVisitor) CoreException(org.eclipse.core.runtime.CoreException) Collectors(java.util.stream.Collectors) CoreMarkupModelListener(nl.tudelft.watchdog.core.logic.ui.listeners.staticanalysis.CoreMarkupModelListener) StaticAnalysisMessageClassifier(nl.tudelft.watchdog.core.logic.ui.listeners.staticanalysis.StaticAnalysisMessageClassifier) List(java.util.List) IResourceVisitor(org.eclipse.core.resources.IResourceVisitor) Document(nl.tudelft.watchdog.core.logic.document.Document) Warning(nl.tudelft.watchdog.core.logic.ui.listeners.staticanalysis.Warning) IPath(org.eclipse.core.runtime.IPath) IResourceDelta(org.eclipse.core.resources.IResourceDelta) Map(java.util.Map) IResource(org.eclipse.core.resources.IResource) IFile(org.eclipse.core.resources.IFile) Collections(java.util.Collections) IMarker(org.eclipse.core.resources.IMarker) Warning(nl.tudelft.watchdog.core.logic.ui.listeners.staticanalysis.Warning) FileWarningSnapshotEvent(nl.tudelft.watchdog.core.logic.event.eventtypes.staticanalysis.FileWarningSnapshotEvent)

Example 4 with FileWarningSnapshotEvent

use of nl.tudelft.watchdog.core.logic.event.eventtypes.staticanalysis.FileWarningSnapshotEvent in project watchdog by TestRoots.

the class IntelliJMarkupModelListener method processWarningSnapshot.

private void processWarningSnapshot(RangeHighlighter[] highlighters) {
    if (highlighters.length == 0) {
        return;
    }
    // markupModel.getAllHighlighters returns a list of RangeHighlighter,
    // even though we know they are all instances of RangeHighlighterEx.
    // Therefore do an instanceof check and then explicitly cast them
    // to use them in the other methods
    final Stream<RangeHighlighterEx> rangeHighlighters = Arrays.stream(highlighters).filter(RangeHighlighterEx.class::isInstance).map(RangeHighlighterEx.class::cast);
    final List<Warning<String>> warnings = rangeHighlighters.filter(IntelliJMarkupModelListener::isWarningRangeHighlighter).map(rangeHighlighter -> createWarningFromRangeHighlighter(rangeHighlighter, null)).map(IntelliJMarkupModelListener::classifyWarning).collect(Collectors.toList());
    this.trackingEventManager.addEvent(new FileWarningSnapshotEvent(this.document.prepareDocument(), warnings));
}
Also used : Warning(nl.tudelft.watchdog.core.logic.ui.listeners.staticanalysis.Warning) RangeHighlighterEx(com.intellij.openapi.editor.ex.RangeHighlighterEx) FileWarningSnapshotEvent(nl.tudelft.watchdog.core.logic.event.eventtypes.staticanalysis.FileWarningSnapshotEvent)

Aggregations

FileWarningSnapshotEvent (nl.tudelft.watchdog.core.logic.event.eventtypes.staticanalysis.FileWarningSnapshotEvent)4 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 Document (nl.tudelft.watchdog.core.logic.document.Document)2 TrackingEventManager (nl.tudelft.watchdog.core.logic.event.TrackingEventManager)2 Warning (nl.tudelft.watchdog.core.logic.ui.listeners.staticanalysis.Warning)2 IFile (org.eclipse.core.resources.IFile)2 IMarker (org.eclipse.core.resources.IMarker)2 CoreException (org.eclipse.core.runtime.CoreException)2 IEditorPart (org.eclipse.ui.IEditorPart)2 PartInitException (org.eclipse.ui.PartInitException)2 Test (org.junit.Test)2 RangeHighlighterEx (com.intellij.openapi.editor.ex.RangeHighlighterEx)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 StandardCharsets (java.nio.charset.StandardCharsets)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 Map (java.util.Map)1