Commit 72e40b78 authored by Johannes Roith's avatar Johannes Roith

Update statistics, even if the other jobs failed.

parent 8e09c716
......@@ -123,8 +123,8 @@ public class DocumentDidChangeJob extends Job {
if (result != null) {
jobStatusList.add(new JobStatus(JobsToDo.parseCode, false));
ParserResultJob resultModelJob = new ParserResultJob(result,
context, revNumber);
ParserResultJob resultModelJob = new ParserResultJob(editor,
result, context, revNumber);
resultModelJob.setSystem(true);
resultModelJob.schedule();
try {
......@@ -133,8 +133,12 @@ public class DocumentDidChangeJob extends Job {
e.printStackTrace();
}
} else {
StatisticsIfFailedJob statisticsJob = new StatisticsIfFailedJob(
editor, context, revNumber);
statisticsJob.setSystem(true);
statisticsJob.schedule();
// TODO: we need to notify listeners THAT/WHY the call failed.
jobStatusList.add(new JobStatus(JobsToDo.parseCode, true));
//return Status.CANCEL_STATUS;
}
......@@ -162,8 +166,8 @@ public class DocumentDidChangeJob extends Job {
if (lalrResult != null) {
jobStatusList.add(new JobStatus(JobsToDo.buildTable, false));
LaLrResultJob resultLaLrModelJob = new LaLrResultJob(editor,
lalrResult, revNumber, context);
LaLrResultJob resultLaLrModelJob = new LaLrResultJob(
editor, lalrResult, revNumber, context);
resultLaLrModelJob.setSystem(true);
resultLaLrModelJob.schedule();
try {
......@@ -173,9 +177,16 @@ public class DocumentDidChangeJob extends Job {
e.printStackTrace();
}
} else {
// TODO: we need to notify listeners THAT/WHY the call failed.
// TODO: we run the statistics job twice, here, even if we failed
// to build the parser. This should only run once.
StatisticsIfFailedJob statisticsJob = new StatisticsIfFailedJob(
editor, context, revNumber);
statisticsJob.setSystem(true);
statisticsJob.schedule();
jobStatusList.add(new JobStatus(JobsToDo.buildTable, true));
//return Status.CANCEL_STATUS;
}
}
......@@ -214,35 +225,6 @@ public class DocumentDidChangeJob extends Job {
}
}
class ParserResultJob extends UIJob {
private ParserResult parserResult;
private CupContext context;
@SuppressWarnings("unused")
private long parserModelRevisionNumber;
public ParserResultJob(ParserResult result, CupContext context,
long revisionNumber) {
super("Parser Result UI Job");
this.context = context;
this.parserResult = result;
this.parserModelRevisionNumber = revisionNumber;
}
@Override
public IStatus runInUIThread(IProgressMonitor monitor) {
IDocument document = editor.getDocument();
if (document != null) {
Model model = Model.getInstanceForDocument(document);
model.setASTModel(this.parserResult, context, revNumber);
model.setStatistics(context.getStatistics(), revNumber);
return Status.OK_STATUS;
}
return Status.CANCEL_STATUS;
}
}
class SetupJob extends UIJob {
private DocumentDidChangeJob documentDidChangeJob;
......
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.in.tum.www2.cup.CupContext;
import de.in.tum.www2.cup.ast.ParserResult;
import de.tum.in.www2.cupplugin.editors.CupTextEditor;
import de.tum.in.www2.cupplugin.model.Model;
class ParserResultJob extends UIJob {
private CupTextEditor editor;
private ParserResult parserResult;
private CupContext context;
private long parserModelRevisionNumber;
public ParserResultJob(CupTextEditor editor, ParserResult result, CupContext context,
long revisionNumber) {
super("Parser Result UI Job");
this.editor = editor;
this.context = context;
this.parserResult = result;
this.parserModelRevisionNumber = revisionNumber;
}
@Override
public IStatus runInUIThread(IProgressMonitor monitor) {
IDocument document = editor.getDocument();
if (document != null) {
Model model = Model.getInstanceForDocument(document);
model.setASTModel(this.parserResult, context, parserModelRevisionNumber);
model.setStatistics(context.getStatistics(), parserModelRevisionNumber);
return Status.OK_STATUS;
}
return Status.CANCEL_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.in.tum.www2.cup.CupContext;
import de.tum.in.www2.cupplugin.editors.CupTextEditor;
import de.tum.in.www2.cupplugin.model.Model;
class StatisticsIfFailedJob extends UIJob {
private CupTextEditor editor;
private CupContext context;
private long revisionNumber;
public StatisticsIfFailedJob(CupTextEditor editor, CupContext context, long revisionNumber) {
super("Parser Result UI Job");
this.editor = editor;
this.context = context;
this.revisionNumber = revisionNumber;
}
@Override
public IStatus runInUIThread(IProgressMonitor monitor) {
IDocument document = editor.getDocument();
if (document != null) {
Model model = Model.getInstanceForDocument(document);
model.setStatistics(context.getStatistics(), revisionNumber);
return Status.OK_STATUS;
}
return Status.CANCEL_STATUS;
}
}
\ No newline at end of file
......@@ -102,6 +102,11 @@ public class Model {
public void setStatistics(Statistics statistics, long revisionNumber) {
synchronized(statisticsLock) {
this.statistics = statistics;
for(Object observer : modelObservers) {
if(observer instanceof ICupStatisticsChangeObserver) {
((ICupStatisticsChangeObserver) observer).modelChanged(this);
}
}
}
}
......@@ -112,7 +117,7 @@ public class Model {
this.astModelRevisionNumber = revisionNumber;
for(Object observer : modelObservers) {
if(observer instanceof ICupParserASTChangeObserver) {
((ICupParserASTChangeObserver)observer).modelChanged(this);
((ICupParserASTChangeObserver) observer).modelChanged(this);
}
}
}
......@@ -147,7 +152,7 @@ public class Model {
this.lalrContext = lalrContext;
for(Object observer : modelObservers) {
if (observer instanceof ICupParserLaLrChangeObserver) {
((ICupParserLaLrChangeObserver)observer).modelChanged(this);
((ICupParserLaLrChangeObserver) observer).modelChanged(this);
}
}
//System.out.println(lalrModel.getReduceTable().toString());
......
......@@ -215,7 +215,6 @@ public class CupOverviewView extends FailableView
@Override
public void jobStatusChanged(JobStatus status) {
// TODO Auto-generated method stub
}
private void updateStatistics(Statistics statistics) {
......@@ -223,7 +222,7 @@ public class CupOverviewView extends FailableView
return;
analysisSection.getSecond().setRowValue(ERROR_ROW, statistics.getErrorCount());
}
@Override
public void modelChanged(Model model) {
if (model == null)
......
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