### Eclipse Workspace Patch 1.0 #P org.eclipse.epsilon.evl.emf.validation Index: src/org/eclipse/epsilon/evl/emf/validation/EvlValidator.java =================================================================== --- src/org/eclipse/epsilon/evl/emf/validation/EvlValidator.java (revision 2391) +++ src/org/eclipse/epsilon/evl/emf/validation/EvlValidator.java (working copy) @@ -14,6 +14,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; +import java.util.List; import java.util.Map; import java.util.Set; @@ -30,6 +31,7 @@ import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.emf.ecore.util.Diagnostician; import org.eclipse.epsilon.common.dt.util.LogUtil; +import org.eclipse.epsilon.common.parse.problem.ParseProblem; import org.eclipse.epsilon.emc.emf.EmfPrettyPrinter; import org.eclipse.epsilon.emc.emf.InMemoryEmfModel; import org.eclipse.epsilon.eol.dt.launching.EclipseContextManager; @@ -54,6 +56,8 @@ protected String modelName; protected String ePackageUri; protected String bundleId; + protected boolean showErrorDialog = true; + protected List problemListeners = new ArrayList(); public static final String DEFAULT_MODEL_NAME = "_Model"; @@ -179,15 +183,22 @@ try { module.parse(source); } catch (Exception e) { - LogUtil.log("An error was encountered while parsing " + source + " : " + e.getMessage(), e, true); + LogUtil.log("An error was encountered while parsing " + source + " : " + e.getMessage(), e, isShowErrorDialog()); + for (ValidationProblemListener listener : problemListeners) { + listener.onParseException(module, e); + } + return; } if (module.getParseProblems().size() > 0) { - LogUtil.log(source + " has one or more syntax errors : " + module.getParseProblems().get(0).toString(), null, true); + LogUtil.log(source + " has one or more syntax errors : " + module.getParseProblems().get(0).toString(), null, isShowErrorDialog()); + for (ValidationProblemListener listener : problemListeners) { + listener.onParseProblems(module, module.getParseProblems()); + } + return; } InMemoryEmfModel model = new InMemoryEmfModel(modelName, resource, ePackageUri); - //model.setName(modelName); module.getContext().getModelRepository().addModel(model); Object monitor = null; @@ -213,26 +224,29 @@ try { module.execute(); - } catch (EolRuntimeException e) { - LogUtil.log("A runtime error was raised during the evaluation of " + source + " : " + e.getMessage(), e, true); - } + module.setUnsatisfiedConstraintFixer(new IEvlFixer() { + public void fix(IEvlModule module) throws EolRuntimeException { + // Do nothing + } + }); - module.setUnsatisfiedConstraintFixer(new IEvlFixer() { - public void fix(IEvlModule module) throws EolRuntimeException { - // Do nothing + for (EvlUnsatisfiedConstraint unsatisfied : module.getContext().getUnsatisfiedConstraints()) { + Object key = unsatisfied.getInstance(); + if (!results.containsKey(key)) { + results.put(key, new ArrayList()); + } + results.get(key).add(unsatisfied); } - }); - - for (EvlUnsatisfiedConstraint unsatisfied : module.getContext().getUnsatisfiedConstraints()) { - Object key = unsatisfied.getInstance(); - if (!results.containsKey(key)) { - results.put(key, new ArrayList()); + } catch (EolRuntimeException e) { + LogUtil.log("A runtime error was raised during the evaluation of " + source + " : " + e.getMessage(), e, isShowErrorDialog()); + for (ValidationProblemListener listener : problemListeners) { + listener.onRuntimeException(module, e); } - results.get(key).add(unsatisfied); } - - module.getContext().dispose(); - module.getContext().getModelRepository().dispose(); + finally { + module.getContext().dispose(); + module.getContext().getModelRepository().dispose(); + } } protected void addMarkers(String msgPrefix, EObject eObject, DiagnosticChain diagnostics) { @@ -251,5 +265,31 @@ } } } - + + public boolean isShowErrorDialog() { + return showErrorDialog; + } + + public void setShowErrorDialog(boolean showErrorDialog) { + this.showErrorDialog = showErrorDialog; + } + + public void addValidationProblemListener(ValidationProblemListener listener) { + problemListeners.add(listener); + } + + public boolean removeValidationProblemListener(ValidationProblemListener listener) { + return problemListeners.remove(listener); + } + + public interface ValidationProblemListener { + + public void onParseProblems(EvlModule module, List parseProblems); + + public void onRuntimeException(EvlModule module, EolRuntimeException ex); + + public void onParseException(EvlModule module, Exception ex); + + } + }