Commit 6e4846a2 authored by Marco Konersmann's avatar Marco Konersmann

TranslationModelToProgramCodeTask can now handle added, changed, and deleted elements

parent 03682a5b
......@@ -22,10 +22,12 @@ public abstract class ImplementationLanguageDefinition extends LanguageDefinitio
public abstract TransformationResult transformTMToIM(List<EObject> ilRoots, IDRegistry idRegistry)
throws CodelingException;
public abstract void transformIMToCode(List<EObject> newModelRoots, List<EObject> oldModelRoots, IDRegistry idRegistry_newModel,
IDRegistry idregistry_oldModel, List<IJavaProject> projects) throws CodelingException;
public abstract void transformIMToCode(List<EObject> newModelRoots, List<EObject> oldModelRoots,
IDRegistry idRegistry_newModel, IDRegistry idregistry_oldModel, List<IJavaProject> projects)
throws CodelingException;
public abstract void transformTMToCode(List<EObject> ilRoots, List<EObject> cmRoots, IDRegistry idRegistry,
public abstract void transformTMToCode(List<EObject> newIMRoots, List<EObject> oldIMRoots, List<EObject> newTMRoots,
List<EObject> oldTMRoots, IDRegistry idRegistry_newModel, IDRegistry idregistry_oldModel,
List<IJavaProject> projects) throws CodelingException;
}
......@@ -24,8 +24,8 @@ public class TranslationModelToProgramCodeTask extends AbstractTask {
final ImplementationLanguageDefinition implementationLanguage;
final List<EObject> ilModelRoots;
public TranslationModelToProgramCodeTask(ImplementationLanguageDefinition implementationLanguage, List<IJavaProject> projects,
List<EObject> ilModelRoots) {
public TranslationModelToProgramCodeTask(ImplementationLanguageDefinition implementationLanguage,
List<IJavaProject> projects, List<EObject> ilModelRoots) {
super(TASK_NAME);
this.projects = projects;
this.implementationLanguage = implementationLanguage;
......@@ -36,42 +36,44 @@ public class TranslationModelToProgramCodeTask extends AbstractTask {
protected IStatus run(IProgressMonitor progress) {
if (progress == null)
progress = new NullProgressMonitor();
final int scale = 100;
progress.beginTask("Executing " + TASK_NAME, 100);
progress.beginTask("Executing " + TASK_NAME, 20);
progress.subTask(String.format("Loading prior registry: %s", TranslationModelToImplementationModelTask.ID_FILEPATH));
IDRegistry tmpIdRegistry = IDRegistry.load(ImplementationModelToProgramCodeTask.ID_FILEPATH);
if (tmpIdRegistry == null) {
progress.subTask(
String.format("No prior id registry available. Loading IDRegistry: %s", ProgramCodeToTranslationModelTask.ID_FILEPATH));
tmpIdRegistry = IDRegistry.load(ProgramCodeToTranslationModelTask.ID_FILEPATH);
}
final IDRegistry idRegistry = tmpIdRegistry;
progress.worked(1 * scale);
progress.subTask(String.format("Loading prior registry: %s", ProgramCodeToTranslationModelTask.ID_FILEPATH));
IDRegistry priorIdRegistry = IDRegistry.load(ProgramCodeToTranslationModelTask.ID_FILEPATH);
progress.worked(1);
progress.subTask(String.format("Loading Component Model: %s", TranslationModelToImplementationModelTask.MODEL_FILEPATH));
List<EObject> tmpComponentModelRoots = Models.loadFrom(TranslationModelToImplementationModelTask.MODEL_FILEPATH);
if (tmpComponentModelRoots == null) {
progress.subTask(
String.format("No model available. Loading prior Component Model: %s", ProgramCodeToImplementationModelTask.MODEL_FILEPATH));
tmpComponentModelRoots = Models.loadFrom(ProgramCodeToImplementationModelTask.MODEL_FILEPATH);
}
final List<EObject> componentModelRoots = tmpComponentModelRoots;
progress.worked(1 * scale);
progress.subTask(String.format("Loading IDRegistry: %s", ImplementationModelToProgramCodeTask.ID_FILEPATH));
final IDRegistry idRegistry = IDRegistry.load(ImplementationModelToProgramCodeTask.ID_FILEPATH);
progress.worked(1);
progress.subTask(String.format("Loading prior Component Model: %s",
ProgramCodeToImplementationModelTask.MODEL_FILEPATH));
List<EObject> priorComponentModelRoots = Models.loadFrom(ProgramCodeToImplementationModelTask.MODEL_FILEPATH);
progress.worked(1);
progress.subTask(String.format("Loading Intermediate Language Model: %s",
progress.subTask(
String.format("Loading Component Model: %s", TranslationModelToImplementationModelTask.MODEL_FILEPATH));
final List<EObject> componentModelRoots = Models
.loadFrom(TranslationModelToImplementationModelTask.MODEL_FILEPATH);
progress.worked(1);
progress.subTask(String.format("Loading prior Intermediate Language Model: %s",
InterProfileTransformationToSpecificationModelTask.MODEL_FILEPATH));
List<EObject> priorIlModelRoots = Models
.loadFrom(InterProfileTransformationToSpecificationModelTask.MODEL_FILEPATH);
progress.worked(1);
progress.subTask(String.format("Loading Intermediate Language Model Model: %s",
InterProfileTransformationToImplementationModelTask.MODEL_FILEPATH));
List<EObject> tmpIlModelRoots = Models.loadFrom(InterProfileTransformationToImplementationModelTask.MODEL_FILEPATH);
if (tmpIlModelRoots == null) {
progress.subTask(
String.format("No model available. Loading prior Intermediate Language Model Model: %s", ProgramCodeToTranslationModelTask.MODEL_FILEPATH));
tmpIlModelRoots = Models.loadFrom(ProgramCodeToTranslationModelTask.MODEL_FILEPATH);
}
final List<EObject> ilModelRoots = tmpIlModelRoots;
progress.worked(1 * scale);
final List<EObject> ilModelRoots = Models
.loadFrom(InterProfileTransformationToImplementationModelTask.MODEL_FILEPATH);
progress.worked(1);
try {
implementationLanguage.transformTMToCode(ilModelRoots, componentModelRoots, idRegistry, projects);
progress.subTask(String.format("Translating Transformation Model to Program Code",
ProgramCodeToTranslationModelTask.MODEL_FILEPATH));
implementationLanguage.transformTMToCode(componentModelRoots, priorComponentModelRoots, ilModelRoots,
priorIlModelRoots, idRegistry, priorIdRegistry, projects);
} catch (final CodelingException e) {
addError("Could not transform IL model and AIL model to code", e);
progress.done();
......
......@@ -26,11 +26,11 @@ import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IJavaProject;
import org.modelversioning.emfprofileapplication.EMFProfileApplicationPackage;
import org.modelversioning.emfprofileapplication.StereotypeApplication;
import de.mkonersmann.advert.java.embed.transformation.AbstractModelCodeTransformation;
import de.mkonersmann.advert.java.embed.transformation.FindTranslatedElements;
import de.mkonersmann.advert.java.embed.transformation.references.IALTransformation;
import de.mkonersmann.advert.java.embed.transformation.references.IALHolder;
public abstract class JavaBasedImplementationLanguageDefinition extends ImplementationLanguageDefinition {
......@@ -94,39 +94,59 @@ public abstract class JavaBasedImplementationLanguageDefinition extends Implemen
}
@Override
public void transformTMToCode(List<EObject> tmRoots, List<EObject> imRoots, IDRegistry idRegistry,
public void transformTMToCode(List<EObject> newIMRoots, List<EObject> oldIMRoots, List<EObject> newTMRoots,
List<EObject> oldTMRoots, IDRegistry idRegistry_newModel, IDRegistry idRegistry_oldModel,
List<IJavaProject> projects) throws CodelingException {
idRegistry.getRegistryEntries().keySet().stream().forEach(id -> {
final EObject cmElement = idRegistry.resolveImplementationModelElement(id, imRoots);
if (cmElement == null)
return;
final EObject foundationalIALElement = idRegistry.resolveTranslationModelElement(id, tmRoots);
if (foundationalIALElement == null)
return;
final IJavaElement codeElement = resolveCodeElement(idRegistry, cmElement);
if (codeElement == null)
// Update or create elements
idRegistry_newModel.getRegistryEntries().keySet().stream().forEach(id -> {
final EObject imElement = idRegistry_newModel.resolveImplementationModelElement(id, newIMRoots);
if (imElement == null)
return;
final List<? extends IALTransformation<?, ?>> ialTransformations = createIALTransformationInstance(
cmElement);
imElement);
if (ialTransformations == null || ialTransformations.isEmpty())
return;
final EObject foundationalIALElement = idRegistry_newModel.resolveTranslationModelElement(id, newTMRoots);
final EObject priorFoundationalIALElement = idRegistry_oldModel.resolveTranslationModelElement(id,
oldTMRoots);
final IJavaElement codeElement = idRegistry_newModel.getCodeElement(id);
if (ialTransformations != null) {
ialTransformations.stream().forEach(t -> {
t.setIDRegistry(idRegistry);
t.setModelElement(t.resolveTranslatedIALElement());
if (findTranslatedElements == null)
findTranslatedElements = new FindTranslatedElements();
t.setWhereToFindTranslatedElements(findTranslatedElements);
t.getIALHolder().setFoundationalIALElement(foundationalIALElement);
t.getIALHolder().setIALCodeElement(codeElement);
final ModelToJavaTransformation executor = new ModelToJavaTransformation(projects,
(AbstractModelCodeTransformation<?, ?>) t, new LinkedList<>());
executor.execute(monitor);
try {
t.setIDRegistry(idRegistry_newModel);
t.setPriorIDRegistry(idRegistry_oldModel);
t.getIALHolder().setFoundationalIALElement(foundationalIALElement);
t.getIALHolder().setPriorFoundationalIALElement(priorFoundationalIALElement);
t.getIALHolder().setIALCodeElement(codeElement);
if (findTranslatedElements == null)
findTranslatedElements = new FindTranslatedElements();
t.setWhereToFindTranslatedElements(findTranslatedElements);
foundationalIALElement.eResource();
StereotypeApplication modelElement = t.resolveTranslatedIALElement(foundationalIALElement);
StereotypeApplication priorModelElement = t
.resolveTranslatedIALElement(priorFoundationalIALElement);
if (modelElement == null && priorModelElement == null)
return; // No new, existing, or deleted element
t.setModelElement(modelElement);
t.setPriorModelElement(priorModelElement);
final ModelToJavaTransformation executor = new ModelToJavaTransformation(projects,
(AbstractModelCodeTransformation<?, ?>) t, new LinkedList<>());
executor.execute(monitor);
} catch (Exception e) {
addError(
"Error while setting up or executing Model-to-Java transformation from Translation Model to Program Code",
e);
}
});
}
});
// TODO: Delete elements
monitor.worked(10);
}
......@@ -239,13 +259,14 @@ public abstract class JavaBasedImplementationLanguageDefinition extends Implemen
referenceTrans = (IALTransformation<EObject, IJavaElement>) constructor
.newInstance(new Object[0]);
break;
} else if (constructor.getParameterCount() == 1
&& constructor.getParameterTypes()[0] == AbstractModelCodeTransformation.class) {
} else if (constructor.getParameterCount() == 1 && AbstractModelCodeTransformation.class
.isAssignableFrom(constructor.getParameterTypes()[0])) {
referenceTrans = (IALTransformation<EObject, IJavaElement>) constructor
.newInstance(new Object[] { null });
break;
} else if (constructor.getParameterCount() == 2
&& constructor.getParameterTypes()[0] == AbstractModelCodeTransformation.class
&& AbstractModelCodeTransformation.class
.isAssignableFrom(constructor.getParameterTypes()[0])
&& ENamedElement.class.isAssignableFrom(constructor.getParameterTypes()[1])) {
referenceTrans = (IALTransformation<EObject, IJavaElement>) constructor.newInstance(null,
tuple.getIlElement());
......
......@@ -15,10 +15,10 @@ public interface IALTransformation<ELEMENTECLASS extends EObject, JAVAELEMENTCLA
public IALHolder getIALHolder();
/**
* Returns the actual IAL element that is translated. E.g. a stereotype upon a
* Returns the IAL element that is translated. E.g. a stereotype upon a
* component type that owns a reference.
*/
public StereotypeApplication resolveTranslatedIALElement();
public StereotypeApplication resolveTranslatedIALElement(EObject foundationalElement);
/**
* Returns whether the code fragment for the IAL element exists.
......
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