Search in sources :

Example 1 with Warning

use of nl.tudelft.watchdog.core.logic.ui.listeners.staticanalysis.Warning 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 2 with Warning

use of nl.tudelft.watchdog.core.logic.ui.listeners.staticanalysis.Warning in project watchdog by TestRoots.

the class MarkerBackTrackingAlgorithm method traverseMemoizationTable.

/**
 * Traverse the memoized matrix and based on the length of the path
 * either invoke addCreatedWarning or addRemovedWarning as defined in
 * {@link CoreMarkupModelListener}.
 *
 * @param row The current row in the matrix
 * @param column The current column in the matrix
 */
void traverseMemoizationTable(int row, int column) {
    // The markers at this position are equal, just continue traversing through the matrix
    if (row > 0 && column > 0 && oldMarkers.get(row - 1).equals(currentMarkers.get(column - 1))) {
        traverseMemoizationTable(row - 1, column - 1);
    // The markers are not the same. In this case, the length to traverse by choosing the column
    // is longer, which means that a new marker was added (as the column is larger) in currentMarkers
    } else if (column > 0 && (row == 0 || memoization[row][column - 1] >= memoization[row - 1][column])) {
        MarkerHolder warning = currentMarkers.get(column - 1);
        this.createdWarningTypes.add(new Warning<>(warning.message, warning.lineNumber, DateTime.now().toDate()));
        traverseMemoizationTable(row, column - 1);
    // In this case, the row length is lower, which means that the oldMarkers was longer at this point
    // Therefore it is a removed warning
    } else if (row > 0 && (column == 0 || memoization[row][column - 1] < memoization[row - 1][column])) {
        MarkerHolder warning = oldMarkers.get(row - 1);
        DateTime now = DateTime.now();
        this.removedWarningTypes.add(new Warning<>(warning.message, warning.lineNumber, now.toDate(), Seconds.secondsBetween(warning.warningCreationTime, now).getSeconds()));
        traverseMemoizationTable(row - 1, column);
    }
// In this case we are at the end of the matrix (0th row/column), so nothing  happens
}
Also used : Warning(nl.tudelft.watchdog.core.logic.ui.listeners.staticanalysis.Warning) DateTime(org.joda.time.DateTime)

Example 3 with Warning

use of nl.tudelft.watchdog.core.logic.ui.listeners.staticanalysis.Warning 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)

Example 4 with Warning

use of nl.tudelft.watchdog.core.logic.ui.listeners.staticanalysis.Warning in project watchdog by TestRoots.

the class IntelliJMarkupModelListener method createWarningFromRangeHighlighter.

@NotNull
private Warning<RangeHighlighterEx> createWarningFromRangeHighlighter(@NotNull RangeHighlighterEx rangeHighlighterEx, DateTime creationTime) {
    final DateTime now = DateTime.now();
    int seconds;
    if (creationTime == null) {
        seconds = -1;
    } else {
        seconds = Seconds.secondsBetween(creationTime, now).getSeconds();
    }
    return new Warning<>(rangeHighlighterEx, getLineNumberForHighlighter(rangeHighlighterEx), now.toDate(), seconds);
}
Also used : Warning(nl.tudelft.watchdog.core.logic.ui.listeners.staticanalysis.Warning) DateTime(org.joda.time.DateTime) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

Warning (nl.tudelft.watchdog.core.logic.ui.listeners.staticanalysis.Warning)4 DateTime (org.joda.time.DateTime)3 FileWarningSnapshotEvent (nl.tudelft.watchdog.core.logic.event.eventtypes.staticanalysis.FileWarningSnapshotEvent)2 RangeHighlighterEx (com.intellij.openapi.editor.ex.RangeHighlighterEx)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 List (java.util.List)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 Document (nl.tudelft.watchdog.core.logic.document.Document)1 TrackingEventManager (nl.tudelft.watchdog.core.logic.event.TrackingEventManager)1 CoreMarkupModelListener (nl.tudelft.watchdog.core.logic.ui.listeners.staticanalysis.CoreMarkupModelListener)1 StaticAnalysisMessageClassifier (nl.tudelft.watchdog.core.logic.ui.listeners.staticanalysis.StaticAnalysisMessageClassifier)1 DocumentCreator (nl.tudelft.watchdog.eclipse.logic.document.DocumentCreator)1 IFile (org.eclipse.core.resources.IFile)1 IMarker (org.eclipse.core.resources.IMarker)1 IResource (org.eclipse.core.resources.IResource)1 IResourceDelta (org.eclipse.core.resources.IResourceDelta)1 IResourceDeltaVisitor (org.eclipse.core.resources.IResourceDeltaVisitor)1 IResourceVisitor (org.eclipse.core.resources.IResourceVisitor)1