Commit e34eac58 authored by Marco Konersmann's avatar Marco Konersmann

Refines error handling

parent e816c852
......@@ -6,7 +6,6 @@ import java.util.List;
import org.codeling.languageregistry.ImplementationLanguageDefinition;
import org.codeling.transformationmanager.internal.AbstractTask;
import org.codeling.utils.CodelingConfiguration;
import org.codeling.utils.CodelingException;
import org.codeling.utils.IDRegistry;
import org.codeling.utils.Models;
import org.eclipse.core.runtime.IProgressMonitor;
......@@ -74,7 +73,7 @@ public class ImplementationModelToProgramCodeTask extends AbstractTask {
// New code elements should be propagated to the ID registry.
idregistry_newModel.saveToFile(ID_FILEPATH);
} catch (final CodelingException e) {
} catch (final Throwable e) {
e.printStackTrace();
progressMonitor.done();
return Status.CANCEL_STATUS;
......
......@@ -53,10 +53,14 @@ public class ModelToJavaTransformation extends ModelIntegrationConceptTransforma
// Propagate new code elements to the IDRegistry
rootTransformation.getWhereToFindTranslatedElements().getAllTransformations().forEach(t -> {
// Some transformations do not have a code element (NinjaSingleton and related)
if (t.getCodeElement() != null && t.getModelElement() != null) {
String id = idRegistry.getIDFromImplementationModelElement(t.getModelElement());
idRegistry.updateCodeElement(id, t.getCodeElement().getHandleIdentifier());
try {
// Some transformations do not have a code element (NinjaSingleton and related)
if (t.getCodeElement() != null && t.getModelElement() != null) {
String id = idRegistry.getIDFromImplementationModelElement(t.getModelElement());
idRegistry.updateCodeElement(id, t.getCodeElement().getHandleIdentifier());
}
} catch (Throwable throwble) {
addError("Error while propagating new code elements to the ID registry.", throwble);
}
});
}
......
......@@ -118,15 +118,19 @@ public abstract class AbstractModelCodeTransformation<ELEMENTECLASS extends EObj
*/
@Override
protected void compute() {
LinkedList<String> validationMessages = new LinkedList<>();
if (toCode) {
if (validateToCode(validationMessages))
computeTransformationToCode();
} else {
if (validateToModel(validationMessages))
computeTransformationToModel();
else
validationMessages.forEach(m -> addWarning(m));
try {
LinkedList<String> validationMessages = new LinkedList<>();
if (toCode) {
if (validateToCode(validationMessages))
computeTransformationToCode();
} else {
if (validateToModel(validationMessages))
computeTransformationToModel();
else
validationMessages.forEach(m -> addWarning(m));
}
} catch (Throwable t) {
addError("Error while executing model-code transformation " + this.getClass().getSimpleName(), t);
}
}
......@@ -153,21 +157,28 @@ public abstract class AbstractModelCodeTransformation<ELEMENTECLASS extends EObj
final String message = String.format(
"Could not execute model-to-code transformation '%s' for element '%s'.",
this.getClass().getName(), modelElement);
issues.addError(message, e);
addError(message, e);
} finally {
// Execute child transformations.
// ReferenceMechanismTransformation already do this themselves, because they use
// the results of the child transformations. Therefore we only execute
// childTransformations that do not already exist.
if (childTransformations == null || childTransformations.isEmpty()) {
childTransformations = createChildTransformationsToCode();
childTransformations.forEach(c -> c.setOnlyCrossReferences(onlyCrossReferences));
invokeAll(childTransformations);
try {
// Execute child transformations.
// ReferenceMechanismTransformation already do this themselves, because they use
// the results of the child transformations. Therefore we only execute
// childTransformations that do not already exist.
if (childTransformations == null || childTransformations.isEmpty()) {
childTransformations = createChildTransformationsToCode();
childTransformations.forEach(c -> c.setOnlyCrossReferences(onlyCrossReferences));
invokeAll(childTransformations);
}
} catch (final Throwable e) {
final String message = String.format(
"Could not create model-to-code cross reference transformations of '%s' for the elemnet '%s'.",
this.getClass().getName(), modelElement);
issues.addError(message, e);
} finally {
// Registers all class, reference, and attribute transformations for an Eclass.
EClass eClass = modelElement == null ? priorModelElement.eClass() : modelElement.eClass();
findTranslatedElements.addTransformation(eClass, this);
}
// Registers all class, reference, and attribute transformations for an Eclass.
EClass eClass = modelElement == null ? priorModelElement.eClass() : modelElement.eClass();
findTranslatedElements.addTransformation(eClass, this);
}
} else {
try {
......@@ -178,7 +189,7 @@ public abstract class AbstractModelCodeTransformation<ELEMENTECLASS extends EObj
final String message = String.format(
"Could not execute cross reference model-to-code transformation '%s' for element '%s'.",
this.getClass().getName(), modelElement);
issues.addError(message, e);
addError(message, e);
}
}
......@@ -203,7 +214,7 @@ public abstract class AbstractModelCodeTransformation<ELEMENTECLASS extends EObj
final String message = String.format(
"Errors during the execution of the code-to-model transformation '%s' for code element '%s'.",
this.getClass().getName(), elementName);
issues.addWarning(message, e);
addError(message, e);
} finally {
// Execute child transformations.
// Some Transformations, such as the ReferenceMechanismTransformations, already
......@@ -214,7 +225,7 @@ public abstract class AbstractModelCodeTransformation<ELEMENTECLASS extends EObj
childTransformations = createChildTransformationsToModel();
invokeAll(childTransformations);
}
// Registers all class, reference, and attribute transformations for an Eclass.
findTranslatedElements.addTransformation(modelElement.eClass(), this);
}
......@@ -230,7 +241,7 @@ public abstract class AbstractModelCodeTransformation<ELEMENTECLASS extends EObj
final String message = String.format(
"Errors during the execution of the cross-reference code-to-model transformation '%s' for code element '%s'.",
this.getClass().getName(), elementName);
issues.addWarning(message, e);
addError(message, e);
}
}
......@@ -246,7 +257,8 @@ public abstract class AbstractModelCodeTransformation<ELEMENTECLASS extends EObj
@Override
public JAVAELEMENTCLASS resolveCodeElement() throws CodelingException {
if (priorIDRegistry != null && priorModelElement != null)
codeElement = (JAVAELEMENTCLASS) priorIDRegistry.getCodeElementFromImplementationModelElement(priorModelElement);
codeElement = (JAVAELEMENTCLASS) priorIDRegistry
.getCodeElementFromImplementationModelElement(priorModelElement);
else
codeElement = (JAVAELEMENTCLASS) idRegistry.getCodeElementFromImplementationModelElement(modelElement);
return codeElement;
......
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