diff options
Diffstat (limited to 'plugins/toolsmiths/gmf-tooling/org.eclipse.papyrus.gmf.codegen.xtend/xtend/metamodel/MetaModel.xtend')
-rw-r--r-- | plugins/toolsmiths/gmf-tooling/org.eclipse.papyrus.gmf.codegen.xtend/xtend/metamodel/MetaModel.xtend | 66 |
1 files changed, 38 insertions, 28 deletions
diff --git a/plugins/toolsmiths/gmf-tooling/org.eclipse.papyrus.gmf.codegen.xtend/xtend/metamodel/MetaModel.xtend b/plugins/toolsmiths/gmf-tooling/org.eclipse.papyrus.gmf.codegen.xtend/xtend/metamodel/MetaModel.xtend index a0be2736b5c..60b5e261a38 100644 --- a/plugins/toolsmiths/gmf-tooling/org.eclipse.papyrus.gmf.codegen.xtend/xtend/metamodel/MetaModel.xtend +++ b/plugins/toolsmiths/gmf-tooling/org.eclipse.papyrus.gmf.codegen.xtend/xtend/metamodel/MetaModel.xtend @@ -1,17 +1,19 @@ -/****************************************************************************** - * Copyright (c) 2008, 2020 Borland Software Corporation, CEA LIST, Artal and others +/***************************************************************************** + * Copyright (c) 2008, 2015, 2021 Anatoliy Tischenko, Borland Software Corporation, CEA LIST, Artal and others * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * + * https://www.eclipse.org/legal/epl-2.0/ + * * SPDX-License-Identifier: EPL-2.0 * - * Contributors: - * Artem Tikhomirov (Borland) - initial API and implementation - * Michael Golubev (Montages) - #386838 - migrate to Xtend2 - * Aurelien Didier (ARTAL) - aurelien.didier51@gmail.com - Bug 569174 + * Contributors: + * Anatoliy Tischenko - Initial API and implementation + * Artem Tikhomirov (Borland) - initial API and implementation + * Michael Golubev (Montages) - #386838 - migrate to Xtend2 + * Etienne Allogo (ARTAL) - etienne.allogo@artal.fr - Bug 569174 : 1.4 Merge papyrus extension templates into codegen.xtend + * Etienne Allogo (ARTAL) - etienne.allogo@artal.fr - Bug 569174 : L1.2 clean up providers *****************************************************************************/ package metamodel @@ -75,8 +77,13 @@ import xpt.GenModelUtils_qvto «IF genClass.externalInterface»«IF needsCastToResultType»((«featureTargetType(it)») «ENDIF»«parenthesizedCast(containerVar, container, null)».eGet(«MetaFeature(it)»)«IF needsCastToResultType»)«ENDIF»«ELSE»«parenthesizedCast(containerVar, container, genClass)».«it.getAccessor»()«ENDIF» ''' - def modifyFeature(GenFeature it, String targetVar, GenClass targetType, String value) // - '''«IF it.listType»«getFeatureValue(it, targetVar, targetType)».add(«value»);«ELSE»«setFeatureValue(it, targetVar, targetType, value)»;«ENDIF»''' + def modifyFeature(GenFeature it, String targetVar, GenClass targetType, String value)''' + «IF it.listType»«getFeatureValue(it, targetVar, targetType)» + .add(«value»); + «ELSE» + «setFeatureValue(it, targetVar, targetType, value)»; + «ENDIF» + ''' def replaceFeatureValue(GenFeature it, String targetVar, GenClass targetType, String oldValue, String newValue) // ''' @@ -90,24 +97,27 @@ import xpt.GenModelUtils_qvto «modifyFeature(it, newTarget, targetType, value)» ''' - def setFeatureValue(GenFeature it, String targetVar, GenClass targetType, String valueVar) // - '''«setFeatureValue(it, targetVar, targetType, valueVar, false)»''' + def setFeatureValue(GenFeature it, String targetVar, GenClass targetType, String valueVar)'''«setFeatureValue(it, targetVar, targetType, valueVar, false)»''' // FIXME support list features as well, i.e. do .add() instead of eSet - def setFeatureValue(GenFeature it, String targetVar, GenClass targetType, String valueVar, boolean isPlainObjectValue) // - ''' - «IF targetType.externalInterface» - ((org.eclipse.emf.ecore.EObject) «targetVar»).eSet(«MetaFeature(it)», «valueVar») - «ELSE» - «targetVar».set«it.accessorName»( - «IF !isPlainObjectValue»«valueVar» - «ELSE» - «IF isPrimitiveType(it)»«unwrapObjectToPrimitiveValue(it, valueVar)» - «ELSE»(«featureTargetType(it)») «valueVar» - «ENDIF» - «ENDIF») - «ENDIF» - ''' + def setFeatureValue(GenFeature it, String targetVar, GenClass targetType, String valueVar, boolean isPlainObjectValue) { + if(targetType.externalInterface) { + '''((org.eclipse.emf.ecore.EObject) «targetVar»).eSet(«MetaFeature(it)», «valueVar»)''' + } else { + '''«targetVar».set«it.accessorName»(«setFeatureArgs(it, valueVar, isPlainObjectValue)»)''' + } + } + + protected def setFeatureArgs(GenFeature it, String valueVar, boolean isPlainObjectValue){ + if(!isPlainObjectValue) { + '''«valueVar»''' + } else if (isPrimitiveType(it)) { + '''«unwrapObjectToPrimitiveValue(it, valueVar)»''' + } else { + '''(«featureTargetType(it)»)«valueVar»''' + } + } + protected def unwrapObjectToPrimitiveValue(GenFeature it, String valueVar) '''((«featureTargetType(it)») «valueVar»).«ecoreFeature.EType.instanceClassName»Value()''' @@ -174,7 +184,7 @@ import xpt.GenModelUtils_qvto * Same as DeclareAndAssign, with extra operation applied to source object */ def DeclareAndAssign2(GenClass it, String assignee, String src, GenClass srcMetaClass, GenFeature srcFeature, String srcExt, boolean needCast) // - '''«getQualifiedInterfaceName(it)» «assignee» = «IF needCast»(«getQualifiedInterfaceName(it)») «ENDIF»«getFeatureValue(srcFeature, src, srcMetaClass)».«srcExt»;''' + '''«getQualifiedInterfaceName(it)» «assignee» = «getFeatureValue(srcFeature, src, srcMetaClass)».«srcExt»;''' /** * Cast value of type EObject to specific type. Would be no-op with dynamic model instances, @@ -193,4 +203,4 @@ import xpt.GenModelUtils_qvto def dispatch QualifiedClassName(GenClassifier xptSelf) '''«getQualifiedClassName(xptSelf)»''' -} +}
\ No newline at end of file |