Commit 5f596bfa authored by Johannes Roith's avatar Johannes Roith

- Fix potential bug in SetupJob.

- Fix jobs into their own files.
- Minor changes.
parent 6583d816
package de.tum.in.www2.cupplugin.controller;
import java.util.List;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.ui.progress.UIJob;
import de.tum.in.www2.cupplugin.editors.CupTextEditor;
class CallbackJob extends UIJob {
private CupTextEditor editor = null;
private List<JobStatus>jobStatusList;
public CallbackJob(CupTextEditor editor, List<JobStatus>jobStatusList) {
super("" + editor.hashCode());
this.editor = editor;
this.jobStatusList = jobStatusList;
}
@Override
public IStatus runInUIThread(IProgressMonitor monitor) {
for(JobStatus status:jobStatusList) {
Controller.getInstance(editor).notifyObserversOfJobStatus(status);
}
Controller.getInstance(editor).notifyChangeJobFinished();
return Status.OK_STATUS;
}
}
\ No newline at end of file
......@@ -15,7 +15,6 @@ import org.eclipse.jface.text.DocumentEvent;
import org.eclipse.jface.text.IDocument;
import org.eclipse.ui.part.FileEditorInput;
import org.eclipse.ui.progress.UIJob;
import org.eclipse.ui.texteditor.IDocumentProvider;
import de.in.tum.www2.cup.CupContext;
import de.in.tum.www2.cup.CupParser;
......@@ -25,24 +24,21 @@ import de.in.tum.www2.cup.internal.internal_error;
import de.tum.in.www2.cupplugin.controller.Controller.JobsToDo;
import de.tum.in.www2.cupplugin.editors.CupEditorErrorReporter;
import de.tum.in.www2.cupplugin.editors.CupTextEditor;
import de.tum.in.www2.cupplugin.editors.RevisionManager;
import de.tum.in.www2.cupplugin.model.Model;
public class DocumentDidChangeJob extends Job {
boolean iAmCurrentlyRunning = false;
boolean currentlyRunning = false;
CupTextEditor editor = null;
private List<DocumentEvent> documentEvents;
private EnumSet<JobsToDo> jobs;
List<DocumentEvent> documentEvents;
EnumSet<JobsToDo> jobs;
String codeText;
private ParserResult result;
private CupContext context;
private LALRResult lalrResult;
private List<JobStatus> jobStatusList;
private String codeText;
// Revision Number for checks
public long revNumber;
public DocumentDidChangeJob(CupTextEditor editor) {
......@@ -52,14 +48,19 @@ public class DocumentDidChangeJob extends Job {
}
public boolean running() {
return iAmCurrentlyRunning;
return currentlyRunning;
}
@Override
protected IStatus run(IProgressMonitor monitor) {
iAmCurrentlyRunning = true;
currentlyRunning = true;
SetupJob setup = new SetupJob(this);
// TODO: this was moved here from the SetupJob.
// I think it's correct and safe here, but this TODO
// should only be removed, once we are sure.
jobStatusList.clear();
SetupJob setup = new SetupJob(editor, revNumber, this);
setup.setSystem(true);
setup.schedule();
try {
......@@ -90,12 +91,7 @@ public class DocumentDidChangeJob extends Job {
if (editor == null)
return Status.CANCEL_STATUS;
IDocumentProvider provider = editor.getDocumentProvider();
if (provider == null)
return Status.CANCEL_STATUS;
IDocument document = provider.getDocument(editor.getEditorInput());
IDocument document = editor.getDocument();
if (document == null)
return Status.CANCEL_STATUS;
......@@ -192,12 +188,10 @@ public class DocumentDidChangeJob extends Job {
errorReporter.pushToUIThread();
/* System.out.println(jobs); TODO: REMOVE OUTPUT */
documentEvents.clear();
jobs.clear();
iAmCurrentlyRunning = false;
currentlyRunning = false;
CallbackJob cb = new CallbackJob(editor, jobStatusList);
cb.setSystem(true);
cb.schedule();
......@@ -205,68 +199,6 @@ public class DocumentDidChangeJob extends Job {
return Status.OK_STATUS;
}
static class CallbackJob extends UIJob {
private CupTextEditor editor = null;
private List<JobStatus>jobStatusList;
public CallbackJob(CupTextEditor editor, List<JobStatus>jobStatusList) {
super("" + editor.hashCode());
this.editor = editor;
this.jobStatusList = jobStatusList;
}
@Override
public IStatus runInUIThread(IProgressMonitor monitor) {
for(JobStatus status:jobStatusList) {
Controller.getInstance(editor).notifyObserversOfJobStatus(status);
}
Controller.getInstance(editor).notifyChangeJobFinished();
return Status.OK_STATUS;
}
}
class SetupJob extends UIJob {
private DocumentDidChangeJob documentDidChangeJob;
public SetupJob(DocumentDidChangeJob documentDidChangeJob) {
super("Parser Setup Job");
this.documentDidChangeJob = documentDidChangeJob;
}
@Override
public IStatus runInUIThread(IProgressMonitor monitor) {
Controller controller = Controller.getInstance(editor);
if (documentDidChangeJob.documentEvents == null
|| documentDidChangeJob.documentEvents.isEmpty()) {
documentDidChangeJob.documentEvents = controller
.popAllDocumentEvents();
} else {
documentDidChangeJob.documentEvents.addAll(controller
.popAllDocumentEvents());
}
if (documentDidChangeJob.jobs == null
|| documentDidChangeJob.jobs.isEmpty()) {
documentDidChangeJob.jobs = controller.popJobsToDo();
} else {
documentDidChangeJob.jobs.addAll(controller.popJobsToDo());
}
jobStatusList.clear();
if (editor == null || editor.hasBeenDisposed())
return Status.CANCEL_STATUS;
IDocument document = editor.getDocument();
if (revNumber != RevisionManager.get(document))
return Status.CANCEL_STATUS;
documentDidChangeJob.codeText = document.get();
return Status.OK_STATUS;
}
}
}
package de.tum.in.www2.cupplugin.controller;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.text.IDocument;
import org.eclipse.ui.progress.UIJob;
import de.tum.in.www2.cupplugin.editors.CupTextEditor;
import de.tum.in.www2.cupplugin.editors.RevisionManager;
class SetupJob extends UIJob {
private DocumentDidChangeJob ddcJob;
private CupTextEditor editor;
private long revision;
public SetupJob(CupTextEditor editor, long revision,
DocumentDidChangeJob documentDidChangeJob) {
super("Parser Setup Job");
this.editor = editor;
this.ddcJob = documentDidChangeJob;
this.revision = revision;
}
@Override
public IStatus runInUIThread(IProgressMonitor monitor) {
Controller controller = Controller.getInstance(editor);
if (ddcJob.documentEvents == null || ddcJob.documentEvents.isEmpty())
ddcJob.documentEvents = controller.popAllDocumentEvents();
else
ddcJob.documentEvents.addAll(controller.popAllDocumentEvents());
if (ddcJob.jobs == null || ddcJob.jobs.isEmpty())
ddcJob.jobs = controller.popJobsToDo();
else
ddcJob.jobs.addAll(controller.popJobsToDo());
if (editor == null || editor.hasBeenDisposed())
return Status.CANCEL_STATUS;
IDocument document = editor.getDocument();
if (revision != RevisionManager.get(document))
return Status.CANCEL_STATUS;
ddcJob.codeText = document.get();
return Status.OK_STATUS;
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment