diff options
Diffstat (limited to 'extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass')
42 files changed, 1199 insertions, 1060 deletions
diff --git a/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/CreationUtils.java b/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/CreationUtils.java index 305dd5319c9..bafb282bd89 100644 --- a/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/CreationUtils.java +++ b/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/CreationUtils.java @@ -16,7 +16,7 @@ package org.eclipse.papyrus.qompass.designer.core; import org.eclipse.core.runtime.Status; import org.eclipse.emf.common.util.EList; -import org.eclipse.papyrus.qompass.designer.core.transformations.Copy; +import org.eclipse.papyrus.qompass.designer.core.transformations.LazyCopier; import org.eclipse.uml2.uml.NamedElement; import org.eclipse.uml2.uml.Namespace; import org.eclipse.uml2.uml.Package; @@ -55,7 +55,7 @@ public class CreationUtils { if(pkg == null) { // package does not exist => create it. pkg = root.createNestedPackage(ns.getName()); - Copy.copyID(ns, pkg); + LazyCopier.copyID(ns, pkg); // copy stereotype to create package StUtils.copyStereotypes(ns, pkg); } diff --git a/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/ModelManagement.java b/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/ModelManagement.java index 36c6182b57b..d0a77e9f4ab 100644 --- a/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/ModelManagement.java +++ b/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/ModelManagement.java @@ -75,6 +75,11 @@ public class ModelManagement { public Model getModel() { return model; } + + public void saveModel(IProject project, String modelFolder, String modelPostfix) { + String path = this.getPath(project, modelFolder, this.getModel().getName() + modelPostfix); + this.saveModel(path); + } /** * Save a model within a passed project and a specified folder diff --git a/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/OperationUtils.java b/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/OperationUtils.java index c01bd7a6932..04779cd1e99 100644 --- a/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/OperationUtils.java +++ b/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/OperationUtils.java @@ -16,7 +16,7 @@ package org.eclipse.papyrus.qompass.designer.core; import java.util.Iterator; -import org.eclipse.papyrus.qompass.designer.core.transformations.Copy; +import org.eclipse.papyrus.qompass.designer.core.transformations.LazyCopier; import org.eclipse.uml2.uml.Class; import org.eclipse.uml2.uml.Operation; import org.eclipse.uml2.uml.Parameter; @@ -141,7 +141,7 @@ public class OperationUtils { */ public static void syncOperation(Operation sourceOp, Operation targetOp) { if(targetOp != null) { - Copy.copyFeatureModifiers(sourceOp, targetOp); + LazyCopier.copyFeatureModifiers(sourceOp, targetOp); // ordered and unique are derived from ret-parameter targetOp.setIsQuery(sourceOp.isQuery()); targetOp.setIsAbstract(sourceOp.isAbstract()); @@ -152,7 +152,7 @@ public class OperationUtils { Parameter newParameter = targetOp.createOwnedParameter(parameter.getLabel(), type); newParameter.setDirection(parameter.getDirection()); - Copy.copyMultElemModifiers(parameter, newParameter); + LazyCopier.copyMultElemModifiers(parameter, newParameter); StUtils.copyStereotypes(parameter, newParameter); } } diff --git a/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/StUtils.java b/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/StUtils.java index c484f764b1b..b387ae32341 100644 --- a/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/StUtils.java +++ b/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/StUtils.java @@ -18,7 +18,7 @@ import org.eclipse.emf.common.util.BasicEList; import org.eclipse.emf.common.util.EList; import org.eclipse.emf.ecore.EClass; import org.eclipse.emf.ecore.EObject; -import org.eclipse.papyrus.qompass.designer.core.transformations.Copy; +import org.eclipse.papyrus.qompass.designer.core.transformations.LazyCopier; import org.eclipse.papyrus.uml.tools.utils.StereotypeUtil; import org.eclipse.uml2.uml.Connector; import org.eclipse.uml2.uml.Element; @@ -43,7 +43,7 @@ public class StUtils { * @param destination * @return */ - public static void copyStereotypes(Copy copy, Element source, Element destination) { + public static void copyStereotypes(LazyCopier copy, Element source, Element destination) { for(Stereotype stereotype : source.getAppliedStereotypes()) { copyAttributes(copy, stereotype.getQualifiedName(), source, destination); } @@ -66,7 +66,7 @@ public class StUtils { * @return */ @SuppressWarnings({ "unchecked" }) - public static boolean copyAttributes(Copy copy, String stereotypeName, Element source, Element destination) { + public static boolean copyAttributes(LazyCopier copy, String stereotypeName, Element source, Element destination) { Stereotype stereoSource = source.getAppliedStereotype(stereotypeName); Stereotype stereoDest = destination.getApplicableStereotype(stereotypeName); diff --git a/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/acceleo/EnumService.java b/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/acceleo/EnumService.java index e1e5d8eb9a0..e010bcc1140 100644 --- a/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/acceleo/EnumService.java +++ b/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/acceleo/EnumService.java @@ -135,6 +135,7 @@ public class EnumService { } public static void createEnumPackage(Package root) { + init(); enumPkg = root.createNestedPackage(GLOBALENUMS); } diff --git a/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/deployment/BootLoaderGen.java b/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/deployment/BootLoaderGen.java index 70f319beed4..1109a6fa230 100644 --- a/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/deployment/BootLoaderGen.java +++ b/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/deployment/BootLoaderGen.java @@ -30,7 +30,7 @@ import org.eclipse.papyrus.qompass.designer.core.StUtils; import org.eclipse.papyrus.qompass.designer.core.Utils; import org.eclipse.papyrus.qompass.designer.core.acceleo.UMLTool; import org.eclipse.papyrus.qompass.designer.core.transformations.CompImplTrafos; -import org.eclipse.papyrus.qompass.designer.core.transformations.Copy; +import org.eclipse.papyrus.qompass.designer.core.transformations.LazyCopier; import org.eclipse.papyrus.qompass.designer.core.transformations.PrefixConstants; import org.eclipse.papyrus.qompass.designer.core.transformations.TransformationException; import org.eclipse.papyrus.uml.tools.utils.ConnectorUtil; @@ -77,7 +77,7 @@ public class BootLoaderGen { * @param The * package in which the bootloader should be created */ - public BootLoaderGen(Copy copy, int nodeIndex, int numberOfNodes) + public BootLoaderGen(LazyCopier copy, int nodeIndex, int numberOfNodes) throws TransformationException { // Class composite = (Class) ut.getClassifier (mainInstance); // place in root (getModel()) to avoid the problem that the declaration of the bootLoader @@ -300,7 +300,7 @@ public class BootLoaderGen { * @param containerSlot * @return */ - public static boolean hasUnconnectedStartRoutine(Copy copy, Class implementation, Slot containerSlot) { + public static boolean hasUnconnectedStartRoutine(LazyCopier copy, Class implementation, Slot containerSlot) { if(implementation != null) { Port startPort = AllocUtils.getStartPort(implementation); if (startPort != null) { @@ -320,7 +320,7 @@ public class BootLoaderGen { * @param name * @return */ - public static boolean hasUnconnectedLifeCycle(Copy copy, Class implementation, Slot containerSlot) { + public static boolean hasUnconnectedLifeCycle(LazyCopier copy, Class implementation, Slot containerSlot) { if(implementation != null) { Element lcPortElem = Utils.getNamedElementFromList(implementation.getAllAttributes(), "lc"); //$NON-NLS-1$ if(lcPortElem instanceof Port) { @@ -344,7 +344,7 @@ public class BootLoaderGen { * @Param a port that is checked for being connected * @return true, if connected */ - private static boolean isConnected(Copy copy, Slot containerSlot, Port port) { + private static boolean isConnected(LazyCopier copy, Slot containerSlot, Port port) { if(containerSlot != null) { StructuralFeature sf = containerSlot.getDefiningFeature(); if(sf instanceof Property) { @@ -523,7 +523,7 @@ public class BootLoaderGen { /** * copy variable (instances still point to non-copied classes) */ - private Copy m_copy; + private LazyCopier m_copy; /** * Store a map with index values to manage configuration of arrays diff --git a/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/deployment/Deploy.java b/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/deployment/Deploy.java index 29c9fd2685e..10b3c5bde4e 100644 --- a/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/deployment/Deploy.java +++ b/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/deployment/Deploy.java @@ -19,7 +19,7 @@ import java.util.Stack; import org.eclipse.papyrus.qompass.designer.core.Messages; import org.eclipse.papyrus.qompass.designer.core.extensions.ILangSupport; import org.eclipse.papyrus.qompass.designer.core.extensions.InstanceConfigurator; -import org.eclipse.papyrus.qompass.designer.core.transformations.Copy; +import org.eclipse.papyrus.qompass.designer.core.transformations.LazyCopier; import org.eclipse.papyrus.qompass.designer.core.transformations.TransformationException; import org.eclipse.uml2.uml.Class; import org.eclipse.uml2.uml.Classifier; @@ -48,7 +48,7 @@ public class Deploy { * @param instance * @throws TransformationException */ - public Deploy(Copy copy, ILangSupport langSupport, InstanceSpecification node, + public Deploy(LazyCopier copy, ILangSupport langSupport, InstanceSpecification node, int nodeIndex, int numberOfNodes) throws TransformationException { @@ -71,7 +71,7 @@ public class Deploy { * distribute an instance, its contained sub-instances and the referenced * classifiers to a certain node * - * @param copy + * @param copier * @param node * @param nodeIndex * @param numberOfNodes @@ -181,5 +181,5 @@ public class Deploy { protected InstanceDeployer depInstance; - protected Copy copy; + protected LazyCopier copy; } diff --git a/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/deployment/GatherConfigData.java b/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/deployment/GatherConfigData.java index d1b707e3573..22739bcaeb6 100644 --- a/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/deployment/GatherConfigData.java +++ b/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/deployment/GatherConfigData.java @@ -16,8 +16,8 @@ package org.eclipse.papyrus.qompass.designer.core.deployment; import org.eclipse.emf.ecore.EObject; import org.eclipse.papyrus.qompass.designer.core.extensions.ILangSupport; -import org.eclipse.papyrus.qompass.designer.core.listeners.CopyListener; -import org.eclipse.papyrus.qompass.designer.core.transformations.Copy; +import org.eclipse.papyrus.qompass.designer.core.listeners.PreCopyListener; +import org.eclipse.papyrus.qompass.designer.core.transformations.LazyCopier; import org.eclipse.uml2.uml.Class; /** @@ -27,7 +27,7 @@ import org.eclipse.uml2.uml.Class; * * @author ansgar */ -public class GatherConfigData implements CopyListener { +public class GatherConfigData implements PreCopyListener { /** * Gather configuration data for a code generation project @@ -40,7 +40,7 @@ public class GatherConfigData implements CopyListener { this.langSupport = langSupport; } - public EObject copyEObject(Copy copy, EObject sourceEObj) { + public EObject preCopyEObject(LazyCopier copy, EObject sourceEObj) { if(sourceEObj instanceof Class) { langSupport.gatherConfigData((Class)sourceEObj); } diff --git a/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/deployment/InstanceDeployer.java b/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/deployment/InstanceDeployer.java index c3ccc2ea8fb..e15562044f8 100644 --- a/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/deployment/InstanceDeployer.java +++ b/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/deployment/InstanceDeployer.java @@ -16,7 +16,7 @@ package org.eclipse.papyrus.qompass.designer.core.deployment; import java.util.Stack; -import org.eclipse.papyrus.qompass.designer.core.transformations.Copy; +import org.eclipse.papyrus.qompass.designer.core.transformations.LazyCopier; import org.eclipse.papyrus.qompass.designer.core.transformations.TransformationException; import org.eclipse.uml2.uml.InstanceSpecification; import org.eclipse.uml2.uml.Slot; @@ -39,7 +39,7 @@ public interface InstanceDeployer { * @param node * the node onto which the allocation should be done. */ - public void init(Copy sat, BootLoaderGen bootloader, InstanceSpecification node); + public void init(LazyCopier sat, BootLoaderGen bootloader, InstanceSpecification node); /** * Deploy an instance and copy the required classes into the target model. diff --git a/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/deployment/PartialCopy.java b/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/deployment/PartialCopy.java index a49c7627a27..f000234df5c 100644 --- a/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/deployment/PartialCopy.java +++ b/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/deployment/PartialCopy.java @@ -16,7 +16,7 @@ package org.eclipse.papyrus.qompass.designer.core.deployment; import java.util.Stack; -import org.eclipse.papyrus.qompass.designer.core.transformations.Copy; +import org.eclipse.papyrus.qompass.designer.core.transformations.LazyCopier; import org.eclipse.papyrus.qompass.designer.core.transformations.TransformationException; import org.eclipse.papyrus.uml.tools.utils.ConnectorUtil; import org.eclipse.uml2.uml.Class; @@ -46,7 +46,7 @@ import org.eclipse.uml2.uml.Slot; */ public class PartialCopy implements InstanceDeployer { - public void init(Copy copy, BootLoaderGen bootloader, + public void init(LazyCopier copy, BootLoaderGen bootloader, InstanceSpecification node) { this.copy = copy; this.node = node; // only needed for debug output @@ -120,5 +120,5 @@ public class PartialCopy implements InstanceDeployer { private InstanceSpecification node; - private Copy copy; + private LazyCopier copy; } diff --git a/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/extensions/BindingHelperExt.java b/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/extensions/BindingHelperExt.java index c8e363d11a9..9ed97f25fb9 100644 --- a/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/extensions/BindingHelperExt.java +++ b/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/extensions/BindingHelperExt.java @@ -18,8 +18,9 @@ import org.eclipse.core.runtime.Platform; import org.eclipse.emf.ecore.EObject; import org.eclipse.papyrus.FCM.BindingHelper; import org.eclipse.papyrus.FCM.util.IBindingHelper; -import org.eclipse.papyrus.qompass.designer.core.listeners.CopyListener; -import org.eclipse.papyrus.qompass.designer.core.transformations.Copy; +import org.eclipse.papyrus.qompass.designer.core.listeners.PostCopyListener; +import org.eclipse.papyrus.qompass.designer.core.listeners.PreCopyListener; +import org.eclipse.papyrus.qompass.designer.core.transformations.LazyCopier; import org.eclipse.papyrus.qompass.designer.core.transformations.TransformationRTException; import org.eclipse.uml2.uml.Element; import org.eclipse.uml2.uml.TemplateBinding; @@ -39,16 +40,33 @@ public class BindingHelperExt { * containing composite (container) * @param instance */ - public static EObject applyHelper(BindingHelper helper, Copy copy, TemplateBinding binding, EObject sourceEObj) { + public static EObject applyPreHelper(BindingHelper helper, LazyCopier copier, TemplateBinding binding, EObject sourceEObj) { IBindingHelper ihelper = getBindingHelper(helper.getBase_Class().getName()); if (sourceEObj instanceof Element) { ihelper.handleElement(binding, (Element) sourceEObj); } - if(ihelper instanceof CopyListener) { - return ((CopyListener) ihelper).copyEObject(copy, sourceEObj); + if(ihelper instanceof PreCopyListener) { + return ((PreCopyListener) ihelper).preCopyEObject(copier, sourceEObj); } return sourceEObj; } + + /** + * + * @param iConfiguratorName + * @param component + * containing composite (container) + * @param instance + */ + public static void applyPostHelper(BindingHelper helper, LazyCopier copier, TemplateBinding binding, EObject targetEObj) { + IBindingHelper ihelper = getBindingHelper(helper.getBase_Class().getName()); + if (targetEObj instanceof Element) { + ihelper.handleElement(binding, (Element) targetEObj); + } + if(ihelper instanceof PostCopyListener) { + ((PostCopyListener) ihelper).postCopyEObject(copier, targetEObj); + } + } public static IBindingHelper getBindingHelper(BindingHelper helper) { if (helper != null) { diff --git a/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/extensions/ILangSupport.java b/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/extensions/ILangSupport.java index de5417e6931..163216422fa 100644 --- a/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/extensions/ILangSupport.java +++ b/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/extensions/ILangSupport.java @@ -45,6 +45,8 @@ public interface ILangSupport { * the project (must already been initialized) */ public void setProject(IProject project); + + public IProject getProject(); /** * Re-create the project settings from model information diff --git a/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/transformations/filters/FilterComments.java b/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/listeners/PostCopyListener.java index 163d333c6b2..1500627eb64 100644 --- a/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/transformations/filters/FilterComments.java +++ b/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/listeners/PostCopyListener.java @@ -12,34 +12,24 @@ * *****************************************************************************/ -package org.eclipse.papyrus.qompass.designer.core.transformations.filters; +package org.eclipse.papyrus.qompass.designer.core.listeners; import org.eclipse.emf.ecore.EObject; -import org.eclipse.papyrus.qompass.designer.core.listeners.CopyListener; -import org.eclipse.papyrus.qompass.designer.core.transformations.Copy; -import org.eclipse.uml2.uml.Comment; +import org.eclipse.papyrus.qompass.designer.core.transformations.LazyCopier; /** - * Do not copy comments - * - * @author ansgar - * + * Interface for listeners that are notified when an eObject + * is copied + * + * @see org.eclipse.papyrus.qompass.designer.core.transformations.LazyCopier */ -public class FilterComments implements CopyListener { - - public static FilterComments getInstance() { - if(instance == null) { - instance = new FilterComments(); - } - return instance; - } - - public EObject copyEObject(Copy copy, EObject sourceEObj) { - if(sourceEObj instanceof Comment) { - return null; - } - return sourceEObj; - } +public interface PostCopyListener { - private static FilterComments instance = null; + /** + * Is called for each EObject after is has been copied. + * + * @param targetEObj + * the EObject that has been copied + */ + public void postCopyEObject(LazyCopier copy, EObject targetEObj); } diff --git a/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/listeners/CopyListener.java b/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/listeners/PreCopyListener.java index 4052008abd3..f4a1a874e23 100644 --- a/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/listeners/CopyListener.java +++ b/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/listeners/PreCopyListener.java @@ -15,15 +15,15 @@ package org.eclipse.papyrus.qompass.designer.core.listeners; import org.eclipse.emf.ecore.EObject; -import org.eclipse.papyrus.qompass.designer.core.transformations.Copy; +import org.eclipse.papyrus.qompass.designer.core.transformations.LazyCopier; /** - * Interface for listeners that are notified for the addition of a classifier - * via copy + * Interface for listeners that are notified when an eObject + * is copied * - * @see org.eclipse.papyrus.qompass.designer.core.transformations.Copy + * @see org.eclipse.papyrus.qompass.designer.core.transformations.LazyCopier */ -public interface CopyListener { +public interface PreCopyListener { /** * Is called for each EObject that is copied. If it returns null, the @@ -34,5 +34,5 @@ public interface CopyListener { * @param sourceEObj * the added classifier */ - public EObject copyEObject(Copy copy, EObject sourceEObj); + public EObject preCopyEObject(LazyCopier copy, EObject sourceEObj); } diff --git a/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/sync/SyncBehaviorParameters.java b/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/sync/SyncBehaviorParameters.java index c7867b27203..1d06985049e 100644 --- a/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/sync/SyncBehaviorParameters.java +++ b/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/sync/SyncBehaviorParameters.java @@ -15,7 +15,7 @@ package org.eclipse.papyrus.qompass.designer.core.sync; import org.eclipse.papyrus.qompass.designer.core.StUtils; -import org.eclipse.papyrus.qompass.designer.core.transformations.Copy; +import org.eclipse.papyrus.qompass.designer.core.transformations.LazyCopier; import org.eclipse.uml2.uml.Behavior; import org.eclipse.uml2.uml.BehavioralFeature; import org.eclipse.uml2.uml.Parameter; @@ -36,7 +36,7 @@ public class SyncBehaviorParameters { for (Parameter parameter : bf.getOwnedParameters()) { Parameter newParameter = method.createOwnedParameter(parameter.getName(), parameter.getType()); newParameter.setDirection(parameter.getDirection()); - Copy.copyMultElemModifiers(parameter, newParameter); + LazyCopier.copyMultElemModifiers(parameter, newParameter); StUtils.copyStereotypes(parameter, newParameter); } } diff --git a/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/templates/BindingUtils.java b/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/templates/BindingUtils.java index 27293a7923a..6dc84b895fd 100644 --- a/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/templates/BindingUtils.java +++ b/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/templates/BindingUtils.java @@ -20,7 +20,7 @@ import org.eclipse.papyrus.C_Cpp.ConstInit; import org.eclipse.papyrus.qompass.designer.core.Messages; import org.eclipse.papyrus.qompass.designer.core.PortUtils; import org.eclipse.papyrus.qompass.designer.core.acceleo.AcceleoDriverWrapper; -import org.eclipse.papyrus.qompass.designer.core.transformations.Copy; +import org.eclipse.papyrus.qompass.designer.core.transformations.LazyCopier; import org.eclipse.papyrus.qompass.designer.core.transformations.TransformationContext; import org.eclipse.papyrus.qompass.designer.core.transformations.TransformationException; import org.eclipse.uml2.uml.Class; @@ -44,7 +44,7 @@ public class BindingUtils { * @param operation The operation template * @return */ - public static Operation instantiateOperation(Copy copy, Element actual, Operation operation) { + public static Operation instantiateOperation(LazyCopier copy, Element actual, Operation operation) { try { Operation newOperation = copy.getCopy(operation); if(actual instanceof Operation) { @@ -76,7 +76,7 @@ public class BindingUtils { * @return instantiated (bound) behavior. * @throws TransformationException */ - public static OpaqueBehavior instantiateBehavior(Copy copy, Element actual, OpaqueBehavior opaqueBehavior) throws TransformationException { + public static OpaqueBehavior instantiateBehavior(LazyCopier copy, Element actual, OpaqueBehavior opaqueBehavior) throws TransformationException { OpaqueBehavior newBehavior = copy.getCopy(opaqueBehavior); if(actual instanceof NamedElement) { String newName = AcceleoDriverWrapper.evaluate(opaqueBehavior.getName(), actual, null); diff --git a/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/templates/InstantiateCppInclude.java b/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/templates/InstantiateCppInclude.java deleted file mode 100644 index 4fcbc12df1f..00000000000 --- a/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/templates/InstantiateCppInclude.java +++ /dev/null @@ -1,76 +0,0 @@ -/***************************************************************************** - * Copyright (c) 2013 CEA LIST. - * - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Ansgar Radermacher ansgar.radermacher@cea.fr - * - *****************************************************************************/ - -package org.eclipse.papyrus.qompass.designer.core.templates; - -import org.eclipse.emf.ecore.EObject; -import org.eclipse.papyrus.C_Cpp.Include; -import org.eclipse.papyrus.qompass.designer.core.acceleo.AcceleoDriverWrapper; -import org.eclipse.papyrus.qompass.designer.core.listeners.CopyListener; -import org.eclipse.papyrus.qompass.designer.core.transformations.Copy; -import org.eclipse.papyrus.qompass.designer.core.transformations.TransformationContext; -import org.eclipse.papyrus.qompass.designer.core.transformations.TransformationException; -import org.eclipse.uml2.uml.Classifier; -import org.eclipse.uml2.uml.TemplateBinding; -import org.eclipse.uml2.uml.util.UMLUtil; - -/** - * Instantiate the text within a C++Include tag. - * TODO: this function is C++ specific and should not be here - * - */ -public class InstantiateCppInclude implements CopyListener { - - public static InstantiateCppInclude getInstance() { - if(instance == null) { - instance = new InstantiateCppInclude(); - } - return instance; - } - - public void init(TemplateBinding binding, Object[] args) { - this.binding = binding; - } - - public EObject copyEObject(Copy copy, EObject targetEObj) { - // if (copy.get(sourceEObj) isWithinTemplate) - if(targetEObj instanceof Classifier) { - // TODO: C++ specific code! - Classifier targetCl = (Classifier)targetEObj; - try { - Classifier actual = TemplateUtils.getFirstActualFromBinding(binding); - Include cppInclude = UMLUtil.getStereotypeApplication(targetCl, Include.class); - if((actual != null) && (cppInclude != null)) { - TransformationContext.classifier = targetCl; - String newBody = AcceleoDriverWrapper.evaluate(cppInclude.getBody(), actual, null); - String newPreBody = AcceleoDriverWrapper.evaluate(cppInclude.getPreBody(), actual, null); - String newHeader = AcceleoDriverWrapper.evaluate(cppInclude.getHeader(), actual, null); - cppInclude.setBody(newBody); - cppInclude.setPreBody(newPreBody); - cppInclude.setHeader(newHeader); - } - } catch (TransformationException e) { - // create nested exception - throw new RuntimeException(e); - } - } - return targetEObj; - } - - private static InstantiateCppInclude instance = null; - - private TemplateBinding binding; - - // private Copy copy; -} diff --git a/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/templates/InstantiateCppIncludeWOB.java b/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/templates/InstantiateCppIncludeWOB.java deleted file mode 100644 index 85f5766d599..00000000000 --- a/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/templates/InstantiateCppIncludeWOB.java +++ /dev/null @@ -1,72 +0,0 @@ -/***************************************************************************** - * Copyright (c) 2013 CEA LIST. - * - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Ansgar Radermacher ansgar.radermacher@cea.fr - * - *****************************************************************************/ - -package org.eclipse.papyrus.qompass.designer.core.templates; - -import org.eclipse.emf.ecore.EObject; -import org.eclipse.papyrus.C_Cpp.Include; -import org.eclipse.papyrus.FCM.Template; -import org.eclipse.papyrus.qompass.designer.core.acceleo.AcceleoDriverWrapper; -import org.eclipse.papyrus.qompass.designer.core.listeners.CopyListener; -import org.eclipse.papyrus.qompass.designer.core.transformations.Copy; -import org.eclipse.papyrus.qompass.designer.core.transformations.TransformationContext; -import org.eclipse.papyrus.qompass.designer.core.transformations.TransformationException; -import org.eclipse.uml2.uml.Classifier; -import org.eclipse.uml2.uml.util.UMLUtil; - -/** - * Instantiate the text within a C++Include tag. - * Difference to InstantiateCppInclude: This function does not obtain the actual from a template - * binding. - * - * TODO: this function is C++ specific and should not be here - * - */ -public class InstantiateCppIncludeWOB implements CopyListener { - - public static InstantiateCppIncludeWOB getInstance() { - if(instance == null) { - instance = new InstantiateCppIncludeWOB(); - } - return instance; - } - - public EObject copyEObject(Copy copy, EObject targetEObj) { - // if (copy.get(sourceEObj) isWithinTemplate) - if(targetEObj instanceof Classifier) { - // TODO: C++ specific code! - Classifier targetCl = (Classifier)targetEObj; - Template template = UMLUtil.getStereotypeApplication(targetCl, Template.class); - // apply, in case of pass-classifier - if((template != null) && (template.getHelper() == null)) { - try { - Include cppInclude = UMLUtil.getStereotypeApplication(targetCl, Include.class); - TransformationContext.classifier = targetCl; - String newBody = AcceleoDriverWrapper.evaluate(cppInclude.getBody(), targetCl, null); - String newPreBody = AcceleoDriverWrapper.evaluate(cppInclude.getPreBody(), targetCl, null); - String newHeader = AcceleoDriverWrapper.evaluate(cppInclude.getHeader(), targetCl, null); - cppInclude.setBody(newBody); - cppInclude.setPreBody(newPreBody); - cppInclude.setHeader(newHeader); - } catch (TransformationException e) { - // create nested exception - throw new RuntimeException(e); - } - } - } - return targetEObj; - } - - private static InstantiateCppIncludeWOB instance = null; -} diff --git a/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/templates/PostTemplateInstantiationListener.java b/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/templates/PostTemplateInstantiationListener.java new file mode 100644 index 00000000000..2809ac60fb5 --- /dev/null +++ b/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/templates/PostTemplateInstantiationListener.java @@ -0,0 +1,61 @@ +/***************************************************************************** + * Copyright (c) 2013 CEA LIST. + * + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Ansgar Radermacher ansgar.radermacher@cea.fr + * + *****************************************************************************/ + +package org.eclipse.papyrus.qompass.designer.core.templates; + +import org.eclipse.emf.ecore.EObject; +import org.eclipse.papyrus.FCM.BindingHelper; +import org.eclipse.papyrus.FCM.Template; +import org.eclipse.papyrus.qompass.designer.core.extensions.BindingHelperExt; +import org.eclipse.papyrus.qompass.designer.core.listeners.PostCopyListener; +import org.eclipse.papyrus.qompass.designer.core.transformations.LazyCopier; +import org.eclipse.uml2.uml.Element; +import org.eclipse.uml2.uml.TemplateBinding; +import org.eclipse.uml2.uml.util.UMLUtil; + +/** + * Template instantiation is implemented by means of a PostCopyListener that + * evaluates the template stereotype. + */ + +public class PostTemplateInstantiationListener implements PostCopyListener { + + public static PostTemplateInstantiationListener getInstance() { + if(postTemplateInstantiationListener == null) { + postTemplateInstantiationListener = new PostTemplateInstantiationListener(); + } + return postTemplateInstantiationListener; + } + + public void init(LazyCopier copy, TemplateBinding binding, Object[] args) { + this.binding = binding; + } + + private TemplateBinding binding; + + private static PostTemplateInstantiationListener postTemplateInstantiationListener; + + public void postCopyEObject(LazyCopier copy, EObject targetEObj) { + if(targetEObj instanceof Element) { + + Template template = UMLUtil.getStereotypeApplication((Element)targetEObj, Template.class); + if((template != null)) { + BindingHelper helper = template.getHelper(); + if (helper != null) { + BindingHelperExt.applyPostHelper(helper, copy, binding, targetEObj); + } + } + } + } +} diff --git a/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/templates/TemplateInstantiationListener.java b/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/templates/PreTemplateInstantiationListener.java index 9e3c5958ab4..1c97d6de0be 100644 --- a/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/templates/TemplateInstantiationListener.java +++ b/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/templates/PreTemplateInstantiationListener.java @@ -18,8 +18,8 @@ import org.eclipse.emf.ecore.EObject; import org.eclipse.papyrus.FCM.BindingHelper; import org.eclipse.papyrus.FCM.Template; import org.eclipse.papyrus.qompass.designer.core.extensions.BindingHelperExt; -import org.eclipse.papyrus.qompass.designer.core.listeners.CopyListener; -import org.eclipse.papyrus.qompass.designer.core.transformations.Copy; +import org.eclipse.papyrus.qompass.designer.core.listeners.PreCopyListener; +import org.eclipse.papyrus.qompass.designer.core.transformations.LazyCopier; import org.eclipse.uml2.uml.BehavioralFeature; import org.eclipse.uml2.uml.Element; import org.eclipse.uml2.uml.OpaqueBehavior; @@ -29,20 +29,19 @@ import org.eclipse.uml2.uml.util.UMLUtil; /** * Template instantiation is implemented by means of an CopyListener that * evaluates the template stereotype. - * This is a pre-copy listener. */ -public class TemplateInstantiationListener implements CopyListener { +public class PreTemplateInstantiationListener implements PreCopyListener { - public static TemplateInstantiationListener getInstance() { - if(templateInstantiationListener == null) { - templateInstantiationListener = new TemplateInstantiationListener(); - templateInstantiationListener.treatTemplate = false; + public static PreTemplateInstantiationListener getInstance() { + if(preTemplateInstantiationListener == null) { + preTemplateInstantiationListener = new PreTemplateInstantiationListener(); + preTemplateInstantiationListener.treatTemplate = false; } - return templateInstantiationListener; + return preTemplateInstantiationListener; } - public void init(Copy copy, TemplateBinding binding, Object[] args) { + public void init(LazyCopier copy, TemplateBinding binding, Object[] args) { this.binding = binding; } @@ -50,9 +49,9 @@ public class TemplateInstantiationListener implements CopyListener { private boolean treatTemplate; - private static TemplateInstantiationListener templateInstantiationListener; + private static PreTemplateInstantiationListener preTemplateInstantiationListener; - public EObject copyEObject(Copy copy, EObject sourceEObj) { + public EObject preCopyEObject(LazyCopier copy, EObject sourceEObj) { if(treatTemplate) { return sourceEObj; } @@ -62,7 +61,7 @@ public class TemplateInstantiationListener implements CopyListener { return targetEObj; } - protected EObject checkEObject(Copy copy, EObject sourceEObj) { + protected EObject checkEObject(LazyCopier copy, EObject sourceEObj) { // Specific treatment of OpaqueBehaviors: Template instantiations are typically managed // by the associated operation which instantiates operation and behavior. In this case, the @@ -84,7 +83,7 @@ public class TemplateInstantiationListener implements CopyListener { if((template != null)) { BindingHelper helper = template.getHelper(); if (helper != null) { - return BindingHelperExt.applyHelper(helper, copy, binding, sourceEObj); + return BindingHelperExt.applyPreHelper(helper, copy, binding, sourceEObj); } } } diff --git a/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/templates/TemplateInstantiation.java b/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/templates/TemplateInstantiation.java index dd7ec368b62..2900ae8783f 100644 --- a/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/templates/TemplateInstantiation.java +++ b/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/templates/TemplateInstantiation.java @@ -18,7 +18,7 @@ import org.eclipse.emf.common.util.EList; import org.eclipse.papyrus.FCM.BindingHelper; import org.eclipse.papyrus.FCM.Template; import org.eclipse.papyrus.qompass.designer.core.Messages; -import org.eclipse.papyrus.qompass.designer.core.transformations.Copy; +import org.eclipse.papyrus.qompass.designer.core.transformations.LazyCopier; import org.eclipse.papyrus.qompass.designer.core.transformations.TransformationContext; import org.eclipse.papyrus.qompass.designer.core.transformations.TransformationException; import org.eclipse.papyrus.qompass.designer.core.transformations.filters.FilterSignatures; @@ -50,18 +50,18 @@ import org.eclipse.uml2.uml.util.UMLUtil; public class TemplateInstantiation { - public TemplateInstantiation(Copy copy, TemplateBinding binding) throws TransformationException { + public TemplateInstantiation(LazyCopier copy, TemplateBinding binding) throws TransformationException { this(copy, binding, null); } /** * - * @param copy_ copier + * @param copier_ copier * @param binding UML template binding * @param args currently unused * @throws TransformationException */ - public TemplateInstantiation(final Copy copy_, final TemplateBinding binding, Object args[]) throws TransformationException { + public TemplateInstantiation(final LazyCopier copier_, final TemplateBinding binding, Object args[]) throws TransformationException { if(binding == null) { // user should never see this exception throw new TransformationException("Passed binding is null"); //$NON-NLS-1$ @@ -79,28 +79,28 @@ public class TemplateInstantiation { * copy.postCopyListeners = new BasicEList<CopyListener>(); * copy.postCopyListeners.addAll(copy_.postCopyListeners); */ - copy = copy_; + copier = copier_; Package boundPackage = (Package)binding.getBoundElement(); // set template instantiation parameter. Used by Acceleo templates to get relation between // formal and actual parameters TransformationContext.setTemplateInstantiation(this); - copy.setPackageTemplate(packageTemplate, boundPackage); + copier.setPackageTemplate(packageTemplate, boundPackage); // some parameters of the package template may not be owned. Thus, an additional package // template is involved in the instantiation for(TemplateParameter parameter : signature.getParameters()) { // if(parameter.getSignature() != signature) { Package addedPkgTemplate = parameter.getSignature().getNearestPackage(); - copy.setPackageTemplate(addedPkgTemplate, boundPackage); + copier.setPackageTemplate(addedPkgTemplate, boundPackage); } } if (boundPackage.getPackagedElements() != null) { // bound package is not empty, but copy does not know about it. Fill copyMap with information about the relation // This happens, if the original model already contains template instantiations, e.g. for template ports - if (copy.getMap(signature).keySet().size() == 0) { + if (copier.getMap(signature).keySet().size() == 0) { syncCopyMap(packageTemplate, boundPackage); } } @@ -113,29 +113,28 @@ public class TemplateInstantiation { for(TemplateParameterSubstitution substitution : binding.getParameterSubstitutions()) { ParameterableElement formal = substitution.getFormal().getParameteredElement(); ParameterableElement actual = substitution.getActual(); - copy.putPair(formal, actual); + copier.putPair(formal, actual); } // add copy listeners --- // remove template signature - if(!copy.preCopyListeners.contains(FilterSignatures.getInstance())) { - copy.preCopyListeners.add(FilterSignatures.getInstance()); + if(!copier.preCopyListeners.contains(FilterSignatures.getInstance())) { + copier.preCopyListeners.add(FilterSignatures.getInstance()); } - // 2. special treatment for elements stereotyped with template parameter - if(!copy.preCopyListeners.contains(TemplateInstantiationListener.getInstance())) { - copy.preCopyListeners.add(TemplateInstantiationListener.getInstance()); + // 2a. special treatment for elements stereotyped with template parameter + if(!copier.preCopyListeners.contains(PreTemplateInstantiationListener.getInstance())) { + copier.preCopyListeners.add(PreTemplateInstantiationListener.getInstance()); } - TemplateInstantiationListener.getInstance().init(copy, binding, args); - - if(!copy.postCopyListeners.contains(FixTemplateSync.getInstance())) { - copy.postCopyListeners.add(FixTemplateSync.getInstance()); + PreTemplateInstantiationListener.getInstance().init(copier, binding, args); + // 2b. special treatment for elements stereotyped with template parameter + if(!copier.postCopyListeners.contains(PostTemplateInstantiationListener.getInstance())) { + copier.postCopyListeners.add(PostTemplateInstantiationListener.getInstance()); } + PostTemplateInstantiationListener.getInstance().init(copier, binding, args); - // TODO: programming language specific code!! - InstantiateCppInclude.getInstance().init(binding, args); - if(!copy.postCopyListeners.contains(InstantiateCppInclude.getInstance())) { - copy.postCopyListeners.add(InstantiateCppInclude.getInstance()); + if(!copier.postCopyListeners.contains(FixTemplateSync.getInstance())) { + copier.postCopyListeners.add(FixTemplateSync.getInstance()); } } @@ -149,7 +148,7 @@ public class TemplateInstantiation { * @param targetPkg The bound package (target) */ public void syncCopyMap(Package sourcePkg, Package targetPkg) { - copy.put(sourcePkg, targetPkg); + copier.put(sourcePkg, targetPkg); for (PackageableElement target : targetPkg.getPackagedElements()) { if (target instanceof NamedElement) { String targetName = ((NamedElement) target).getName(); @@ -158,7 +157,7 @@ public class TemplateInstantiation { syncCopyMap((Package) source, (Package) target); } else { - copy.put(source, target); + copier.put(source, target); } } } @@ -168,7 +167,7 @@ public class TemplateInstantiation { public TemplateBinding binding; - public Copy copy; + public LazyCopier copier; TemplateSignature signature; @@ -183,7 +182,7 @@ public class TemplateInstantiation { * actually created within the bound package. We call this mechanism lazy * instantiation/binding * - * @param copy + * @param copier * Source and target model * @param namedElement * A member within the package template which should be bound, @@ -225,7 +224,7 @@ public class TemplateInstantiation { Element owner = TemplateUtils.getTemplateOwner(namedElement, signature); if(owner != null) { // note that we might overwrite an existing value - copy.put(owner, boundPackage); + copier.put(owner, boundPackage); } } else { @@ -238,8 +237,8 @@ public class TemplateInstantiation { // template parameter) TemplateSignature signatureOfNE = TemplateUtils.getSignature((TemplateableElement)namedElement); if((signatureOfNE != null) && (signature != signatureOfNE)) { - TemplateBinding subBinding = TemplateUtils.getSubBinding(copy.target, (TemplateableElement)namedElement, binding); - TemplateInstantiation ti = new TemplateInstantiation(copy, subBinding, args); + TemplateBinding subBinding = TemplateUtils.getSubBinding(copier.target, (TemplateableElement)namedElement, binding); + TemplateInstantiation ti = new TemplateInstantiation(copier, subBinding, args); NamedElement ret = ti.bindNamedElement(namedElement); return (T)ret; } @@ -249,13 +248,13 @@ public class TemplateInstantiation { // since the template is potentially instantiated in another model, // the referenced element might need to be copied. - return copy.getCopy(namedElement); + return copier.getCopy(namedElement); } // element is contained in the template package, examine whether it // already exists in the // bound package. - NamedElement existingMember = (NamedElement)copy.get(namedElement); + NamedElement existingMember = (NamedElement)copier.get(namedElement); /* if((existingMember != null) && (templateKind != TemplateKind.ACCUMULATE)) { // element is already existing (and thus bound), nothing to do @@ -271,9 +270,9 @@ public class TemplateInstantiation { */ if(existingMember == null) { FilterTemplate.getInstance().setActive(false); - T copiedElement = copy.getCopy(namedElement); + T copiedElement = copier.getCopy(namedElement); FilterTemplate.getInstance().setActive(true); - copy.setPackageTemplate(null, null); + copier.setPackageTemplate(null, null); return copiedElement; } diff --git a/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/templates/TemplateUtils.java b/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/templates/TemplateUtils.java index ef8ea120182..51f7ac4e79f 100644 --- a/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/templates/TemplateUtils.java +++ b/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/templates/TemplateUtils.java @@ -24,7 +24,7 @@ import org.eclipse.papyrus.qompass.designer.core.Log; import org.eclipse.papyrus.qompass.designer.core.Messages; import org.eclipse.papyrus.qompass.designer.core.PortUtils; import org.eclipse.papyrus.qompass.designer.core.Utils; -import org.eclipse.papyrus.qompass.designer.core.transformations.Copy; +import org.eclipse.papyrus.qompass.designer.core.transformations.LazyCopier; import org.eclipse.papyrus.qompass.designer.core.transformations.TransformationException; import org.eclipse.papyrus.uml.tools.utils.ConnectorUtil; import org.eclipse.uml2.uml.Classifier; @@ -228,7 +228,7 @@ public class TemplateUtils { * @param sat * @param binding */ - public static void adaptActualsToTargetModel(Copy copy, TemplateBinding binding) { + public static void adaptActualsToTargetModel(LazyCopier copy, TemplateBinding binding) { for(TemplateParameterSubstitution substitution : binding.getParameterSubstitutions()) { substitution.setActual(copy.getCopy(substitution.getActual())); } diff --git a/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/transformations/AbstractContainerTrafo.java b/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/transformations/AbstractContainerTrafo.java index eb6e8fee831..7f7646ad10d 100644 --- a/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/transformations/AbstractContainerTrafo.java +++ b/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/transformations/AbstractContainerTrafo.java @@ -85,7 +85,7 @@ public abstract class AbstractContainerTrafo { /** * Copy class from source to target model */ - protected Copy copy; + protected LazyCopier copier; /** diff --git a/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/transformations/AcceleoException.java b/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/transformations/AcceleoException.java new file mode 100644 index 00000000000..2eb51c4c4ca --- /dev/null +++ b/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/transformations/AcceleoException.java @@ -0,0 +1,10 @@ +package org.eclipse.papyrus.qompass.designer.core.transformations;
+
+public class AcceleoException extends Exception {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
+}
diff --git a/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/transformations/AllocTransfo.java b/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/transformations/AllocTransfo.java index 95f6cfbf170..7c3e1c4a04f 100644 --- a/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/transformations/AllocTransfo.java +++ b/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/transformations/AllocTransfo.java @@ -31,7 +31,7 @@ public class AllocTransfo { * @param composite A composite. We analyze the allocations of the properties within this * Composite. The composite must be an element of the target model that can be modified. */ - public void transformAllocs(Copy copy, Class composite) { + public void transformAllocs(LazyCopier copy, Class composite) { EList<Property> attributeList = new BasicEList<Property>(); attributeList.addAll(composite.getOwnedAttributes()); // use a copy, since the loop eventually destroys an element of the list. for (Property attribute : attributeList) { diff --git a/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/transformations/ApplyInstanceConfigurators.java b/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/transformations/ApplyInstanceConfigurators.java deleted file mode 100644 index 35839a25539..00000000000 --- a/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/transformations/ApplyInstanceConfigurators.java +++ /dev/null @@ -1,40 +0,0 @@ -/***************************************************************************** - * Copyright (c) 2013 CEA LIST. - * - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Ansgar Radermacher ansgar.radermacher@cea.fr - * - *****************************************************************************/ - -package org.eclipse.papyrus.qompass.designer.core.transformations; - -import org.eclipse.papyrus.qompass.designer.core.deployment.DepUtils; -import org.eclipse.papyrus.qompass.designer.core.extensions.InstanceConfigurator; -import org.eclipse.uml2.uml.InstanceSpecification; -import org.eclipse.uml2.uml.Property; -import org.eclipse.uml2.uml.Slot; - - -/** - * Apply instance configurators - * - */ -public class ApplyInstanceConfigurators { - public static void applyInstanceConfigurators(InstanceSpecification instance) { - for (Slot slot : instance.getSlots()) { - InstanceSpecification subInstance = DepUtils.getInstance(slot); - if (!DepUtils.isShared(slot) && (subInstance != null)) { - if (slot.getDefiningFeature() instanceof Property) { - InstanceConfigurator.configureInstance(subInstance, (Property) slot.getDefiningFeature(), instance); - } - applyInstanceConfigurators(subInstance); - } - } - } -} diff --git a/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/transformations/CompImplTrafos.java b/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/transformations/CompImplTrafos.java index da51cfadac2..77f44c5219f 100644 --- a/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/transformations/CompImplTrafos.java +++ b/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/transformations/CompImplTrafos.java @@ -36,6 +36,7 @@ import org.eclipse.uml2.uml.Connector; import org.eclipse.uml2.uml.ConnectorEnd; import org.eclipse.uml2.uml.Element; import org.eclipse.uml2.uml.Interface; +import org.eclipse.uml2.uml.Model; import org.eclipse.uml2.uml.OpaqueBehavior; import org.eclipse.uml2.uml.Operation; import org.eclipse.uml2.uml.Package; @@ -48,19 +49,19 @@ import org.eclipse.uml2.uml.Type; import org.eclipse.uml2.uml.UMLPackage; /** - * This class realizes the transformations for a component implementation (the executor) - * It includes: - * 1. add the get_p operation for a port with a provided interface. - * 2. add the connect_q operation and realization (*including a storage attribute*) for - * a port with a required interface - * 3. add an implementation for the getcnx_q operation for a port with a required interface - * (the operation itself has been added before) + * This class realizes the transformations for a component implementation (the + * executor) It includes: 1. add the get_p operation for a port with a provided + * interface. 2. add the connect_q operation and realization (*including a + * storage attribute*) for a port with a required interface 3. add an + * implementation for the getcnx_q operation for a port with a required + * interface (the operation itself has been added before) * * TODO: C++ specific, support different "component to OO" mappings * - * Caveat: Assure that the folder derivedInterfaces already exists in a model. Otherwise - * the call to getProvided/getRequired interface might trigger its creation resulting in - * the corruption of list iterators (ConcurrentAccess exception) + * Caveat: Assure that the folder derivedInterfaces already exists in a model. + * Otherwise the call to getProvided/getRequired interface might trigger its + * creation resulting in the corruption of list iterators (ConcurrentAccess + * exception) * */ public class CompImplTrafos { @@ -68,20 +69,25 @@ public class CompImplTrafos { public static Class bootloader; public static final String retParamName = "ret"; //$NON-NLS-1$ - + public static final String progLang = "C/C++"; //$NON-NLS-1$ - - public static void addPortOperations(Copy copy, Package pkg) throws TransformationException { + + public static void addPortOperations(LazyCopier copy, Package pkg) + throws TransformationException { EList<PackageableElement> peList = new BasicEList<PackageableElement>(); peList.addAll(pkg.getPackagedElements()); - for(PackageableElement element : peList) { - if(element instanceof Package) { - addPortOperations(copy, (Package)element); - } else if(element instanceof Class) { - Class implementation = (Class)element; - // we may not apply the transformation to the boot-loader itself, in particular it would transform + for (PackageableElement element : peList) { + if (element instanceof Package) { + addPortOperations(copy, (Package) element); + } else if (element instanceof Class) { + Class implementation = (Class) element; + // we may not apply the transformation to the boot-loader + // itself, in particular it would transform // singletons into pointers. - if(Utils.isCompImpl(implementation) && (implementation != bootloader) && !StereotypeUtil.isApplied(implementation, PortKind.class)) { + if (Utils.isCompImpl(implementation) + && (implementation != bootloader) + && !StereotypeUtil.isApplied(implementation, + PortKind.class)) { addGetPortOperation(copy, implementation); addConnectPortOperation(copy, implementation); markPartsPointer(implementation); @@ -92,80 +98,103 @@ public class CompImplTrafos { } /** - * Add the get_p operation for each port with a provided interface. It also adds a suitable - * implementation that evaluates delegation connectors from the port to a property within - * the composite. The delegation target could either be a normal class (no port) or an - * inner component. + * Add the get_p operation for each port with a provided interface. It also + * adds a suitable implementation that evaluates delegation connectors from + * the port to a property within the composite. The delegation target could + * either be a normal class (no port) or an inner component. * * @param implementation */ - private static void addGetPortOperation(Copy copy, Class implementation) { - for(PortInfo portInfo : PortUtils.flattenExtendedPorts(PortUtils.getAllPorts2(implementation))) { + private static void addGetPortOperation(LazyCopier copy, Class implementation) { + for (PortInfo portInfo : PortUtils.flattenExtendedPorts(PortUtils + .getAllPorts2(implementation))) { Interface providedIntf = portInfo.getProvided(); - if(providedIntf != null) { - // port provides an interface, add "get_p" operation & implementation + if (providedIntf != null) { + // port provides an interface, add "get_p" operation & + // implementation - String opName = PrefixConstants.getP_Prefix + portInfo.getName(); - Operation op = implementation.getOwnedOperation(opName, null, null); + String opName = PrefixConstants.getP_Prefix + + portInfo.getName(); + Operation op = implementation.getOwnedOperation(opName, null, + null); if (op != null) { - // operation already exists. Assume that user wants to override standard delegation + // operation already exists. Assume that user wants to + // override standard delegation if (op.getType() != providedIntf) { op.createOwnedParameter(retParamName, providedIntf); } continue; } - op = implementation.createOwnedOperation(opName, null, null, providedIntf); + op = implementation.createOwnedOperation(opName, null, null, + providedIntf); Parameter retParam = op.getOwnedParameters().get(0); retParam.setName(retParamName); StereotypeUtil.apply(retParam, Ptr.class); - OpaqueBehavior behavior = (OpaqueBehavior) - implementation.createOwnedBehavior(opName, - UMLPackage.eINSTANCE.getOpaqueBehavior()); + OpaqueBehavior behavior = (OpaqueBehavior) implementation + .createOwnedBehavior(opName, + UMLPackage.eINSTANCE.getOpaqueBehavior()); op.getMethods().add(behavior); - ConnectorEnd ce = ConnectorUtil.getDelegation(implementation, portInfo.getModelPort()); - // if there is an delegation to an inner property, delegate to it - // Make distinction between delegation to component (with a port) or + ConnectorEnd ce = ConnectorUtil.getDelegation(implementation, + portInfo.getModelPort()); + // if there is an delegation to an inner property, delegate to + // it + // Make distinction between delegation to component (with a + // port) or // "normal" class (without). String body; - if(ce != null) { + if (ce != null) { Property part = ce.getPartWithPort(); ConnectableElement role = ce.getRole(); - body = "return "; //$NON-NLS-1$ - if(role instanceof Port) { - // check whether the part exists within the implementation (might not be the case + body = "return "; //$NON-NLS-1$ + if (role instanceof Port) { + // check whether the part exists within the + // implementation (might not be the case // due to partially copied composites). - // Check is based on names, since the connector points to elements within another - // model (copyClassifier does not make a proper connector copy) + // Check is based on names, since the connector points + // to elements within another + // model (copyClassifier does not make a proper + // connector copy) // body += part.getName() + refOp(part) + opName + "();"; //$NON-NLS-1$ // TODO: this will NOT work for extended ports! - body += part.getName() + refOp(part) + PrefixConstants.getP_Prefix + role.getName() + "();"; //$NON-NLS-1$ - } - else { - // role is not a port: connector connects directly to a structural feature + body += part.getName() + refOp(part) + + PrefixConstants.getP_Prefix + role.getName() + + "();"; //$NON-NLS-1$ + } else { + // role is not a port: connector connects directly to a + // structural feature // without passing via a port // TODO: check whether structural feature exists body += role.getName(); } } else { - // no delegation, check whether port implements provided interface - boolean implementsIntf = implementation.getInterfaceRealization(null, providedIntf) != null; + // no delegation, check whether port implements provided + // interface + boolean implementsIntf = implementation + .getInterfaceRealization(null, providedIntf) != null; if (!implementsIntf) { - // The extended port itself is not copied to the target model (since referenced via a stereotype). Therefore, - // a port of an extended port still points to the original model. We try whether the providedIntf within - // the target model is within the interface realizations. - Interface providedIntfInCopy = (Interface) copy.get(providedIntf); - implementsIntf = implementation.getInterfaceRealization(null, providedIntfInCopy) != null; + // The extended port itself is not copied to the target + // model (since referenced via a stereotype). Therefore, + // a port of an extended port still points to the + // original model. We try whether the providedIntf + // within + // the target model is within the interface + // realizations. + Interface providedIntfInCopy = (Interface) copy + .get(providedIntf); + implementsIntf = implementation + .getInterfaceRealization(null, + providedIntfInCopy) != null; } if (implementsIntf) { - body = "return this;"; //$NON-NLS-1$ - } - else { + body = "return this;"; //$NON-NLS-1$ + } else { throw new RuntimeException(String.format( - Messages.CompImplTrafos_IntfNotImplemented, - providedIntf.getName(), portInfo.getPort().getName(), implementation.getName())); + Messages.CompImplTrafos_IntfNotImplemented, + providedIntf.getName(), portInfo.getPort() + .getName(), implementation.getName())); } } // todo: defined by template @@ -176,23 +205,24 @@ public class CompImplTrafos { } /** - * if the bootloader is responsible for creating an instance (if it is a abstract type), mark - * the associated part as a C++ pointer. - * We do not want to change the aggregation kind, since it remains logically a composition, it - * is merely an implementation issue that it must be a pointer for C++ if the concrete type is - * not yet known. + * if the bootloader is responsible for creating an instance (if it is a + * abstract type), mark the associated part as a C++ pointer. We do not want + * to change the aggregation kind, since it remains logically a composition, + * it is merely an implementation issue that it must be a pointer for C++ if + * the concrete type is not yet known. * * * @param implementation */ private static void markPartsPointer(Class implementation) { - for(Property attribute : Utils.getParts(implementation)) { + for (Property attribute : Utils.getParts(implementation)) { Type type = attribute.getType(); - if(type instanceof Class) { - Class cl = (Class)type; - // => requires adaptations of boot-loader which is then only responsible for creating instances - // corresponding to types - if(instantiateViaBootloader(cl)) { + if (type instanceof Class) { + Class cl = (Class) type; + // => requires adaptations of boot-loader which is then only + // responsible for creating instances + // corresponding to types + if (instantiateViaBootloader(cl)) { StereotypeUtil.apply(attribute, Ptr.class); } } @@ -201,63 +231,79 @@ public class CompImplTrafos { /** * Add a connect_<portName> operation for ports with a required interface. - * Whereas operation and a behavior is added for each owned port, a behavior (method) is - * needed for ports inherited from a component type (the behavior is implementation specific, - * as it needs to take delegation to parts into account) + * Whereas operation and a behavior is added for each owned port, a behavior + * (method) is needed for ports inherited from a component type (the + * behavior is implementation specific, as it needs to take delegation to + * parts into account) * * @param implementation */ - private static void addConnectPortOperation(Copy sat, Class implementation) { - for(PortInfo portInfo : PortUtils.flattenExtendedPorts(PortUtils.getAllPorts2(implementation))) { + private static void addConnectPortOperation(LazyCopier sat, Class implementation) { + for (PortInfo portInfo : PortUtils.flattenExtendedPorts(PortUtils + .getAllPorts2(implementation))) { Interface requiredIntf = portInfo.getRequired(); - if(requiredIntf != null) { - // port requires an interface, add "connect_p" operation & implementation + if (requiredIntf != null) { + // port requires an interface, add "connect_p" operation & + // implementation - String opName = PrefixConstants.connectQ_Prefix + portInfo.getName(); + String opName = PrefixConstants.connectQ_Prefix + + portInfo.getName(); if (implementation.getOwnedOperation(opName, null, null) != null) { - // do not add the operation, if it already exists. This means that the - // user wants to override it with custom behavior. In case of extended + // do not add the operation, if it already exists. This + // means that the + // user wants to override it with custom behavior. In case + // of extended // ports, we may have to do that. continue; } - Operation op = implementation.createOwnedOperation(opName, null, null); - boolean multiPort = (portInfo.getUpper() > 1) || (portInfo.getUpper() == -1); // -1 indicates "*" - if(multiPort) { + Operation op = implementation.createOwnedOperation(opName, + null, null); + boolean multiPort = (portInfo.getUpper() > 1) + || (portInfo.getUpper() == -1); // -1 indicates "*" + if (multiPort) { // add index parameter - Element eLong = Utils.getQualifiedElement(Utils.getTop(implementation), CompTypeTrafos.INDEX_TYPE_FOR_MULTI_RECEPTACLE); - if(eLong instanceof Type) { - op.createOwnedParameter("index", (Type)eLong); //$NON-NLS-1$ - } - else { + Element eLong = Utils.getQualifiedElement( + Utils.getTop(implementation), + CompTypeTrafos.INDEX_TYPE_FOR_MULTI_RECEPTACLE); + if (eLong instanceof Type) { + op.createOwnedParameter("index", (Type) eLong); //$NON-NLS-1$ + } else { throw new RuntimeException(String.format( - Messages.CompImplTrafos_CannotFindType, - CompTypeTrafos.INDEX_TYPE_FOR_MULTI_RECEPTACLE)); + Messages.CompImplTrafos_CannotFindType, + CompTypeTrafos.INDEX_TYPE_FOR_MULTI_RECEPTACLE)); } } - Parameter refParam = op.createOwnedParameter("ref", requiredIntf); //$NON-NLS-1$ + Parameter refParam = op.createOwnedParameter( + "ref", requiredIntf); //$NON-NLS-1$ StereotypeUtil.apply(refParam, Ptr.class); - OpaqueBehavior behavior = (OpaqueBehavior) - implementation.createOwnedBehavior(opName, - UMLPackage.eINSTANCE.getOpaqueBehavior()); + OpaqueBehavior behavior = (OpaqueBehavior) implementation + .createOwnedBehavior(opName, + UMLPackage.eINSTANCE.getOpaqueBehavior()); op.getMethods().add(behavior); - ConnectorEnd ce = ConnectorUtil.getDelegation(implementation, portInfo.getModelPort()); - // if there is an delegation to an inner property, delegate to it - // Make distinction between delegation to component (with a port) or + ConnectorEnd ce = ConnectorUtil.getDelegation(implementation, + portInfo.getModelPort()); + // if there is an delegation to an inner property, delegate to + // it + // Make distinction between delegation to component (with a + // port) or // "normal" class (without). String body; - if(ce != null) { + if (ce != null) { Property part = ce.getPartWithPort(); body = part.getName(); ConnectableElement role = ce.getRole(); - if(role instanceof Port) { - // in case of a delegation, use name of target port which might be different - String targetOpName = PrefixConstants.connectQ_Prefix + role.getName(); + if (role instanceof Port) { + // in case of a delegation, use name of target port + // which might be different + String targetOpName = PrefixConstants.connectQ_Prefix + + role.getName(); body += refOp(part) + targetOpName; // TODO: no check that multiplicity of both port matches - if((portInfo.getUpper() > 1) || (portInfo.getUpper() == -1)) { + if ((portInfo.getUpper() > 1) + || (portInfo.getUpper() == -1)) { body += "(index, ref);"; //$NON-NLS-1$ } else { body += "(ref);"; //$NON-NLS-1$ @@ -268,42 +314,55 @@ public class CompImplTrafos { } } else { // no delegation - create attribute for port - String attributeName = PrefixConstants.attributePrefix + portInfo.getName(); - if(!Utils.hasNonPortOwnedAttribute(implementation, attributeName)) { - Property attr = implementation.createOwnedAttribute(attributeName, requiredIntf); - Copy.copyMultElemModifiers(portInfo.getPort(), attr); + String attributeName = PrefixConstants.attributePrefix + + portInfo.getName(); + if (!Utils.hasNonPortOwnedAttribute(implementation, + attributeName)) { + Property attr = implementation.createOwnedAttribute( + attributeName, requiredIntf); + LazyCopier.copyMultElemModifiers(portInfo.getPort(), attr); // is shared (should store a reference) attr.setAggregation(AggregationKind.SHARED_LITERAL); } - body = attributeName + (multiPort ? "[index]" : "") + " = ref;"; //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ + body = attributeName + + (multiPort ? "[index]" : "") + " = ref;"; //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ } // TODO: defined by template behavior.getLanguages().add(progLang); behavior.getBodies().add(body); // ------------------------- - // add body to get-connection operation (which exists already if the port is also - // owned, since it is synchronized automatically during model edit) - // getConnQ prefix may be empty to indicate that the port is accessed directly - // TODO: reconsider optimization that delegated required ports do not have a - // local attribute & associated operation (an inner class may delegate, but the - // composite may be using it as well). - if((PrefixConstants.getConnQ_Prefix.length() > 0) && (ce != null)) { - opName = PrefixConstants.getConnQ_Prefix + portInfo.getName(); + // add body to get-connection operation (which exists already if + // the port is also + // owned, since it is synchronized automatically during model + // edit) + // getConnQ prefix may be empty to indicate that the port is + // accessed directly + // TODO: reconsider optimization that delegated required ports + // do not have a + // local attribute & associated operation (an inner class may + // delegate, but the + // composite may be using it as well). + if ((PrefixConstants.getConnQ_Prefix.length() > 0) + && (ce != null)) { + opName = PrefixConstants.getConnQ_Prefix + + portInfo.getName(); op = implementation.getOwnedOperation(opName, null, null); - if(op == null) { - op = implementation.createOwnedOperation(opName, null, null, requiredIntf); + if (op == null) { + op = implementation.createOwnedOperation(opName, null, + null, requiredIntf); Parameter retParam = op.getOwnedParameters().get(0); retParam.setName(retParamName); StereotypeUtil.apply(retParam, Ptr.class); } - behavior = (OpaqueBehavior) - implementation.createOwnedBehavior(opName, - UMLPackage.eINSTANCE.getOpaqueBehavior()); + behavior = (OpaqueBehavior) implementation + .createOwnedBehavior(opName, + UMLPackage.eINSTANCE.getOpaqueBehavior()); op.getMethods().add(behavior); // no delegation - String name = PrefixConstants.attributePrefix + portInfo.getName(); + String name = PrefixConstants.attributePrefix + + portInfo.getName(); body = "return " + name + ";"; //$NON-NLS-1$ //$NON-NLS-2$ behavior.getLanguages().add(progLang); behavior.getBodies().add(body); @@ -313,37 +372,42 @@ public class CompImplTrafos { } /** - * Add an operation "createConnections" that implements the connections between composite - * parts. It only takes the assembly connections into account, since delegation connectors - * are handled by the get_ and connect_ port operations above. + * Add an operation "createConnections" that implements the connections + * between composite parts. It only takes the assembly connections into + * account, since delegation connectors are handled by the get_ and connect_ + * port operations above. * * @param implementation */ private static void addCreateConnections(Class implementation) - throws TransformationException { + throws TransformationException { String createConnBody = ""; //$NON-NLS-1$ Map<ConnectorEnd, Integer> indexMap = new HashMap<ConnectorEnd, Integer>(); - for(Connector connector : implementation.getOwnedConnectors()) { - if(ConnectorUtil.isAssembly(connector)) { + for (Connector connector : implementation.getOwnedConnectors()) { + if (ConnectorUtil.isAssembly(connector)) { // Boolean associationBased = false; if (connector.getEnds().size() != 2) { - throw new TransformationException("Connector <" + connector.getName() + "> does not have two ends. This is currently not supported"); //$NON-NLS-1$ //$NON-NLS-2$ + throw new TransformationException( + "Connector <" + connector.getName() + "> does not have two ends. This is currently not supported"); //$NON-NLS-1$ //$NON-NLS-2$ } ConnectorEnd end1 = connector.getEnds().get(0); ConnectorEnd end2 = connector.getEnds().get(1); String cmd; - cmd = "// realization of connector <" + connector.getName() + ">\n"; //$NON-NLS-1$//$NON-NLS-2$ - if ((end1.getRole() instanceof Port) && PortUtils.isExtendedPort((Port) end1.getRole())) { + cmd = "// realization of connector <" + connector.getName() + ">\n"; //$NON-NLS-1$//$NON-NLS-2$ + if ((end1.getRole() instanceof Port) + && PortUtils.isExtendedPort((Port) end1.getRole())) { Port port = (Port) end1.getRole(); - EList<PortInfo> subPorts = PortUtils.flattenExtendedPort(port); + EList<PortInfo> subPorts = PortUtils + .flattenExtendedPort(port); for (PortInfo subPort : subPorts) { - cmd += " // realization of connection for sub-port " + subPort.getPort().getName() + "\n"; //$NON-NLS-1$//$NON-NLS-2$ - cmd += connectPorts(indexMap, connector, end1, end2, subPort.getPort()); - cmd += connectPorts(indexMap, connector, end2, end1, subPort.getPort()); + cmd += " // realization of connection for sub-port " + subPort.getPort().getName() + "\n"; //$NON-NLS-1$//$NON-NLS-2$ + cmd += connectPorts(indexMap, connector, end1, end2, + subPort.getPort()); + cmd += connectPorts(indexMap, connector, end2, end1, + subPort.getPort()); } - } - else { + } else { cmd += connectPorts(indexMap, connector, end1, end2, null); cmd += connectPorts(indexMap, connector, end2, end1, null); } @@ -351,12 +415,13 @@ public class CompImplTrafos { } } // TODO: use template, as in bootloader - if(createConnBody.length() > 0) { - Operation operation = implementation.createOwnedOperation("createConnections", null, null); //$NON-NLS-1$ + if (createConnBody.length() > 0) { + Operation operation = implementation.createOwnedOperation( + "createConnections", null, null); //$NON-NLS-1$ - OpaqueBehavior behavior = (OpaqueBehavior) - implementation.createOwnedBehavior("b:" + operation.getName(), //$NON-NLS-1$ - UMLPackage.eINSTANCE.getOpaqueBehavior()); + OpaqueBehavior behavior = (OpaqueBehavior) implementation + .createOwnedBehavior("b:" + operation.getName(), //$NON-NLS-1$ + UMLPackage.eINSTANCE.getOpaqueBehavior()); behavior.getLanguages().add(progLang); behavior.getBodies().add(createConnBody); behavior.setSpecification(operation); @@ -364,100 +429,127 @@ public class CompImplTrafos { } /** - * Create a connection between the two ends of a receptacle. This function checks whether the first end really is - * a receptacle and the second really is a facet. - * @param indexMap a map of indices that are used in case of multiplex receptacles - * @param connector a connector - * @param receptacleEnd an end of the connector that may point to a receptacle port - * @param facetEnd an end of the connector that may point to a facet port - * @param subPort a sub-port in case of extended ports + * Create a connection between the two ends of a receptacle. This function + * checks whether the first end really is a receptacle and the second really + * is a facet. + * + * @param indexMap + * a map of indices that are used in case of multiplex + * receptacles + * @param connector + * a connector + * @param receptacleEnd + * an end of the connector that may point to a receptacle port + * @param facetEnd + * an end of the connector that may point to a facet port + * @param subPort + * a sub-port in case of extended ports * @return * @throws TransformationException */ - public static String connectPorts(Map<ConnectorEnd, Integer> indexMap, Connector connector, ConnectorEnd receptacleEnd, ConnectorEnd facetEnd, Port subPort) - throws TransformationException - { + public static String connectPorts(Map<ConnectorEnd, Integer> indexMap, + Connector connector, ConnectorEnd receptacleEnd, + ConnectorEnd facetEnd, Port subPort) throws TransformationException { Association association = connector.getType(); - if((receptacleEnd.getRole() instanceof Port) && (facetEnd.getRole() instanceof Port)) { + if ((receptacleEnd.getRole() instanceof Port) + && (facetEnd.getRole() instanceof Port)) { Port facetPort = (Port) facetEnd.getRole(); Port receptaclePort = (Port) receptacleEnd.getRole(); PortInfo facetPI = PortInfo.fromSubPort(facetPort, subPort); - PortInfo receptaclePI = PortInfo.fromSubPort(receptaclePort, subPort); + PortInfo receptaclePI = PortInfo.fromSubPort(receptaclePort, + subPort); - if((facetPI.getProvided() != null) && (receptaclePI.getRequired() != null)) { + if ((facetPI.getProvided() != null) + && (receptaclePI.getRequired() != null)) { Property facetPart = facetEnd.getPartWithPort(); Property receptaclePart = receptacleEnd.getPartWithPort(); - + String subPortName = (subPort != null) ? "_" + subPort.getName() : ""; //$NON-NLS-1$ //$NON-NLS-2$ - String indexName = getIndexName(indexMap, receptaclePort, receptacleEnd); - String setter = receptaclePart.getName() + refOp(receptaclePart) + "connect_" + receptaclePort.getName() + subPortName; //$NON-NLS-1$ - String getter = facetPart.getName() + refOp(facetPart) + "get_" + facetPort.getName() + subPortName + "()"; //$NON-NLS-1$ //$NON-NLS-2$ + String indexName = getIndexName(indexMap, receptaclePort, + receptacleEnd); + String setter = receptaclePart.getName() + + refOp(receptaclePart) + + "connect_" + receptaclePort.getName() + subPortName; //$NON-NLS-1$ + String getter = facetPart.getName() + refOp(facetPart) + + "get_" + facetPort.getName() + subPortName + "()"; //$NON-NLS-1$ //$NON-NLS-2$ return setter + "(" + indexName + getter + ");\n"; //$NON-NLS-1$ //$NON-NLS-2$ } - - } - else if(receptacleEnd.getRole() instanceof Port) { + + } else if (receptacleEnd.getRole() instanceof Port) { // only the receptacle end is of type port. Port receptaclePort = (Port) receptacleEnd.getRole(); - if(PortUtils.getRequired(receptaclePort) != null) { + if (PortUtils.getRequired(receptaclePort) != null) { Property facetPart = (Property) facetEnd.getRole(); Property receptaclePart = facetEnd.getPartWithPort(); - - String indexName = getIndexName(indexMap, receptaclePort, receptacleEnd); - String setter = receptaclePart.getName() + refOp(receptaclePart) + "connect_" + receptaclePort.getName(); //$NON-NLS-1$ - String getter = facetPart.getName() + refOp(facetPart) + facetPart.getName(); + + String indexName = getIndexName(indexMap, receptaclePort, + receptacleEnd); + String setter = receptaclePart.getName() + + refOp(receptaclePart) + + "connect_" + receptaclePort.getName(); //$NON-NLS-1$ + String getter = facetPart.getName() + refOp(facetPart) + + facetPart.getName(); return setter + "(" + indexName + getter + ");\n"; //$NON-NLS-1$ //$NON-NLS-2$ } - } - else if(facetEnd.getRole() instanceof Port) { + } else if (facetEnd.getRole() instanceof Port) { // only the receptacle end is of type port. Port facetPort = (Port) facetEnd.getRole(); - if(PortUtils.getProvided(facetPort) != null) { + if (PortUtils.getProvided(facetPort) != null) { Property facetPart = facetEnd.getPartWithPort(); Property receptaclePart = (Property) facetEnd.getRole(); - + String setter = receptaclePart.getName(); - String getter = facetPart.getName() + refOp(facetPart) + "get_" + facetPort.getName() + " ()"; //$NON-NLS-1$ //$NON-NLS-2$ + String getter = facetPart.getName() + refOp(facetPart) + + "get_" + facetPort.getName() + " ()"; //$NON-NLS-1$ //$NON-NLS-2$ return setter + " = " + getter + ";\n"; //$NON-NLS-1$ //$NON-NLS-2$ } - } - else if(association != null) { - // both connector ends do not target ports. In this case, we require that the connector is typed - // with an association. We use this association to find out which end is navigable and assume that - // the part pointed to by the other end is a pointer that gets initialized with the part of the + } else if (association != null) { + // both connector ends do not target ports. In this case, we require + // that the connector is typed + // with an association. We use this association to find out which + // end is navigable and assume that + // the part pointed to by the other end is a pointer that gets + // initialized with the part of the // navigable end. Property facetPart = (Property) facetEnd.getRole(); Property receptaclePart = (Property) receptacleEnd.getRole(); - - Property assocProp1 = association.getMemberEnd(null, facetPart.getType()); + + Property assocProp1 = association.getMemberEnd(null, + facetPart.getType()); // Property assocProp2 = facetPart.getOtherEnd(); - if((assocProp1 != null) && assocProp1.isNavigable()) { - String setter = receptaclePart.getName() + refOp(receptaclePart)+ assocProp1.getName(); + if ((assocProp1 != null) && assocProp1.isNavigable()) { + String setter = receptaclePart.getName() + + refOp(receptaclePart) + assocProp1.getName(); String getter = "&" + facetPart.getName(); //$NON-NLS-1$ return setter + " = " + getter + ";\n"; //$NON-NLS-1$ //$NON-NLS-2$ } - } - else { + } else { // not handled (a connector not targeting a port must be typed) - throw new TransformationException("Connector <" + connector.getName() + //$NON-NLS-1$ - "> does not use ports, but it is not typed (only connectors between ports should not be typed)"); //$NON-NLS-1$ + throw new TransformationException( + "Connector <" + connector.getName() + //$NON-NLS-1$ + "> does not use ports, but it is not typed (only connectors between ports should not be typed)"); //$NON-NLS-1$ } return ""; //$NON-NLS-1$ } - + /** - * Handle ports with multiplicity > 1. The idea is that we could have multiple connections targeting a receptacle. - * The first connection would start with index 0. Implementations can make no assumption which connection is associated - * with a certain index. [want to avoid associative array in runtime]. + * Handle ports with multiplicity > 1. The idea is that we could have + * multiple connections targeting a receptacle. The first connection would + * start with index 0. Implementations can make no assumption which + * connection is associated with a certain index. [want to avoid associative + * array in runtime]. + * * @param port * @param end * @return */ - public static String getIndexName (Map<ConnectorEnd, Integer> indexMap, Port port, ConnectorEnd end) { - if((port.getUpper() > 1) || (port.getUpper() == -1)) { - // index depends of combination of property and port, use connector end as key + public static String getIndexName(Map<ConnectorEnd, Integer> indexMap, + Port port, ConnectorEnd end) { + if ((port.getUpper() > 1) || (port.getUpper() == -1)) { + // index depends of combination of property and port, use connector + // end as key Integer indexValue = indexMap.get(end); - if(indexValue == null) { + if (indexValue == null) { indexValue = 0; indexMap.put(end, indexValue); } @@ -465,67 +557,70 @@ public class CompImplTrafos { indexValue++; indexMap.put(end, indexValue); return index; - } + } return ""; //$NON-NLS-1$ - } - + } + public static void deleteConnectors(Package pkg) { - Iterator<PackageableElement> elements = pkg.getPackagedElements().iterator(); - while(elements.hasNext()) { + Iterator<PackageableElement> elements = pkg.getPackagedElements() + .iterator(); + while (elements.hasNext()) { PackageableElement element = elements.next(); - if(element instanceof Package) { - deleteConnectors((Package)element); - } else if(element instanceof Class) { - Class implementation = (Class)element; + if (element instanceof Package) { + deleteConnectors((Package) element); + } else if (element instanceof Class) { + Class implementation = (Class) element; implementation.getOwnedConnectors().clear(); } } } /** - * Return true, if the bootloader is responsible for the instantiation of a part. - * [Structual difference: bootloader can decide instance based - and instances are deployed] + * Return true, if the bootloader is responsible for the instantiation of a + * part. [Structual difference: bootloader can decide instance based - and + * instances are deployed] * - * If a part is a component type or an abstract implementation, it cannot be instantiated. Thus, a heir - * has to be selected in the deployment plan. Since the selection might be different for different instances - * of the composite, the instantiation is not done by the component itself, but by the bootloader. - * The bootloader also has to instantiate, if different allocation variants are required. - * (this is for instance the case for distribution connectors and for the system itself) + * If a part is a component type or an abstract implementation, it cannot be + * instantiated. Thus, a heir has to be selected in the deployment plan. + * Since the selection might be different for different instances of the + * composite, the instantiation is not done by the component itself, but by + * the bootloader. The bootloader also has to instantiate, if different + * allocation variants are required. (this is for instance the case for + * distribution connectors and for the system itself) * - * If possible, we want to let composites instantiate sub-components, since this eases - * the transition to systems which support reconfiguration. + * If possible, we want to let composites instantiate sub-components, since + * this eases the transition to systems which support reconfiguration. * - * [TODO: optimization: analyze whether the deployment plan selects a single implementation. If yes, let the - * composite instantiate] + * [TODO: optimization: analyze whether the deployment plan selects a single + * implementation. If yes, let the composite instantiate] * - * [TODO: elements within an assembly need to be instantiated by composite - if System - by bootloader. - * assembly also need to be instantiated by composite!! + * [TODO: elements within an assembly need to be instantiated by composite - + * if System - by bootloader. assembly also need to be instantiated by + * composite!! * * @param implementation * @return */ public static boolean instantiateViaBootloader(Class implementation) { - return - implementation.isAbstract() || - Utils.isAssembly(implementation); + return implementation.isAbstract() || Utils.isAssembly(implementation); } /** - * Return whether a part needs to be instantiated by the bootloader instead by the - * composite in which it is contained. The criteria is based on the question whether - * the containing composite is flattened, as it is the case for the system - * component and the interaction components for distribution. + * Return whether a part needs to be instantiated by the bootloader instead + * by the composite in which it is contained. The criteria is based on the + * question whether the containing composite is flattened, as it is the case + * for the system component and the interaction components for distribution. + * * @param part * @return */ public static boolean instantiateViaBootloader(StructuralFeature part) { - if(part != null) { - if(part.getType() instanceof Class) { - Class implementation = (Class)part.getType(); + if (part != null) { + if (part.getType() instanceof Class) { + Class implementation = (Class) part.getType(); // TODO: wrong criteria? (must be shared or not?) return instantiateViaBootloader(implementation); - } - else { + } else { // not a class, assume primitive type instantiated by composite return false; } @@ -534,15 +629,40 @@ public class CompImplTrafos { } /** - * return the operator for (de-) referencing a part. If the part is instantiate via the - * bootloader, it becomes a pointer. If it is instantiated by the composite itself, - * it is not a pointer, it will be instantiated along with the composite + * return the operator for (de-) referencing a part. If the part is + * instantiate via the bootloader, it becomes a pointer. If it is + * instantiated by the composite itself, it is not a pointer, it will be + * instantiated along with the composite * * @param part * @return */ protected static String refOp(Property part) { - return ((part.getAggregation() == AggregationKind.SHARED_LITERAL) || StereotypeUtil.isApplied(part, Ptr.class)) ? - "->" : "."; //$NON-NLS-1$ //$NON-NLS-2$ + return ((part.getAggregation() == AggregationKind.SHARED_LITERAL) || StereotypeUtil + .isApplied(part, Ptr.class)) ? "->" : "."; //$NON-NLS-1$ //$NON-NLS-2$ + } + + public static void transform(Class bootloader2, LazyCopier targetCopy, + Model genModel, boolean OOmodel) throws TransformationException { + // 2c: add get_p/connect_q operations + // caveat: may modify imported classes + CompImplTrafos.bootloader = bootloader2; + CompImplTrafos.addPortOperations(targetCopy, genModel); + + if (OOmodel) { + // 3: component -> OO transformations related to ports: + // complete port access operations + // (get<PortName>/connect<PortName> and + // remove the ports afterwards + CompTypeTrafos.completeAccessOps(genModel); + CompTypeTrafos.removePorts(genModel); + } + + // 4: remove connectors from implementations, since their + // endpoint's roles + // have disappeared during step 4b (targeted ports have been + // deleted together with the types). + CompImplTrafos.deleteConnectors(genModel); + } } diff --git a/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/transformations/ConnectorReification.java b/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/transformations/ConnectorReification.java index 3b46d557aa9..7583049239f 100644 --- a/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/transformations/ConnectorReification.java +++ b/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/transformations/ConnectorReification.java @@ -110,7 +110,7 @@ public class ConnectorReification { /** * - * @param copy + * @param copier * @param tmComponent * @param smConnectorPart * Part representing the connector @@ -122,7 +122,7 @@ public class ConnectorReification { * connector * @throws TransformationException */ - public static Property reifyConnector(Copy copy, Class tmComponent, + public static Property reifyConnector(LazyCopier copier, Class tmComponent, Property smConnectorPart, InstanceSpecification tmIS, Object[] args) throws TransformationException { // 1st step: create part for the connector without actually changing the type. @@ -143,14 +143,14 @@ public class ConnectorReification { Class connectorImplem; if(binding != null) { - TemplateUtils.adaptActualsToTargetModel(copy, binding); - TemplateInstantiation ti = new TemplateInstantiation(copy, binding, args); + TemplateUtils.adaptActualsToTargetModel(copier, binding); + TemplateInstantiation ti = new TemplateInstantiation(copier, binding, args); connectorImplem = (Class)ti.bindNamedElement(connectorImplemTemplate); } else { // no binding, class is not a template => copy as it is - connectorImplem = copy.getCopy(connectorImplemTemplate); + connectorImplem = copier.getCopy(connectorImplemTemplate); } - Property tmConnectorPart = copy.getCopy(smConnectorPart); + Property tmConnectorPart = copier.getCopy(smConnectorPart); tmConnectorPart.setType(connectorImplem); // now re-target connectors towards this part TemplateUtils.retargetConnectors(tmComponent, tmConnectorPart); @@ -160,8 +160,8 @@ public class ConnectorReification { /** * Reify a connector * - * @param copy - * The copy obect (from source to target mode) + * @param copier + * The coper from source to target mode * @param tmComponent * containing composite in target target * @param name @@ -173,11 +173,11 @@ public class ConnectorReification { * (the part typed with the instantiated interaction component) should be created. * The instance is only used to find a suitable implementation. * @param args - * addtion args for the Acceleo transformation + * additional arguments for the Acceleo transformation * @return the created part within tmComponent * @throws TransformationException */ - public static Property reifyConnector(Copy copy, Class tmComponent, + public static Property reifyConnector(LazyCopier copier, Class tmComponent, String name, Connector smConnector, InstanceSpecification tmIS, Object[] args) throws TransformationException { @@ -197,17 +197,17 @@ public class ConnectorReification { Class connectorImplem; if(binding != null) { - TemplateUtils.adaptActualsToTargetModel(copy, binding); + TemplateUtils.adaptActualsToTargetModel(copier, binding); // make copy of bound package and restore it later. Required for nested template instantiations, in particular // the bound package is set within container transformations and is (by default) restored to "null" afterwards. // TODO: TemplateInstantiation should do this automatically - copy.pushPackageTemplate(); - TemplateInstantiation ti = new TemplateInstantiation(copy, binding, args); + copier.pushPackageTemplate(); + TemplateInstantiation ti = new TemplateInstantiation(copier, binding, args); connectorImplem = (Class)ti.bindNamedElement(connectorImplemTemplate); - copy.popPackageTemplate(); + copier.popPackageTemplate(); } else { // no binding, class is not a template => copy as it is - connectorImplem = copy.getCopy(connectorImplemTemplate); + connectorImplem = copier.getCopy(connectorImplemTemplate); } if(connectorImplem == null) { @@ -218,7 +218,7 @@ public class ConnectorReification { Property tmConnectorPart = tmComponent.createOwnedAttribute(name, connectorImplemTemplate); // copy id, but prefix it with "p" (for part) - Copy.copyID(smConnector, tmConnectorPart, "p"); //$NON-NLS-1$ + LazyCopier.copyID(smConnector, tmConnectorPart, "p"); //$NON-NLS-1$ tmConnectorPart.setIsComposite(true); Log.log(Status.INFO, Log.TRAFO_CONNECTOR, @@ -230,7 +230,7 @@ public class ConnectorReification { for(ConnectorEnd smEnd : smConnector.getEnds()) { Connector tmConnector = tmComponent.createOwnedConnector("c " //$NON-NLS-1$ + name + " " + String.valueOf(i)); //$NON-NLS-1$ - Copy.copyID(smConnector, tmConnector); + LazyCopier.copyID(smConnector, tmConnector); i++; // the new connector connects the existing end with an end of the // reified connector (the newly created property.) @@ -239,9 +239,9 @@ public class ConnectorReification { // non-connector part) ConnectorEnd tmEnd1 = tmConnector.createEnd(); Property smPartWithPort = smEnd.getPartWithPort(); - Property tmPartWithPort = copy.getCopy(smPartWithPort); + Property tmPartWithPort = copier.getCopy(smPartWithPort); ConnectableElement smRole = smEnd.getRole(); - ConnectableElement tmRole = copy.getCopy(smRole); + ConnectableElement tmRole = copier.getCopy(smRole); tmEnd1.setPartWithPort(tmPartWithPort); tmEnd1.setRole(tmRole); diff --git a/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/transformations/ContainerTrafo.java b/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/transformations/ContainerTrafo.java index 20927702bed..a7faefb946f 100644 --- a/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/transformations/ContainerTrafo.java +++ b/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/transformations/ContainerTrafo.java @@ -84,8 +84,8 @@ public class ContainerTrafo extends AbstractContainerTrafo { * @param tmCDP * deployment plan within target model */ - public ContainerTrafo(Copy copy, Package tmCDP, InstanceSpecification executorIS) { - this.copy = copy; + public ContainerTrafo(LazyCopier copier, Package tmCDP, InstanceSpecification executorIS) { + this.copier = copier; this.tmCDP = tmCDP; this.executorIS = executorIS; portInfo = new HashMap<Property, Port>(); @@ -121,11 +121,11 @@ public class ContainerTrafo extends AbstractContainerTrafo { if (isSingleton) { StereotypeUtil.apply(tmContainerImpl, Singleton.class); } - Copy.copyID(tmComponent, tmContainerImpl, containerPostfix); + LazyCopier.copyID(tmComponent, tmContainerImpl, containerPostfix); // add part and slot corresponding to component; executorPart = tmContainerImpl.createOwnedAttribute(executorPartName, tmComponent); - Copy.copyID(tmComponent, executorPart, "e"); //$NON-NLS-1$ + LazyCopier.copyID(tmComponent, executorPart, "e"); //$NON-NLS-1$ executorPart.setIsComposite(true); @@ -142,7 +142,7 @@ public class ContainerTrafo extends AbstractContainerTrafo { // create delegation for application port Connector containerDelegation = tmContainerImpl.createOwnedConnector("delegation " + port.getName()); //$NON-NLS-1$ - Copy.copyID(tmContainerImpl, containerDelegation); + LazyCopier.copyID(tmContainerImpl, containerDelegation); ConnectorEnd end1 = containerDelegation.createEnd(); end1.setRole(newPort); ConnectorEnd end2 = containerDelegation.createEnd(); @@ -175,7 +175,7 @@ public class ContainerTrafo extends AbstractContainerTrafo { public void createHwContainer(Class tmComponent) throws TransformationException { Package tmPkgOwner = (Package)tmComponent.getOwner(); tmContainerImpl = tmPkgOwner.createOwnedClass(tmComponent.getName() + hwContainerPostfix, false); - Copy.copyID(tmComponent, tmContainerImpl, hwContainerPostfix); + LazyCopier.copyID(tmComponent, tmContainerImpl, hwContainerPostfix); // register created container containers.put(tmComponent, this); @@ -262,7 +262,7 @@ public class ContainerTrafo extends AbstractContainerTrafo { slotCopy.setDefiningFeature(slot.getDefiningFeature()); // copy values (use CopyTo.copyTo(slot, containerIS) instead?) for (ValueSpecification value : slot.getValues()) { - Copy.copyValue(value, slotCopy); + LazyCopier.copyValue(value, slotCopy); } } return containerIS; @@ -333,9 +333,9 @@ public class ContainerTrafo extends AbstractContainerTrafo { Property extensionPart = expandAggregationExtension(part, extOrInterceptor, tmComponent); // register relation to facilitate connector copy - copy.setPackageTemplate(smContainerRule.getBase_Class(), tmContainerImpl); - copy.putPair(part, extensionPart); - copy.setPackageTemplate(null, null); + copier.setPackageTemplate(smContainerRule.getBase_Class(), tmContainerImpl); + copier.putPair(part, extensionPart); + copier.setPackageTemplate(null, null); } } } @@ -347,7 +347,7 @@ public class ContainerTrafo extends AbstractContainerTrafo { // the types of the referenced parts). // [main issue here: properties of container rule are not copies in the sense of identical // copies] - copy.setPackageTemplate(smContainerRule.getBase_Class(), tmContainerImpl); + copier.setPackageTemplate(smContainerRule.getBase_Class(), tmContainerImpl); for(Connector connector : smContainerRule.getBase_Class().getOwnedConnectors()) { Property ruleInterceptorPart = null; @@ -364,25 +364,25 @@ public class ContainerTrafo extends AbstractContainerTrafo { for(Property interceptorPart : interceptorPartsMap.get(ruleInterceptorPart)) { // map an interceptor part within rule successively to to an interceptor part // within the container - copy.putPair(ruleInterceptorPart, interceptorPart); - copy.removeForCopy(connector); - copy.getCopy(connector); + copier.putPair(ruleInterceptorPart, interceptorPart); + copier.removeForCopy(connector); + copier.getCopy(connector); } } else { // check whether FCM connector org.eclipse.papyrus.FCM.Connector fcmConn = StUtils.getConnector(connector); if(fcmConn != null) { - ConnectorReification.reifyConnector(copy, tmContainerImpl, + ConnectorReification.reifyConnector(copier, tmContainerImpl, UMLTool.varName(connector), connector, executorIS, null); } else { - copy.remove(connector); - copy.getCopy(connector); + copier.remove(connector); + copier.getCopy(connector); } } } - copy.setPackageTemplate(null, null); + copier.setPackageTemplate(null, null); TemplateUtils.retargetConnectors(tmContainerImpl); } @@ -401,7 +401,7 @@ public class ContainerTrafo extends AbstractContainerTrafo { TemplateSignature signature = TemplateUtils.getSignature(smContainerExtImpl); if(signature == null) { // no template signature, just copy the container extension into the target model - tmContainerExtImpl = copy.getCopy(smContainerExtImpl); + tmContainerExtImpl = copier.getCopy(smContainerExtImpl); } else { // template signature found, instantiate container extension via template binding mechanism @@ -417,9 +417,9 @@ public class ContainerTrafo extends AbstractContainerTrafo { } // template signature and instantiate container extension via the // template binding mechanism, use executor component as actual - TemplateBinding binding = TemplateUtils.fixedBinding(copy.target, smContainerExtImpl, actual); + TemplateBinding binding = TemplateUtils.fixedBinding(copier.target, smContainerExtImpl, actual); Object[] args = new Object[]{}; - TemplateInstantiation ti = new TemplateInstantiation(copy, binding, args); + TemplateInstantiation ti = new TemplateInstantiation(copier, binding, args); tmContainerExtImpl = (Class)ti.bindNamedElement(smContainerExtImpl); } @@ -441,7 +441,7 @@ public class ContainerTrafo extends AbstractContainerTrafo { throw new TransformationException(Messages.ContainerTrafo_RecursiveLWnotSupported); } else { - containerTrafo = new ContainerTrafo(copy, tmCDP, null); + containerTrafo = new ContainerTrafo(copier, tmCDP, null); } containerTrafo.createContainer(smContainerExtImpl, tmContainerExtImpl); } @@ -463,8 +463,8 @@ public class ContainerTrafo extends AbstractContainerTrafo { // Copy.copyID(tmComponent, extensionPart, "a"); extensionPart.setAggregation(smExtensionPart.getAggregation()); - Copy.copyMultElemModifiers(smExtensionPart, extensionPart); - Copy.copyFeatureModifiers(smExtensionPart, extensionPart); + LazyCopier.copyMultElemModifiers(smExtensionPart, extensionPart); + LazyCopier.copyFeatureModifiers(smExtensionPart, extensionPart); return extensionPart; } @@ -547,7 +547,7 @@ public class ContainerTrafo extends AbstractContainerTrafo { Object[] args = new Object[]{ executorIS, port }; TransformationContext.instance = executorIS; TransformationContext.port = port; - connectorPart = ConnectorReification.reifyConnector(copy, tmContainerImpl, UMLTool.varName(interceptionConnector), interceptionConnector, executorIS, args); + connectorPart = ConnectorReification.reifyConnector(copier, tmContainerImpl, UMLTool.varName(interceptionConnector), interceptionConnector, executorIS, args); connectorParts.add(connectorPart); TransformationContext.port = null; portInfo.put(connectorPart, port); diff --git a/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/transformations/InstantiateDepPlan.java b/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/transformations/InstantiateDepPlan.java index a1e27391ee8..117c7e86d26 100644 --- a/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/transformations/InstantiateDepPlan.java +++ b/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/transformations/InstantiateDepPlan.java @@ -27,7 +27,6 @@ import org.eclipse.emf.ecore.impl.MinimalEObjectImpl; import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.papyrus.FCM.Configuration; -import org.eclipse.papyrus.FCM.DeploymentPlan; import org.eclipse.papyrus.FCM.util.MapUtil; import org.eclipse.papyrus.acceleo.AcceleoDriver; import org.eclipse.papyrus.qompass.designer.core.Log; @@ -47,31 +46,25 @@ import org.eclipse.papyrus.qompass.designer.core.extensions.InstanceConfigurator import org.eclipse.papyrus.qompass.designer.core.extensions.LanguageSupport; import org.eclipse.papyrus.qompass.designer.core.generate.GenerateCode; import org.eclipse.papyrus.qompass.designer.core.generate.GenerationOptions; -import org.eclipse.papyrus.qompass.designer.core.templates.InstantiateCppIncludeWOB; -import org.eclipse.papyrus.qompass.designer.core.transformations.filters.FilterComments; import org.eclipse.papyrus.qompass.designer.core.transformations.filters.FilterRuleApplication; import org.eclipse.papyrus.qompass.designer.core.transformations.filters.FilterStateMachines; import org.eclipse.papyrus.qompass.designer.core.transformations.filters.FilterTemplate; -import org.eclipse.papyrus.uml.tools.utils.StereotypeUtil; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; import org.eclipse.uml2.uml.Classifier; -import org.eclipse.uml2.uml.Element; import org.eclipse.uml2.uml.InstanceSpecification; import org.eclipse.uml2.uml.Model; import org.eclipse.uml2.uml.NamedElement; import org.eclipse.uml2.uml.Package; import org.eclipse.uml2.uml.PackageableElement; import org.eclipse.uml2.uml.Profile; -import org.eclipse.uml2.uml.util.UMLUtil; /** * This class executes all transformations during the instantiation of a - * deployment plan, i.e. - * 1. The reification of connectors (including template instantiation). This transformation targets a new model - * 2. Adding get_p/connect_q operations to a class (transformation within same model) - * 3. Remove all component types - * 4. distribute to nodes + * deployment plan, i.e. 1. The reification of connectors (including template + * instantiation). This transformation targets a new model 2. Adding + * get_p/connect_q operations to a class (transformation within same model) 3. + * Remove all component types 4. distribute to nodes * * @author ansgar * @@ -79,302 +72,414 @@ import org.eclipse.uml2.uml.util.UMLUtil; public class InstantiateDepPlan { /** - * The location of the temporary model (relative to current project). - * TODO: make configurable? + * The location of the temporary model (relative to current project). TODO: + * make configurable? */ public static final String TEMP_MODEL_FOLDER = "tmpModel"; //$NON-NLS-1$ - + /** * Postfix of the temporary model (prefix = name of top-level package). * TODO: make configurable? */ public static final String TEMP_MODEL_POSTFIX = "Tmp.uml"; //$NON-NLS-1$ - - + /** - * Instantiate a deployment plan, i.e. generate an intermediate model via a sequence of transformations - * - * @param cdpOrConfig a deployment plan (UML package) or a configuration (UML class) - * @param monitor a progress monitor. - - * @param project the current project. This information is used to store the intermediate model in - * a subfolder (tmpModel) of the current project - * @param genOptions select whether to produce an intermediate model only, also code, ... @see GenerationOptions + * Progress monitor of Eclipse. */ - public static void instantiate(Element cdpOrConfig, IProgressMonitor monitor, IProject project, int genOptions) { - boolean OOmodel = true; - if(project == null) { - String projectName = cdpOrConfig.eResource().getURI().toString(); - project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName); + protected IProgressMonitor monitor = null; + + protected int generationOptions; + + protected boolean generateCode; + + protected boolean generateCACOnly; + + protected Package srcModelComponentDeploymentPlan = null; + + protected Configuration configuration = null; + + protected IProject project; + + protected boolean modelIsObjectOriented = true; + + public void instantiate(Configuration configuration, + IProgressMonitor monitor, IProject project, int genOptions) { + this.configuration = configuration; + srcModelComponentDeploymentPlan = configuration + .getDeploymentPlan().getBase_Package(); + // + if (srcModelComponentDeploymentPlan == null) { + String message = String + .format(Messages.InstantiateDepPlan_DepPlanStereotypeNotInitialized, + configuration.getBase_Class().getName()); + displayError(Messages.InstantiateDepPlan_TransformationException, + message); } - Model tmpModel = null; - ModelManagement tmpMM = null; - - boolean generateCode = (genOptions & GenerationOptions.MODEL_ONLY) == 0; - boolean generateCACOnly = (genOptions & GenerationOptions.CAC_ONLY) != 0; - - AcceleoDriver.clearErrors(); - Package smCDP; - Configuration configuration = null; - if(cdpOrConfig instanceof Package) { - smCDP = (Package)cdpOrConfig; - RuleManagement.setConfiguration(null); + + this.project = project; + if (project == null) { + String projectName = configuration.getBase_Class().eResource() + .getURI().toString(); + this.project = ResourcesPlugin.getWorkspace().getRoot() + .getProject(projectName); } - else if(StereotypeUtil.isApplied(cdpOrConfig, Configuration.class)) { - configuration = UMLUtil.getStereotypeApplication(cdpOrConfig, Configuration.class); - DeploymentPlan fcmCDP = configuration.getDeploymentPlan(); - if(fcmCDP == null) { - final NamedElement config = (NamedElement)cdpOrConfig; - Display.getDefault().syncExec(new Runnable() { - - public void run() { - Shell shell = new Shell(); - MessageDialog.openError(shell, Messages.InstantiateDepPlan_CannotGenModel, - String.format(Messages.InstantiateDepPlan_DepPlanStereotypeNotInitialized, config.getName())); - } - }); - return; - } - smCDP = fcmCDP.getBase_Package(); - RuleManagement.setConfiguration(configuration); - } else { - return; + // + instantiate(monitor, genOptions); + } + + public void instantiate(Package pkg, IProgressMonitor monitor, + IProject project, int genOptions) { + configuration = null; + srcModelComponentDeploymentPlan = pkg; + // + this.project = project; + if (project == null) { + String projectName = pkg.eResource().getURI().toString(); + this.project = ResourcesPlugin.getWorkspace().getRoot() + .getProject(projectName); } + // + instantiate(monitor, genOptions); + } + + /** + * Instantiate a deployment plan, i.e. generate an intermediate model via a + * sequence of transformations + * + * @param umlElement + * a deployment plan (UML package) or a configuration (UML class) + * @param monitor + * a progress monitor. + * + * @param project + * the current project. This information is used to store the + * intermediate model in a subfolder (tmpModel) of the current + * project + * @param genOptions + * select whether to produce an intermediate model only, also + * code, ... @see GenerationOptions + */ + private void instantiate(IProgressMonitor monitor, int genOptions) { try { - EnumService.init(); - InstanceSpecification rootIS = DepUtils.getMainInstance(smCDP); - // Package copyCDP = dt.getCopyCDT (selectedCDP); - - EList<InstanceSpecification> nodes = AllocUtils.getAllNodes(rootIS); - - // -- calc # of steps for progress monitor - // 1 (tmpModel creation) + 1 (reification) + 1 (tmpModel save) - // 5x on each deployed node (see below) - // problem? Connector reification is a single, relatively long step - int steps = 3; - steps += 5 * nodes.size(); - if(generateCode) { - steps += nodes.size(); - } - monitor.beginTask(Messages.InstantiateDepPlan_InfoGeneratingModel, steps); - if(monitor.isCanceled()) { - return; - } + initialize(monitor, genOptions); + AcceleoDriver.clearErrors(); + executeTransformation(); + } catch (AcceleoException e) { + displayError(Messages.InstantiateDepPlan_AcceleoErrors, + Messages.InstantiateDepPlan_AcceleoErrorsCheckLog); + } catch (final TransformationException e) { + printAndDisplayErrorMessage(e, + Messages.InstantiateDepPlan_TransformationException, false); + } catch (final Exception e) { + printAndDisplayErrorMessage(e, + Messages.InstantiateDepPlan_ErrorsDuringTransformation, + true); + } + } - // 1a: create a new model (and applies same profiles / imports) - Model existingModel = smCDP.getModel(); - TransformationContext.sourceRoot = existingModel; - tmpMM = createTargetModel(existingModel, monitor, existingModel.getName(), true); - tmpModel = tmpMM.getModel(); - // Declare that the new model is a derivedElement (kind of hack, since the source - // element (attribute of derive element) remains undefined). This is used to - // de-activate automatic transformations that should not be applied to the generated - // model. - monitor.worked(1); - if(monitor.isCanceled()) { - return; - } + private void initialize(IProgressMonitor monitor, int genOptions) + throws TransformationException { + this.monitor = monitor; + this.generationOptions = genOptions; + this.generateCode = (genOptions & GenerationOptions.MODEL_ONLY) == 0; + this.generateCACOnly = (genOptions & GenerationOptions.CAC_ONLY) != 0; - // LateEval.clear(); + RuleManagement.setConfiguration(configuration); + } - EnumService.createEnumPackage(tmpModel); + protected void executeTransformation() throws Exception { + modelIsObjectOriented = true; + ModelManagement intermediateModelManagement = null; + + InstanceSpecification mainInstance = DepUtils + .getMainInstance(srcModelComponentDeploymentPlan); + EList<InstanceSpecification> nodes = AllocUtils + .getAllNodes(mainInstance); + + initiateProgressMonitor(generateCode, nodes); + + // -------------------------------------------------------------------- + checkProgressStatus(); + // -------------------------------------------------------------------- + + // 1a: create a new model (and applies same profiles / imports) + Model existingModel = srcModelComponentDeploymentPlan.getModel(); + TransformationContext.sourceRoot = existingModel; + + intermediateModelManagement = createTargetModel(existingModel, + existingModel.getName(), true); + + // Declare that the new model is a derivedElement (kind of hack, + // since the source element (attribute of derive element) remains + // undefined). This is used to deactivate automatic transformations + // that should not be applied to the generated model. + + // -------------------------------------------------------------------- + checkProgressStatus(); + // -------------------------------------------------------------------- + + // get the temporary model + Model intermediateModel = intermediateModelManagement.getModel(); + + // create a package for global enumerations that are used by Acceleo code + EnumService.createEnumPackage(intermediateModel); + + // create a lazy copier towards the intermediate model + LazyCopier intermediateModelCopier = new LazyCopier(existingModel, intermediateModel, false, true); + // add pre-copy and post-copy listeners to the copier + intermediateModelCopier.preCopyListeners.add(FilterTemplate.getInstance()); + + // 1b: reify the connectors "into" the new model + monitor.subTask(Messages.InstantiateDepPlan_InfoExpandingConnectors); + + // obtain the component deployment plan in target model + Package intermediateModelComponentDeploymentPlan = (Package) intermediateModelCopier + .shallowCopy(srcModelComponentDeploymentPlan); + intermediateModelCopier.createShallowContainer(srcModelComponentDeploymentPlan); + + ContainerTrafo.init(); + InstanceConfigurator.onNodeModel = false; + MainModelTrafo mainModelTrafo = new MainModelTrafo(intermediateModelCopier, + intermediateModelComponentDeploymentPlan); + InstanceSpecification newMainInstance = mainModelTrafo + .transformInstance(mainInstance, null); + + // -------------------------------------------------------------------- + checkProgressStatus(); + // -------------------------------------------------------------------- + + TransformationUtil.applyInstanceConfigurators(newMainInstance); + + FlattenInteractionComponents.getInstance().flattenAssembly( + newMainInstance, null); + + TransformationUtil.propagateAllocation(newMainInstance); + + intermediateModelManagement.saveModel(project, TEMP_MODEL_FOLDER, + TEMP_MODEL_POSTFIX); + + // -------------------------------------------------------------------- + checkProgressStatus(); + // -------------------------------------------------------------------- + + if (!generateCACOnly) { + deployOnNodes(mainInstance, existingModel, intermediateModel, + newMainInstance); + } - Copy tmpCopy = new Copy(existingModel, tmpModel, false); - tmpCopy.preCopyListeners.add(FilterTemplate.getInstance()); - tmpCopy.preCopyListeners.add(FilterComments.getInstance()); - tmpCopy.postCopyListeners.add(InstantiateCppIncludeWOB.getInstance()); + intermediateModelManagement.dispose(); - Copy.copyID(existingModel, tmpModel); + if (AcceleoDriver.hasErrors()) { + throw new AcceleoException(); + } - // 1b: reify the connectors "into" the new model - monitor.subTask(Messages.InstantiateDepPlan_InfoExpandingConnectors); + } + + private void deployOnNodes(InstanceSpecification mainInstance, + Model existingModel, Model tmpModel, InstanceSpecification newRootIS) + throws TransformationException, InterruptedException { - // obtain reference to CDP in target model - // - tmpCopy.createShallowContainer(rootIS); - Package tmCDP = (Package)tmpCopy.get(smCDP); + // not deploy on each node + DepCreation.initAutoValues(newRootIS); - ContainerTrafo.init(); - InstanceConfigurator.onNodeModel = false; - MainModelTrafo mainModelTrafo = new MainModelTrafo(tmpCopy, tmCDP); - InstanceSpecification newRootIS = mainModelTrafo.transformInstance(rootIS, null); - monitor.worked(1); + EList<InstanceSpecification> nodes = AllocUtils.getAllNodes(newRootIS); + if (nodes.size() > 0) { + InstanceConfigurator.onNodeModel = true; + for (int nodeIndex = 0; nodeIndex < nodes.size(); nodeIndex++) { + InstanceSpecification node = nodes.get(nodeIndex); - // 1c: late bindings - // LateEval.bindLateOperations(); - // 3: distribute to nodes + deployNode(mainInstance, existingModel, tmpModel, newRootIS, + nodes, nodeIndex, node); + } + } else { + throw new TransformationException( + Messages.InstantiateDepPlan_InfoNoneAllocated); + } + } - // UpdateDerivedInterfaces.updateIntfs(newRootIS); - - ApplyInstanceConfigurators.applyInstanceConfigurators(newRootIS); + private void deployNode(InstanceSpecification mainInstance, + Model existingModel, Model tmpModel, + InstanceSpecification newRootIS, + EList<InstanceSpecification> nodes, int nodeIndex, + InstanceSpecification node) throws TransformationException, + InterruptedException { + ModelManagement genModelManagement = createTargetModel(existingModel, + MapUtil.rootModelName, false); + Model generatedModel = genModelManagement.getModel(); + + // -------------------------------------------------------------------- + checkProgressStatus(); + // -------------------------------------------------------------------- + + // new model has name "root" and contains a package with the + // existing model + // Package originalRoot = genModel.createNestedPackage + // (existingModel.getName ()); + LazyCopier targetCopy = new LazyCopier(tmpModel, generatedModel, true, true); + // TODO: distribution to nodes is currently not done. How + // can it be realized with a copy filter ? + targetCopy.preCopyListeners.add(FilterStateMachines.getInstance()); + targetCopy.preCopyListeners.add(FilterRuleApplication.getInstance()); + + monitor.setTaskName(String.format( + Messages.InstantiateDepPlan_InfoDeployingForNode, + node.getName())); + + ILangSupport langSupport = configureLanguageSupport(mainInstance, + existingModel, node); + + Deploy deployment = new Deploy(targetCopy, langSupport, node, + nodeIndex, nodes.size()); + InstanceSpecification nodeRootIS = deployment + .distributeToNode(newRootIS); + TransformationUtil.updateDerivedInterfaces(nodeRootIS); + + // -------------------------------------------------------------------- + checkProgressStatus(); + // -------------------------------------------------------------------- + + removeDerivedInterfacesInRoot(generatedModel); + + CompImplTrafos.transform( + deployment.getBootloader(), targetCopy, generatedModel, + modelIsObjectOriented); + + // -------------------------------------------------------------------- + checkProgressStatus(); + // -------------------------------------------------------------------- + + destroyDeploymentPlanFolder(generatedModel); + + if (generateCode) { + GenerateCode codeGenerator = new GenerateCode( + langSupport.getProject(), langSupport, genModelManagement, + monitor); + boolean option = (generationOptions & GenerationOptions.ONLY_CHANGED) != 0; + codeGenerator.generate(node, getTargetLanguage(mainInstance), + option); + } - FlattenInteractionComponents.getInstance().flattenAssembly(newRootIS, null); - - PropagateAllocationToSharedInstances.propagateAllocation(newRootIS); - - String tmpPath = tmpMM.getPath(project, TEMP_MODEL_FOLDER, tmpModel.getName() + TEMP_MODEL_POSTFIX); - tmpMM.saveModel(tmpPath); + genModelManagement.dispose(); + } - if(monitor.isCanceled()) { - return; + private ILangSupport configureLanguageSupport( + InstanceSpecification mainInstance, Model existingModel, + InstanceSpecification node) throws TransformationException { + ILangSupport langSupport = LanguageSupport + .getLangSupport(getTargetLanguage(mainInstance)); + langSupport.resetConfigurationData(); + + String modelName = getModelName(existingModel, node); + IProject genProject = ProjectManagement.getNamedProject(modelName); + if ((genProject == null) || !genProject.exists()) { + genProject = langSupport.createProject(modelName, node); + } else { + langSupport.setProject(genProject); + if ((generationOptions & GenerationOptions.REWRITE_SETTINGS) != 0) { + langSupport.setSettings(node); } - monitor.worked(1); + } + return langSupport; + } - if(!generateCACOnly) { - // not deploy on each node - DepCreation.initAutoValues(newRootIS); + private void destroyDeploymentPlanFolder(Model generatedModel) { + PackageableElement deploymentPlanFolder = generatedModel + .getPackagedElement(DeployConstants.depPlanFolderHw); + if (deploymentPlanFolder != null) { + deploymentPlanFolder.destroy(); + } + } - nodes = AllocUtils.getAllNodes(newRootIS); - if(nodes.size() == 0) { - throw new TransformationException(Messages.InstantiateDepPlan_InfoNoneAllocated); + private void removeDerivedInterfacesInRoot(Model generatedModel) { + // 2b: remove derived interfaces in root: derived interfaces + // that can not be placed in the same package as the port type (e.g. + // since read-only type from system library), are put in a top-level + // package called "derivedInterfaces". Due to the copying of imports, + // the top-level package has changed which implies that new derived + // interfaces are put into a different package and the derivedInterfaces + // package in the original root becomes obsolete. Delete this obsolete + // package, if existing. + for (PackageableElement packagedElement : generatedModel + .getPackagedElements()) { + if (packagedElement instanceof Package) { + NamedElement derivedInterfaces = ((Package) packagedElement) + .getPackagedElement("derivedInterfaces"); //$NON-NLS-1$ + if (derivedInterfaces instanceof Package) { + derivedInterfaces.destroy(); } - int nodeIndex = 0; - Classifier cl = DepUtils.getClassifier(rootIS); - String targetLanguage = DepUtils.getLanguageFromPackage(cl.getNearestPackage()); - if (targetLanguage == null) { - targetLanguage = "C++"; //$NON-NLS-1$ - } - - InstanceConfigurator.onNodeModel = true; - for(InstanceSpecification node : nodes) { - String modelName = existingModel.getName() + "_" + node.getName(); //$NON-NLS-1$ - if(configuration != null) { - modelName += "_" + configuration.getBase_Class().getName(); //$NON-NLS-1$ - } else { - modelName += "_" + smCDP.getName(); //$NON-NLS-1$ - } - ModelManagement genMM = createTargetModel(existingModel, monitor, MapUtil.rootModelName, false); - Model genModel = genMM.getModel(); - - if(monitor.isCanceled()) { - return; - } - monitor.worked(1); - // new model has name "root" and contains a package with the - // existing model - // Package originalRoot = genModel.createNestedPackage - // (existingModel.getName ()); - Copy targetCopy = new Copy(tmpModel, genModel, true); - // TODO: distribution to nodes is currently not done. How can it be realized with a copy filter ? - targetCopy.preCopyListeners.add(FilterStateMachines.getInstance()); - targetCopy.preCopyListeners.add(FilterRuleApplication.getInstance()); - targetCopy.postCopyListeners.add(InstantiateCppIncludeWOB.getInstance()); - - monitor.setTaskName(String.format(Messages.InstantiateDepPlan_InfoDeployingForNode, node.getName())); - ILangSupport langSupport = LanguageSupport.getLangSupport(targetLanguage); - langSupport.resetConfigurationData(); - - Deploy deploy = new Deploy(targetCopy, langSupport, node, nodeIndex, nodes.size()); - InstanceSpecification nodeRootIS = deploy.distributeToNode(newRootIS); - UpdateDerivedInterfaces.updateIntfs(nodeRootIS); - - if(monitor.isCanceled()) { - return; - } - monitor.worked(1); - // 2b: remove derived interfaces in root: derived interfaces that can - // not be placed in the same package as the port type (e.g. since read-only - // type from system library), are put in a top-level package called "derivedInterfaces". - // Due to the copying of imports, the top-level package has changed which implies that new - // derived interfaces are put into a different package and the derivedInterfaces package in - // the original root becomes obsolete. Delete this obsolete package, if existing. - for (PackageableElement pe : genModel.getPackagedElements()) { - if (pe instanceof Package) { - NamedElement derivedInterfaces = ((Package) pe).getPackagedElement("derivedInterfaces"); //$NON-NLS-1$ - if(derivedInterfaces instanceof Package) { - derivedInterfaces.destroy(); - } - } - } - // 2c: add get_p/connect_q operations - // caveat: may modify imported classes - CompImplTrafos.bootloader = deploy.getBootloader(); - CompImplTrafos.addPortOperations(targetCopy, genModel); - - if(OOmodel) { - // 3: component -> OO transformations related to ports: - // complete port access operations - // (get<PortName>/connect<PortName> and - // remove the ports afterwards - CompTypeTrafos.completeAccessOps(genModel); - CompTypeTrafos.removePorts(genModel); - } - - // 4: remove connectors from implementations, since their endpoint's roles - // have disappeared during step 4b (targeted ports have been - // deleted together with the types). - CompImplTrafos.deleteConnectors(genModel); - if(monitor.isCanceled()) { - return; - } - monitor.worked(1); + } + } + } - PackageableElement depPlanFolder = genModel.getPackagedElement(DeployConstants.depPlanFolderHw); - if (depPlanFolder != null) { - depPlanFolder.destroy(); - } - IProject genProject = ProjectManagement.getNamedProject(modelName); - if((genProject == null) || !genProject.exists()) { - genProject = langSupport.createProject(modelName, node); - } - else { - langSupport.setProject(genProject); - if((genOptions & GenerationOptions.REWRITE_SETTINGS) != 0) { - langSupport.setSettings(node); - } - } + private String getModelName(Model existingModel, InstanceSpecification node) { + String modelName = existingModel.getName() + "_" + node.getName(); //$NON-NLS-1$ + if (configuration != null) { + modelName += "_" + configuration.getBase_Class().getName(); //$NON-NLS-1$ + } else { + modelName += "_" + srcModelComponentDeploymentPlan.getName(); //$NON-NLS-1$ + } + return modelName; + } - - if(generateCode) { - GenerateCode codeGen = new GenerateCode(genProject, langSupport, genMM, monitor); - codeGen.generate(node, targetLanguage, (genOptions & GenerationOptions.ONLY_CHANGED) != 0); - } + private String getTargetLanguage(InstanceSpecification mainInstance) { + Classifier cl = DepUtils.getClassifier(mainInstance); + String targetLanguage = DepUtils.getLanguageFromPackage(cl + .getNearestPackage()); + if (targetLanguage == null) { + targetLanguage = "C++"; //$NON-NLS-1$ + } + return targetLanguage; + } - nodeIndex++; - genMM.dispose(); - } - } - } catch (TransformationException te) { - // Get UI thread to show dialog - final TransformationException teFinal = te; - Display.getDefault().syncExec(new Runnable() { - - public void run() { - Shell shell = new Shell(); - MessageDialog.openError(shell, Messages.InstantiateDepPlan_TransformationException, teFinal.getMessage()); - } - }); - Log.log(Status.ERROR, Log.DEPLOYMENT, "", teFinal); //$NON-NLS-1$ - } catch (Exception e) { - final Exception eFinal = e; - e.printStackTrace(); - Display.getDefault().syncExec(new Runnable() { - - public void run() { - Shell shell = new Shell(); - String msg = eFinal.toString() + "\n\n" + //$NON-NLS-1$ - Messages.InstantiateDepPlan_ConsultConsole; - MessageDialog.openError(shell, Messages.InstantiateDepPlan_ErrorsDuringTransformation, msg); - } - }); - Log.log(Status.ERROR, Log.DEPLOYMENT, "", e); //$NON-NLS-1$ + private void initiateProgressMonitor(boolean generateCode, + EList<InstanceSpecification> nodes) { + // -- calc # of steps for progress monitor + // 1 (tmpModel creation) + 1 (reification) + 1 (tmpModel save) + // 5x on each deployed node (see below) + // problem? Connector reification is a single, relatively long step + int steps = 3; + steps += 5 * nodes.size(); + if (generateCode) { + steps += nodes.size(); } - if(tmpMM != null) { - tmpMM.dispose(); + monitor.beginTask(Messages.InstantiateDepPlan_InfoGeneratingModel, + steps); + } + + private void checkProgressStatus() throws InterruptedException { + if (monitor.isCanceled()) { + throw new InterruptedException(); } - if (AcceleoDriver.hasErrors()) { - Display.getDefault().syncExec(new Runnable() { - public void run() { - Shell shell = new Shell(); - MessageDialog.openInformation(shell, Messages.InstantiateDepPlan_AcceleoErrors, - Messages.InstantiateDepPlan_AcceleoErrorsCheckLog); - } - }); + monitor.worked(1); + } + + private void printAndDisplayErrorMessage(Exception e, final String title, + final boolean consultConsole) { + String message = e.toString(); //$NON-NLS-1$ + if (consultConsole) { + message = message + "\n\n" + + Messages.InstantiateDepPlan_ConsultConsole; } + printAndDisplayErrorMessage(e, title, message, consultConsole); } + private void printAndDisplayErrorMessage(Exception e, final String title, + final String message, final boolean consultConsole) { + e.printStackTrace(); + displayError(title, message); + Log.log(Status.ERROR, Log.DEPLOYMENT, "", e); //$NON-NLS-1$ + } + + private void displayError(final String title, final String message) { + Display.getDefault().syncExec(new Runnable() { + public void run() { + Shell shell = new Shell(); + MessageDialog.openInformation(shell, title, message); + } + }); + } /** * Create a new empty model from an existing model that applies the same @@ -383,83 +488,110 @@ public class InstantiateDepPlan { * @param existingModel * @return */ - public static ModelManagement createTargetModel(Model existingModel, IProgressMonitor monitor, String name, boolean copyImports) throws TransformationException { + public ModelManagement createTargetModel(Model existingModel, String name, + boolean copyImports) throws TransformationException { ModelManagement mm = new ModelManagement(); Model newModel = mm.getModel(); newModel.setName(name); try { // copy profile application - for(Profile profile : existingModel.getAppliedProfiles()) { + for (Profile profile : existingModel.getAppliedProfiles()) { // reload profile in resource of new model - monitor.subTask(Messages.InstantiateDepPlan_InfoApplyProfile + profile.getQualifiedName()); + monitor.subTask(Messages.InstantiateDepPlan_InfoApplyProfile + + profile.getQualifiedName()); - if(profile.eResource() == null) { + if (profile.eResource() == null) { String profileName = profile.getQualifiedName(); - if(profileName == null) { - if(profile instanceof MinimalEObjectImpl.Container) { - URI uri = ((MinimalEObjectImpl.Container)profile).eProxyURI(); - if(uri != null) { - throw new TransformationException(String.format(Messages.InstantiateDepPlan_CheckInputModelProfileNoRes, uri)); + if (profileName == null) { + if (profile instanceof MinimalEObjectImpl.Container) { + URI uri = ((MinimalEObjectImpl.Container) profile) + .eProxyURI(); + if (uri != null) { + throw new TransformationException( + String.format( + Messages.InstantiateDepPlan_CheckInputModelProfileNoRes, + uri)); } } - throw new TransformationException(Messages.InstantiateDepPlan_CheckInputModelProfileNoResNoName); + throw new TransformationException( + Messages.InstantiateDepPlan_CheckInputModelProfileNoResNoName); } - throw new TransformationException(String.format(Messages.InstantiateDepPlan_CheckInputModelProfile3, profileName)); + throw new TransformationException( + String.format( + Messages.InstantiateDepPlan_CheckInputModelProfile3, + profileName)); } Resource profileResource = null; try { - profileResource = ModelManagement.getResourceSet().getResource(profile.eResource().getURI(), true); + profileResource = ModelManagement.getResourceSet() + .getResource(profile.eResource().getURI(), true); } catch (WrappedException e) { - // read 2nd time (some diagnostic errors are raised only once) - Log.log(Status.WARNING, Log.DEPLOYMENT, "Warning: exception in profile.eResource() " + e.getMessage()); //$NON-NLS-1$ - profileResource = ModelManagement.getResourceSet().getResource(profile.eResource().getURI(), true); + // read 2nd time (some diagnostic errors are raised only + // once) + Log.log(Status.WARNING, + Log.DEPLOYMENT, + "Warning: exception in profile.eResource() " + e.getMessage()); //$NON-NLS-1$ + profileResource = ModelManagement.getResourceSet() + .getResource(profile.eResource().getURI(), true); } - Profile newProfileTop = (Profile)profileResource.getContents().get(0); + Profile newProfileTop = (Profile) profileResource.getContents() + .get(0); Profile newProfile; String qname = profile.getQualifiedName(); - if((qname != null) && qname.contains("::")) { //$NON-NLS-1$ + if ((qname != null) && qname.contains("::")) { //$NON-NLS-1$ // profile is a sub-profile within same resource // TODO: should Copy class copy profile applications? // Should be handled in shallowContainer class. - // if we put profile/newProfile pair into copy map, copy would find (and copy profile + // if we put profile/newProfile pair into copy map, copy + // would find (and copy profile // applications in sub-folders qname = qname.substring(qname.indexOf("::") + 2); //$NON-NLS-1$ - newProfile = (Profile)Utils.getQualifiedElement(newProfileTop, qname); - } - else { + newProfile = (Profile) Utils.getQualifiedElement( + newProfileTop, qname); + } else { newProfile = newProfileTop; } newProfile.getMember("dummy"); // force profile loading //$NON-NLS-1$ newModel.applyProfile(newProfile); } } catch (IllegalArgumentException e) { - throw new TransformationException(Messages.InstantiateDepPlan_IllegalArgumentDuringCopy + e.toString()); + throw new TransformationException( + Messages.InstantiateDepPlan_IllegalArgumentDuringCopy + + e.toString()); } - // copy imports (and load resources associated - TODO: might not be necessary) - // While this is useful in general, it implies that code for imported models - // has been generated and compiled (for the right target) into a library. This may be + // copy imports (and load resources associated - TODO: might not be + // necessary) + // While this is useful in general, it implies that code for imported + // models + // has been generated and compiled (for the right target) into a + // library. This may be // quite tedious, unless automatically managed. - // Therefore we do not activate this option in a first pass of the model transformations. - if(copyImports) { - for(Package importedPackage : existingModel.getImportedPackages()) { - if(importedPackage == null) { - throw new TransformationException(Messages.InstantiateDepPlan_CheckInputImportPkg); + // Therefore we do not activate this option in a first pass of the model + // transformations. + if (copyImports) { + for (Package importedPackage : existingModel.getImportedPackages()) { + if (importedPackage == null) { + throw new TransformationException( + Messages.InstantiateDepPlan_CheckInputImportPkg); } - if(importedPackage.eResource() == null) { + if (importedPackage.eResource() == null) { String errorMsg = Messages.InstantiateDepPlan_CheckInputImportPkgNoRes; - if(importedPackage instanceof MinimalEObjectImpl.Container) { - URI uri = ((MinimalEObjectImpl.Container)importedPackage).eProxyURI(); - if(uri != null) { + if (importedPackage instanceof MinimalEObjectImpl.Container) { + URI uri = ((MinimalEObjectImpl.Container) importedPackage) + .eProxyURI(); + if (uri != null) { errorMsg += " - URI: " + uri.devicePath(); //$NON-NLS-1$ } } throw new TransformationException(errorMsg); } newModel.createPackageImport(importedPackage); - monitor.subTask(String.format(Messages.InstantiateDepPlan_InfoImportPackage, importedPackage.getName())); + monitor.subTask(String.format( + Messages.InstantiateDepPlan_InfoImportPackage, + importedPackage.getName())); try { importedPackage.eResource().load(null); diff --git a/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/transformations/LWContainerTrafo.java b/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/transformations/LWContainerTrafo.java index 75b169e87ab..46c96e53786 100644 --- a/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/transformations/LWContainerTrafo.java +++ b/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/transformations/LWContainerTrafo.java @@ -74,8 +74,8 @@ public class LWContainerTrafo extends AbstractContainerTrafo { * @param tmCDP * deployment plan within target model */ - public LWContainerTrafo(Copy copy, Package tmCDP) { - this.copy = copy; + public LWContainerTrafo(LazyCopier copy, Package tmCDP) { + this.copier = copy; this.tmCDP = tmCDP; interceptionOpMap = new HashMap<Operation, Operation>(); } @@ -224,9 +224,9 @@ public class LWContainerTrafo extends AbstractContainerTrafo { Property extensionPart = expandAggregationExtension(part.getName(), extOrInterceptor, tmComponent); // register relation to facilitate connector copy - copy.setPackageTemplate(smContainerRule.getBase_Class(), tmClass); - copy.put(part, extensionPart); - copy.setPackageTemplate(null, null); + copier.setPackageTemplate(smContainerRule.getBase_Class(), tmClass); + copier.put(part, extensionPart); + copier.setPackageTemplate(null, null); } } else { @@ -271,13 +271,13 @@ public class LWContainerTrafo extends AbstractContainerTrafo { TemplateSignature signature = TemplateUtils.getSignature(smContainerExtImpl); if(signature == null) { // no template signature, just copy the container extension into the target model - tmContainerExtImpl = copy.getCopy(smContainerExtImpl); + tmContainerExtImpl = copier.getCopy(smContainerExtImpl); } else { // template signature found, instantiate container extension via the // template binding mechanism - TemplateBinding binding = TemplateUtils.fixedBinding(copy.target, smContainerExtImpl, tmComponent); + TemplateBinding binding = TemplateUtils.fixedBinding(copier.target, smContainerExtImpl, tmComponent); Object[] args = new Object[]{}; - TemplateInstantiation ti = new TemplateInstantiation(copy, binding, args); + TemplateInstantiation ti = new TemplateInstantiation(copier, binding, args); tmContainerExtImpl = (Class)ti.bindNamedElement(smContainerExtImpl); } @@ -293,7 +293,7 @@ public class LWContainerTrafo extends AbstractContainerTrafo { throws TransformationException { for(Operation smOperation : operations) { - Operation tmOperation = copy.getCopy(smOperation); + Operation tmOperation = copier.getCopy(smOperation); String interceptionBody = ""; //$NON-NLS-1$ for(Behavior behavior : interceptionOperationInRule.getMethods()) { if(behavior instanceof OpaqueBehavior) { diff --git a/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/transformations/Copy.java b/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/transformations/LazyCopier.java index b930350bf66..f47eacbdbaa 100644 --- a/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/transformations/Copy.java +++ b/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/transformations/LazyCopier.java @@ -33,7 +33,8 @@ import org.eclipse.emf.ecore.util.EcoreUtil.Copier; import org.eclipse.emf.ecore.util.InternalEList; import org.eclipse.emf.ecore.xmi.XMLResource; import org.eclipse.papyrus.qompass.designer.core.Log; -import org.eclipse.papyrus.qompass.designer.core.listeners.CopyListener; +import org.eclipse.papyrus.qompass.designer.core.listeners.PostCopyListener; +import org.eclipse.papyrus.qompass.designer.core.listeners.PreCopyListener; import org.eclipse.uml2.uml.Behavior; import org.eclipse.uml2.uml.Class; import org.eclipse.uml2.uml.Classifier; @@ -75,10 +76,8 @@ import org.eclipse.uml2.uml.util.UMLUtil; * A shallow copy can be transformed into a "real" copy * by explicitly copying it. * - * @author ansgar - * */ -public class Copy extends Copier { +public class LazyCopier extends Copier { public enum CopyStatus { /** @@ -106,13 +105,20 @@ public class Copy extends Copier { SHALLOW } - public Copy(Package source_, Package target_, boolean copyExtResources_) { - source = source_; - target = target_; + /** + * + * @param source source package (root) + * @param target target package (root) + * @param copyExtResources_ copy elements that are not within the same resource instead of referencing them. + * @param copyID copyID true, if XML IDs should be copied as well. + */ + public LazyCopier(Package source, Package target, boolean copyExtResources_, boolean copyID) { + this.source = source; + this.target = target; // useOriginalReferences = false; copyExtReferences = copyExtResources_; - preCopyListeners = new BasicEList<CopyListener>(); - postCopyListeners = new BasicEList<CopyListener>(); + preCopyListeners = new BasicEList<PreCopyListener>(); + postCopyListeners = new BasicEList<PostCopyListener>(); templateMapInfo = new HashMap<EObject, Map<EObject, EObject>>(); standardMap = new HashMap<EObject, EObject>(); statusMap = new HashMap<EObject, CopyStatus>(); @@ -127,6 +133,10 @@ public class Copy extends Copier { put(source, target); setStatus(target, CopyStatus.SHALLOW); } + this.copyID = copyID; + if (copyID) { + copyID(source, target); + } }; /** @@ -154,28 +164,30 @@ public class Copy extends Copier { /** * Bound package template */ - private Namespace boundPackage; + protected Namespace boundPackage; /** * Map to identify target objects when given source objects */ - private Map<EObject, EObject> standardMap; + protected Map<EObject, EObject> standardMap; /** * Map to identify target objects when given source objects */ - private Map<EObject, EObject> templateMap; + protected Map<EObject, EObject> templateMap; /** * Set of maps for template instantiations */ - private Map<EObject, Map<EObject, EObject>> templateMapInfo; + protected Map<EObject, Map<EObject, EObject>> templateMapInfo; /** * Map using a target EObject as key */ - private Map<EObject, CopyStatus> statusMap; + protected Map<EObject, CopyStatus> statusMap; + protected boolean copyID; + /** * Elements within package templates must be treated differently, we have to ensure that: * (1) several instantiations with same binding of the same package template do not lead to double copies @@ -439,8 +451,8 @@ public class Copy extends Copier { return sourceEObj; } - for(CopyListener listener : preCopyListeners) { - EObject result = listener.copyEObject(this, sourceEObj); + for(PreCopyListener listener : preCopyListeners) { + EObject result = listener.preCopyEObject(this, sourceEObj); if(result != sourceEObj) { return result; } @@ -470,7 +482,9 @@ public class Copy extends Copier { targetEObj = createCopy(sourceEObj); put(sourceEObj, targetEObj); setStatus(targetEObj, CopyStatus.INPROGRESS); - + if (copyID) { + copyID(sourceEObj, targetEObj); + } // creates a shallow copy of the container. This container will update containment references (such as packagedElement) // and thus update links createShallowContainer(sourceEObj); @@ -507,17 +521,25 @@ public class Copy extends Copier { } } } + else if ((eStructuralFeature instanceof EReference)) { + if (eStructuralFeature.getName().equals("clientDependency")) { //$NON-NLS-1$ + Object feature = sourceEObj.eGet(eStructuralFeature); + + if(feature instanceof Element) { + copy((Element)feature); + } else if(feature instanceof EList) { + copyAll((EList<Object>)feature); + } + } + } } copyProxyURI(sourceEObj, targetEObj); copyID(sourceEObj, targetEObj); copyStereotypes(sourceEObj); setStatus(targetEObj, CopyStatus.FULL); - for(CopyListener listener : postCopyListeners) { - EObject result = listener.copyEObject(this, targetEObj); - if(result != targetEObj) { - return result; - } + for(PostCopyListener listener : postCopyListeners) { + listener.postCopyEObject(this, targetEObj); } return targetEObj; @@ -715,6 +737,9 @@ public class Copy extends Copier { targetEObj = createCopy(sourceEObj); put(sourceEObj, targetEObj); setStatus(targetEObj, CopyStatus.SHALLOW); + if (copyID) { + copyID(sourceEObj, targetEObj); + } first = true; } else if(getStatus(targetEObj) == CopyStatus.FULL) { @@ -754,9 +779,9 @@ public class Copy extends Copier { return (T)copy(source); } - public EList<CopyListener> preCopyListeners; + public EList<PreCopyListener> preCopyListeners; - public EList<CopyListener> postCopyListeners; + public EList<PostCopyListener> postCopyListeners; /** * Called to handle the copying of a cross reference; diff --git a/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/transformations/MainModelTrafo.java b/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/transformations/MainModelTrafo.java index 79dee8f8763..e5948f5117a 100644 --- a/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/transformations/MainModelTrafo.java +++ b/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/transformations/MainModelTrafo.java @@ -78,7 +78,7 @@ public class MainModelTrafo { * @param tmCDP * deployment plan in target model */ - public MainModelTrafo(Copy copy, Package tmCDP) { + public MainModelTrafo(LazyCopier copy, Package tmCDP) { nodeHandled = new HashMap<InstanceSpecification, Boolean>(); this.copy = copy; this.tmCDP = tmCDP; @@ -463,7 +463,7 @@ public class MainModelTrafo { /** * Copier from source to target model */ - protected Copy copy; + protected LazyCopier copy; /** * deployment plan within target model diff --git a/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/transformations/PropagateAllocationToSharedInstances.java b/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/transformations/PropagateAllocationToSharedInstances.java deleted file mode 100644 index cc34e630d6e..00000000000 --- a/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/transformations/PropagateAllocationToSharedInstances.java +++ /dev/null @@ -1,58 +0,0 @@ -/***************************************************************************** - * Copyright (c) 2013 CEA LIST. - * - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Ansgar Radermacher ansgar.radermacher@cea.fr - * - *****************************************************************************/ - -package org.eclipse.papyrus.qompass.designer.core.transformations; - -import org.eclipse.core.runtime.Status; -import org.eclipse.emf.common.util.EList; -import org.eclipse.emf.common.util.UniqueEList; -import org.eclipse.papyrus.qompass.designer.core.Log; -import org.eclipse.papyrus.qompass.designer.core.deployment.AllocUtils; -import org.eclipse.papyrus.qompass.designer.core.deployment.DepUtils; -import org.eclipse.uml2.uml.InstanceSpecification; -import org.eclipse.uml2.uml.Slot; - - -/** - * Propagate allocation to shared instances: if a class references another instance - * via sharing, the shared instance must be allocated on the node of the referencing - * class as well. - * - */ -public class PropagateAllocationToSharedInstances { - public static void propagateAllocation(InstanceSpecification instance) { - propagateAllocation(instance, new UniqueEList<InstanceSpecification>()); - } - - public static void propagateAllocation(InstanceSpecification instance, EList<InstanceSpecification> nodes) { - // create copy of node (otherwise, more and more nodes get aggregated. - UniqueEList<InstanceSpecification> nodesCopy = new UniqueEList<InstanceSpecification>(); - nodesCopy.addAll(nodes); - nodesCopy.addAll(AllocUtils.getNodes(instance)); - for (Slot slot : instance.getSlots()) { - InstanceSpecification subInstance = DepUtils.getInstance(slot); - if (subInstance != null) { - if (DepUtils.isShared(slot)) { - for (InstanceSpecification node : nodesCopy) { - Log.log(Status.INFO, Log.DEPLOYMENT, String.format("Propagate node allocation: %s to %s", subInstance.getName(), node.getName())); //$NON-NLS-1$ - AllocUtils.allocate(subInstance, node); - } - } - else { - propagateAllocation(subInstance, nodesCopy); - } - } - } - } -} diff --git a/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/transformations/TrafoAndCodegenPackage.java b/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/transformations/TrafoAndCodegenPackage.java index 13592311d51..5d418127c0c 100644 --- a/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/transformations/TrafoAndCodegenPackage.java +++ b/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/transformations/TrafoAndCodegenPackage.java @@ -41,8 +41,6 @@ import org.eclipse.papyrus.qompass.designer.core.deployment.DepUtils; import org.eclipse.papyrus.qompass.designer.core.extensions.ILangSupport; import org.eclipse.papyrus.qompass.designer.core.extensions.LanguageSupport; import org.eclipse.papyrus.qompass.designer.core.generate.GenerateCode; -import org.eclipse.papyrus.qompass.designer.core.templates.InstantiateCppIncludeWOB; -import org.eclipse.papyrus.qompass.designer.core.transformations.filters.FilterComments; import org.eclipse.papyrus.qompass.designer.core.transformations.filters.FilterTemplate; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; @@ -72,7 +70,7 @@ public class TrafoAndCodegenPackage { * @param pkg * @throws TransformationException */ - public static void applyTrafo(Copy copy, Package pkg) throws TransformationException { + public static void applyTrafo(LazyCopier copy, Package pkg) throws TransformationException { EList<PackageableElement> peList = new BasicEList<PackageableElement>(); peList.addAll(pkg.getPackagedElements()); for(PackageableElement element : peList) { @@ -168,14 +166,10 @@ public class TrafoAndCodegenPackage { EnumService.createEnumPackage(tmpModel); - Copy tmpCopy = new Copy(existingModel, tmpModel, false); + LazyCopier tmpCopy = new LazyCopier(existingModel, tmpModel, false, true); tmpCopy.preCopyListeners.add(FilterTemplate.getInstance()); - tmpCopy.preCopyListeners.add(FilterComments.getInstance()); - tmpCopy.postCopyListeners.add(InstantiateCppIncludeWOB.getInstance()); - Copy.copyID(existingModel, tmpModel); - - // 1b: reify the connectors "into" the new model + // 1b: reify the connectors "into" the new model monitor.subTask(Messages.InstantiateDepPlan_InfoExpandingConnectors); // obtain reference to CDP in target model diff --git a/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/transformations/TransformationUtil.java b/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/transformations/TransformationUtil.java new file mode 100644 index 00000000000..86b5e26e49a --- /dev/null +++ b/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/transformations/TransformationUtil.java @@ -0,0 +1,81 @@ +package org.eclipse.papyrus.qompass.designer.core.transformations; + +import org.eclipse.core.runtime.Status; +import org.eclipse.emf.common.util.EList; +import org.eclipse.emf.common.util.UniqueEList; +import org.eclipse.papyrus.qompass.designer.core.Log; +import org.eclipse.papyrus.qompass.designer.core.deployment.AllocUtils; +import org.eclipse.papyrus.qompass.designer.core.deployment.DepUtils; +import org.eclipse.papyrus.qompass.designer.core.extensions.InstanceConfigurator; +import org.eclipse.papyrus.qompass.designer.core.sync.CompImplSync; +import org.eclipse.uml2.uml.Class; +import org.eclipse.uml2.uml.Classifier; +import org.eclipse.uml2.uml.InstanceSpecification; +import org.eclipse.uml2.uml.Property; +import org.eclipse.uml2.uml.Slot; + +public class TransformationUtil { + public static void applyInstanceConfigurators(InstanceSpecification instance) { + for (Slot slot : instance.getSlots()) { + InstanceSpecification subInstance = DepUtils.getInstance(slot); + if (!DepUtils.isShared(slot) && (subInstance != null)) { + if (slot.getDefiningFeature() instanceof Property) { + InstanceConfigurator.configureInstance(subInstance, (Property) slot.getDefiningFeature(), instance); + } + applyInstanceConfigurators(subInstance); + } + } + } + + public static void propagateAllocation(InstanceSpecification instance) { + propagateAllocation(instance, new UniqueEList<InstanceSpecification>()); + } + + public static void propagateAllocation(InstanceSpecification instance, EList<InstanceSpecification> nodes) { + // create copy of node (otherwise, more and more nodes get aggregated. + UniqueEList<InstanceSpecification> nodesCopy = new UniqueEList<InstanceSpecification>(); + nodesCopy.addAll(nodes); + nodesCopy.addAll(AllocUtils.getNodes(instance)); + for (Slot slot : instance.getSlots()) { + InstanceSpecification subInstance = DepUtils.getInstance(slot); + if (subInstance != null) { + if (DepUtils.isShared(slot)) { + for (InstanceSpecification node : nodesCopy) { + Log.log(Status.INFO, Log.DEPLOYMENT, String.format("Propagate node allocation: %s to %s", subInstance.getName(), node.getName())); //$NON-NLS-1$ + AllocUtils.allocate(subInstance, node); + } + } + else { + propagateAllocation(subInstance, nodesCopy); + } + } + } + } + + /** + * Update derived interfaces of ports. This is required, since the Copier does not follow references + * that are referenced via a derived attribute. Derived attributes are used for provided and required + * interfaces in the stereotype attributes of an FCM port. Thus, required (derived) interfaces would be + * unavailable in the copy, if not explicitly updated. + * However, the provided interface is not concerned as it appears in an "implements" relation. If the + * port is connected, the used interface of one port is the provided interface of the port counter part. + * Thus, the explicit update done by this function is not needed in most cases. + * + * see also FixTemplateSync (remove the latter?) + */ + public static void updateDerivedInterfaces(InstanceSpecification instance) { + Classifier cl = DepUtils.getClassifier(instance); + if (cl instanceof Class) { + Class implementation = (Class) cl; + CompImplSync.updatePorts(implementation); + CompImplSync.syncRealizations(implementation); + } + for (Slot slot : instance.getSlots()) { + InstanceSpecification subInstance = DepUtils.getInstance(slot); + if (!DepUtils.isShared(slot) && (subInstance != null)) { + updateDerivedInterfaces(subInstance); + } + } + } + +} diff --git a/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/transformations/UpdateDerivedInterfaces.java b/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/transformations/UpdateDerivedInterfaces.java deleted file mode 100644 index 1bec8c88131..00000000000 --- a/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/transformations/UpdateDerivedInterfaces.java +++ /dev/null @@ -1,51 +0,0 @@ -/***************************************************************************** - * Copyright (c) 2013 CEA LIST. - * - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Ansgar Radermacher ansgar.radermacher@cea.fr - * - *****************************************************************************/ - -package org.eclipse.papyrus.qompass.designer.core.transformations; - -import org.eclipse.papyrus.qompass.designer.core.deployment.DepUtils; -import org.eclipse.papyrus.qompass.designer.core.sync.CompImplSync; -import org.eclipse.uml2.uml.Class; -import org.eclipse.uml2.uml.Classifier; -import org.eclipse.uml2.uml.InstanceSpecification; -import org.eclipse.uml2.uml.Slot; - - -/** - * Update derived interfaces of ports. This is required, since the Copier does not follow references - * that are referenced via a derived attribute. Derived attributes are used for provided and required - * interfaces in the stereotype attributes of an FCM port. Thus, required (derived) interfaces would be - * unavailable in the copy, if not explicitly updated. - * However, the provided interface is not concerned as it appears in an "implements" relation. If the - * port is connected, the used interface of one port is the provided interface of the port counter part. - * Thus, the explicit update done by this function is not needed in most cases. - * - * see also FixTemplateSync (remove the latter?) - */ -public class UpdateDerivedInterfaces { - public static void updateIntfs(InstanceSpecification instance) { - Classifier cl = DepUtils.getClassifier(instance); - if (cl instanceof Class) { - Class implementation = (Class) cl; - CompImplSync.updatePorts(implementation); - CompImplSync.syncRealizations(implementation); - } - for (Slot slot : instance.getSlots()) { - InstanceSpecification subInstance = DepUtils.getInstance(slot); - if (!DepUtils.isShared(slot) && (subInstance != null)) { - updateIntfs(subInstance); - } - } - } -} diff --git a/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/transformations/filters/FilterRuleApplication.java b/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/transformations/filters/FilterRuleApplication.java index e84f6392cd4..784ba9fbec0 100644 --- a/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/transformations/filters/FilterRuleApplication.java +++ b/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/transformations/filters/FilterRuleApplication.java @@ -16,8 +16,8 @@ package org.eclipse.papyrus.qompass.designer.core.transformations.filters; import org.eclipse.emf.ecore.EObject; import org.eclipse.papyrus.FCM.RuleApplication; -import org.eclipse.papyrus.qompass.designer.core.listeners.CopyListener; -import org.eclipse.papyrus.qompass.designer.core.transformations.Copy; +import org.eclipse.papyrus.qompass.designer.core.listeners.PreCopyListener; +import org.eclipse.papyrus.qompass.designer.core.transformations.LazyCopier; /** * Filter the rule application stereotype. The rule application stereotype is not @@ -25,7 +25,7 @@ import org.eclipse.papyrus.qompass.designer.core.transformations.Copy; * can contain interceptors which typically reference elements from package templates. * These elements should not should be copied into the target model. */ -public class FilterRuleApplication implements CopyListener { +public class FilterRuleApplication implements PreCopyListener { public static FilterRuleApplication getInstance() { if(instance == null) { @@ -34,7 +34,7 @@ public class FilterRuleApplication implements CopyListener { return instance; } - public EObject copyEObject(Copy copy, EObject sourceEObj) { + public EObject preCopyEObject(LazyCopier copy, EObject sourceEObj) { if(sourceEObj instanceof RuleApplication) { return null; } diff --git a/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/transformations/filters/FilterSignatures.java b/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/transformations/filters/FilterSignatures.java index 277d449f83c..18589ec2659 100644 --- a/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/transformations/filters/FilterSignatures.java +++ b/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/transformations/filters/FilterSignatures.java @@ -15,8 +15,8 @@ package org.eclipse.papyrus.qompass.designer.core.transformations.filters; import org.eclipse.emf.ecore.EObject; -import org.eclipse.papyrus.qompass.designer.core.listeners.CopyListener; -import org.eclipse.papyrus.qompass.designer.core.transformations.Copy; +import org.eclipse.papyrus.qompass.designer.core.listeners.PreCopyListener; +import org.eclipse.papyrus.qompass.designer.core.transformations.LazyCopier; import org.eclipse.uml2.uml.TemplateSignature; @@ -27,7 +27,7 @@ import org.eclipse.uml2.uml.TemplateSignature; * @author ansgar * */ -public class FilterSignatures implements CopyListener { +public class FilterSignatures implements PreCopyListener { public static FilterSignatures getInstance() { if(instance == null) { @@ -36,7 +36,7 @@ public class FilterSignatures implements CopyListener { return instance; } - public EObject copyEObject(Copy copy, EObject sourceEObj) { + public EObject preCopyEObject(LazyCopier copy, EObject sourceEObj) { if(sourceEObj instanceof TemplateSignature) { if(copy.withinTemplate(sourceEObj)) { return null; diff --git a/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/transformations/filters/FilterStateMachines.java b/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/transformations/filters/FilterStateMachines.java index 1dd7b5ce874..88c7b1257b6 100644 --- a/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/transformations/filters/FilterStateMachines.java +++ b/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/transformations/filters/FilterStateMachines.java @@ -17,8 +17,8 @@ package org.eclipse.papyrus.qompass.designer.core.transformations.filters; import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.util.EcoreUtil; import org.eclipse.papyrus.qompass.designer.core.StUtils; -import org.eclipse.papyrus.qompass.designer.core.listeners.CopyListener; -import org.eclipse.papyrus.qompass.designer.core.transformations.Copy; +import org.eclipse.papyrus.qompass.designer.core.listeners.PreCopyListener; +import org.eclipse.papyrus.qompass.designer.core.transformations.LazyCopier; import org.eclipse.uml2.uml.Behavior; import org.eclipse.uml2.uml.Class; import org.eclipse.uml2.uml.Element; @@ -29,7 +29,7 @@ import org.eclipse.uml2.uml.StateMachine; import org.eclipse.uml2.uml.Transition; -public class FilterStateMachines implements CopyListener { +public class FilterStateMachines implements PreCopyListener { public static FilterStateMachines getInstance() { if(instance == null) { @@ -38,7 +38,7 @@ public class FilterStateMachines implements CopyListener { return instance; } - public EObject copyEObject(Copy copy, EObject sourceEObj) { + public EObject preCopyEObject(LazyCopier copy, EObject sourceEObj) { if(sourceEObj instanceof StateMachine) { StateMachine sm = (StateMachine)sourceEObj; Class tmClass = getTargetClass(copy, sm); @@ -62,7 +62,7 @@ public class FilterStateMachines implements CopyListener { return sourceEObj; } - public Class getTargetClass(Copy copy, StateMachine sm) { + public Class getTargetClass(LazyCopier copy, StateMachine sm) { Element smOwner = sm.getOwner(); EObject tmOwner = copy.getMap(smOwner).get(smOwner); if(tmOwner instanceof Class) { diff --git a/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/transformations/filters/FilterTemplate.java b/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/transformations/filters/FilterTemplate.java index f1784d9e26b..1647d7103b4 100644 --- a/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/transformations/filters/FilterTemplate.java +++ b/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/transformations/filters/FilterTemplate.java @@ -17,9 +17,9 @@ package org.eclipse.papyrus.qompass.designer.core.transformations.filters; import org.eclipse.emf.ecore.EObject; import org.eclipse.papyrus.FCM.Connector; import org.eclipse.papyrus.FCM.InteractionComponent; +import org.eclipse.papyrus.qompass.designer.core.listeners.PreCopyListener; +import org.eclipse.papyrus.qompass.designer.core.transformations.LazyCopier; import org.eclipse.papyrus.uml.tools.utils.StereotypeUtil; -import org.eclipse.papyrus.qompass.designer.core.listeners.CopyListener; -import org.eclipse.papyrus.qompass.designer.core.transformations.Copy; import org.eclipse.uml2.uml.Class; import org.eclipse.uml2.uml.Element; @@ -40,7 +40,7 @@ import org.eclipse.uml2.uml.Element; * @author ansgar * */ -public class FilterTemplate implements CopyListener { +public class FilterTemplate implements PreCopyListener { public FilterTemplate() { active = true; @@ -53,7 +53,7 @@ public class FilterTemplate implements CopyListener { return instance; } - public EObject copyEObject(Copy copy, EObject sourceEObj) { + public EObject preCopyEObject(LazyCopier copy, EObject sourceEObj) { if(active && (sourceEObj instanceof Element)) { Element sourceElem = (Element)sourceEObj; if((sourceEObj instanceof Connector) && StereotypeUtil.isApplied(sourceElem, Connector.class)) { diff --git a/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/transformations/filters/FixTemplateSync.java b/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/transformations/filters/FixTemplateSync.java index 02a492bb162..72deac65511 100644 --- a/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/transformations/filters/FixTemplateSync.java +++ b/extraplugins/qompass-designer/org.eclipse.papyrus.qompass.designer.core/src/org/eclipse/papyrus/qompass/designer/core/transformations/filters/FixTemplateSync.java @@ -16,9 +16,9 @@ package org.eclipse.papyrus.qompass.designer.core.transformations.filters; import org.eclipse.emf.ecore.EObject; import org.eclipse.papyrus.qompass.designer.core.Utils; -import org.eclipse.papyrus.qompass.designer.core.listeners.CopyListener; +import org.eclipse.papyrus.qompass.designer.core.listeners.PostCopyListener; import org.eclipse.papyrus.qompass.designer.core.sync.CompImplSync; -import org.eclipse.papyrus.qompass.designer.core.transformations.Copy; +import org.eclipse.papyrus.qompass.designer.core.transformations.LazyCopier; import org.eclipse.uml2.uml.Behavior; import org.eclipse.uml2.uml.Class; @@ -28,7 +28,7 @@ import org.eclipse.uml2.uml.Class; * (e.g. derived push interface with formal parameter T would be at wrong location). * TODO: need better explanation. Solution is quite a hack. */ -public class FixTemplateSync implements CopyListener { +public class FixTemplateSync implements PostCopyListener { public static FixTemplateSync getInstance() { if(instance == null) { @@ -37,7 +37,7 @@ public class FixTemplateSync implements CopyListener { return instance; } - public EObject copyEObject(Copy copy, EObject targetEObj) { + public void postCopyEObject(LazyCopier copy, EObject targetEObj) { // if (copy.get(sourceEObj) isWithinTemplate) if (!(targetEObj instanceof Behavior)) { if((targetEObj instanceof Class) && Utils.isCompImpl((Class)targetEObj)) { @@ -49,7 +49,6 @@ public class FixTemplateSync implements CopyListener { // CompImplSync.syncDerivedOperations(implementation); } } - return targetEObj; } private static FixTemplateSync instance = null; |