use of abs.frontend.delta.DeltaModellingException in project abstools by abstools.
the class JavaJob method generateJavaCode.
/**
* Generates .java files (no .class files).
* If 'product' is set, will flatten accordingly.
* @param monitor - must not be null
* @param path - where to add the modules / java-files
* @param project - the ABS project
* @throws IOException, if unable to create java files
* @throws AbsJobException, if unable to generate java files
* @throws JavaCodeGenerationException, if unable to generate java files
* @throws CoreException
* @throws NoModelException
*/
private void generateJavaCode(IProgressMonitor monitor, Path path, IProject project) throws AbsJobException, IOException, JavaCodeGenerationException, CoreException, NoModelException {
assert monitor != null;
monitor.subTask("Creating java source files");
AbsNature nat = UtilityFunctions.getAbsNature(project);
synchronized (nat.modelLock) {
Model model = nat.getCompleteModel();
if (model == null)
throw new NoModelException();
JavaCode javaCode = new JavaCode(path.toFile());
if (product != null) {
/* [stolz] Flattening for a product will mangle the model according to [ramus]...
*/
// work on a copy:
model = model.treeCopyNoTransform();
model.flushTreeCache();
String productN = product.getName();
try {
model.flattenForProduct(productN);
model.flushCache();
if (model.hasErrors() || model.hasTypeErrors()) {
nat.createMarkers(model);
throw new AbsJobException("An ABS file in the project has type errors after applying deltas");
}
} catch (WrongProgramArgumentException e) {
throw new AbsJobException(e);
} catch (DeltaModellingException e) {
throw new AbsJobException(e);
}
}
// TODO: the second parameter toggles listener code creation (3
// Java method calls per ABS statement); make this configurable
model.generateJavaCode(javaCode, true);
int countUnits = model.getNumCompilationUnit();
if (countUnits == 0)
throw new AbsJobException("No compilation unit found");
}
}
use of abs.frontend.delta.DeltaModellingException in project abstools by abstools.
the class MaudeJob method runJob.
public IStatus runJob(IProgressMonitor monitor) {
abort = false;
boolean failed = false;
StringBuffer output = new StringBuffer();
AbsNature nature = getAbsNature(project);
if (nature == null) {
return new Status(IStatus.INFO, PLUGIN_ID, "Could not compile current selection. Project is not an ABS project.");
}
// Compile Maude Code
monitor.subTask("Compiling ABS model to Maude");
try {
if (!abort)
compileMaude(monitor, nature);
} catch (CoreException e1) {
return new Status(IStatus.ERROR, PLUGIN_ID, "Fatal error while compilig", e1);
} catch (IOException e2) {
return new Status(IStatus.ERROR, PLUGIN_ID, "Fatal error while compilig", e2);
} catch (ParseException e4) {
return new Status(IStatus.INFO, PLUGIN_ID, MAUDE_ERROR, "Could not compile current selection. Code has parse errors.", e4);
} catch (TypeCheckerException e5) {
return new Status(IStatus.INFO, PLUGIN_ID, MAUDE_ERROR, "Could not compile current selection. Code has type errors.", e5);
} catch (WrongProgramArgumentException e) {
return new Status(IStatus.ERROR, PLUGIN_ID, MAUDE_ERROR, "Could not compile current selection.", e);
} catch (DeltaModellingException e) {
return new Status(IStatus.ERROR, PLUGIN_ID, MAUDE_ERROR, "Could not compile current selection.", e);
} catch (NoModelException e) {
return new Status(IStatus.INFO, PLUGIN_ID, "No ABS model in project");
}
monitor.worked(5);
// Execute generated Maude code
monitor.subTask("Executing generated Maude code");
if (exec) {
try {
if (!abort)
failed = !executeMaude(output);
} catch (IOException e1) {
return new Status(IStatus.INFO, PLUGIN_ID, MAUDE_ERROR_MAUDE_PATH, "Encountered IOException while executing Maude (probably misconfigured location of maude executable)", e1);
} catch (InterruptedException e2) {
return new Status(IStatus.ERROR, PLUGIN_ID, "Fatal error while executing Maude", e2);
} finally {
if (!monitor.isCanceled()) {
monitor.worked(5);
monitor.done();
}
}
}
// If an error was encountered during Maude execution, the info code of the status is set to ERROR_MAUDE, otherwise MAUDE_INFO.
if (!abort) {
if (failed) {
return new Status(IStatus.OK, PLUGIN_ID, MAUDE_ERROR_MAUDE, output.toString(), null);
} else {
if (exec) {
return new Status(IStatus.OK, PLUGIN_ID, MAUDE_INFO, output.toString(), null);
} else {
return new Status(IStatus.OK, PLUGIN_ID, MAUDE_OK, output.toString(), null);
}
}
} else {
monitor.setCanceled(true);
return new Status(IStatus.INFO, PLUGIN_ID, MAUDE_USER_ABORT, null, null);
}
}
use of abs.frontend.delta.DeltaModellingException in project abstools by abstools.
the class IncrementalModelBuilder method typeCheckModel.
public synchronized SemanticConditionList typeCheckModel(IProgressMonitor monitor, boolean locationTypeChecking, String defaultloctype, String locationTypePrecision, boolean checkProducts) throws NoModelException, TypecheckInternalException {
if (model == null)
throw new NoModelException();
if (model.hasParserErrors())
// don't typecheck if the model has parsererrors
return new SemanticConditionList();
// throw new TypecheckInternalException(new Exception("Model has parser errors!"));
// model.flushCache();
flushAll(model);
model.getTypeExt().clearTypeSystemExtensions();
if (locationTypeChecking) {
LocationType defaultLocType = LocationType.createFromName(defaultloctype);
LocationTypeInferrerExtension ltie = new LocationTypeInferrerExtension(model);
this.ltie = ltie;
ltie.setDefaultType(defaultLocType);
ltie.setLocationTypingPrecision(LocationTypingPrecision.valueOf(locationTypePrecision));
model.registerTypeSystemExtension(ltie);
}
try {
SemanticConditionList semerrors = model.getErrors();
/* Don't typecheck with semerrors, it might trip up. */
if (!semerrors.containsErrors())
semerrors = model.typeCheck();
/* Check products for errors.
* Only the first error is reported (if any), on the product AST-node.
* TODO: May be time-consuming for large projects, hence the checkProducts-switch.
* Also could use a timer to switch off if it becomes excessive.
* TODO: Use Eclipse's nested markers to show ALL contained errors?
* TODO: The outline could indicate the broken product as well.
*/
if (!semerrors.containsErrors() && checkProducts) {
// arbitrary value
monitor = new SubProgressMonitor(monitor, 10);
monitor.beginTask("Checking products", model.getProductDecls().size());
for (ProductDecl p : model.getProductDecls()) {
monitor.subTask("Checking " + p.getName());
Model m2 = model.treeCopyNoTransform();
m2.flushTreeCache();
try {
m2.flattenForProduct(p);
SemanticConditionList p_errs = m2.typeCheck();
if (p_errs.containsErrors()) {
// Only show first error, on product
semerrors.add(new SemanticError(p, ErrorMessage.ERROR_IN_PRODUCT, p.getName(), p_errs.getFirstError().getMessage()));
}
} catch (WrongProgramArgumentException e) {
semerrors.add(new SemanticError(p, ErrorMessage.ERROR_IN_PRODUCT, p.getName(), e.getMessage()));
} catch (DeltaModellingException e) {
/* We we have a better location for error reporting? */
final ASTNode<?> loc;
if (e instanceof DeltaModellingWithNodeException)
loc = ((DeltaModellingWithNodeException) e).getNode();
else
loc = p;
if (e.getDelta() == null)
semerrors.add(new SemanticError(loc, ErrorMessage.ERROR_IN_PRODUCT, p.getName(), e.getMessage()));
else
semerrors.add(new SemanticError(loc, ErrorMessage.ERROR_IN_PRODUCT_WITH_DELTA, p.getName(), e.getDelta().getName(), e.getMessage()));
}
}
monitor.done();
}
return semerrors;
} catch (TypeCheckerException e) {
return new SemanticConditionList(e);
} catch (RuntimeException e) {
throw new TypecheckInternalException(e);
}
}
use of abs.frontend.delta.DeltaModellingException in project abstools by abstools.
the class AbstractTab method updateErrors.
/**
* Don't recommend to start projects which have errors.
* TODO: manipulating the error message here does not cooperate well with isValid().
*/
protected boolean updateErrors() {
boolean res = true;
String projectName = getSelectedProjectName();
String prod = getSelectedProductName();
if (this.lastProjectName != null && this.lastProd != null && this.lastProjectName.equals(projectName) && this.lastProd.equals(prod)) {
// every time something changes in the run configuration dialog
return lastResult;
}
if (projectName != null) {
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
try {
AbsNature nat = UtilityFunctions.getAbsNature(project);
assert nat != null;
synchronized (nat.modelLock) {
Model model = nat.getCompleteModel();
/* E.g. errors in the project */
if (model == null)
return false;
/* Check product if any */
// work on a copy:
model = model.treeCopyNoTransform();
model.flushTreeCache();
if (prod != null) {
model.flattenForProduct(prod);
/* Type check again */
// #335, see IncrementalModelBuilder#flushAll()
model.flushCache();
}
SemanticConditionList errs = model.getErrors();
// TODO: check for warnings also
if (errs != null && errs.containsErrors()) {
createMarkers(nat, errs);
throw new AbsJobException(new TypeCheckerException(errs));
}
errs = model.typeCheck();
// TODO: check for warnings also
if (errs != null && errs.containsErrors()) {
createMarkers(nat, errs);
throw new AbsJobException(new TypeCheckerException(errs));
}
}
setErrorMessage(null);
} catch (AbsJobException e) {
setErrorMessage(e.getMessage());
res = false;
} catch (WrongProgramArgumentException e) {
setErrorMessage(e.getMessage());
res = false;
} catch (DeltaModellingException e) {
setErrorMessage(e.getMessage());
res = false;
}
getLaunchConfigurationDialog().updateMessage();
}
// cache the result
lastProd = prod;
lastProjectName = projectName;
lastResult = res;
return res;
}
Aggregations