use of nl.tudelft.watchdog.core.logic.document.Document 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));
}
use of nl.tudelft.watchdog.core.logic.document.Document in project watchdog by TestRoots.
the class ResourceAndResourceDeltaVisitor method visit.
/**
* The Eclipse API trashes and recreates all markers after a build.
* This means that we have to handle two lists of markers and compute
* the difference between them. Delegate this implementation to
* {@link MarkerBackTrackingAlgorithm}, which is an abstraction around
* the diffing algorithm.
*/
private boolean visit(IResource resource, boolean shouldComputeDiff) throws CoreException {
if (!resource.exists()) {
return false;
}
if (resource instanceof IFile) {
IFile file = (IFile) resource;
IPath filePath = file.getFullPath();
List<MarkerHolder> oldMarkers = currentFileMarkers.get(filePath);
List<MarkerHolder> currentMarkers = Arrays.stream(file.findMarkers(IMarker.PROBLEM, true, IResource.DEPTH_ZERO)).map(MarkerHolder::fromIMarker).sorted().collect(Collectors.toList());
if (shouldComputeDiff && oldMarkers == null) {
oldMarkers = Collections.emptyList();
}
Document document = DocumentCreator.createDocument(file.getName(), file).prepareDocument();
if (this.shouldCreateSnapshot) {
createWarningSnapshotForMarkers(currentMarkers, document);
}
if (oldMarkers != null) {
MarkerBackTrackingAlgorithm diffingAlgorithm = new MarkerBackTrackingAlgorithm(oldMarkers, currentMarkers);
diffingAlgorithm.computeMemoizationTable().traverseMemoizationTable();
CoreMarkupModelListener.addCreatedWarnings(this.trackingEventManager, diffingAlgorithm.createdWarningTypes.stream().map(this::createWarning), document);
CoreMarkupModelListener.addRemovedWarnings(this.trackingEventManager, diffingAlgorithm.removedWarningTypes.stream().map(this::createWarning), document);
}
currentFileMarkers.put(filePath, currentMarkers);
}
return true;
}
use of nl.tudelft.watchdog.core.logic.document.Document in project watchdog by TestRoots.
the class IntervalJsonConverterTest method testJsonTypingIntervalDiffsModification.
@Test
public void testJsonTypingIntervalDiffsModification() {
ITextEditor editor = Mockito.mock(ITextEditor.class);
TypingInterval interval = new TypingInterval(new EditorWrapper(editor), new Date(1));
interval.setDocument(new Document("Project", "filepath", "Production.java", "blah-document"));
interval.setEndingDocument(new Document("Project", "filepath", "Production.java", "blah-documens"));
interval.close();
sleepABit();
ArrayList<WatchDogItem> intervals = new ArrayList<>();
intervals.add(interval);
assertEquals("[{\"endingDocument\":{\"pn\":\"f6f4da8d93e88a08220e03b7810451d3ba540a34\",\"fn\":\"e4afa075bb910c8ecb427e9950426a4599b21d7e\",\"sloc\":1,\"dt\":\"un\"},\"diff\":1,\"modCountDiff\":0,\"charLengthDiff\":0,\"doc\":{\"pn\":\"f6f4da8d93e88a08220e03b7810451d3ba540a34\",\"fn\":\"e4afa075bb910c8ecb427e9950426a4599b21d7e\",\"sloc\":1,\"dt\":\"un\"},\"it\":\"ty\",\"ts\":1," + pasteWDVAndClient() + "}]", transferer.toJson(intervals));
}
use of nl.tudelft.watchdog.core.logic.document.Document in project watchdog by TestRoots.
the class DocumentCreator method createDocument.
/**
* Factory method that creates and returns a {@link nl.tudelft.watchdog.core.logic.document.Document} from a given
* {@link Editor}. For this to succeed, it is necessary that the the
* supplied part is Project.
*/
public static Document createDocument(Editor editor) {
String activeProjectName = null;
String filePath = "";
String title = "";
Project project = editor.getProject();
try {
VirtualFile virtualFile = FileDocumentManager.getInstance().getFile(editor.getDocument());
activeProjectName = project.getName();
filePath = virtualFile.getPath();
title = virtualFile.getName();
} catch (NullPointerException ex) {
// Intentionally left empty
}
try {
return new Document(activeProjectName, title, filePath, getEditorOrFileContent(editor));
} catch (IllegalArgumentException exception) {
WatchDogLogger.getInstance().logSevere(exception);
}
return new Document(activeProjectName, title, filePath, null);
}
use of nl.tudelft.watchdog.core.logic.document.Document in project watchdog by TestRoots.
the class DocumentCreator method createDocument.
private static Document createDocument(String title, IFile file, String content) {
String activeProjectName = null;
String filePath = "";
try {
IProject activeProject = file.getProject();
activeProjectName = activeProject.getName();
filePath = file.getProjectRelativePath().toString();
} catch (IllegalArgumentException ex) {
// Intentionally left empty
}
try {
return new Document(activeProjectName, title, filePath, WatchDogUtils.getContentForFileFromDisk(file));
} catch (IllegalArgumentException exception) {
WatchDogLogger.getInstance().logSevere(exception);
}
return new Document(activeProjectName, title, filePath, null);
}
Aggregations