Commit 544980c1 authored by Johannes Roith's avatar Johannes Roith

- Show better message if parse tables could not be built, due to parse errors.

- Wrap message in FailableView.
- Name Statistics job correctly.
parent 5f596bfa
......@@ -12,9 +12,7 @@ import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
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 de.in.tum.www2.cup.CupContext;
import de.in.tum.www2.cup.CupParser;
......@@ -66,34 +64,13 @@ public class DocumentDidChangeJob extends Job {
try {
setup.join();
} catch (InterruptedException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
if (setup.getResult() == Status.CANCEL_STATUS) {
if (setup.getResult() == Status.CANCEL_STATUS)
return Status.CANCEL_STATUS;
}
// TODO: can we really work with the document just like that
// on this thread? What about changes that are happening
// to the document? We should probably copy the document
// data first or something !!!
// -> We should instead read the document into a buffer in the UI
// thread.
// and store it, along with the revision that we also get on the UI
// thread.
// -> The actual parsing and analysis can then be done on the background
// job.
// We need these null checks, because the document might have been
// closed already.
if (editor == null)
return Status.CANCEL_STATUS;
IDocument document = editor.getDocument();
if (document == null)
if (editor == null || editor.getDocument() == null)
return Status.CANCEL_STATUS;
IFile file = ((FileEditorInput) editor.getEditorInput()).getFile();
......@@ -136,26 +113,19 @@ public class DocumentDidChangeJob extends Job {
statisticsJob.schedule();
}
jobStatusList.add(new JobStatus(JobsToDo.parseCode, true));
//return Status.CANCEL_STATUS;
}
}
if (jobs.contains(JobsToDo.buildTable)) {
boolean hasParserErrors = false;
lalrResult = null;
try {
if (parser != null && !parser.hasParseErrors()) {
lalrResult = LALRResult.Compute(context,
context.start_production);
} else {
/*
* System.out.println("LALRResult.Compute was not called, "
* + "because the parser has reported errors."); TODO:
* REMOVE
*/
// TODO: we need to notify listeners THAT/WHY the call failed.
}
if (parser != null && !parser.hasParseErrors())
lalrResult = LALRResult.Compute(context, context.start_production);
else
hasParserErrors = true;
} catch (internal_error e) {
e.printStackTrace();
}
......@@ -169,7 +139,6 @@ public class DocumentDidChangeJob extends Job {
try {
resultLaLrModelJob.join();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else {
......@@ -182,7 +151,13 @@ public class DocumentDidChangeJob extends Job {
statisticsJob.setSystem(true);
statisticsJob.schedule();
}
jobStatusList.add(new JobStatus(JobsToDo.buildTable, true));
String message = null;
if (hasParserErrors)
message = "The parse tables were not created, because the " +
"grammar could not be parsed correctly.";
jobStatusList.add(new JobStatus(JobsToDo.buildTable, true, message));
}
}
......@@ -195,10 +170,7 @@ public class DocumentDidChangeJob extends Job {
CallbackJob cb = new CallbackJob(editor, jobStatusList);
cb.setSystem(true);
cb.schedule();
return Status.OK_STATUS;
}
}
......@@ -5,17 +5,27 @@ import de.tum.in.www2.cupplugin.controller.Controller.JobsToDo;
public class JobStatus {
private boolean failed;
private String message;
private JobsToDo affectedJob;
public JobStatus(JobsToDo affectedJob, boolean failed) {
this(affectedJob, failed, null);
}
public JobStatus(JobsToDo affectedJob, boolean failed, String message) {
this.affectedJob = affectedJob;
this.failed = failed;
this.message = message;
}
public boolean hasFailed() {
return failed;
}
public String getMessage() {
return message;
}
public JobStatus(boolean failed) {
this.failed = failed;
}
......
......@@ -17,7 +17,7 @@ class StatisticsIfFailedJob extends UIJob {
private long revisionNumber;
public StatisticsIfFailedJob(CupTextEditor editor, CupContext context, long revisionNumber) {
super("Parser Result UI Job");
super("StatisticsIfFailed UI Job");
this.editor = editor;
this.context = context;
this.revisionNumber = revisionNumber;
......
......@@ -454,8 +454,12 @@ public class CupConflictsView extends FailableView implements ICupEditorPageVisi
@Override
public void jobStatusChanged(JobStatus status) {
if (status.getAffectedJob() == JobsToDo.buildTable && status.hasFailed())
showParseTablesError();
if (status.getAffectedJob() == JobsToDo.buildTable && status.hasFailed()) {
if (status.getMessage() != null)
showError(status.getMessage());
else
showParseTablesError();
}
}
}
......@@ -6,10 +6,8 @@ import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
......@@ -76,7 +74,7 @@ public abstract class FailableView {
fillLayout.marginHeight = ERROR_MARGIN;
error.setLayout(fillLayout);
message = new Label (error, SWT.CENTER);
message = new Label (error, SWT.CENTER|SWT.WRAP);
FontData[] fD = message.getFont().getFontData();
fD[0].setHeight(ERROR_FONTSIZE);
message.setFont(new Font(Display.getCurrent(),fD[0]));
......
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