Commit 68aa8b62 authored by Marco Konersmann's avatar Marco Konersmann

Refactoring for better describability

parent 870432fb
......@@ -39,15 +39,6 @@ public class ModelToJavaTransformation extends ModelIntegrationConceptTransforma
// references
ForkJoinPool.commonPool().invoke(rootTransformation);
// 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.getIDFromComponentModelElement(t.getModelElement());
idRegistry.updateCodeElement(id, t.getCodeElement().getHandleIdentifier());
}
});
// Translate non-containment references
if (crossReferenceOrder == null)
crossReferenceOrder = new LinkedList<>();
......@@ -59,6 +50,15 @@ public class ModelToJavaTransformation extends ModelIntegrationConceptTransforma
ForkJoinPool.commonPool().invoke(t);
});
}
// 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.getIDFromComponentModelElement(t.getModelElement());
idRegistry.updateCodeElement(id, t.getCodeElement().getHandleIdentifier());
}
});
}
}
......@@ -138,43 +138,50 @@ public abstract class AbstractModelCodeTransformation<ELEMENTECLASS extends EObj
modelElement != null && modelElement.eClass().getEAttributes().stream()
.filter(a -> a.getName().equals("name")).count() > 0 ? getNameAttributeValue(modelElement)
: "(none)"));
try {
if (!onlyCrossReferences) {
if (modelElement == null) {
if (!onlyCrossReferences) {
try {
if (modelElement == null) { // The model element has been deleted
resolveCodeElement();
deleteCodeFragments();
} else if (priorModelElement == null) {
} else if (priorModelElement == null) { // The model element is new
createCodeFragments();
} else {
} else { // The model element might have changed
resolveCodeElement();
updateCodeFragments();
}
// Registers all class, reference, and attribute transformations for an eclass.
// Registers all class, reference, and attribute transformations for an Eclass.
EClass eClass = modelElement == null ? priorModelElement.eClass() : modelElement.eClass();
findTranslatedElements.addTransformation(eClass, this);
} else {
final List<AbstractModelCodeTransformation<? extends EObject, ? extends IJavaElement>> crossReferenceTransformations = createCrossReferencesTransformations();
} catch (final Throwable e) {
final String message = String.format(
"Could not execute model-to-code transformation '%s' for element '%s'.",
this.getClass().getName(), modelElement);
issues.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);
}
}
} else {
try {
final List<AbstractModelCodeTransformation<?, ?>> crossReferenceTransformations = createCrossReferencesTransformations();
crossReferenceTransformations.forEach(t -> t.setToCode());
invokeAll(crossReferenceTransformations);
}
} catch (final Throwable e) {
final String message = String.format(
"Could not execute model-to-code transformation '%s' for element '%s'.", this.getClass().getName(),
modelElement);
issues.addError(message, e);
} finally {
// Execute child transformations.
// Some Transformations, such as the ReferenceMechanismTransformations, 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 execute cross reference model-to-code transformation '%s' for element '%s'.",
this.getClass().getName(), modelElement);
issues.addError(message, e);
}
}
}
private void computeTransformationToModel() {
......@@ -182,40 +189,50 @@ public abstract class AbstractModelCodeTransformation<ELEMENTECLASS extends EObj
String.format("Executing %s in direction Code-to-Model for the Java element %s",
this.getClass().getSimpleName(),
codeElement != null ? codeElement.getHandleIdentifier() : "(none)"));
try {
if (onlyCrossReferences) {
// Instantiate all cross reference transformations and invoke them.
// These transformation instances will not have the flag "onlyCrossReferences"
// set, because they shall actually be executed.
final List<AbstractModelCodeTransformation<? extends EObject, ? extends IJavaElement>> crossReferenceTransformations = createCrossReferencesTransformations();
invokeAll(crossReferenceTransformations);
} else {
if (!onlyCrossReferences) {
try {
// Actually execute the transformation
transformToModel();
if (modelElement == null)
throw new CodelingException("The transformation " + this.getClass().getName()
+ " resulted in 'null' as model element.");
// Registers all class, reference, and attribute transformations for an eclass.
// Registers all class, reference, and attribute transformations for an Eclass.
findTranslatedElements.addTransformation(modelElement.eClass(), this);
} catch (final Throwable e) {
final String elementName = codeElement == null ? "[codeElement is null]"
: codeElement.getHandleIdentifier();
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);
} finally {
// Execute child transformations.
// Some Transformations, such as the ReferenceMechanismTransformations, 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 = createChildTransformationsToModel();
invokeAll(childTransformations);
}
}
} catch (final Throwable e) {
final String elementName = codeElement == null ? "[codeElement is null]"
: codeElement.getHandleIdentifier();
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);
} finally {
// Execute child transformations.
// Some Transformations, such as the ReferenceMechanismTransformations, 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 = createChildTransformationsToModel();
invokeAll(childTransformations);
} else {
try {
// Instantiate all cross reference transformations and invoke them.
// These transformation instances will not have the flag "onlyCrossReferences"
// set, because they shall actually be executed.
invokeAll(createCrossReferencesTransformations());
} catch (final Throwable e) {
final String elementName = codeElement == null ? "[codeElement is null]"
: codeElement.getHandleIdentifier();
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);
}
}
}
/*
......
......@@ -149,6 +149,7 @@ abstract class AnnotatedMemberReferenceTransformation<OWNERECLASS extends EObjec
}
override IType resolveCodeElement() {
super.resolveCodeElement();
if (fields.isEmpty)
for (IField field : (codeElement as IType).fields)
if (hasExpectedAnnotation(field))
......
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