Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoraradermache2013-04-04 18:03:13 -0400
committeraradermache2013-04-04 18:03:13 -0400
commit168bcb97ea99372e921c00bd859b0bab61076cf8 (patch)
tree1b182af08dd573928591906d9adf4b2d13373524 /extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src
parent51518784b0995b2f15bff5982cd1421be3fe6910 (diff)
downloadorg.eclipse.papyrus-168bcb97ea99372e921c00bd859b0bab61076cf8.tar.gz
org.eclipse.papyrus-168bcb97ea99372e921c00bd859b0bab61076cf8.tar.xz
org.eclipse.papyrus-168bcb97ea99372e921c00bd859b0bab61076cf8.zip
Transition to Acceleo based generator
Diffstat (limited to 'extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src')
-rw-r--r--extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/Constants.java2
-rw-r--r--extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/acceleo/Constants.mtl52
-rw-r--r--extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/acceleo/CppBindBody.mtl40
-rw-r--r--extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/acceleo/CppBindHeader.mtl38
-rw-r--r--extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/acceleo/CppClassBody.mtl37
-rw-r--r--extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/acceleo/CppClassHeader.mtl94
-rw-r--r--extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/acceleo/CppPackageHeader.mtl52
-rw-r--r--extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/acceleo/IncludeUtils.mtl28
-rw-r--r--extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/acceleo/util/CppDocumentation.mtl22
-rw-r--r--extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/acceleo/util/CppEnumerations.mtl14
-rw-r--r--extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/acceleo/util/CppPrimitiveTypes.mtl29
-rw-r--r--extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/acceleo/util/CppTemplates.mtl26
-rw-r--r--extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/acceleo/util/clazz/CppClassAttributesDeclaration.mtl12
-rw-r--r--extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/acceleo/util/clazz/CppClassFriendDeclaration.mtl15
-rw-r--r--extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/acceleo/util/clazz/CppClassIncludeClassDeclaration.mtl40
-rw-r--r--extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/acceleo/util/clazz/CppClassIncludeDeclaration.mtl19
-rw-r--r--extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/acceleo/util/clazz/CppClassInheritedDeclarations.mtl24
-rw-r--r--extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/acceleo/util/clazz/CppClassOperationsDeclaration.mtl11
-rw-r--r--extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/acceleo/util/clazz/CppClassOperationsImplementation.mtl15
-rw-r--r--extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/acceleo/util/clazz/CppClassTypeAndEnum.mtl30
-rw-r--r--extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/acceleo/util/operation/CppOperationDeclaration.mtl79
-rw-r--r--extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/acceleo/util/operation/CppParameter.mtl18
-rw-r--r--extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/acceleo/util/property/CppAttributeDeclaration.mtl21
-rw-r--r--extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/acceleo/util/property/CppAttributeImplementation.mtl35
-rw-r--r--extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/preferences/CppCodeGenConstants.java5
-rw-r--r--extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/preferences/CppCodeGenPreferenceInitializer.java1
-rw-r--r--extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/preferences/CppCodeGenUtils.java5
-rw-r--r--extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/preferences/CppCodeGenUtils.mtl13
-rw-r--r--extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/transformation/CppModelElementsCreator.java158
-rw-r--r--extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/transformation/ModelElementsCreator.java420
-rw-r--r--extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/utils/ClassUtils.java152
-rw-r--r--extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/utils/ClassUtils.mtl6
-rw-r--r--extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/utils/GenUtils.java129
-rw-r--r--extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/utils/GenUtils.mtl104
-rw-r--r--extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/utils/Modifier.java96
-rw-r--r--extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/utils/Modifier.mtl15
36 files changed, 1229 insertions, 628 deletions
diff --git a/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/Constants.java b/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/Constants.java
index 33e044a0323..34ebf025224 100644
--- a/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/Constants.java
+++ b/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/Constants.java
@@ -33,4 +33,6 @@ public class Constants {
public static final String forwardDecl = "// forward declarations";
public static final String staticAttributes = "// static attributes (if any)";
+
+ public static final String undefinedType = "undefined";
}
diff --git a/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/acceleo/Constants.mtl b/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/acceleo/Constants.mtl
new file mode 100644
index 00000000000..2aea121b9e5
--- /dev/null
+++ b/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/acceleo/Constants.mtl
@@ -0,0 +1,52 @@
+[comment encoding = UTF-8 /]
+[module Constants('http://www.eclipse.org/uml2/4.0.0/UML')]
+
+
+[template public includeHFile(dummy : Element)]
+// include associated header file
+[/template]
+
+[template public IncludeHeaderStart(dummy : Element)]
+// Include from Include stereotype (header)
+[/template]
+
+[template public IncludePreBodyStart(dummy : Element)]
+// Include from Include stereotype (pre-body)
+[/template]
+
+[template public IncludePreBodyEnd(dummy : Element)]
+// End of Include stereotype (pre-body)
+[/template]
+
+[template public IncludeBodyStart(dummy : Element)]
+// Include from Include declaration (body)
+[/template]
+
+[template public IncludeHeaderEnd(dummy : Element)]
+// End of Include stereotype (header)
+[/template]
+
+[template public IncludeBodyEnd(dummy : Element)]
+// End of Include stereotype (body)
+[/template]
+
+[template public derivedIncludes(dummy : Element)]
+// Derived includes directives
+[/template]
+
+[template public forwardDecl(dummy : Element)]
+// forward declarations
+[/template]
+
+[template public staticAttributes(dummy : Element)]
+// static attributes (if any)
+[/template]
+
+[template public packageTypes(dummy : Element)]
+// Types defined within the package
+[/template]
+
+
+[template public undefinedType(dummy : Element)]
+undefined
+[/template]
diff --git a/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/acceleo/CppBindBody.mtl b/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/acceleo/CppBindBody.mtl
new file mode 100644
index 00000000000..da720a05838
--- /dev/null
+++ b/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/acceleo/CppBindBody.mtl
@@ -0,0 +1,40 @@
+[module CppBindBody('http://www.eclipse.org/uml2/4.0.0/UML')/]
+[import org::eclipse::papyrus::cpp::codegen::utils::GenUtils/]
+[import org::eclipse::papyrus::cpp::codegen::utils::ClassUtils/]
+[import org::eclipse::papyrus::cpp::codegen::acceleo::IncludeUtils/]
+[import org::eclipse::papyrus::cpp::codegen::preferences::CppCodeGenUtils/]
+[import org::eclipse::papyrus::cpp::codegen::acceleo::Constants/]
+[import org::eclipse::papyrus::cpp::codegen::acceleo::util::CppTemplates/]
+[import org::eclipse::papyrus::cpp::codegen::acceleo::util::clazz::CppClassIncludeClassDeclaration/]
+
+
+[template public CppBindBody(class : Class)]
+#define [getFullNameUC()/]_BODY
+
+/************************************************************
+ [class.name/] template binding body
+ ************************************************************/
+
+[IncludePreBody()/]
+
+[includeHFile()/]
+#include <[_package.getFullPath()/][class.name/].[getHeaderSuffix()/]>
+
+[IncludeBody()/]
+
+[openNS()/]
+
+[derivedIncludes()/]
+[CppClassAllIncludesDeclaration()/]
+
+/************************************************************/
+[let tb : TemplateBinding = getTemplateBindings()]
+[let templateElement : Classifier = tb.target->asSequence()->first()]
+template class [templateElement.name/] <[for (tb.parameterSubstitution)][CppTemplateBindingParameter()/][/for]> [class.name/];
+[/let][/let]
+[closeNS()/]
+
+/************************************************************
+ End of [class.name/] template binding body
+ ************************************************************/
+[/template]
diff --git a/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/acceleo/CppBindHeader.mtl b/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/acceleo/CppBindHeader.mtl
new file mode 100644
index 00000000000..99148264afc
--- /dev/null
+++ b/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/acceleo/CppBindHeader.mtl
@@ -0,0 +1,38 @@
+[module CppBindHeader('http://www.eclipse.org/uml2/4.0.0/UML')/]
+[import org::eclipse::papyrus::cpp::codegen::utils::GenUtils/]
+[import org::eclipse::papyrus::cpp::codegen::acceleo::util::clazz::CppClassIncludeClassDeclaration/]
+[import org::eclipse::papyrus::cpp::codegen::acceleo::util::CppTemplates/]
+[import org::eclipse::papyrus::cpp::codegen::preferences::CppCodeGenUtils/]
+
+
+[template public CppBindHeader(class : Class)]
+#ifndef [getFullNameUC()/]_H
+#define [getFullNameUC()/]_H
+
+/************************************************************
+ [class.name/] template binding header
+ ************************************************************/
+
+[_package.CppOwnerPackageIncludeDeclaration()/]
+
+[CppClassAllIncludesDeclaration()/]
+
+[getApplication(C_Cpp::Include).oclAsType(C_Cpp::Include).header/]
+
+[let tb : TemplateBinding = getTemplateBindings()]
+[let templateElement : Classifier = tb.target->asSequence()->first()]
+#include <[_package.getFullPath()/]/[templateElement.owner.oclAsType(NamedElement).name/].[getHeaderSuffix()/]>
+
+[openNS()/]
+/************************************************************/
+typedef [templateElement.name/] <[for (tb.parameterSubstitution)][CppTemplateBindingParameter()/][/for]> [class.name/];
+
+[closeNS()/]
+[/let][/let]
+
+/************************************************************
+ End of [class.name/] template binding header
+ ************************************************************/
+
+#endif
+[/template]
diff --git a/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/acceleo/CppClassBody.mtl b/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/acceleo/CppClassBody.mtl
new file mode 100644
index 00000000000..cf2e1f70034
--- /dev/null
+++ b/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/acceleo/CppClassBody.mtl
@@ -0,0 +1,37 @@
+[module CppClassBody('http://www.eclipse.org/uml2/4.0.0/UML')/]
+[import org::eclipse::papyrus::cpp::codegen::utils::GenUtils/]
+[import org::eclipse::papyrus::cpp::codegen::utils::ClassUtils/]
+[import org::eclipse::papyrus::cpp::codegen::acceleo::Constants/]
+[import org::eclipse::papyrus::cpp::codegen::acceleo::IncludeUtils/]
+[import org::eclipse::papyrus::cpp::codegen::preferences::CppCodeGenUtils/]
+[import org::eclipse::papyrus::cpp::codegen::acceleo::util::clazz::CppClassIncludeClassDeclaration/]
+[import org::eclipse::papyrus::cpp::codegen::acceleo::util::clazz::CppClassOperationsImplementation/]
+[import org::eclipse::papyrus::cpp::codegen::acceleo::util::property::CppAttributeImplementation/]
+
+
+[template public CppClassBody(class : Classifier)]
+#define [getFullName()/]_BODY
+
+/************************************************************
+ [class.name/] class body
+ ************************************************************/
+
+[IncludePreBody()/]
+
+[includeHFile()/]
+#include <[_package.getFullPath()/]/[class.name/].[getHeaderSuffix()/]>
+
+[IncludeBody()/]
+
+[derivedIncludes()/]
+[CppClassAllIncludesDeclaration()/]
+
+[openNS(class)/]
+[CppStaticAttributes(class)/]
+[CppClassOperationsImplementation(false)/]
+[closeNS(class)/]
+
+/************************************************************
+ End of [class.name/] class body
+ ************************************************************/
+[/template]
diff --git a/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/acceleo/CppClassHeader.mtl b/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/acceleo/CppClassHeader.mtl
new file mode 100644
index 00000000000..54920cec07c
--- /dev/null
+++ b/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/acceleo/CppClassHeader.mtl
@@ -0,0 +1,94 @@
+[module CppClassHeader('http://www.eclipse.org/uml2/4.0.0/UML')/]
+[import org::eclipse::papyrus::cpp::codegen::utils::GenUtils/]
+[import org::eclipse::papyrus::cpp::codegen::utils::ClassUtils/]
+[import org::eclipse::papyrus::cpp::codegen::acceleo::Constants/]
+[import org::eclipse::papyrus::cpp::codegen::acceleo::IncludeUtils/]
+[import org::eclipse::papyrus::cpp::codegen::acceleo::util::clazz::CppClassIncludeClassDeclaration/]
+[import org::eclipse::papyrus::cpp::codegen::acceleo::util::clazz::CppClassTypeAndEnum/]
+[import org::eclipse::papyrus::cpp::codegen::acceleo::util::clazz::CppClassFriendDeclaration/]
+[import org::eclipse::papyrus::cpp::codegen::acceleo::util::clazz::CppClassInheritedDeclarations/]
+[import org::eclipse::papyrus::cpp::codegen::acceleo::util::clazz::CppClassAttributesDeclaration/]
+[import org::eclipse::papyrus::cpp::codegen::acceleo::util::clazz::CppClassOperationsDeclaration/]
+[import org::eclipse::papyrus::cpp::codegen::acceleo::util::clazz::CppClassOperationsImplementation/]
+[import org::eclipse::papyrus::cpp::codegen::acceleo::util::CppTemplates/]
+[import org::eclipse::papyrus::cpp::codegen::acceleo::util::CppDocumentation/]
+
+
+
+[query public classUnionOrStruct(classifier : Classifier) : String =
+if (hasStereotype(C_Cpp::Union)) then 'union'
+else
+ if (oclIsKindOf(DataType)) then 'struct'
+ else 'class'
+ endif
+endif
+/]
+
+[comment default initializer for non-static attributes with a default value
+TODO: should be disabled by default, since non-static members can be initialized directly
+in C++ 011/]
+[template public defaultInitializer(classifier : Classifier) post(trim())]
+[let attributeList : Set(Property) = attribute->select(
+ (isStatic = false) and
+ (defaultValue <> null) and
+ (defaultValue.stringValue() <> null))]
+[if not attributeList->isEmpty()]
+ [classifier.name/]() : [for (a : Property | attributeList) separator(', ')
+ ][name/]([defaultValue.stringValue()/])[/for] {}
+[/if][/let]
+[/template]
+
+
+[template public CppClassHeader(class : Classifier)]
+#ifndef [getFullNameUC()/]_H
+#define [getFullNameUC()/]_H
+
+/************************************************************
+ [class.name/] class header
+ ************************************************************/
+
+[_package.CppOwnerPackageIncludeDeclaration()/]
+
+[CppClassAllIncludesDeclaration()/]
+
+[IncludeHeader()/]
+
+[openNS()/]
+[_package.CppClassTypeAndEnumPackage()/]
+/************************************************************/
+[CppElementDoc()/]
+[templateSignature()/][classUnionOrStruct()/] [class.name/][CppClassInheritedDeclarations()/] {
+[CppClassIncludeFriendDeclaration()/][CppClassTypeAndEnum()/]
+
+ public:
+[defaultInitializer()/][CppClassAttributesDeclaration(VisibilityKind::public)/][CppClassOperationsDeclaration(VisibilityKind::public)/]
+
+ protected:
+[CppClassAttributesDeclaration(VisibilityKind::protected)/][CppClassOperationsDeclaration(VisibilityKind::protected)/]
+
+ private:
+[CppClassAttributesDeclaration(VisibilityKind::private)/][CppClassOperationsDeclaration(VisibilityKind::private)/]
+
+};
+/************************************************************/
+/* External declarations (package visibility) */
+[CppClassAttributesDeclaration(VisibilityKind::_package)/]
+[CppClassOperationsDeclaration(VisibilityKind::_package)/]
+/************************************************************/
+
+[if (isTemplate())]
+/************************************************************/
+/* Template functions */
+[CppClassOperationsImplementation(false)/]
+[/if]
+
+/* Inline functions */
+[CppClassOperationsImplementation(true)/]
+[closeNS()/]
+
+/************************************************************
+ End of [class.name/] class header
+ ************************************************************/
+
+#endif
+[/template]
diff --git a/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/acceleo/CppPackageHeader.mtl b/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/acceleo/CppPackageHeader.mtl
new file mode 100644
index 00000000000..95a0f6b8e65
--- /dev/null
+++ b/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/acceleo/CppPackageHeader.mtl
@@ -0,0 +1,52 @@
+[module CppPackageHeader('http://www.eclipse.org/uml2/4.0.0/UML')/]
+[import org::eclipse::papyrus::cpp::codegen::utils::GenUtils/]
+[import org::eclipse::papyrus::cpp::codegen::preferences::CppCodeGenUtils/]
+[import org::eclipse::papyrus::cpp::codegen::acceleo::Constants/]
+[import org::eclipse::papyrus::cpp::codegen::acceleo::IncludeUtils/]
+[import org::eclipse::papyrus::cpp::codegen::acceleo::util::clazz::CppClassIncludeClassDeclaration/]
+[import org::eclipse::papyrus::cpp::codegen::acceleo::util::clazz::CppClassTypeAndEnum/]
+[import org::eclipse::papyrus::cpp::codegen::acceleo::util::clazz::CppClassFriendDeclaration/]
+
+
+[import org::eclipse::papyrus::cpp::codegen::acceleo::util::CppDocumentation/]
+
+
+[template public CppPackageHeader(pkg : Package)]
+#ifndef PKG_[getFullNameUC()/]
+#define PKG_[getFullNameUC()/]
+
+/************************************************************
+ Pkg_[name/] package header
+ ************************************************************/
+
+[nestingPackage.CppOwnerPackageIncludeDeclaration()/]
+
+#ifndef _IN_
+#define _IN_
+#endif
+#ifndef _OUT_
+#define _OUT_
+#endif
+#ifndef _INOUT_
+#define _INOUT_
+#endif
+
+
+/* Package dependency header include */
+[for (getUsedPackages())]
+#include <[getFullPath()/]/Pkg_[name/].[getHeaderSuffix()/]>
+[/for]
+
+[IncludeHeader()/]
+
+[openNS()/]
+[packageTypes()/]
+[CppClassTypeAndEnumPackage()/]
+[closeNS()/]
+
+/************************************************************
+ End of Pkg_[name/] package header
+ ************************************************************/
+
+#endif
+[/template]
diff --git a/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/acceleo/IncludeUtils.mtl b/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/acceleo/IncludeUtils.mtl
new file mode 100644
index 00000000000..cd81da94794
--- /dev/null
+++ b/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/acceleo/IncludeUtils.mtl
@@ -0,0 +1,28 @@
+[comment encoding = UTF-8 /]
+[module IncludeUtils('http://www.eclipse.org/uml2/4.0.0/UML')]
+[import org::eclipse::papyrus::cpp::codegen::utils::GenUtils/]
+[import org::eclipse::papyrus::cpp::codegen::acceleo::Constants/]
+
+[template public IncludeHeader(ne : NamedElement)]
+[if (hasStereotype(C_Cpp::Include) and (getApplication(C_Cpp::Include).oclAsType(C_Cpp::Include).header.size() > 0))]
+[IncludeHeaderStart()/]
+[getApplication(C_Cpp::Include).oclAsType(C_Cpp::Include).header/]
+[IncludeHeaderEnd()/]
+[/if]
+[/template]
+
+[template public IncludeBody(ne : NamedElement)]
+[if (hasStereotype(C_Cpp::Include) and (getApplication(C_Cpp::Include).oclAsType(C_Cpp::Include)._body <> null))]
+[IncludeBodyStart()/]
+[getApplication(C_Cpp::Include).oclAsType(C_Cpp::Include)._body/]
+[IncludeBodyEnd()/]
+[/if]
+[/template]
+
+[template public IncludePreBody(ne : NamedElement)]
+[if (hasStereotype(C_Cpp::Include))]
+[IncludePreBodyStart()/]
+[getApplication(C_Cpp::Include).oclAsType(C_Cpp::Include).preBody/]
+[IncludePreBodyEnd()/]
+[/if]
+[/template]
diff --git a/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/acceleo/util/CppDocumentation.mtl b/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/acceleo/util/CppDocumentation.mtl
new file mode 100644
index 00000000000..644096558af
--- /dev/null
+++ b/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/acceleo/util/CppDocumentation.mtl
@@ -0,0 +1,22 @@
+[module CppDocumentation('http://www.eclipse.org/uml2/4.0.0/UML')/]
+[import org::eclipse::papyrus::cpp::codegen::utils::GenUtils/]
+
+
+[template public CppElementDoc(argument : Element)]
+/**
+ * [getComments().replaceAll('\n', '\n * ')/]
+ */
+[/template]
+
+
+[template public CppOperationDoc(operation : Operation)]
+/**
+ * [getComments().replaceAll('\n', '\n * ')/]
+ * [for (ownedParameter)][CppParamDoc()/][/for]
+ */
+[/template]
+
+
+[template public CppParamDoc(parameter : Parameter)]
+@param [name/] [getComments().replaceAll('\n', '\n * ')/]
+[/template]
diff --git a/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/acceleo/util/CppEnumerations.mtl b/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/acceleo/util/CppEnumerations.mtl
new file mode 100644
index 00000000000..97f7653d5c2
--- /dev/null
+++ b/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/acceleo/util/CppEnumerations.mtl
@@ -0,0 +1,14 @@
+[module CppEnumerations('http://www.eclipse.org/uml2/4.0.0/UML', 'http://papyrus/C_CppProfile/1')/]
+[import org::eclipse::papyrus::cpp::codegen::utils::GenUtils/]
+[import org::eclipse::papyrus::cpp::codegen::acceleo::util::CppDocumentation/]
+
+[template public CppEnumerationDefinition(enum : Enumeration)]
+[CppElementDoc()/]
+enum [enum.name/] {
+[for (ownedLiteral)]/
+ [CppElementDoc()/]
+ [name/][if hasStereotype(CppInit)] = [getApplication(CppInit).oclAsType(CppInit).value/][/if],
+[/for]
+};
+
+[/template]
diff --git a/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/acceleo/util/CppPrimitiveTypes.mtl b/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/acceleo/util/CppPrimitiveTypes.mtl
new file mode 100644
index 00000000000..28072961454
--- /dev/null
+++ b/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/acceleo/util/CppPrimitiveTypes.mtl
@@ -0,0 +1,29 @@
+[module CppPrimitiveTypes('http://www.eclipse.org/uml2/4.0.0/UML', 'http://papyrus/C_CppProfile/1')/]
+[import org::eclipse::papyrus::cpp::codegen::utils::GenUtils/]
+[import org::eclipse::papyrus::cpp::codegen::acceleo::util::CppDocumentation/]
+
+
+[comment
+ * Support two different kinds of primitive types
+ * (1) those that are native types of the programming language such as long
+ * For these, no additional definition has to be done and they should be referenced
+ * with their name only
+ * (2) those that correspond to a typedef (e.g. typedef long ErrorType). These require
+ * a typedef definition within the package and need to be referenced with their
+ * fully qualified name (e.g. MyPackage::ErrorType)
+ * (3) Sometimes the name of the type defined by a typedef does not appear at the end, e.g.
+ * when defining functionPointers such as "typedef int (*HandlerFct) (void*);"
+ * (a function with a void* argument returning int)
+ * Support this case via a specific 'typeName' constant that gets replaced by the name of the
+ * type
+ */
+/]
+[template public CppPrimitiveTypeDefinition(primitiveType : PrimitiveType)]
+[CppElementDoc()/]
+[if (hasStereotype(Typedef))]
+typedef [getApplication(Typedef).oclAsType(Typedef).definition.replaceAll('typeName', primitiveType.name)
+ /][if (not getApplication(Typedef).oclAsType(Typedef).definition.contains('typeName'))] [primitiveType.name/][/if];
+[else]
+[getStdtypes(primitiveType)/];
+[/if]
+[/template]
diff --git a/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/acceleo/util/CppTemplates.mtl b/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/acceleo/util/CppTemplates.mtl
new file mode 100644
index 00000000000..0cb88942a45
--- /dev/null
+++ b/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/acceleo/util/CppTemplates.mtl
@@ -0,0 +1,26 @@
+[module CppTemplates('http://www.eclipse.org/uml2/4.0.0/UML')/]
+[import org::eclipse::papyrus::cpp::codegen::utils::GenUtils/]
+
+
+[query public CppTemplateBindingParameter(tps : TemplateParameterSubstitution) : String =
+if (tps.actual.oclIsKindOf(LiteralInteger)) then
+ tps.actual.oclAsType(LiteralInteger).value
+else
+ tps.actual.oclAsType(NamedElement).name
+endif
+/]
+
+[query public isTemplate(class : Classifier) : Boolean =
+ getTemplateParameters()->size() > 0
+/]
+
+
+[template public templateSignature(class : Classifier)]
+[if isTemplate()]
+template<[for (getTemplateParameters()) separator(', ')][getType()/][/for]> [/if]
+[/template]
+
+
+[template public templateSignature(operation : Operation)]
+[owner.oclAsType(Classifier).templateSignature()/]
+[/template] \ No newline at end of file
diff --git a/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/acceleo/util/clazz/CppClassAttributesDeclaration.mtl b/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/acceleo/util/clazz/CppClassAttributesDeclaration.mtl
new file mode 100644
index 00000000000..0b184a07bc2
--- /dev/null
+++ b/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/acceleo/util/clazz/CppClassAttributesDeclaration.mtl
@@ -0,0 +1,12 @@
+[module CppClassAttributesDeclaration('http://www.eclipse.org/uml2/4.0.0/UML')/]
+[import org::eclipse::papyrus::cpp::codegen::utils::GenUtils/]
+[import org::eclipse::papyrus::cpp::codegen::acceleo::util::property::CppAttributeDeclaration/]
+
+
+
+[template public CppClassAttributesDeclaration(class : Classifier, visibilityFilter : VisibilityKind)]
+[for (attribute->select(visibility = visibilityFilter))]
+
+ [CppAttributeDeclaration()/]
+[/for]
+[/template]
diff --git a/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/acceleo/util/clazz/CppClassFriendDeclaration.mtl b/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/acceleo/util/clazz/CppClassFriendDeclaration.mtl
new file mode 100644
index 00000000000..8477e8483dc
--- /dev/null
+++ b/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/acceleo/util/clazz/CppClassFriendDeclaration.mtl
@@ -0,0 +1,15 @@
+[module CppClassFriendDeclaration('http://www.eclipse.org/uml2/4.0.0/UML')/]
+[import org::eclipse::papyrus::cpp::codegen::utils::GenUtils/]
+
+
+[template public CppClassFriendDeclaration(friend : Classifier)]
+friend class [friend.qualifiedName()/];
+[/template]
+
+[template public CppClassIncludeFriendDeclaration(class : Classifier)]
+[for (getUsedClassifiers())]
+ [if hasStereotype(C_Cpp::Friend) and (not hasStereotype(C_Cpp::NoCodeGen))]
+ [CppClassFriendDeclaration()/]
+ [/if]
+[/for]
+[/template] \ No newline at end of file
diff --git a/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/acceleo/util/clazz/CppClassIncludeClassDeclaration.mtl b/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/acceleo/util/clazz/CppClassIncludeClassDeclaration.mtl
new file mode 100644
index 00000000000..8db26305532
--- /dev/null
+++ b/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/acceleo/util/clazz/CppClassIncludeClassDeclaration.mtl
@@ -0,0 +1,40 @@
+[module CppClassIncludeClassDeclaration('http://www.eclipse.org/uml2/4.0.0/UML', 'http://papyrus/C_CppProfile/1')/]
+[import org::eclipse::papyrus::cpp::codegen::utils::GenUtils/]
+[import org::eclipse::papyrus::cpp::codegen::utils::ClassUtils/]
+[import org::eclipse::papyrus::cpp::codegen::acceleo::util::clazz::CppClassIncludeDeclaration/]
+
+[comment USED??? /]
+[template public CppClassIncludeClassDeclarationTemplate(class : Class)]
+[openNS()/]
+[if hasStereotype(class, 'CppTemplate.class')]template [/if]class [class.name/];
+[closeNS()/]
+[/template]
+
+
+[template public CppOwnerPackageIncludeDeclaration(pkg : Package)]
+[comment if currentPkg is not root it is referenced here/]
+[if ((pkg <> null) and (not hasStereotype(CppRoot)))]
+/* Owner package header include */
+#include <[getFullPath()/]/Pkg_[pkg.name/].h>
+[/if]
+[/template]
+
+
+[template public CppClassAllIncludesDeclaration(class : Classifier)]
+[for (cl : Classifier | includedClassifiers())]
+ [comment Only add include if this is not for the current class and if it does not have the stereotype "CppNoCodeGen", unless
+ it has stereotype "CppExternalClass"/]
+ [if((cl <> class) and (not hasStereotype(NoCodeGen)) or hasStereotype(ExternClass))]
+ [if(oclIsKindOf(Enumeration) or oclIsKindOf(PrimitiveType))]
+ [comment Enumeration is not defined in a separate file, but in the package that owns it
+ => include the owning package (might be a duplicate input, if owning package is also the owner of current class/]
+ [if (cl.owner.oclIsKindOf(Package))]
+[cl.owner.oclAsType(Package).CppOwnerPackageIncludeDeclaration()/]
+ [/if]
+ [else]
+ [comment include file associated with the classifier/]
+[CppClassIncludeDeclaration()/]
+ [/if]
+ [/if]
+[/for]
+[/template]
diff --git a/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/acceleo/util/clazz/CppClassIncludeDeclaration.mtl b/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/acceleo/util/clazz/CppClassIncludeDeclaration.mtl
new file mode 100644
index 00000000000..9634496107a
--- /dev/null
+++ b/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/acceleo/util/clazz/CppClassIncludeDeclaration.mtl
@@ -0,0 +1,19 @@
+[module CppClassIncludeDeclaration('http://www.eclipse.org/uml2/4.0.0/UML', 'http://papyrus/C_CppProfile/1')/]
+[import org::eclipse::papyrus::cpp::codegen::utils::GenUtils/]
+[import org::eclipse::papyrus::cpp::codegen::preferences::CppCodeGenUtils/]
+
+
+[query public includeName(ne : NamedElement) : String =
+if (hasStereotype(Template)) then
+ getApplication(Template).oclAsType(Template).declaration
+else
+ if (hasStereotype(ExternClass)) then getApplication(ExternClass).oclAsType(ExternClass).name
+ else ne.name + '.' + getHeaderSuffix()
+ endif
+endif
+/]
+
+[comment TODO: original code did not use nearest package, if stereotype CppRoot was applied/]
+[template public CppClassIncludeDeclaration(ne : NamedElement)]
+#include <[getNearestPackage().getFullPath()/]/[ne.includeName()/]>
+[/template]
diff --git a/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/acceleo/util/clazz/CppClassInheritedDeclarations.mtl b/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/acceleo/util/clazz/CppClassInheritedDeclarations.mtl
new file mode 100644
index 00000000000..22eb62b8de0
--- /dev/null
+++ b/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/acceleo/util/clazz/CppClassInheritedDeclarations.mtl
@@ -0,0 +1,24 @@
+[module CppClassInheritedDeclarations('http://www.eclipse.org/uml2/4.0.0/UML', 'http://papyrus/C_CppProfile/1')/]
+[import org::eclipse::papyrus::cpp::codegen::utils::GenUtils/]
+
+[comment
+Return a list of relationships that are either Generalizations or InterfaceRealiazations
+and the target does not point to a classifier that has the no-code-gen Stereotype
+TODO: not sure if it makes sense NOT to declare an inheritance, since we do not generate code.
+/]
+[query public filteredRelationships(class : Classifier) : Set(DirectedRelationship) =
+ getSourceDirectedRelationships()->select(
+ (oclIsKindOf(Generalization) or oclIsKindOf(InterfaceRealization)) and
+ (not target->asSequence()->first().hasStereotype(NoCodeGen))
+ )
+/]
+
+[query public getCppVisibility(relationship : Relationship) : String =
+if (hasStereotype(Visibility)) then getApplication(Visibility).oclAsType(Visibility).value else 'public' endif
+/]
+
+[template public CppClassInheritedDeclarations(class : Classifier)]
+[if (filteredRelationships()->size() > 0)] : [/if]
+[for (filteredRelationships()) separator(', \n')]
+ [getCppVisibility()/] [target->asSequence()->first().oclAsType(Classifier).qualifiedName()/][/for]
+[/template]
diff --git a/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/acceleo/util/clazz/CppClassOperationsDeclaration.mtl b/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/acceleo/util/clazz/CppClassOperationsDeclaration.mtl
new file mode 100644
index 00000000000..e15580adddf
--- /dev/null
+++ b/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/acceleo/util/clazz/CppClassOperationsDeclaration.mtl
@@ -0,0 +1,11 @@
+[module CppClassOperationsDeclaration('http://www.eclipse.org/uml2/4.0.0/UML')/]
+[import org::eclipse::papyrus::cpp::codegen::utils::GenUtils/]
+[import org::eclipse::papyrus::cpp::codegen::acceleo::util::operation::CppOperationDeclaration/]
+
+
+[template public CppClassOperationsDeclaration(class : Classifier, visibilityFilter : VisibilityKind)]
+[for (getOperations()->select(visibility = visibilityFilter))]
+
+ [CppOperationDeclaration()/]
+[/for]
+[/template]
diff --git a/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/acceleo/util/clazz/CppClassOperationsImplementation.mtl b/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/acceleo/util/clazz/CppClassOperationsImplementation.mtl
new file mode 100644
index 00000000000..aeaf01f3fe6
--- /dev/null
+++ b/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/acceleo/util/clazz/CppClassOperationsImplementation.mtl
@@ -0,0 +1,15 @@
+[module CppClassOperationsImplementation('http://www.eclipse.org/uml2/4.0.0/UML', 'http://papyrus/C_CppProfile/1')/]
+[import org::eclipse::papyrus::cpp::codegen::utils::GenUtils/]
+[import org::eclipse::papyrus::cpp::codegen::acceleo::util::operation::CppOperationDeclaration/]
+
+
+[comment implementations of a classifier, parameter controls whether only inline (or only not inline) operations
+ are produced/]
+[template public CppClassOperationsImplementation(class : Classifier, inline : Boolean)]
+[for (getOperations()->select(
+ (not (hasStereotype(NoCodeGen) or isAbstract)) and
+ (hasStereotype(C_Cpp::Inline) = inline)))]
+
+[CppOperationImplementation()/]
+[/for]
+[/template]
diff --git a/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/acceleo/util/clazz/CppClassTypeAndEnum.mtl b/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/acceleo/util/clazz/CppClassTypeAndEnum.mtl
new file mode 100644
index 00000000000..50f2a7c4928
--- /dev/null
+++ b/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/acceleo/util/clazz/CppClassTypeAndEnum.mtl
@@ -0,0 +1,30 @@
+[module CppClassTypeAndEnum('http://www.eclipse.org/uml2/4.0.0/UML', 'http://papyrus/C_CppProfile/1')/]
+[import org::eclipse::papyrus::cpp::codegen::utils::GenUtils/]
+[import org::eclipse::papyrus::cpp::codegen::acceleo::util::CppPrimitiveTypes/]
+[import org::eclipse::papyrus::cpp::codegen::acceleo::util::CppEnumerations/]
+
+[template public TypeAndEnumForVisibility(element : Element, visibilityFilter : VisibilityKind)]
+[if (not hasStereotype(NoCodeGen) and oclIsKindOf(Classifier) and oclAsType(Classifier).visibility = visibilityFilter)]
+[ if (oclIsKindOf(Enumeration))][oclAsType(Enumeration).CppEnumerationDefinition()/][/if]
+[ if (oclIsKindOf(PrimitiveType))][oclAsType(PrimitiveType).CppPrimitiveTypeDefinition()/][/if]
+[/if]
+[/template]
+
+[template public TypesAndEnumsForVisibility(ne : Namespace, visibilityFilter : VisibilityKind)]
+[for (ownedElement)][TypeAndEnumForVisibility(visibilityFilter)/][/for]
+[/template]
+
+[template public CppClassTypeAndEnum(class : Classifier)]
+ public:
+ [TypesAndEnumsForVisibility(VisibilityKind::public)/]
+ protected:
+ [TypesAndEnumsForVisibility(VisibilityKind::protected)/]
+ private:
+ [TypesAndEnumsForVisibility(VisibilityKind::private)/]
+[/template]
+
+
+[template public CppClassTypeAndEnumPackage(pkg : Package)]
+[TypesAndEnumsForVisibility(VisibilityKind::_package)/]
+[TypesAndEnumsForVisibility(VisibilityKind::public)/]
+[/template] \ No newline at end of file
diff --git a/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/acceleo/util/operation/CppOperationDeclaration.mtl b/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/acceleo/util/operation/CppOperationDeclaration.mtl
new file mode 100644
index 00000000000..f37e2687c9d
--- /dev/null
+++ b/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/acceleo/util/operation/CppOperationDeclaration.mtl
@@ -0,0 +1,79 @@
+[module CppOperationDeclaration('http://www.eclipse.org/uml2/4.0.0/UML', 'http://papyrus/C_CppProfile/1', 'http://www.eclipse.org/uml2/4.0.0/UML/Profile/L2')/]
+[import org::eclipse::papyrus::cpp::codegen::utils::GenUtils/]
+[import org::eclipse::papyrus::cpp::codegen::utils::Modifier/]
+[import org::eclipse::papyrus::cpp::codegen::acceleo::util::CppDocumentation/]
+[import org::eclipse::papyrus::cpp::codegen::acceleo::util::operation::CppParameter/]
+[import org::eclipse::papyrus::cpp::codegen::acceleo::util::CppTemplates/]
+
+
+[template public virtualTxt(operation : Operation)]
+[if((operation.interface <> null) or (operation.isAbstract) or (operation.hasStereotype(Virtual)))]virtual [/if]
+[/template]
+
+
+[template public virtualSuffix(operation : Operation)]
+[if((operation.interface <> null) or (operation.isAbstract))] = 0[/if]
+[/template]
+
+
+[query public ConsDestructorOrVoid(operation : Operation) : String =
+if (hasStereotype(l2::Create)) then
+ ''
+else
+ if (hasStereotype(l2::Destroy)) then
+ '~'
+ else
+ 'void '
+ endif
+endif
+/]
+
+
+[template public CppReturnSpec(operation : Operation)]
+[modConst()/][if (type = null)][ConsDestructorOrVoid()/][else][type.qualifiedName()/] [/if][returnResult().modPtr()/][returnResult().modRef()/]
+[/template]
+
+
+[template public CppConstOp(operation : Operation)]
+[if (hasStereotype(operation, 'Const'))] const[/if]
+[/template]
+
+
+[template public InlineTxt(element : Element)]
+[if (hasStereotype(Inline))]inline [/if]
+[/template]
+
+
+[template public staticTxt(operation : Operation)]
+[if (isStatic)]static [/if]
+[/template]
+
+[template public CppOperationDeclaration(operation : Operation)]
+[CppOperationDoc()/]
+[InlineTxt()/][virtualTxt()/][staticTxt()/][CppReturnSpec()/] [operation.name/]([CppOperationParameters()/])[CppConstOp()/][virtualSuffix()/];
+[/template]
+
+
+[template public CppConstInit(operation : Operation)]
+[if (hasStereotype(ConstInit) and hasStereotype(l2::Create))] : [getApplication(ConstInit).oclAsType(ConstInit).initialisation/][/if]
+[/template]
+
+
+[comment wrapper for native query (otherwise Acceleo does not indent properly)/]
+[template public getBodyInTemplate(operation : Operation, language : String)]
+[getBody(language).trim()/]
+[/template]
+
+
+[template public CppOperationImplementation(operation : Operation)]
+[CppOperationDoc()/]
+[if (operation.name = 'main')]
+[CppReturnSpec()/][operation.name/]([CppOperationParameters()/]) {
+ [getBody('C/C++')/]
+}
+[else]
+[templateSignature()/][InlineTxt()/][CppReturnSpec()/][operation.class.name/]::[operation.name/]([CppOperationParameters()/])[CppConstOp()/][CppConstInit()/] {
+ [getBodyInTemplate('C/C++')/]
+}
+[/if]
+[/template]
diff --git a/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/acceleo/util/operation/CppParameter.mtl b/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/acceleo/util/operation/CppParameter.mtl
new file mode 100644
index 00000000000..5b5e08e92ca
--- /dev/null
+++ b/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/acceleo/util/operation/CppParameter.mtl
@@ -0,0 +1,18 @@
+[module CppParameter('http://www.eclipse.org/uml2/4.0.0/UML')/]
+[import org::eclipse::papyrus::cpp::codegen::utils::GenUtils/]
+[import org::eclipse::papyrus::cpp::codegen::utils::Modifier/]
+
+
+
+[template public defaultValue(parameter : Parameter)]
+[if (hasStereotype(C_Cpp::Default))] = [getApplication(C_Cpp::Default).oclAsType(C_Cpp::Default).value/][/if]
+[/template]
+
+[template public CppParameter(parameter : Parameter)]
+[modConst()/][parameter.type.qualifiedName()/][modPtr()/][modRef()/] [parameter.name/][modArray()/][defaultValue()/]
+[/template]
+
+
+[template public CppOperationParameters(operation : Operation)]
+[for (ownedParameter->select(direction <> ParameterDirectionKind::return)) separator(', ')][CppParameter()/][/for]
+[/template] \ No newline at end of file
diff --git a/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/acceleo/util/property/CppAttributeDeclaration.mtl b/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/acceleo/util/property/CppAttributeDeclaration.mtl
new file mode 100644
index 00000000000..9a22ee68143
--- /dev/null
+++ b/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/acceleo/util/property/CppAttributeDeclaration.mtl
@@ -0,0 +1,21 @@
+[module CppAttributeDeclaration('http://www.eclipse.org/uml2/4.0.0/UML')/]
+[import org::eclipse::papyrus::cpp::codegen::utils::GenUtils/]
+[import org::eclipse::papyrus::cpp::codegen::utils::Modifier/]
+[import org::eclipse::papyrus::cpp::codegen::acceleo::util::CppDocumentation/]
+
+
+
+
+[template public defaultValue(attribute : Property)]
+[if (defaultValue <> null) and isStatic] = [attribute.defaultValue.stringValue()/][/if]
+[/template]
+
+[template public staticValue(attribute : Property)]
+[if (attribute.isStatic)]static [/if]
+[/template]
+
+[template public CppAttributeDeclaration(attribute : Property)]
+[CppElementDoc()/]
+[staticValue()/][modConst()/][attribute.type.qualifiedName()/][modPtr()/][modRef()/] [attribute.name/][modArray()/][defaultValue()/];
+[/template]
+
diff --git a/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/acceleo/util/property/CppAttributeImplementation.mtl b/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/acceleo/util/property/CppAttributeImplementation.mtl
new file mode 100644
index 00000000000..57aae8be4d8
--- /dev/null
+++ b/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/acceleo/util/property/CppAttributeImplementation.mtl
@@ -0,0 +1,35 @@
+[module CppAttributeImplementation('http://www.eclipse.org/uml2/4.0.0/UML')/]
+[import org::eclipse::papyrus::cpp::codegen::utils::GenUtils/]
+[import org::eclipse::papyrus::cpp::codegen::utils::Modifier/]
+[import org::eclipse::papyrus::cpp::codegen::acceleo::util::CppDocumentation/]
+
+
+[comment
+// for static implementation:
+// If attribute is aggregation then generate a pointer
+ if (GenUtils.isAggregation(currentAttribute)) {
+ // attributeName = "(*"+attributeName+")"; // this produce a pointer on a tab
+ isAgg = "*"; // this produce a tab of pointers
+ }
+/]
+
+[template public CppAttributeImplementation(attribute : Property)]
+ [CppElementDoc()/]
+ [modConst()/][attribute.type.qualifiedName()/][modPtr()/][modRef()/] [attribute.name/][modArray()/];
+[/template]
+
+[template public CppStaticAttributeImplementation(attribute : Property)]
+ [CppElementDoc()/]
+ [type.qualifiedName()/][modPtr()/][modRef()/][attribute.class.name/]::[attribute.name/][modArray()/];
+[/template]
+
+[comment
+Loop over attributes. Check that the attribute is not a static const.
+Constant static attributes are declared within the class declaration/]
+[template public CppStaticAttributes(classifier : Classifier)]
+[for (classifier.attribute)]
+ [if(isStatic and (not hasStereotype(C_Cpp::Const)))]
+ [CppStaticAttributeImplementation()/]
+ [/if]
+[/for]
+[/template]
diff --git a/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/preferences/CppCodeGenConstants.java b/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/preferences/CppCodeGenConstants.java
index 3e579c05b10..27adfd59abb 100644
--- a/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/preferences/CppCodeGenConstants.java
+++ b/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/preferences/CppCodeGenConstants.java
@@ -24,6 +24,11 @@ public class CppCodeGenConstants {
public static final String P_IMPLEM_SUFFIX = "implSuffix";
/**
+ * Suffix for generated body/implementation files
+ */
+ public static final String P_OUT_INOUT_OP = "outInoutOp";
+
+ /**
* User defined comment header in generated files
*/
public static final String P_COMMENT_HEADER = "commentHeader";
diff --git a/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/preferences/CppCodeGenPreferenceInitializer.java b/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/preferences/CppCodeGenPreferenceInitializer.java
index 96cacb33444..0de1976c2a8 100644
--- a/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/preferences/CppCodeGenPreferenceInitializer.java
+++ b/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/preferences/CppCodeGenPreferenceInitializer.java
@@ -27,6 +27,7 @@ public class CppCodeGenPreferenceInitializer extends AbstractPreferenceInitializ
IPreferenceStore store = Activator.getDefault().getPreferenceStore();
store.setDefault(CppCodeGenConstants.P_HEADER_SUFFIX, "h");
store.setDefault(CppCodeGenConstants.P_IMPLEM_SUFFIX, "cpp");
+ store.setDefault(CppCodeGenConstants.P_OUT_INOUT_OP, "*");
// Default value for P_COMMENT_HEADER
String NL = System.getProperties().getProperty("line.separator");
diff --git a/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/preferences/CppCodeGenUtils.java b/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/preferences/CppCodeGenUtils.java
index d7094ee9786..58ee3e6ae9a 100644
--- a/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/preferences/CppCodeGenUtils.java
+++ b/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/preferences/CppCodeGenUtils.java
@@ -34,6 +34,11 @@ public class CppCodeGenUtils {
return preferenceStore.getString(CppCodeGenConstants.P_IMPLEM_SUFFIX);
}
+ public static String getOutInoutOp() {
+ initPreferenceStore();
+ return preferenceStore.getString(CppCodeGenConstants.P_OUT_INOUT_OP);
+ }
+
public static String getCommentHeader() {
initPreferenceStore();
return preferenceStore.getString(CppCodeGenConstants.P_COMMENT_HEADER);
diff --git a/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/preferences/CppCodeGenUtils.mtl b/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/preferences/CppCodeGenUtils.mtl
new file mode 100644
index 00000000000..05979359e41
--- /dev/null
+++ b/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/preferences/CppCodeGenUtils.mtl
@@ -0,0 +1,13 @@
+[comment encoding = UTF-8 /]
+[module CppCodeGenUtils('http://www.eclipse.org/uml2/4.0.0/UML')/]
+
+[query public getHeaderSuffix() : String
+ = invoke('org.eclipse.papyrus.cpp.codegen.preferences.CppCodeGenUtils', 'getHeaderSuffix()', Sequence{}) /]
+
+
+[query public getBodySuffix() : String
+ = invoke('org.eclipse.papyrus.cpp.codegen.preferences.CppCodeGenUtils', 'getBodySuffix()', Sequence{}) /]
+
+[query public getCommentHeader() : String
+ = invoke('org.eclipse.papyrus.cpp.codegen.preferences.CppCodeGenUtils', 'getCommentHeader()', Sequence{}) /]
+
diff --git a/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/transformation/CppModelElementsCreator.java b/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/transformation/CppModelElementsCreator.java
new file mode 100644
index 00000000000..7eb3b2ad5d8
--- /dev/null
+++ b/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/transformation/CppModelElementsCreator.java
@@ -0,0 +1,158 @@
+/*******************************************************************************
+ * Copyright (c) 2006 - 2012 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:
+ * CEA LIST - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.papyrus.cpp.codegen.transformation;
+
+import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.papyrus.acceleo.AcceleoDriver;
+import org.eclipse.papyrus.acceleo.ModelElementsCreator;
+import org.eclipse.papyrus.cpp.codegen.preferences.CppCodeGenUtils;
+import org.eclipse.papyrus.cpp.codegen.utils.GenUtils;
+import org.eclipse.papyrus.cpp.profile.StUtils;
+import org.eclipse.uml2.uml.Class;
+import org.eclipse.uml2.uml.Classifier;
+import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.Namespace;
+import org.eclipse.uml2.uml.Package;
+
+import C_Cpp.CppRoot;
+import C_Cpp.ExternClass;
+import C_Cpp.Include;
+import C_Cpp.ManualGeneration;
+import C_Cpp.NoCodeGen;
+import C_Cpp.Template;
+
+
+
+/**
+ * Main class of code generator
+ */
+public class CppModelElementsCreator extends ModelElementsCreator {
+
+ public static final String ACCELEO_PREFIX = "org::eclipse::papyrus::cpp::codegen::acceleo::";
+
+ public static final String CppClassBody = ACCELEO_PREFIX + "CppClassBody";
+
+ public static final String CppClassHeader = ACCELEO_PREFIX + "CppClassHeader";
+
+ public static final String CppBindBody = ACCELEO_PREFIX + "CppBindBody";
+
+ public static final String CppBindHeader = ACCELEO_PREFIX + "CppBindHeader";
+
+ public static final String CppPackageHeader = ACCELEO_PREFIX + "CppPackageHeader";
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param project
+ * the project in which the generated code should be placed
+ */
+ public CppModelElementsCreator(IProject project) {
+ super(project, CppCodeGenUtils.getCommentHeader());
+ hppExt = CppCodeGenUtils.getHeaderSuffix();
+ cppExt = CppCodeGenUtils.getBodySuffix();
+ }
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param project
+ * the project in which the generated code should be placed
+ * @param commentHeader
+ * Custom prefix for each generated file
+ */
+ public CppModelElementsCreator(IProject project, String commentHeader) {
+ super(project, commentHeader);
+ hppExt = CppCodeGenUtils.getHeaderSuffix();
+ cppExt = CppCodeGenUtils.getBodySuffix();
+ }
+
+
+ protected String hppExt;
+
+ protected String cppExt;
+
+
+ /**
+ * Creates the files corresponding to the class. For a "simple" class
+ * generates 2 headers (one for the privates concrete operations and one for
+ * the attributes, public operations and virtual / abstract operations and
+ * one body file.
+ *
+ * @param folder
+ * @param classifier
+ * @throws CoreException
+ */
+ protected void createClassifierFiles(IContainer container, Classifier classifier) throws CoreException {
+
+ // treat case of manual code generation
+ if(GenUtils.hasStereotype(classifier, ManualGeneration.class)) {
+ ManualGeneration mg = StUtils.getApplication(classifier, ManualGeneration.class);
+ Include cppInclude = StUtils.getApplication(classifier, Include.class);
+ String fileContent = commentHeader + cppInclude.getHeader();
+ createFile(container, classifier.getName() + "." + hppExt, fileContent, true);
+
+ String manualURI = "TODO"; // fileContent = AcceleoDriver.evaluateURI(new URI(CppPackageHeader)), classifier);
+
+ fileContent = commentHeader + cppInclude.getPreBody() + GenUtils.NL + manualURI + GenUtils.NL + cppInclude.getBody();
+ String ext = GenUtils.maskNull(mg.getExtensionBody());
+ if(ext.length() == 0) {
+ ext = cppExt;
+ }
+ createFile(container, classifier.getName() + "." + ext, fileContent, true);
+ }
+
+ // Only generate when no CppNoCodeGen stereotype is applied to the class
+ else if((!GenUtils.hasStereotype(classifier, NoCodeGen.class)) && (!GenUtils.hasStereotype(classifier, ExternClass.class)) && (!GenUtils.hasStereotype(classifier, Template.class))) {
+
+ // Template Bound Class
+ if(GenUtils.isTemplateBoundElement(classifier)) {
+ String fileContent = commentHeader + AcceleoDriver.evaluateURI(CppBindHeader, classifier);
+ createFile(container, classifier.getName() + "." + hppExt, fileContent, true);
+
+ fileContent = commentHeader + AcceleoDriver.evaluateURI(CppBindBody, classifier);
+ createFile(container, classifier.getName() + "." + cppExt, fileContent, true);
+ }
+ else {
+ // Header file generation
+ String fileContent = commentHeader + AcceleoDriver.evaluateURI(CppClassHeader, classifier);
+ createFile(container, classifier.getName() + "." + hppExt, fileContent, true);
+
+ // Create class body
+ if(classifier instanceof Class) {
+ fileContent = commentHeader + AcceleoDriver.evaluateURI(CppClassBody, classifier);
+ createFile(container, classifier.getName() + "." + cppExt, fileContent, true);
+ }
+ }
+ }
+ }
+
+
+ protected void createPackageFiles(IContainer packageContainer, IProgressMonitor monitor, Package pkg) throws CoreException {
+ // Creates the header for the package.
+ String fileContent = commentHeader + AcceleoDriver.evaluateURI(CppPackageHeader, pkg);
+ createFile(packageContainer, "Pkg_" + pkg.getName() + "." + hppExt, fileContent, true);
+ }
+
+
+ protected boolean isRoot(Namespace ns) {
+ return GenUtils.hasStereotype(ns, CppRoot.class);
+ }
+
+ protected boolean noCodeGen(Element element) {
+ return GenUtils.hasStereotype(element, NoCodeGen.class);
+ }
+}
diff --git a/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/transformation/ModelElementsCreator.java b/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/transformation/ModelElementsCreator.java
deleted file mode 100644
index 85b2c514068..00000000000
--- a/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/transformation/ModelElementsCreator.java
+++ /dev/null
@@ -1,420 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2006 - 2012 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:
- * CEA LIST - initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.papyrus.cpp.codegen.transformation;
-
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.net.URI;
-
-import org.eclipse.core.filesystem.EFS;
-import org.eclipse.core.filesystem.IFileStore;
-import org.eclipse.core.resources.IContainer;
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IFolder;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.emf.common.util.EList;
-import org.eclipse.papyrus.cpp.codegen.jet.CppBindBody;
-import org.eclipse.papyrus.cpp.codegen.jet.CppBindHeader;
-import org.eclipse.papyrus.cpp.codegen.jet.CppClassBody;
-import org.eclipse.papyrus.cpp.codegen.jet.CppClassHeader;
-import org.eclipse.papyrus.cpp.codegen.jet.CppInterfaceHeader;
-import org.eclipse.papyrus.cpp.codegen.jet.CppPackageHeader;
-import org.eclipse.papyrus.cpp.codegen.jet.CppTemplateHeader;
-import org.eclipse.papyrus.cpp.codegen.jet.util.CppClassIncludeDeclaration;
-import org.eclipse.papyrus.cpp.codegen.utils.GenUtils;
-import org.eclipse.papyrus.cpp.profile.StUtils;
-import org.eclipse.uml2.uml.Class;
-import org.eclipse.uml2.uml.Classifier;
-import org.eclipse.uml2.uml.DataType;
-import org.eclipse.uml2.uml.Enumeration;
-import org.eclipse.uml2.uml.Interface;
-import org.eclipse.uml2.uml.NamedElement;
-import org.eclipse.uml2.uml.Namespace;
-import org.eclipse.uml2.uml.Package;
-import org.eclipse.uml2.uml.PackageableElement;
-import org.eclipse.uml2.uml.PrimitiveType;
-import org.eclipse.uml2.uml.Relationship;
-import org.eclipse.uml2.uml.Usage;
-
-import Cpp.CppExternClass;
-import Cpp.CppInclude;
-import Cpp.CppNoCodeGen;
-import Cpp.CppRoot;
-import Cpp.CppTemplate;
-import Cpp.ManualGeneration;
-
-
-
-/**
- * Main class of code generator
- */
-public class ModelElementsCreator {
-
- /**
- *
- * Constructor.
- *
- * @param project
- * the project in which the generated code should be placed
- * @param hppExt
- * The file suffix for c++ header files
- * @param cppExt
- * The file suffix for c++ implementation files
- * @param headerComment
- * Prefix for each generated file
- */
- public ModelElementsCreator(IProject project, String hppExt, String cppExt, String headerComment) {
- this.hppExt = hppExt;
- this.cppExt = cppExt;
- this.headerComment = headerComment;
- this.project = project;
- }
-
- private String hppExt;
-
- private String cppExt;
-
- private String headerComment;
-
- private IProject project;
-
- /**
- * Main function for user calls. Creates code for a packageable element.
- *
- * @param monitor
- * a progress monitor
- * @param element
- * the element for which code should be generated
- * @throws CoreException
- */
- public void createPackageableElement(IProgressMonitor monitor, PackageableElement element) throws CoreException {
- IContainer packageContainer = getContainer(element);
- createPackageableElement(packageContainer, monitor, element);
- }
-
- /**
- * Variant of main function: user may supply explicit container (also used by internal function to avoid
- * re-calculating the entry container for each element).
- *
- * @param packageContainer
- * The container (directory), in which code should be created
- * @param monitor
- * a progress monitor
- * @param element
- * the element for which code should be generated
- * @throws CoreException
- */
- public void createPackageableElement(IContainer packageContainer, IProgressMonitor monitor, PackageableElement element) throws CoreException {
- if(element instanceof Package) {
- createPackage(packageContainer, monitor, (Package)element);
- } else if(element instanceof Class) {
- createClassFiles(packageContainer, (Class)element);
- } else if(element instanceof Interface) {
- createInterfaceFile(packageContainer, (Interface)element);
- } else if((element instanceof PrimitiveType) || (element instanceof Enumeration) || (element instanceof Usage)) {
- // do nothing, included in package
- } else if(element instanceof DataType) {
- createDataTypeFiles(packageContainer, (DataType)element);
- } else if(element instanceof Relationship) {
- // no code generation for relationships
- } else {
- System.err.println("C++ code generator: unsupported model element " + element);
- }
- }
-
- public void removePackageableElement(IProgressMonitor monitor, PackageableElement element) throws CoreException {
- IContainer packageContainer = getContainer(element);
- if(packageContainer instanceof IFolder) {
- if(element instanceof Package) {
- IFolder folder = ((IFolder)packageContainer).getFolder(element.getName());
- folder.delete(true, null);
- } else if(element instanceof Classifier) {
- IFile file = ((IFolder)packageContainer).getFile(element.getName());
- file.delete(true, null);
- }
- }
- }
-
- /**
- * Creates the files corresponding to the class. For a "simple" class
- * generates 2 headers (one for the privates concrete operations and one for
- * the attributes, public operations and virtual / abstract operations and
- * one body file.
- *
- * @param folder
- * @param classObject
- * @throws CoreException
- */
- protected void createClassFiles(IContainer container, Class classObject) throws CoreException {
-
- // treat case of manual code generation
- if(GenUtils.hasStereotype(classObject, ManualGeneration.class)) {
- ManualGeneration mg = StUtils.getApplication(classObject, ManualGeneration.class);
- CppInclude cppInclude = StUtils.getApplication(classObject, CppInclude.class);
- String fileContent = headerComment + cppInclude.getHeader();
- createFile(container, classObject.getName() + "." + hppExt, fileContent, true);
-
- CppClassIncludeDeclaration jetIDecl = new CppClassIncludeDeclaration();
- String include = jetIDecl.generate(classObject);
-
- fileContent = headerComment + cppInclude.getPreBody() + GenUtils.NL + include + GenUtils.NL + cppInclude.getBody();
- String ext = GenUtils.maskNull(mg.getExtensionBody());
- if(ext.length() == 0) {
- ext = cppExt;
- }
- createFile(container, classObject.getName() + "." + ext, fileContent, true);
- }
-
- // Only generate when no CppNoCodeGen stereotype is applied to the class
- else if((!GenUtils.hasStereotype(classObject, CppNoCodeGen.class)) && (!GenUtils.hasStereotype(classObject, CppExternClass.class)) && (!GenUtils.hasStereotype(classObject, CppTemplate.class))) {
-
- CppClassHeader headerGenerator = new CppClassHeader();
- CppClassBody bodyGenerator = new CppClassBody();
-
- // Template Bound Class
- if(GenUtils.isTemplateBoundElement(classObject)) {
- CppBindHeader templateBindingGenerator = new CppBindHeader();
- CppBindBody bodyBindingGenerator = new CppBindBody();
- String fileContent = headerComment + templateBindingGenerator.generate(classObject);
- createFile(container, classObject.getName() + "." + hppExt, fileContent, true);
-
- fileContent = headerComment + bodyBindingGenerator.generate(classObject);
- createFile(container, classObject.getName() + "." + cppExt, fileContent, true);
- } else {
- if(classObject.isTemplate()) {
- CppTemplateHeader templateGenerator = new CppTemplateHeader();
- String fileContent = headerComment + templateGenerator.generate(classObject);
- createFile(container, classObject.getName() + "." + hppExt, fileContent, true);
- } else {
-
- // The class is actually a class.
-
- // Header file generation
- String fileContent = headerComment + headerGenerator.generate(classObject);
- createFile(container, classObject.getName() + "." + hppExt, fileContent, true);
-
- // "Traditional" code generation : one body file for all
- // operations.
- fileContent = headerComment + bodyGenerator.generate(classObject);
- createFile(container, classObject.getName() + "." + cppExt, fileContent, true);
- }
- }
- }
- }
-
- /**
- * Creates the files corresponding to data types.
- *
- * @param container
- * @param dataTypeObject
- * @throws CoreException
- */
- protected void createDataTypeFiles(IContainer container, DataType dataTypeObject) throws CoreException {
-
- CppClassHeader headerGenerator = new CppClassHeader();
- CppClassBody bodyGenerator = new CppClassBody();
-
- String fileContent = "";
-
- // Only generate when no CppNoCodeGen stereotype is applied to the class
- if((!GenUtils.hasStereotype(dataTypeObject, CppNoCodeGen.class)) && (!GenUtils.hasStereotype(dataTypeObject, CppExternClass.class)) && (!GenUtils.hasStereotype(dataTypeObject, CppTemplate.class))) {
-
- // Template Bound Class
- // templates for data types currently not supported
- /*
- * if(dataTypeObject.isTemplateBoundElement())
- * {
- * CppBindHeader templateBindingGenerator = new CppBindHeader();
- * CppBindBody bodyBindingGenerator = new CppBindBody();
- * fileContent = headerComment
- * + templateBindingGenerator.generate(dataTypeObject);
- * createFile(container, dataTypeObject.getName() + "." + hpp,
- * fileContent, true);
- *
- * fileContent = headerComment
- * + bodyBindingGenerator.generate(dataTypeObject);
- * createFile(container, dataTypeObject.getName() + "." + cpp,
- * fileContent, true);
- * } else {
- */
-
- // Header file generation
- fileContent = headerComment + headerGenerator.generate(dataTypeObject);
- createFile(container, dataTypeObject.getName() + "." + hppExt, fileContent, true);
-
- // "Traditional" code generation : one body file for all
- // operations.
- fileContent = headerComment + bodyGenerator.generate(dataTypeObject);
- createFile(container, dataTypeObject.getName() + "." + cppExt, fileContent, true);
- }
- }
-
- /**
- * Creates a <em>text</em> file in an eclipse container (either IFolder or
- * IProject). If this file already exists it is replaced.
- *
- * @param owner
- * the container that will contain the file.
- * @param filename
- * The name of the file to create.
- * @param content
- * Te text content of the file.
- * @throws CoreException
- */
- protected void createFile(IContainer owner, String filename, String content, boolean force) throws CoreException {
- IFile file = null;
- if(owner instanceof IProject) {
- file = ((IProject)owner).getFile(filename);
- } else if(owner instanceof IFolder) {
- file = ((IFolder)owner).getFile(filename);
- } else {
- // undefined
- }
- if(file != null) {
- createFile(file, content, force);
- }
- }
-
- /**
- * Creates a <em>text</em> file in an eclipse folder. If this file already
- * exists it is replaced.
- *
- * @param folder
- * The folder that will contain the file.
- * @param filename
- * The name of the file to create.
- * @param content
- * Te text content of the file.
- * @throws CoreException
- */
- protected void createFile(IFile file, String content, boolean force) throws CoreException {
- if(file.exists() && force) {
- // file.delete(true,true,null);
- // YT - deleting files produce inconsistency in SVN working copies
- final URI locationURI = file.getLocationURI();
- if(locationURI != null) {
- IFileStore store = EFS.getStore(locationURI);
- OutputStream os = store.openOutputStream(0, null);
- try {
- os.write(content.getBytes());
- } catch (IOException e) {
- System.err.println(e);
- }
- }
- // file.setContents(new ByteArrayInputStream(content.getBytes()),
- // true, true, null);
- } else if(file.exists() && !(force)) {
- // the file is not updated
- } else {
- // the file does not exists
- file.create(new ByteArrayInputStream(content.getBytes()), true, null);
- }
- }
-
- /**
- * Creates the header file corresponding to the interface
- *
- * @param folder
- * @param interfaceObject
- * @throws CoreException
- */
- protected void createInterfaceFile(IContainer container, Interface interfaceObject) throws CoreException {
- if(!GenUtils.hasStereotype(interfaceObject, CppNoCodeGen.class)) {
-
- CppInterfaceHeader headerGenerator = new CppInterfaceHeader();
- String fileContent = "";
-
- fileContent = headerComment + headerGenerator.generate(interfaceObject);
- createFile(container, interfaceObject.getName() + "." + hppExt, fileContent, true);
- }
- }
-
- /**
- * Recursively creates folders for a given package
- *
- * @param packageContainer
- * The folder where the folder hierarchy for this package will be
- * created.
- * @param monitor
- * a progress monitor
- * @param pkg
- * the package for which code should be created
- * @throws CoreException
- */
- protected void createPackage(IContainer packageContainer, IProgressMonitor monitor, Package pkg) throws CoreException {
- monitor.subTask("generate package " + pkg.getQualifiedName());
-
- if(!GenUtils.hasStereotype(pkg, CppRoot.class) && !GenUtils.hasStereotype(pkg, CppNoCodeGen.class)) {
-
- String fileContent = "";
-
- packageContainer = (packageContainer instanceof IProject) ? ((IProject)packageContainer).getFolder(pkg.getName()) : ((IFolder)packageContainer).getFolder(pkg.getName());
-
- // Create a new folder corresponding to the package if it does not exist
- if(!packageContainer.exists()) {
- // if packageContainer is a Project, it necessarily exists
- ((IFolder)packageContainer).create(false, true, null);
- }
-
- // Creates the header for the package.
- CppPackageHeader pkgHeaderGenerator = new CppPackageHeader();
- fileContent = "";
- fileContent = headerComment + pkgHeaderGenerator.generate(pkg);
- createFile(packageContainer, "Pkg_" + pkg.getName() + "." + hppExt, fileContent, true);
-
- // Continue generation parsing package content
- // If CppNoCodeGen on package, it applies to its content
-
- for(PackageableElement currentElement : pkg.getPackagedElements()) {
- createPackageableElement(packageContainer, monitor, currentElement);
- }
- }
- }
-
- /**
- * Return a container (folder) for a given named element. The folder is embedded into a set
- * of folders that correspond to the namespaces of the element. These folders will be
- * created, if the do not exist (comparable to "mkdir -p" in Unix).
- *
- * @param element
- * a named element
- * @return folder for this element
- */
- public IContainer getContainer(NamedElement element) {
- try {
- IContainer packageContainer = project;
- EList<Namespace> namespaces = element.allNamespaces();
- for(int i = namespaces.size() - 1; i >= 0; i--) {
- Namespace ns = namespaces.get(i);
- if(GenUtils.hasStereotype(ns, CppRoot.class)) {
- // TODO: not very clean. Is this stereotype still used?
- packageContainer = project;
- } else if(packageContainer instanceof IFolder) {
- packageContainer = ((IFolder)packageContainer).getFolder(ns.getName());
- } else if(packageContainer instanceof IProject) {
- packageContainer = ((IProject)packageContainer).getFolder(ns.getName());
- }
- if(!packageContainer.exists()) {
- // if packageContainer is a Project, it necessarily exists
- ((IFolder)packageContainer).create(false, true, null);
- }
- }
- return packageContainer;
- } catch (CoreException e) {
- e.printStackTrace();
- return null;
- }
- }
-}
diff --git a/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/utils/ClassUtils.java b/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/utils/ClassUtils.java
index 78957b9bccd..301851b5be8 100644
--- a/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/utils/ClassUtils.java
+++ b/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/utils/ClassUtils.java
@@ -13,20 +13,10 @@ package org.eclipse.papyrus.cpp.codegen.utils;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.common.util.UniqueEList;
-import org.eclipse.papyrus.cpp.codegen.Constants;
-import org.eclipse.papyrus.cpp.codegen.jet.util.CppClassIncludeDeclaration;
-import org.eclipse.papyrus.cpp.codegen.jet.util.CppOwnerPackageIncludeDeclaration;
-import org.eclipse.papyrus.cpp.codegen.jet.util.CppStaticAttributeImplementation;
+import org.eclipse.uml2.uml.Class;
import org.eclipse.uml2.uml.Classifier;
-import org.eclipse.uml2.uml.Enumeration;
-import org.eclipse.uml2.uml.Package;
-import org.eclipse.uml2.uml.PrimitiveType;
-import org.eclipse.uml2.uml.Property;
-import Cpp.CppConst;
-import Cpp.CppExternClass;
-import Cpp.CppInclude;
-import Cpp.CppNoCodeGen;
+import C_Cpp.Include;
/**
* A set of utility functions related to classes.
@@ -37,128 +27,30 @@ import Cpp.CppNoCodeGen;
public class ClassUtils {
/**
- * Generate the "pre-body" statements that are stored in the CppInclude stereotype
- * "pre" means: add before the ".cpp" file includes its own header file of a program
- *
- * @param currentClass
- * @return generated text
- */
- public static String getCppIncludePreBody(Classifier currentClass) {
- CppInclude cppInclude = GenUtils.getApplication(currentClass, CppInclude.class);
- if(cppInclude != null) {
- return GenUtils.addNL(cppInclude.getPreBody());
- }
- return "";
- }
-
- /**
- * Generate the body statements that are stored in the CppInclude stereotype
- * Body means that these statements are added at the beginning of the "body" (the ".cpp") file.
- *
- * @param currentClass
- * @return generated text
- */
- public static String getCppIncludeBody(Classifier currentClass) {
- CppInclude cppInclude = GenUtils.getApplication(currentClass, CppInclude.class);
- if(cppInclude != null) {
- return GenUtils.addNL(cppInclude.getBody());
- }
- return "";
- }
-
- /**
- * Generated include statements related to dependencies.
- *
- * @param currentCl
- * @return generated text
- */
- public static String createIncludeDecl(Classifier currentCl) {
- EList<Classifier> depClassifiers = GenUtils.getDependencies(currentCl);
- return createIncludeDecl(depClassifiers, currentCl);
- }
-
- public static String createIncludeDecl(EList<Classifier> usedClassifiers, Classifier currentCl) {
- String includes = "";
- String forwardDecls = Constants.forwardDecl;
-
- // avoid duplicates
- EList<Package> ownerPackages = new UniqueEList<Package>();
-
- for(Classifier cl : usedClassifiers) {
-
- // Only add include if this is not for the current class
- if(!currentCl.equals(cl)) {
- // ... and if it does not have the stereotype "CppNoCodeGen", unless
- // it has stereotype "CppExternalClass"
- if((!GenUtils.hasStereotype(cl, CppNoCodeGen.class)) || GenUtils.hasStereotype(cl, CppExternClass.class)) {
- String newInclude = "";
-
- if((cl instanceof Enumeration) || (cl instanceof PrimitiveType)) {
- // Enumeration is not defined in a separate file, but in the
- // package that owns it => include the owning package (might be a duplicate input, if owning
- // package is also the owner of current class)
- if(cl.getOwner() instanceof Package) {
- Package owner = (Package)cl.getOwner();
- if(!ownerPackages.contains(owner)) {
- ownerPackages.add(owner);
- CppOwnerPackageIncludeDeclaration jetIDecl = new CppOwnerPackageIncludeDeclaration();
- newInclude = jetIDecl.generate(owner);
- }
- }
- } else {
- // include the file associated with the classifier
- CppClassIncludeDeclaration jetIDecl = new CppClassIncludeDeclaration();
- newInclude = jetIDecl.generate(cl);
- }
-
- includes = includes + newInclude;
-
- // generate a forward declaration
- // this is useful, even if the ".h" file associated with the class is included:
- // in case of cyclic dependencies, the include file may actually not be included since
- // its #ifndef rule will exclude code.
- // Don't generate forward for external classes, which may actually be non-classes
- /*
- * if ((cl instanceof Class) && !GenUtils.hasStereotype(cl, CppdxternClass)) {
- * Class classWithoutBinding = (Class) cl;
- * if (classWithoutBinding.getTemplateBindings().isEmpty()) {
- * CppClassIncludeClassDeclaration jetCDecl
- * = new CppClassIncludeClassDeclaration();
- * String newClass = jetCDecl.generate(classWithoutBinding);
- * forwardDecls += newClass;
- * }
- * }
- */
- }
- }
- }
- includes += forwardDecls;
- return includes;
- }
-
- /**
- * get the list of static attributes for the implementation
+ * Calculate the list of classifiers that needs to be included
*
* @param currentClass
* @return
*/
- public static String getStaticAttributes(Classifier currentClass) {
- String attrSDecl = "";
-
- CppStaticAttributeImplementation jetSAttDecl = new CppStaticAttributeImplementation();
-
- for(Property attribute : currentClass.getAttributes()) {
-
- // check that the attribute is not a static const, in that case it is declared and defined in the header file
-
- // Static and not constant (constant static attributes are declared within the class declaration)
- if(attribute.isStatic() && !GenUtils.hasStereotype(attribute, CppConst.class)) {
- attrSDecl = attrSDecl + jetSAttDecl.generate(attribute);
- }
+ public static EList<Classifier> includedClassifiers(Classifier currentClass) {
+ // Retrieve package used by current package (dependencies)
+ // use a unique list to avoid duplicates
+ EList<Classifier> usedClasses = new UniqueEList<Classifier>();
+
+ // class attributes dependencies
+ usedClasses.addAll(GenUtils.getOwnedAttributeTypes(currentClass));
+ // operation parameters dependencies
+ usedClasses.addAll(GenUtils.getIncludesFromOperations(currentClass));
+ // realized interface dependencies
+ if(currentClass instanceof Class) {
+ usedClasses.addAll(GenUtils.getImplementedInterfaces((Class)currentClass));
}
- if(attrSDecl.length() > 0) {
- attrSDecl = Constants.staticAttributes + "\n" + attrSDecl;
- }
- return attrSDecl;
+ // dependencies and associations
+ usedClasses.addAll(GenUtils.getRelationshipsNoDeps(currentClass));
+
+ // template parameters are declared locally (if owned) and do not correspond to a file
+ // that can be included
+ usedClasses.removeAll(GenUtils.getTemplateParameteredElements(currentClass));
+ return usedClasses;
}
}
diff --git a/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/utils/ClassUtils.mtl b/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/utils/ClassUtils.mtl
new file mode 100644
index 00000000000..19e55603802
--- /dev/null
+++ b/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/utils/ClassUtils.mtl
@@ -0,0 +1,6 @@
+[comment encoding = UTF-8 /]
+[module ClassUtils('http://www.eclipse.org/uml2/4.0.0/UML')/]
+
+[query public includedClassifiers(cl : Classifier) : Sequence(Classifier)
+ = invoke('org.eclipse.papyrus.cpp.codegen.utils.ClassUtils', 'includedClassifiers(org.eclipse.uml2.uml.Classifier)', Sequence{cl}) /]
+
diff --git a/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/utils/GenUtils.java b/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/utils/GenUtils.java
index 1c7977bd166..262f936116c 100644
--- a/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/utils/GenUtils.java
+++ b/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/utils/GenUtils.java
@@ -18,7 +18,9 @@ import java.util.Iterator;
import org.eclipse.emf.common.util.BasicEList;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.common.util.UniqueEList;
+import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
+import org.eclipse.papyrus.cpp.codegen.Constants;
import org.eclipse.uml2.uml.AggregationKind;
import org.eclipse.uml2.uml.Behavior;
import org.eclipse.uml2.uml.Class;
@@ -50,10 +52,10 @@ import org.eclipse.uml2.uml.TemplateParameter;
import org.eclipse.uml2.uml.TemplateSignature;
import org.eclipse.uml2.uml.Type;
-import Cpp.CppExternClass;
-import Cpp.CppNoCodeGen;
-import Cpp.CppType;
-import Cpp.CppVisibility;
+import C_Cpp.ExternClass;
+import C_Cpp.NoCodeGen;
+import C_Cpp.Typedef;
+import C_Cpp.Visibility;
@@ -86,14 +88,14 @@ public class GenUtils {
return binding;
}
- public static boolean isTemplateBoundElement(Class uml2Class) {
+ public static boolean isTemplateBoundElement(Classifier cl) {
boolean result = false;
- EList<TemplateBinding> tb = uml2Class.getTemplateBindings();
+ EList<TemplateBinding> tb = cl.getTemplateBindings();
if(tb != null) {
Iterator<TemplateBinding> itb = tb.iterator();
while(itb.hasNext()) {
TemplateBinding currentTb = itb.next();
- result = currentTb.getBoundElement() == uml2Class;
+ result = currentTb.getBoundElement() == cl;
}
}
return result;
@@ -439,6 +441,9 @@ public class GenUtils {
public static String openNS(NamedElement ne) {
String openNS = "";
currentNS = ne.getNamespace();
+ if(ne instanceof Package) {
+ openNS = "namespace " + ne.getName() + " {\n";
+ }
for(Namespace ns : ne.allNamespaces()) {
if(ns.getOwner() != null) {
openNS = "namespace " + ns.getName() + " {\n" + openNS;
@@ -456,6 +461,9 @@ public class GenUtils {
*/
public static String closeNS(NamedElement ne) {
String closeNS = "";
+ if(ne instanceof Package) {
+ closeNS = "} // of namespace " + ne.getName() + "\n";
+ }
for(Namespace ns : ne.allNamespaces()) {
if(ns.getOwner() != null) {
closeNS += "} // of namespace " + ns.getName() + "\n";
@@ -464,13 +472,22 @@ public class GenUtils {
return closeNS;
}
+ /**
+ * Return the qualified name of a named element or "undefined", if it does not exist.
+ *
+ * @param ne
+ * @return
+ */
public static String qualifiedName(NamedElement ne) {
+ if(ne == null) {
+ return Constants.undefinedType;
+ }
Object owner = ne.getOwner();
String owningPkgName = "";
if(owner instanceof Package) {
owningPkgName = ((Package)owner).getName();
}
- if((hasStereotype(ne, CppExternClass.class)) || (hasStereotype(ne, CppNoCodeGen.class))) {
+ if((hasStereotype(ne, ExternClass.class)) || (hasStereotype(ne, NoCodeGen.class))) {
return ne.getName();
} else if(owningPkgName.equals("AnsiCLibrary")) {
// always use the short name for types within the ANSI C library
@@ -483,7 +500,7 @@ public class GenUtils {
return qName;
}
if(ne instanceof PrimitiveType) {
- if(!hasStereotype(ne, CppType.class) && (getStdtypes((PrimitiveType)ne).length() == 0)) {
+ if(!hasStereotype(ne, Typedef.class) && (getStdtypes((PrimitiveType)ne).length() == 0)) {
// is a primitive type without further definition and not a standard primitive type
// => assume that it is a external type without namespace
return qName;
@@ -507,7 +524,8 @@ public class GenUtils {
public static String getComments(Element element) {
String commentText = "";
for(Comment comment : element.getOwnedComments()) {
- commentText += comment.getBody();
+ // remove eventual CRs (avoid confusion in Acceleo template which adds " *" after line breaks)
+ commentText += comment.getBody().replace("\r", "");
}
return commentText;
}
@@ -579,7 +597,7 @@ public class GenUtils {
*/
public static boolean hasStereotype(Element element, java.lang.Class<? extends EObject> clazz) {
for(EObject stereoApplication : element.getStereotypeApplications()) {
- // check whether the stereotype is a subclass of the passed parameter clazz
+ // check whether the stereotype is a suopebclass of the passed parameter clazz
if(clazz.isAssignableFrom(stereoApplication.getClass())) {
return true;
}
@@ -587,6 +605,29 @@ public class GenUtils {
return false;
}
+
+ /**
+ * Is a certain stereotype applied?
+ *
+ * @param element
+ * @param stereotype
+ * fully qualified stereotype name
+ * @return
+ */
+ public static boolean hasStereotypeA(Element element, EClass eClass) {
+ if(element == null) {
+ // make query more robust
+ return false;
+ }
+ for(EObject stereoApplication : element.getStereotypeApplications()) {
+ // check whether the stereotype application has the right eClass
+ if(stereoApplication.eClass() == eClass) {
+ return true;
+ }
+ }
+ return false;
+ }
+
/**
* Return the stereotype application by passing an element of the static profile
*
@@ -607,6 +648,16 @@ public class GenUtils {
return null;
}
+ public static EObject getApplicationA(Element element, EClass eClass) {
+ for(EObject stereoApplication : element.getStereotypeApplications()) {
+ // check whether the stereotype is an instance of the passed parameter clazz
+ if(stereoApplication.eClass() == eClass) {
+ return stereoApplication;
+ }
+ }
+ return null;
+ }
+
/**
* Is a certain stereotype applied?
*
@@ -684,48 +735,25 @@ public class GenUtils {
for(String language : ob.getLanguages()) {
String body = bodies.next();
if(language.equals(selectedLanguage)) {
- return indent(body, "\t");
+ // additional "\r" confuse Acceleo
+ return body.replace("\r", "");
}
}
}
}
return "";
}
-
+
/**
- * Format text output, indent each line with the passed string
- *
- * @param source
- * @param indentStr
- * @return
- */
- public static String indent(String source, String indentStr) {
- String result = "";
- String[] lines = source.split("\n");
- for(int i = 0; i < lines.length; i++) {
- result += indentStr + lines[i];
- if(i < lines.length - 1) {
- result += "\n";
- }
- }
- return result;
- }
-
- /**
- * return true, if shared aggregation (no composition).
- * TODO: consider whether used as association?
- *
- * @param p
+ * Return the C++ visibility (on generalizations) in text form. Return public, if no stereotype
+ * visibility exists
+ *
+ * @param element
* @return
*/
- public static boolean isAggregation(Property p) {
- return /* (p.getAssociation() != null) && */
- (p.getAggregation() == AggregationKind.SHARED_LITERAL);
- }
-
- public static String getVisibility(Element element) {
+ public static String getGeneralizationVisibility(Element element) {
// get visibility and target name
- CppVisibility cppVisibility = GenUtils.getApplication(element, CppVisibility.class);
+ Visibility cppVisibility = GenUtils.getApplication(element, Visibility.class);
if(cppVisibility != null) {
return cppVisibility.getValue();
} else {
@@ -746,20 +774,5 @@ public class GenUtils {
return str;
}
- /**
- * Add a newline character, unless the string is empty and unless it already ends with a
- * newline character
- */
- public static String addNL(String str) {
- if(str == null || str.length() == 0) {
- return "";
- }
- if(str.endsWith(NL)) {
- return str;
- } else {
- return str + NL;
- }
- }
-
private static Namespace currentNS;
}
diff --git a/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/utils/GenUtils.mtl b/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/utils/GenUtils.mtl
new file mode 100644
index 00000000000..c0bc93115e4
--- /dev/null
+++ b/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/utils/GenUtils.mtl
@@ -0,0 +1,104 @@
+[comment encoding = UTF-8 /]
+[module GenUtils('http://www.eclipse.org/uml2/4.0.0/UML')/]
+
+[query public getName(arg0 : TemplateParameter) : String
+ = invoke('org.eclipse.papyrus.cpp.codegen.utils.GenUtils', 'getName(org.eclipse.uml2.uml.TemplateParameter)', Sequence{arg0}) /]
+
+[query public getType(arg0 : TemplateParameter) : String
+ = invoke('org.eclipse.papyrus.cpp.codegen.utils.GenUtils', 'getType(org.eclipse.uml2.uml.TemplateParameter)', Sequence{arg0}) /]
+
+[query public getFullName(arg0 : NamedElement) : String
+ = invoke('org.eclipse.papyrus.cpp.codegen.utils.GenUtils', 'getFullName(org.eclipse.uml2.uml.NamedElement)', Sequence{arg0}) /]
+
+[query public maskNull(arg0 : String) : String
+ = invoke('org.eclipse.papyrus.cpp.codegen.utils.GenUtils', 'maskNull(java.lang.String)', Sequence{arg0}) /]
+
+[query public getNamespace(arg0 : NamedElement) : String
+ = invoke('org.eclipse.papyrus.cpp.codegen.utils.GenUtils', 'getNamespace(org.eclipse.uml2.uml.NamedElement)', Sequence{arg0}) /]
+
+[query public indent(arg0 : String, arg1 : String) : String
+ = invoke('org.eclipse.papyrus.cpp.codegen.utils.GenUtils', 'indent(java.lang.String, java.lang.String)', Sequence{arg0, arg1}) /]
+
+[query public getApplication(arg0 : Element, arg1 : OclAny) : OclAny
+ = invoke('org.eclipse.papyrus.cpp.codegen.utils.GenUtils', 'getApplicationA(org.eclipse.uml2.uml.Element, org.eclipse.emf.ecore.EClass)', Sequence{arg0, arg1}) /]
+
+[query public getFullPath(arg0 : Package) : String
+ = invoke('org.eclipse.papyrus.cpp.codegen.utils.GenUtils', 'getFullPath(org.eclipse.uml2.uml.Package)', Sequence{arg0}) /]
+
+[query public qualifiedName(arg0 : NamedElement) : String
+ = invoke('org.eclipse.papyrus.cpp.codegen.utils.GenUtils', 'qualifiedName(org.eclipse.uml2.uml.NamedElement)', Sequence{arg0}) /]
+
+[query public getGeneralizationVisibility(arg0 : Element) : String
+ = invoke('org.eclipse.papyrus.cpp.codegen.utils.GenUtils', 'getGeneralizationVisibility(org.eclipse.uml2.uml.Element)', Sequence{arg0}) /]
+
+[query public getRelationships(arg0 : Classifier) : Sequence(Relationship)
+ = invoke('org.eclipse.papyrus.cpp.codegen.utils.GenUtils', 'getRelationships(org.eclipse.uml2.uml.Classifier)', Sequence{arg0}) /]
+
+[query public getTemplateBindings(arg0 : Class) : TemplateBinding
+ = invoke('org.eclipse.papyrus.cpp.codegen.utils.GenUtils', 'getTemplateBindings(org.eclipse.uml2.uml.Class)', Sequence{arg0}) /]
+
+[query public getImplementedInterfaces(arg0 : Class) : Sequence(Interface)
+ = invoke('org.eclipse.papyrus.cpp.codegen.utils.GenUtils', 'getImplementedInterfaces(org.eclipse.uml2.uml.Class)', Sequence{arg0}) /]
+
+[query public getBody(arg0 : Operation, arg1 : String) : String
+ = invoke('org.eclipse.papyrus.cpp.codegen.utils.GenUtils', 'getBody(org.eclipse.uml2.uml.Operation, java.lang.String)', Sequence{arg0, arg1}) /]
+
+[query public getTaggedValue(arg0 : Element, arg1 : String, arg2 : String) : String
+ = invoke('org.eclipse.papyrus.cpp.codegen.utils.GenUtils', 'getTaggedValue(org.eclipse.uml2.uml.Element, java.lang.String, java.lang.String)', Sequence{arg0, arg1, arg2}) /]
+
+[query public setTaggedValue(arg0 : Element, arg1 : String, arg2 : String, arg3 : OclAny) : OclVoid
+ = invoke('org.eclipse.papyrus.cpp.codegen.utils.GenUtils', 'setTaggedValue(org.eclipse.uml2.uml.Element, java.lang.String, java.lang.String, java.lang.Object)', Sequence{arg0, arg1, arg2, arg3}) /]
+
+[query public getComments(arg0 : Element) : String
+ = invoke('org.eclipse.papyrus.cpp.codegen.utils.GenUtils', 'getComments(org.eclipse.uml2.uml.Element)', Sequence{arg0}) /]
+
+[query public getDependencies(arg0 : Classifier) : Sequence(Dependency)
+ = invoke('org.eclipse.papyrus.cpp.codegen.utils.GenUtils', 'getDependencies(org.eclipse.uml2.uml.Classifier)', Sequence{arg0}) /]
+
+[query public setStereotype(arg0 : Element, arg1 : String, arg2 : Boolean) : OclVoid
+ = invoke('org.eclipse.papyrus.cpp.codegen.utils.GenUtils', 'setStereotype(org.eclipse.uml2.uml.Element, java.lang.String, boolean)', Sequence{arg0, arg1, arg2}) /]
+
+[query public hasStereotype(arg0 : Element, arg1 : String) : Boolean
+ = invoke('org.eclipse.papyrus.cpp.codegen.utils.GenUtils', 'hasStereotype(org.eclipse.uml2.uml.Element, java.lang.String)', Sequence{arg0, arg1}) /]
+
+[query public hasStereotype(arg0 : Element, arg1 : OclAny) : Boolean
+ = invoke('org.eclipse.papyrus.cpp.codegen.utils.GenUtils', 'hasStereotypeA(org.eclipse.uml2.uml.Element, org.eclipse.emf.ecore.EClass)', Sequence{arg0, arg1}) /]
+
+[query public isTemplateBoundElement(arg0 : Classifier) : Boolean
+ = invoke('org.eclipse.papyrus.cpp.codegen.utils.GenUtils', 'isTemplateBoundElement(org.eclipse.uml2.uml.Classifier)', Sequence{arg0}) /]
+
+[query public getTemplateParameters(arg0 : Classifier) : Collection(TemplateParameter)
+ = invoke('org.eclipse.papyrus.cpp.codegen.utils.GenUtils', 'getTemplateParameters(org.eclipse.uml2.uml.Classifier)', Sequence{arg0}) /]
+
+[query public getTemplateParameteredElements(arg0 : Classifier) : Collection(OclAny)
+ = invoke('org.eclipse.papyrus.cpp.codegen.utils.GenUtils', 'getTemplateParameteredElements(org.eclipse.uml2.uml.Classifier)', Sequence{arg0}) /]
+
+[query public getTemplateParametersWoType(arg0 : Classifier) : String
+ = invoke('org.eclipse.papyrus.cpp.codegen.utils.GenUtils', 'getTemplateParametersWoType(org.eclipse.uml2.uml.Classifier)', Sequence{arg0}) /]
+
+[query public getStdtypes(arg0 : PrimitiveType) : String
+ = invoke('org.eclipse.papyrus.cpp.codegen.utils.GenUtils', 'getStdtypes(org.eclipse.uml2.uml.PrimitiveType)', Sequence{arg0}) /]
+
+[query public getOwnedAttributeTypes(arg0 : Classifier) : Sequence(Type)
+ = invoke('org.eclipse.papyrus.cpp.codegen.utils.GenUtils', 'getOwnedAttributeTypes(org.eclipse.uml2.uml.Classifier)', Sequence{arg0}) /]
+
+[query public getIncludesFromOperations(arg0 : Classifier) : Sequence(Classifier)
+ = invoke('org.eclipse.papyrus.cpp.codegen.utils.GenUtils', 'getIncludesFromOperations(org.eclipse.uml2.uml.Classifier)', Sequence{arg0}) /]
+
+[query public getRelationshipsNoDeps(arg0 : Classifier) : Sequence(Relationship)
+ = invoke('org.eclipse.papyrus.cpp.codegen.utils.GenUtils', 'getRelationshipsNoDeps(org.eclipse.uml2.uml.Classifier)', Sequence{arg0}) /]
+
+[query public getFullNameUC(arg0 : NamedElement) : String
+ = invoke('org.eclipse.papyrus.cpp.codegen.utils.GenUtils', 'getFullNameUC(org.eclipse.uml2.uml.NamedElement)', Sequence{arg0}) /]
+
+[query public openNS(arg0 : NamedElement) : String
+ = invoke('org.eclipse.papyrus.cpp.codegen.utils.GenUtils', 'openNS(org.eclipse.uml2.uml.NamedElement)', Sequence{arg0}) /]
+
+[query public closeNS(arg0 : NamedElement) : String
+ = invoke('org.eclipse.papyrus.cpp.codegen.utils.GenUtils', 'closeNS(org.eclipse.uml2.uml.NamedElement)', Sequence{arg0}) /]
+
+[query public getUsedPackages(arg0 : Package) : Sequence(Package)
+ = invoke('org.eclipse.papyrus.cpp.codegen.utils.GenUtils', 'getUsedPackages(org.eclipse.uml2.uml.Package)', Sequence{arg0}) /]
+
+[query public getUsedClassifiers(arg0 : Classifier) : Sequence(Classifier)
+ = invoke('org.eclipse.papyrus.cpp.codegen.utils.GenUtils', 'getUsedClassifiers(org.eclipse.uml2.uml.Classifier)', Sequence{arg0}) /]
diff --git a/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/utils/Modifier.java b/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/utils/Modifier.java
index 1f0c96d8bc0..c9579d7aead 100644
--- a/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/utils/Modifier.java
+++ b/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/utils/Modifier.java
@@ -11,12 +11,19 @@
package org.eclipse.papyrus.cpp.codegen.utils;
+import org.eclipse.papyrus.cpp.codegen.preferences.CppCodeGenUtils;
+import org.eclipse.uml2.uml.AggregationKind;
import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.MultiplicityElement;
+import org.eclipse.uml2.uml.Parameter;
+import org.eclipse.uml2.uml.ParameterDirectionKind;
+import org.eclipse.uml2.uml.Property;
+
+import C_Cpp.Array;
+import C_Cpp.Const;
+import C_Cpp.Ptr;
+import C_Cpp.Ref;
-import Cpp.CppArray;
-import Cpp.CppConst;
-import Cpp.CppPtr;
-import Cpp.CppRef;
/**
* Utility functions managing the "modifier" of an element, i.e. additional information whether a passed
@@ -27,48 +34,97 @@ import Cpp.CppRef;
*/
public class Modifier {
- public String ptr;
+ public static String ptr;
+
+ public static String ref;
+
+ public static String array;
- public String ref;
+ public static String isConst;
+
+ public static String modPtr(Element propertyOrParameter) {
+ update(propertyOrParameter);
+ return ptr;
+ }
- public String array;
+ public static String modRef(Element propertyOrParameter) {
+ update(propertyOrParameter);
+ return ref;
+ }
- public String isConst;
+ public static String modArray(Element propertyOrParameter) {
+ update(propertyOrParameter);
+ return array;
+ }
- public Modifier() {
- ptr = "";
- ref = "";
- array = "";
- isConst = "";
+ public static String modConst(Element propertyOrParameter) {
+ update(propertyOrParameter);
+ return isConst;
}
/**
* Create instance and initialize the ptr/ref/array/isConst attributes.
*
- * @param currentParameter
+ * @param propertyOrParameter
*/
- public Modifier(Element currentParameter) {
+ public static void update(Element propertyOrParameter) {
// Pointer
- CppPtr cppPtr = GenUtils.getApplication(currentParameter, CppPtr.class);
+ Ptr cppPtr = GenUtils.getApplication(propertyOrParameter, Ptr.class);
if(cppPtr != null) {
ptr = (cppPtr.getDeclaration() != null) ? cppPtr.getDeclaration() : "*";
} else {
ptr = "";
}
-
+ if (propertyOrParameter instanceof Property) {
+ if (((Property) propertyOrParameter).getAggregation() == AggregationKind.SHARED_LITERAL) {
+ ptr += "*";
+ }
+ }
// Ref
- ref = GenUtils.hasStereotype(currentParameter, CppRef.class) ? "&" : "";
+ ref = GenUtils.hasStereotype(propertyOrParameter, Ref.class) ? "&" : "";
+ boolean ptrOrRef = GenUtils.hasStereotype(propertyOrParameter, Ref.class) ||
+ GenUtils.hasStereotype(propertyOrParameter, Ptr.class);
// Array
- CppArray cppArray = GenUtils.getApplication(currentParameter, CppArray.class);
+ Array cppArray = GenUtils.getApplication(propertyOrParameter, Array.class);
if(cppArray != null) {
+ // explicit array definition
array = (cppArray.getDefinition() != null) ? cppArray.getDefinition() : "[]";
} else {
+ // calculate array from multiplicity definition
+ int multiplicity = 1;
+ if(propertyOrParameter instanceof MultiplicityElement) {
+ multiplicity = ((MultiplicityElement)propertyOrParameter).getUpper();
+ }
array = "";
+ if(multiplicity == -1) {
+ ptr += "*";
+ } else if(multiplicity > 1) {
+ array = "[" + multiplicity + "]";
+ }
}
+ // out an inout parameter are realized by means of a pointer
+ if(propertyOrParameter instanceof Parameter) {
+ ParameterDirectionKind directionKind = ((Parameter)propertyOrParameter).getDirection();
+ if(directionKind == ParameterDirectionKind.IN_LITERAL) {
+ ptr += " _IN_";
+ }
+ else if(directionKind == ParameterDirectionKind.OUT_LITERAL) {
+ ptr += " _OUT_";
+ if(!ptrOrRef) {
+ ptr += CppCodeGenUtils.getOutInoutOp();
+ }
+ }
+ else if(directionKind == ParameterDirectionKind.INOUT_LITERAL) {
+ ptr += " _INOUT_";
+ if(!ptrOrRef) {
+ ptr += CppCodeGenUtils.getOutInoutOp();
+ }
+ }
+ }
// Const
- isConst = GenUtils.hasStereotype(currentParameter, CppConst.class) ? "const " : "";
+ isConst = GenUtils.hasStereotype(propertyOrParameter, Const.class) ? "const " : "";
}
}
diff --git a/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/utils/Modifier.mtl b/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/utils/Modifier.mtl
new file mode 100644
index 00000000000..fed35b5d2ff
--- /dev/null
+++ b/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/utils/Modifier.mtl
@@ -0,0 +1,15 @@
+[comment encoding = UTF-8 /]
+[module Modifier('http://www.eclipse.org/uml2/4.0.0/UML')/]
+
+[query public modPtr(propertyOrParameter : Element) : String
+ = invoke('org.eclipse.papyrus.cpp.codegen.utils.Modifier', 'modPtr(org.eclipse.uml2.uml.Element)', Sequence{propertyOrParameter}) /]
+
+[query public modRef(propertyOrParameter : Element) : String
+ = invoke('org.eclipse.papyrus.cpp.codegen.utils.Modifier', 'modRef(org.eclipse.uml2.uml.Element)', Sequence{propertyOrParameter}) /]
+
+[query public modArray(propertyOrParameter : Element) : String
+ = invoke('org.eclipse.papyrus.cpp.codegen.utils.Modifier', 'modArray(org.eclipse.uml2.uml.Element)', Sequence{propertyOrParameter}) /]
+
+[query public modConst(propertyOrParameter : Element) : String
+ = invoke('org.eclipse.papyrus.cpp.codegen.utils.Modifier', 'modConst(org.eclipse.uml2.uml.Element)', Sequence{propertyOrParameter}) /]
+

Back to the top