Commit c691cfcc authored by Marco Konersmann's avatar Marco Konersmann

Translates delegation fields in JEE

parent b80aa333
......@@ -86,6 +86,7 @@ public class ImplementationMigrationTask extends AbstractTask {
TranslationModelToProgramCodeTask ilAndAil2code = new TranslationModelToProgramCodeTask(targetLanguage,
projects, profileTransformation.getResultModelRoots());
ilAndAil2code.setImplementationMigration(true);
ilAndAil2code.setProgressGroup(monitor, 1);
ilAndAil2code.schedule();
ilAndAil2code.join();
......
......@@ -23,6 +23,7 @@ public class TranslationModelToProgramCodeTask extends AbstractTask {
final List<IJavaProject> projects;
final ImplementationLanguageDefinition implementationLanguage;
final List<EObject> ilModelRoots;
private boolean isImplementationMigration = false;
public TranslationModelToProgramCodeTask(ImplementationLanguageDefinition implementationLanguage,
List<IJavaProject> projects, List<EObject> ilModelRoots) {
......@@ -65,10 +66,12 @@ public class TranslationModelToProgramCodeTask extends AbstractTask {
progress.subTask(String.format("Loading Intermediate Language Model Model: %s",
InterProfileTransformationToImplementationModelTask.MODEL_FILEPATH));
final List<EObject> ilModelRoots = Models
.loadFrom(InterProfileTransformationToImplementationModelTask.MODEL_FILEPATH);
List<EObject> ilModelRoots = null;
String tmFilePath = InterProfileTransformationToSpecificationModelTask.MODEL_FILEPATH;
if (!isImplementationMigration)
tmFilePath = InterProfileTransformationToImplementationModelTask.MODEL_FILEPATH;
ilModelRoots = Models.loadFrom(tmFilePath);
progress.worked(1);
try {
progress.subTask(String.format("Translating Transformation Model to Program Code",
ProgramCodeToTranslationModelTask.MODEL_FILEPATH));
......@@ -85,4 +88,8 @@ public class TranslationModelToProgramCodeTask extends AbstractTask {
return Status.OK_STATUS;
}
public void setImplementationMigration(boolean isImplementationMigration) {
this.isImplementationMigration = isImplementationMigration;
}
};
......@@ -47,6 +47,10 @@ public class ModelExtractionHandler extends AbstractHandler {
@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
// If a resource change listener one already existed, delete it first.
if (resourceChangeListener != null)
ResourcesPlugin.getWorkspace().removeResourceChangeListener(resourceChangeListener);
LanguageDefinition[] selectedLanguages;
try {
selectedLanguages = requestLanguagesFromUser();
......@@ -78,11 +82,13 @@ public class ModelExtractionHandler extends AbstractHandler {
@Override
public void done(IJobChangeEvent event) {
final Resource modelResource = job.getResultModelRoots().get(0).eResource();
// Create resource change listener on created resource. If
// one already existed, delete it first.
if (resourceChangeListener != null)
ResourcesPlugin.getWorkspace().removeResourceChangeListener(resourceChangeListener);
try {
// Sleep for a while. Sometimes the code changes are not in the
// resource yet.
Thread.sleep(5000);
} catch (InterruptedException e) {
}
// Create resource change listener on created resource.
resourceChangeListener = new ResourceChangeListener(modelResource, sourceLanguage,
(SpecificationLanguageDefinition) targetLanguage, projects);
ResourcesPlugin.getWorkspace().addResourceChangeListener(resourceChangeListener,
......
......@@ -454,9 +454,9 @@ public class CoCoME_JEE_Migration_CaseStudy extends MayHaveIssues {
assertEquals("The type signature of the child component field " + name + " is not as expected", signature,
field.getTypeSignature());
assertTrue(
"The field " + name + " for the corresponding child component of +" + bean.getElementName()
"The field " + name + " for the corresponding child component of " + bean.getElementName()
+ " does not have the expected annotations.",
ASTUtils.hasAnnotation(field, "org.codeling.lang.jee.ial.mm.componentType.Child",
ASTUtils.hasAnnotation(field, "org.codeling.lang.ejbWithStatemachine.ial.mm.componenttype_feature.Child",
"javax.inject.Inject"));
}
......@@ -472,8 +472,8 @@ public class CoCoME_JEE_Migration_CaseStudy extends MayHaveIssues {
ASTUtils.hasAnnotation(field, "javax.inject.Inject"));
assertFalse(
"The field " + name + " for the corresponding required component of +" + bean.getElementName()
+ " must not have the annotation \"org.codeling.lang.jee.ial.mm.componentType.Child\".",
ASTUtils.hasAnnotation(field, "org.codeling.lang.jee.ial.mm.componentType.Child"));
+ " must not have the annotation \"org.codeling.lang.ejbWithStatemachine.ial.mm.componenttype_feature.Child\".",
ASTUtils.hasAnnotation(field, "org.codeling.lang.ejbWithStatemachine.ial.mm.componenttype_feature.Child"));
}
}
......@@ -180,11 +180,9 @@ public class ProfilesUtils {
private static StereotypeApplication applyStereotype(Stereotype stereotype, Profile profile, EObject eObject,
Resource profileApplicationResource) throws IOException {
Extension extension = getDefaultExtension(stereotype, eObject, profileApplicationResource);
final StereotypeApplication application = (StereotypeApplication) stereotype
.getEPackage().getEFactoryInstance().create(stereotype);
application.setExtension(extension);
application.setAppliedTo(eObject);
eObject.eResource().getContents().add(application);
StereotypeApplication application = createProfileFacadeInstance(profile, profileApplicationResource)
.apply(stereotype, eObject, extension);
application.setExtension(null);
application.eResource().save(null);
return application;
}
......
......@@ -108,6 +108,12 @@ public abstract class AbstractModelCodeTransformation<ELEMENTECLASS extends EObj
this.findTranslatedElements = parentTransformation.findTranslatedElements;
this.codeRoot = parentTransformation.codeRoot;
this.languageDefinition = parentTransformation.getLanguageDefinition();
if (this instanceof IALTransformation && parentTransformation instanceof IALTransformation) {
IALTransformation<?, ?> thisIAL = ((IALTransformation<?, ?>) this);
IALTransformation<?, ?> parentIAL = ((IALTransformation<?, ?>) parentTransformation);
thisIAL.getIALHolder().setIALRoots(parentIAL.getIALHolder().getIALRoots());
}
parentTransformation.addChildIssue(this);
}
}
......@@ -525,17 +531,29 @@ public abstract class AbstractModelCodeTransformation<ELEMENTECLASS extends EObj
for (final IModelCodeTransformation<? extends EObject, ? extends IJavaElement> childTransformation : childTransformations) {
childTransformation.setToCode();
// Set the prior modl element for possibly changed transformation model
// Set the prior model element for possibly changed transformation model
// elements.
// All other model elements or priorModelElements will already be set by the
// doCreate... methods.
final EObject childModelElement = childTransformation.getModelElement();
if (childModelElement != null && idRegistry.knowsImplementationModelElement(childModelElement)) {
final String id = idRegistry.getIDFromImplementationModelElement(childModelElement);
final EObject priorChildElement = priorIDRegistry.resolveImplementationModelElement(id,
EcoreUtil.getRootContainer(priorModelElement));
childTransformation.setPriorModelElement(priorChildElement);
if (childModelElement == null)
continue;
EObject priorChildElement = null;
if (this instanceof IALTransformation) {
if (idRegistry.knowsTranslationModelElement(childModelElement)) {
final String id = idRegistry.getIDFromTranslationModelElement(childModelElement);
priorChildElement = priorIDRegistry.resolveTranslationModelElement(id,
EcoreUtil.getRootContainer(priorModelElement));
}
} else {
if (idRegistry.knowsImplementationModelElement(childModelElement)) {
final String id = idRegistry.getIDFromImplementationModelElement(childModelElement);
priorChildElement = priorIDRegistry.resolveImplementationModelElement(id,
EcoreUtil.getRootContainer(priorModelElement));
}
}
childTransformation.setPriorModelElement(priorChildElement);
}
return childTransformations;
}
......
......@@ -15,6 +15,7 @@ import org.eclipse.jdt.core.IJavaElement;
import de.mkonersmann.advert.java.embed.transformation.AbstractModelCodeTransformation;
import de.mkonersmann.advert.java.embed.transformation.IModelCodeTransformation;
import de.mkonersmann.advert.java.embed.transformation.references.IALTransformation;
public abstract class ReferenceMechanismTransformation<OWNERECLASS extends EObject, TARGETECLASS extends EObject, JAVAELEMENT extends IJavaElement>
extends AbstractModelCodeTransformation<OWNERECLASS, JAVAELEMENT> {
......@@ -30,6 +31,14 @@ public abstract class ReferenceMechanismTransformation<OWNERECLASS extends EObje
setModelElement(parentTransformation.getModelElement());
setPriorModelElement(parentTransformation.getPriorModelElement());
setCodeElement(parentTransformation.getCodeElement());
if (this instanceof IALTransformation && parentTransformation instanceof IALTransformation) {
IALTransformation<?, ?> thisIAL = ((IALTransformation<?, ?>) this);
IALTransformation<?, ?> parentIAL = ((IALTransformation<?, ?>) parentTransformation);
thisIAL.getIALHolder().setFoundationalIALElement(parentIAL.getIALHolder().getFoundationalIALElement());
thisIAL.getIALHolder().setPriorFoundationalIALElement(parentIAL.getIALHolder().getPriorFoundationalIALElement());
thisIAL.getIALHolder().setIALCodeElement(parentIAL.getIALHolder().getIALCodeElement());
}
}
}
......
......@@ -186,6 +186,9 @@ abstract class AnnotatedMemberReferenceTransformation<OWNERECLASS extends EObjec
if (fields.isEmpty)
resolveCodeElement();
if(fields.isEmpty()){
return targetTypes;
}
if (targetIsMarkerInterface) {
val Object annotationValues = ASTUtils.getAnnotationMemberValue(
......
package org.codeling.lang.jee7.transformation.bean_feature;
import java.text.MessageFormat;
import java.util.LinkedList;
import java.util.List;
import org.codeling.lang.jee7.transformation.DelegatedOperationTransformation;
import org.codeling.mechanisms.transformations.ClassMechanismTransformation;
import org.codeling.mechanisms.transformations.references.ContainmentOperationTransformation;
import org.codeling.utils.CodelingException;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IMethod;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaModelException;
import org.modelversioning.emfprofile.Stereotype;
import org.modelversioning.emfprofileapplication.StereotypeApplication;
import de.mkonersmann.advert.java.embed.ProfilesUtils;
import de.mkonersmann.advert.java.embed.transformation.AbstractModelCodeTransformation;
import de.mkonersmann.advert.java.embed.transformation.references.IALHolder;
import de.mkonersmann.advert.java.embed.transformation.references.IALTransformation;
import de.mkonersmann.il.core.ComponentType;
import de.mkonersmann.il.profiles.Profiles;
public class ChildOperationTransformation extends ContainmentOperationTransformation<StereotypeApplication, EObject>
implements IALTransformation<StereotypeApplication, IType> {
private IALHolder holder = new IALHolder();
private ComponentType componentType;
public ChildOperationTransformation(ChildTypeTransformation childTypeTransformation, ComponentType componentType) {
super((ClassMechanismTransformation<StereotypeApplication, IType>) childTypeTransformation
.getParentTransformation(),
ProfilesUtils.getEReference(
ProfilesUtils.getStereotype("OperationInterface", Profiles.INTERFACES_TYPE_OPERATIONS.load()),
"operations"));
this.componentType = componentType;
}
@Override
public void updateCodeFragments() throws CodelingException {
LinkedList<EObject> targets = new LinkedList<>();
if (eReference.isMany()) {
targets.addAll((List<EObject>) modelElement.eGet(eReference));
} else {
targets.add((EObject) modelElement.eGet(eReference));
}
IType type = (IType) codeElement;
for (EObject target : targets) {
if (type.getMethod(getNameAttributeValue(target), new String[0]).exists()) {
// Method already exists. Do nothing
} else {
// Method does not exist. Create a new one.
String targetName = getNameAttributeValue(target);
// For presentation purposes. This is currently only able to handle the name of
// Annotated Member References (Single) references.
String content = "public void " + targetName.substring(0, 1).toLowerCase() + targetName.substring(1)
+ "(){" + componentType.getName().substring(0, 1).toLowerCase()
+ componentType.getName().substring(1) + "." + targetName.substring(0, 1).toLowerCase()
+ targetName.substring(1) + "();" + "}";
try {
methods.add(type.createMethod(content, null, true, null));
} catch (JavaModelException e) {
addWarning(MessageFormat.format("Could not add method [{0}] to [{1}].", target,
codeElement.getElementName()), e);
}
}
}
}
@Override
protected ClassMechanismTransformation<? extends EObject, ? extends IJavaElement> createSpecificTransformation(
EObject targetModelElement) {
return new DelegatedOperationTransformation(this);
}
@Override
protected void doCreateChildTransformationsToModel(
List<AbstractModelCodeTransformation<? extends EObject, ? extends IJavaElement>> result) {
// TODO Auto-generated method stub
}
@Override
public void doCreateCrossReferencesTransformations(
List<AbstractModelCodeTransformation<? extends EObject, ? extends IJavaElement>> result) {
// TODO Auto-generated method stub
}
@Override
public IALHolder getIALHolder() {
return holder;
}
@Override
public StereotypeApplication resolveTranslatedIALElement(EObject foundationalElement) {
EList<StereotypeApplication> appliedStereotypes = ProfilesUtils.getAppliedStereotypes(foundationalElement);
Stereotype scopedComponent = ProfilesUtils.getStereotype("HierarchicalComponentTypeScoped",
Profiles.COMPONENTS_HIERARCHY_SCOPED.load());
for (StereotypeApplication app : appliedStereotypes) {
if (app.getStereotype() == scopedComponent) {
return app;
}
}
return null;
}
@Override
public boolean codeFragmentExists() {
return true;
}
protected String getNewAnnotationName() {
// No annotation
return null;
}
@Override
public boolean hasExpectedAnnotation(IMethod method) {
// No annotation
return true;
}
}
......@@ -78,9 +78,7 @@ public class EjbWithStateMachineLanguage extends JavaBasedImplementationLanguage
@Override
public List<String> getSelectedProfiles() {
List<String> result = new HenshinTGGBasedLanguageDefinitionHelper().getSelectedProfiles(henshinTGGFileURI);
result.add(Profiles.COMPONENTS_HIERARCHY_SCOPED.getNsURI()); // Can also handle scoped hierarchies via the MIC
return result;
return new HenshinTGGBasedLanguageDefinitionHelper().getSelectedProfiles(henshinTGGFileURI);
}
}
......@@ -146,7 +146,7 @@ public class ChildTransformation extends ReferenceMechanismTransformation<Stereo
try {
StereotypeApplication application = ProfilesUtils.findOrApplyStereotype(
"HierarchicalComponentTypeScoped", Profiles.COMPONENTS_HIERARCHY_SCOPED.load(),
modelElement, holder.getFoundationalIALElement().eResource());
holder.getFoundationalIALElement(), holder.getFoundationalIALElement().eResource());
EObject target = idRegistry.resolveTranslationModelElement(id,
EcoreUtil.getRootContainer(holder.getFoundationalIALElement()));
......
......@@ -139,7 +139,7 @@ public class IDRegistry {
public String getIDFromImplementationModelElement(EObject implementationModelElement) {
if (implementationModelElement == null)
throw new IllegalArgumentException("Implementation Model Element must not be null.");
final String implementationModelPath = getPath(implementationModelElement);
for (final Entry<String, String[]> e : id2paths.entrySet()) {
......@@ -154,7 +154,7 @@ public class IDRegistry {
public String getIDFromTranslationModelElement(EObject translationModelElement) {
if (translationModelElement == null)
throw new IllegalArgumentException("Translation Model must not be null.");
final String translationModelPath = getPath(translationModelElement);
for (final Entry<String, String[]> e : id2paths.entrySet()) {
......@@ -169,7 +169,7 @@ public class IDRegistry {
public String getIDFromCodeElement(IJavaElement codeElement) {
if (codeElement == null)
throw new IllegalArgumentException("Code Element must not be null.");
final String codePath = codeElement.getHandleIdentifier();
for (final Entry<String, String[]> e : id2paths.entrySet()) {
......@@ -182,18 +182,21 @@ public class IDRegistry {
}
public EObject resolveImplementationModelElement(EObject translationModelElement,
EObject implementationModelRootElement) {
List<EObject> implementationModelRootElements) {
final String translationModelPath = getPath(translationModelElement);
for (final Entry<String, String[]> e : id2paths.entrySet()) {
if (e.getValue()[2] != null && e.getValue()[2].equals(translationModelPath)) {
return resolve(implementationModelRootElement, e.getValue()[1]);
for (EObject root : implementationModelRootElements) {
EObject resolved = resolve(root, e.getValue()[1]);
if (resolved != null)
return resolved;
}
}
}
throw new IllegalArgumentException(String.format(
"Could not get implementation model element for il element '%s' based on the implementation model root element '%s'.",
translationModelElement, implementationModelRootElement));
throw new IllegalArgumentException(String
.format("Could not get implementation model element for il element '%s'.", translationModelElement));
}
private String generateID() {
......
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