use of nl.tudelft.watchdog.core.logic.document.Document in project watchdog by TestRoots.
the class IntervalJsonConverterTest method testJsonTypingIntervalDiffsAddition.
@Test
public void testJsonTypingIntervalDiffsAddition() {
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-document-add"));
interval.close();
sleepABit();
ArrayList<WatchDogItem> intervals = new ArrayList<>();
intervals.add(interval);
assertEquals("[{\"endingDocument\":{\"pn\":\"f6f4da8d93e88a08220e03b7810451d3ba540a34\",\"fn\":\"e4afa075bb910c8ecb427e9950426a4599b21d7e\",\"sloc\":1,\"dt\":\"un\"},\"diff\":4,\"modCountDiff\":0,\"charLengthDiff\":4,\"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 IntervalJsonConverterTest method createSampleIntervals.
private ArrayList<WatchDogItem> createSampleIntervals(EditorIntervalBase interval) {
interval.setDocument(new Document("Project", "Production.java", "filepath", "blah-document"));
ArrayList<WatchDogItem> intervals = createSampleIntervals((IntervalBase) interval);
return intervals;
}
use of nl.tudelft.watchdog.core.logic.document.Document in project watchdog by TestRoots.
the class IntelliJMarkupModelListener method initializeAfterAnalysisFinished.
/**
* Create a new {@link IntelliJMarkupModelListener} for an editor. This listener is only attached after the
* {@link DaemonCodeAnalyzer} has finished analyzing this file.
*
* The listener is attached to the {@link com.intellij.openapi.editor.markup.MarkupModel} of the document,
* which contains all {@link RangeHighlighterEx}s that represent the Static Analysis warnings.
*
* @param project The project the file exists in.
* @param disposable The disposable to clean up the listeners and any potential {@link MessageBusConnection}.
* @param editor The editor of the document.
* @param trackingEventManager The manager that can process all the events generated.
* @return A newly initiated listener that will later be attached to the {@link com.intellij.openapi.editor.markup.MarkupModel} of the document
*/
public static IntelliJMarkupModelListener initializeAfterAnalysisFinished(Project project, Disposable disposable, Editor editor, TrackingEventManager trackingEventManager) {
final com.intellij.openapi.editor.Document intellijDocument = editor.getDocument();
final IntelliJMarkupModelListener markupModelListener = new IntelliJMarkupModelListener(DocumentCreator.createDocument(editor), trackingEventManager, intellijDocument);
// We need to run this in smart mode, because the very first time you start your editor, it is very briefly
// in dumb mode and the codeAnalyzer thinks (incorrectly) it is finished.
// Therefore, wait for smart mode and only then start listening, to make sure the codeAnalyzer actually did its thing.
// For more information see https://www.jetbrains.org/intellij/sdk/docs/basics/indexing_and_psi_stubs.html
DumbServiceImpl.getInstance(project).runWhenSmart(() -> {
final DaemonCodeAnalyzerImpl analyzer = (DaemonCodeAnalyzerImpl) DaemonCodeAnalyzer.getInstance(project);
final MessageBusConnection codeAnalyzerMessageBusConnection = project.getMessageBus().connect(disposable);
final MessageBusConnection documentMessageBusConnection = project.getMessageBus().connect(disposable);
codeAnalyzerMessageBusConnection.subscribe(DaemonCodeAnalyzer.DAEMON_EVENT_TOPIC, new DaemonCodeAnalyzer.DaemonListenerAdapter() {
@Override
public void daemonFinished() {
// the analyzer actually finished. In this case, `null` indicates: the file is not dirty.
if (analyzer.getFileStatusMap().getFileDirtyScope(intellijDocument, Pass.UPDATE_ALL) == null) {
final MarkupModelImpl markupModel = (MarkupModelImpl) DocumentMarkupModel.forDocument(intellijDocument, project, true);
markupModelListener.processWarningSnapshot(markupModel.getAllHighlighters());
markupModel.addMarkupModelListener(disposable, markupModelListener);
// We batch up changes and only transfer them on every save. This is in-line with the Eclipse
// interface, which only exposes listeners for `POST_BUILD`. Therefore, cache all warnings in
// {@link IntelliJMarkupModelListener#generatedWarnings} and {@link IntelliJMarkupModelListener#warnings}
// and flush these warnings after the fact.
documentMessageBusConnection.subscribe(AppTopics.FILE_DOCUMENT_SYNC, new FileDocumentManagerAdapter() {
@Override
public void beforeDocumentSaving(@NotNull com.intellij.openapi.editor.Document savedDocument) {
if (intellijDocument.equals(savedDocument)) {
markupModelListener.flushForDocument();
}
}
});
codeAnalyzerMessageBusConnection.disconnect();
}
}
});
});
return markupModelListener;
}
Aggregations