Commit 4120c4cc authored by Marco Konersmann's avatar Marco Konersmann

translates child components in the running example

parent 93019372
......@@ -4,7 +4,10 @@ import java.util.LinkedList;
import java.util.List;
import org.codeling.mechanisms.transformations.ClassMechanismTransformation;
import org.codeling.mechanisms.transformations.ReferenceMechanismTransformation;
import org.codeling.mechanisms.transformations.references.AnnotatedMemberReferenceTransformation;
import org.codeling.utils.CodelingException;
import org.codeling.utils.Models;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EReference;
......@@ -15,6 +18,7 @@ import org.eclipse.jdt.core.JavaModelException;
import org.modelversioning.emfprofile.Stereotype;
import org.modelversioning.emfprofileapplication.StereotypeApplication;
import de.mkonersmann.advert.java.embed.ASTUtils;
import de.mkonersmann.advert.java.embed.JDTUtils;
import de.mkonersmann.advert.java.embed.ProfilesUtils;
import de.mkonersmann.advert.java.embed.transformation.AbstractModelCodeTransformation;
......@@ -23,7 +27,7 @@ import de.mkonersmann.advert.java.embed.transformation.references.IALTransformat
import de.mkonersmann.il.core.ComponentType;
import de.mkonersmann.il.profiles.Profiles;
public class ChildTransformation extends AnnotatedMemberReferenceTransformation<StereotypeApplication, ComponentType>
public class ChildTransformation extends ReferenceMechanismTransformation<StereotypeApplication, ComponentType, IType>
implements IALTransformation<StereotypeApplication, IType> {
private IALHolder holder = new IALHolder();
......@@ -33,32 +37,14 @@ public class ChildTransformation extends AnnotatedMemberReferenceTransformation<
super(parentTransformation, eReference);
}
@Override
public String createTypeAnnotationReferenceSingle(EObject target) {
return addChildAnnotation(super.createTypeAnnotationReferenceSingle(target));
}
@Override
public String createMarkerInterfaceReferenceSingle(EObject target) {
return addChildAnnotation(super.createMarkerInterfaceReferenceSingle(target));
}
@Override
public String createMarkerInterfaceReferenceMulti(LinkedList<EObject> targets) {
return addChildAnnotation(super.createMarkerInterfaceReferenceMulti(targets));
}
private String addChildAnnotation(String originalField) {
private void addChildAnnotation(IField field) {
try {
JDTUtils.addImportIfNecessary(codeElement, "org.codeling.lang.ejbWithStatemachine.ial.mm.componentType.Child", null);
JDTUtils.addImportIfNecessary(codeElement,
"org.codeling.lang.ejbWithStatemachine.ial.mm.componentType.Child", null);
ASTUtils.addAnnotation(field, "Child", null);
} catch (JavaModelException e) {
e.printStackTrace();
}
StringBuffer bf = new StringBuffer();
bf.append("@Child");
bf.append(System.getProperty("line.separator"));
bf.append(originalField);
return bf.toString();
}
public boolean hasExpectedAnnotation(IField field) {
......@@ -76,11 +62,6 @@ public class ChildTransformation extends AnnotatedMemberReferenceTransformation<
return childAnnotationExists && injectAnnotationExists;
}
@Override
protected String getNewAnnotationName() {
return "javax.ejb.EJB";
}
@Override
public IALHolder getIALHolder() {
return holder;
......@@ -101,29 +82,57 @@ public class ChildTransformation extends AnnotatedMemberReferenceTransformation<
@Override
public boolean codeFragmentExists() {
resolveCodeElement();
return !fields.isEmpty();
return true; // The reference always exists. It might be empty.
}
@Override
protected void doCreateChildTransformationsToCode(
List<AbstractModelCodeTransformation<? extends EObject, ? extends IJavaElement>> result) {
protected ClassMechanismTransformation<? extends EObject, ? extends IJavaElement> createSpecificTransformation(
EObject targetModelElement) {
return null;
}
@Override
protected ClassMechanismTransformation<? extends EObject, ? extends IJavaElement> createSpecificTransformation(
EObject targetModelElement) {
return null; // not used
public void createCodeFragments() throws CodelingException {
updateCodeFragments(); // Everything is handled in update
}
@Override
public void updateCodeFragments() throws CodelingException {
List<EObject> targets = Models.getTargetsAsList(modelElement, eReference);
for (EObject target : targets) {
String targetName = getNameAttributeValue(target);
targetName = Character.toLowerCase(targetName.charAt(0)) + targetName.substring(1);
IField field = codeElement.getField(targetName);
if (field == null || !field.exists())
continue; // Field must have been created before by the ReferencesTransformation.
if (!hasExpectedAnnotation(field)) {
addChildAnnotation(field);
}
}
}
@Override
public void deleteCodeFragments() throws CodelingException {
updateCodeFragments(); // Everything is handled in update
}
@Override
public StereotypeApplication transformToModel() throws CodelingException {
return null;
}
@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
}
}
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