Search in sources :

Example 1 with Document

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));
}
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 Document

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;
}
Also used : IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) Document(nl.tudelft.watchdog.core.logic.document.Document)

Example 3 with Document

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));
}
Also used : ITextEditor(org.eclipse.ui.texteditor.ITextEditor) TypingInterval(nl.tudelft.watchdog.core.logic.interval.intervaltypes.TypingInterval) EditorWrapper(nl.tudelft.watchdog.eclipse.logic.document.EditorWrapper) ArrayList(java.util.ArrayList) Document(nl.tudelft.watchdog.core.logic.document.Document) Date(java.util.Date) WatchDogItem(nl.tudelft.watchdog.core.logic.storage.WatchDogItem) Test(org.junit.Test)

Example 4 with Document

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);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) Document(nl.tudelft.watchdog.core.logic.document.Document)

Example 5 with Document

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);
}
Also used : Document(nl.tudelft.watchdog.core.logic.document.Document) IProject(org.eclipse.core.resources.IProject)

Aggregations

Document (nl.tudelft.watchdog.core.logic.document.Document)13 Test (org.junit.Test)7 WatchDogItem (nl.tudelft.watchdog.core.logic.storage.WatchDogItem)6 ITextEditor (org.eclipse.ui.texteditor.ITextEditor)6 Date (java.util.Date)5 TypingInterval (nl.tudelft.watchdog.core.logic.interval.intervaltypes.TypingInterval)5 EditorWrapper (nl.tudelft.watchdog.eclipse.logic.document.EditorWrapper)5 ArrayList (java.util.ArrayList)4 IFile (org.eclipse.core.resources.IFile)2 IPath (org.eclipse.core.runtime.IPath)2 DaemonCodeAnalyzer (com.intellij.codeInsight.daemon.DaemonCodeAnalyzer)1 DaemonCodeAnalyzerImpl (com.intellij.codeInsight.daemon.impl.DaemonCodeAnalyzerImpl)1 MarkupModelImpl (com.intellij.openapi.editor.impl.MarkupModelImpl)1 FileDocumentManagerAdapter (com.intellij.openapi.fileEditor.FileDocumentManagerAdapter)1 Project (com.intellij.openapi.project.Project)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 MessageBusConnection (com.intellij.util.messages.MessageBusConnection)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 List (java.util.List)1