Commit cf5649d5 authored by Sebastian Pretscher's avatar Sebastian Pretscher

Some changes for better errorhandling

parent 8c91931b
......@@ -63,10 +63,10 @@ public class Controller {
Debugger.getInstance(editor.getDocument()); // TODO: why is this here?
}
public void notifyObserversOfJobStatus(JobsToDo affectedJob, JobStatus status) {
public void notifyObserversOfJobStatus(JobStatus status) {
synchronized (controllerObservers) {
for (IRegisterForControllerChanges observer : controllerObservers)
observer.jobStatusChanged(affectedJob, status);
observer.jobStatusChanged(status);
}
}
......
......@@ -2,6 +2,7 @@ package de.tum.in.www2.cupplugin.controller;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List;
......@@ -37,7 +38,8 @@ public class DocumentDidChangeJob extends Job {
private ParserResult result;
private CupContext context;
private LALRResult lalrResult;
private List<JobStatus> jobStatusList;
private String codeText;
// Revision Number for checks
......@@ -46,6 +48,7 @@ public class DocumentDidChangeJob extends Job {
public DocumentDidChangeJob(CupTextEditor editor) {
super("" + editor.hashCode());
myEditor = editor;
jobStatusList = new ArrayList<JobStatus>();
}
public boolean running() {
......@@ -119,6 +122,7 @@ public class DocumentDidChangeJob extends Job {
errorReporter.pushToUIThread();
if (result != null) {
jobStatusList.add(new JobStatus(JobsToDo.parseCode, false));
ParserResultJob resultModelJob = new ParserResultJob(result,
context, revNumber);
resultModelJob.setSystem(true);
......@@ -131,8 +135,8 @@ public class DocumentDidChangeJob extends Job {
} else {
// TODO: we need to notify listeners THAT/WHY the call failed.
return Status.CANCEL_STATUS;
jobStatusList.add(new JobStatus(JobsToDo.parseCode, true));
//return Status.CANCEL_STATUS;
}
}
......@@ -157,6 +161,7 @@ public class DocumentDidChangeJob extends Job {
}
if (lalrResult != null) {
jobStatusList.add(new JobStatus(JobsToDo.buildTable, false));
LaLrResultJob resultLaLrModelJob = new LaLrResultJob(myEditor,
lalrResult, revNumber, context);
resultLaLrModelJob.setSystem(true);
......@@ -169,8 +174,8 @@ public class DocumentDidChangeJob extends Job {
}
} else {
// TODO: we need to notify listeners THAT/WHY the call failed.
return Status.CANCEL_STATUS;
jobStatusList.add(new JobStatus(JobsToDo.buildTable, true));
//return Status.CANCEL_STATUS;
}
}
......@@ -182,7 +187,7 @@ public class DocumentDidChangeJob extends Job {
jobs.clear();
iAmCurrentlyRunning = false;
CallbackJob cb = new CallbackJob(myEditor);
CallbackJob cb = new CallbackJob(myEditor, jobStatusList);
cb.setSystem(true);
cb.schedule();
......@@ -191,14 +196,19 @@ public class DocumentDidChangeJob extends Job {
static class CallbackJob extends UIJob {
private CupTextEditor editor = null;
private List<JobStatus>jobStatusList;
public CallbackJob(CupTextEditor editor) {
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;
}
......@@ -264,7 +274,7 @@ public class DocumentDidChangeJob extends Job {
} else {
documentDidChangeJob.jobs.addAll(controller.popJobsToDo());
}
jobStatusList.clear();
if (myEditor == null)
return Status.CANCEL_STATUS;
......
......@@ -14,6 +14,6 @@ public interface IRegisterForControllerChanges {
*/
EnumSet<JobsToDo> getRequiredJobs();
void jobStatusChanged(JobsToDo affectedJob, JobStatus status);
void jobStatusChanged(JobStatus status);
}
package de.tum.in.www2.cupplugin.controller;
import de.tum.in.www2.cupplugin.controller.Controller.JobsToDo;
public class JobStatus {
private boolean failed;
private JobsToDo affectedJob;
public JobStatus(JobsToDo affectedJob, boolean failed) {
this.affectedJob = affectedJob;
this.failed = failed;
}
public boolean hasFailed() {
return failed;
......@@ -11,5 +19,13 @@ public class JobStatus {
public JobStatus(boolean failed) {
this.failed = failed;
}
public JobsToDo getAffectedJob() {
return affectedJob;
}
public void setAffectedJob(JobsToDo affectedJob) {
this.affectedJob = affectedJob;
}
}
......@@ -565,7 +565,7 @@ public class CupContentOutlinePage extends ContentOutlinePage implements
}
@Override
public void jobStatusChanged(JobsToDo affectedJob, JobStatus status) {
public void jobStatusChanged(JobStatus status) {
// TODO Auto-generated method stub
}
......
......@@ -149,7 +149,7 @@ public class CupSourceViewerConfiguration extends SourceViewerConfiguration {
}
@Override
public void jobStatusChanged(JobsToDo affectedJob, JobStatus status) {
public void jobStatusChanged(JobStatus status) {
// no nothing.
}
......
......@@ -242,7 +242,7 @@ public class CupTextEditor extends TextEditor
}
@Override
public void jobStatusChanged(JobsToDo affectedJob, JobStatus status) {
public void jobStatusChanged(JobStatus status) {
// do nothing.
}
......
......@@ -99,7 +99,7 @@ public class CupTextHover implements ITextHover,
}
@Override
public void jobStatusChanged(JobsToDo affectedJob, JobStatus status) {
public void jobStatusChanged(JobStatus status) {
// do nothing.
}
......
......@@ -252,7 +252,7 @@ public class CupActionTableView extends FailableView implements ICupEditorPageVi
}
@Override
public void jobStatusChanged(JobsToDo affectedJob, JobStatus status) {
public void jobStatusChanged(JobStatus status) {
// TODO Auto-generated method stub
}
......
......@@ -82,10 +82,9 @@ import de.tum.in.www2.cupplugin.editors.Jumper;
import de.tum.in.www2.cupplugin.model.ICupParserLaLrChangeObserver;
import de.tum.in.www2.cupplugin.model.Model;
public class CupConflictGraphView extends FailableView
implements ICupParserLaLrChangeObserver,
IZoomableWorkbenchPart, ICupEditorPageVisibility,
IRegisterForControllerChanges {
public class CupConflictGraphView extends FailableView implements
ICupParserLaLrChangeObserver, IZoomableWorkbenchPart,
ICupEditorPageVisibility, IRegisterForControllerChanges {
private static final int BUTTON_WIDTH = 120;
private static final int LABEL_WIDTH = 40;
......@@ -117,11 +116,11 @@ public class CupConflictGraphView extends FailableView
public CupConflictGraphView(Composite realParent, Jumper jumper,
CupTextEditor editor) {
super(realParent);
showErrorNoParseTables();
Composite parent = getMain();
this.editor = editor;
Controller.getInstance(editor).registerObserver(this);
......@@ -325,7 +324,7 @@ public class CupConflictGraphView extends FailableView
private void showErrorNoParseTables() {
showError("Parse tables currently not available");
}
@Override
public void modelChanged(Model model) {
if (!isVisible) {
......@@ -333,17 +332,14 @@ public class CupConflictGraphView extends FailableView
}
stateHashMap.clear();
CupContext lalrContext = model.getLaLrContext();
if (lalrContext == null) {
System.err.println("CupConflictGraphView: lalrResult was null.");
showErrorNoParseTables();
return;
}
// TODO?!
showMain();
lalr_state.lalr_state_shared sharedState = lalr_state
.getShared(lalrContext);
Enumeration allEnum = sharedState.all();
......@@ -450,6 +446,8 @@ public class CupConflictGraphView extends FailableView
IDocument doc = editor.getDocumentProvider().getDocument(
editor.getEditorInput());
modelChanged(Model.getInstanceForDocument(doc));
} else {
showError("Requested job run ...");
}
}
......@@ -833,9 +831,20 @@ public class CupConflictGraphView extends FailableView
}
@Override
public void jobStatusChanged(JobsToDo affectedJob, JobStatus status) {
// TODO Auto-generated method stub
public void jobStatusChanged(JobStatus status) {
if (status.hasFailed()) {
switch (status.getAffectedJob()) {
case buildTable:
showError("Failure while building tables...");
break;
case parseCode:
showError("Failure while parsing code...");
break;
default:
break;
}
}
}
}
......@@ -443,7 +443,7 @@ public class CupConflictsView extends FailableView implements ICupEditorPageVisi
}
@Override
public void jobStatusChanged(JobsToDo affectedJob, JobStatus status) {
public void jobStatusChanged(JobStatus status) {
// TODO: if the job failed, we can show an appropriate error here.
// and update the current status message.
......
......@@ -206,7 +206,7 @@ public class CupOverviewView extends FailableView implements IRegisterForControl
}
@Override
public void jobStatusChanged(JobsToDo affectedJob, JobStatus status) {
public void jobStatusChanged(JobStatus status) {
// TODO Auto-generated method stub
}
......
......@@ -1009,7 +1009,7 @@ public class CupReduceGraphView extends FailableView
}
@Override
public void jobStatusChanged(JobsToDo affectedJob, JobStatus status) {
public void jobStatusChanged(JobStatus status) {
// TODO Auto-generated method stub
}
......
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