diff options
author | aradermache | 2012-12-14 13:33:04 +0000 |
---|---|---|
committer | aradermache | 2012-12-14 13:33:04 +0000 |
commit | 0336a6a797ef0cfdf03106fba76976fc48666e78 (patch) | |
tree | b7a4c4357a37e557d58f5694984603aac34eabbc | |
parent | 4c28eedf601f4f8a0fcb9249bdc3833be723ae40 (diff) | |
download | org.eclipse.papyrus-0336a6a797ef0cfdf03106fba76976fc48666e78.tar.gz org.eclipse.papyrus-0336a6a797ef0cfdf03106fba76976fc48666e78.tar.xz org.eclipse.papyrus-0336a6a797ef0cfdf03106fba76976fc48666e78.zip |
initial
164 files changed, 9530 insertions, 0 deletions
diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/.classpath b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/.classpath new file mode 100644 index 00000000000..9fd92a96b67 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/.classpath @@ -0,0 +1,8 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/> + <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> + <classpathentry kind="src" path="src"/> + <classpathentry kind="src" path="jetsrc"/> + <classpathentry kind="output" path="bin"/> +</classpath> diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/.jetproperties b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/.jetproperties new file mode 100644 index 00000000000..3c3ea9ef3ae --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/.jetproperties @@ -0,0 +1,4 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<jet-settings> + <template-container>templates</template-container> <source-container>jetsrc</source-container> +</jet-settings> diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/.project b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/.project new file mode 100644 index 00000000000..50424ef89ab --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/.project @@ -0,0 +1,39 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>org.eclipse.papyrus.cpp.codegen</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.emf.codegen.JETBuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>com.ibm.etools.common.migration.MigrationBuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.jdt.core.javabuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.ManifestBuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.SchemaBuilder</name> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.emf.codegen.jet.IJETNature</nature> + <nature>org.eclipse.pde.PluginNature</nature> + <nature>org.eclipse.jdt.core.javanature</nature> + </natures> +</projectDescription> diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/META-INF/MANIFEST.MF b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/META-INF/MANIFEST.MF new file mode 100644 index 00000000000..29198468426 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/META-INF/MANIFEST.MF @@ -0,0 +1,26 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: PapyrusCpp core Plug-in +Bundle-SymbolicName: org.eclipse.papyrus.cpp.codegen;singleton:=true +Bundle-Version: 0.8.0.vqualifier +Bundle-Activator: org.eclipse.papyrus.cpp.codegen.Activator +Bundle-Vendor: CEA LIST +Bundle-Localization: plugin +Require-Bundle: org.eclipse.ui, + org.eclipse.core.runtime, + org.eclipse.jface.text, + org.eclipse.uml2.uml, + org.eclipse.core.resources, + org.eclipse.papyrus.cpp.profile;bundle-version="0.8.0", + org.eclipse.ui.ide;bundle-version="3.8.0", + org.eclipse.core.filesystem;bundle-version="1.3.200" +Eclipse-LazyStart: true +Export-Package: org.eclipse.papyrus.cpp.codegen, + org.eclipse.papyrus.cpp.codegen.jet, + org.eclipse.papyrus.cpp.codegen.jet.doc, + org.eclipse.papyrus.cpp.codegen.jet.util, + org.eclipse.papyrus.cpp.codegen.preferences, + org.eclipse.papyrus.cpp.codegen.transformation, + org.eclipse.papyrus.cpp.codegen.utils +Bundle-RequiredExecutionEnvironment: J2SE-1.5 +Bundle-ActivationPolicy: lazy diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/Activator.class b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/Activator.class Binary files differnew file mode 100644 index 00000000000..e7093727611 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/Activator.class diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/Constants.class b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/Constants.class Binary files differnew file mode 100644 index 00000000000..e7595c9ad1d --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/Constants.class diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/StdStereo.class b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/StdStereo.class Binary files differnew file mode 100644 index 00000000000..1b0668384ac --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/StdStereo.class diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/CppBindBody.class b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/CppBindBody.class Binary files differnew file mode 100644 index 00000000000..0b43f99c55c --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/CppBindBody.class diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/CppBindHeader.class b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/CppBindHeader.class Binary files differnew file mode 100644 index 00000000000..f7bca8a084d --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/CppBindHeader.class diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/CppClassBody.class b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/CppClassBody.class Binary files differnew file mode 100644 index 00000000000..2c1365f4005 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/CppClassBody.class diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/CppClassHeader.class b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/CppClassHeader.class Binary files differnew file mode 100644 index 00000000000..62cae498924 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/CppClassHeader.class diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/CppInterfaceHeader.class b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/CppInterfaceHeader.class Binary files differnew file mode 100644 index 00000000000..0a66de5bccf --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/CppInterfaceHeader.class diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/CppPackageHeader.class b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/CppPackageHeader.class Binary files differnew file mode 100644 index 00000000000..9c69b875d3e --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/CppPackageHeader.class diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/CppTemplateHeader.class b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/CppTemplateHeader.class Binary files differnew file mode 100644 index 00000000000..0f01b3e2a5d --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/CppTemplateHeader.class diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/doc/CppElementDoc.class b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/doc/CppElementDoc.class Binary files differnew file mode 100644 index 00000000000..e8ebf7b02ad --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/doc/CppElementDoc.class diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/doc/CppOperationDoc.class b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/doc/CppOperationDoc.class Binary files differnew file mode 100644 index 00000000000..3ff7910f0b1 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/doc/CppOperationDoc.class diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/doc/CppParamDoc.class b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/doc/CppParamDoc.class Binary files differnew file mode 100644 index 00000000000..3eaf8841c36 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/doc/CppParamDoc.class diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/util/CppAttributeDeclaration.class b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/util/CppAttributeDeclaration.class Binary files differnew file mode 100644 index 00000000000..42e6d30130e --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/util/CppAttributeDeclaration.class diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/util/CppAttributeImplementation.class b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/util/CppAttributeImplementation.class Binary files differnew file mode 100644 index 00000000000..04d0284c9e5 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/util/CppAttributeImplementation.class diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/util/CppClassAllIncludesDeclaration.class b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/util/CppClassAllIncludesDeclaration.class Binary files differnew file mode 100644 index 00000000000..b784b60887d --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/util/CppClassAllIncludesDeclaration.class diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/util/CppClassAttributesDeclaration.class b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/util/CppClassAttributesDeclaration.class Binary files differnew file mode 100644 index 00000000000..872bbe2dfc8 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/util/CppClassAttributesDeclaration.class diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/util/CppClassAttributesImplementation.class b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/util/CppClassAttributesImplementation.class Binary files differnew file mode 100644 index 00000000000..a8ab1e3945d --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/util/CppClassAttributesImplementation.class diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/util/CppClassFriendDeclaration.class b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/util/CppClassFriendDeclaration.class Binary files differnew file mode 100644 index 00000000000..f534ac0961a --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/util/CppClassFriendDeclaration.class diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/util/CppClassIncludeClassDeclaration.class b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/util/CppClassIncludeClassDeclaration.class Binary files differnew file mode 100644 index 00000000000..8dee10fad7d --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/util/CppClassIncludeClassDeclaration.class diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/util/CppClassIncludeDeclaration.class b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/util/CppClassIncludeDeclaration.class Binary files differnew file mode 100644 index 00000000000..748c05117ac --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/util/CppClassIncludeDeclaration.class diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/util/CppClassIncludeFriendDeclaration.class b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/util/CppClassIncludeFriendDeclaration.class Binary files differnew file mode 100644 index 00000000000..505c242b621 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/util/CppClassIncludeFriendDeclaration.class diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/util/CppClassInheritedDeclarations.class b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/util/CppClassInheritedDeclarations.class Binary files differnew file mode 100644 index 00000000000..a103912d2fc --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/util/CppClassInheritedDeclarations.class diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/util/CppClassInlineOperationsImplementation.class b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/util/CppClassInlineOperationsImplementation.class Binary files differnew file mode 100644 index 00000000000..6a3c1f09a38 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/util/CppClassInlineOperationsImplementation.class diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/util/CppClassOperationsDeclaration.class b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/util/CppClassOperationsDeclaration.class Binary files differnew file mode 100644 index 00000000000..bf28f4c9e37 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/util/CppClassOperationsDeclaration.class diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/util/CppClassOperationsImplementation.class b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/util/CppClassOperationsImplementation.class Binary files differnew file mode 100644 index 00000000000..8f61ea8c177 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/util/CppClassOperationsImplementation.class diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/util/CppClassTypeAndEnum.class b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/util/CppClassTypeAndEnum.class Binary files differnew file mode 100644 index 00000000000..dfc4cd0c962 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/util/CppClassTypeAndEnum.class diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/util/CppClassTypeAndEnumPackage.class b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/util/CppClassTypeAndEnumPackage.class Binary files differnew file mode 100644 index 00000000000..fb6660fb37f --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/util/CppClassTypeAndEnumPackage.class diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/util/CppEnumerationDefinition.class b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/util/CppEnumerationDefinition.class Binary files differnew file mode 100644 index 00000000000..e43f4800a17 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/util/CppEnumerationDefinition.class diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/util/CppInterfaceAllIncludesDeclaration.class b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/util/CppInterfaceAllIncludesDeclaration.class Binary files differnew file mode 100644 index 00000000000..655c8841205 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/util/CppInterfaceAllIncludesDeclaration.class diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/util/CppInterfaceIncludeDeclaration.class b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/util/CppInterfaceIncludeDeclaration.class Binary files differnew file mode 100644 index 00000000000..fe63092538f --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/util/CppInterfaceIncludeDeclaration.class diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/util/CppInterfaceInheritedDeclarations.class b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/util/CppInterfaceInheritedDeclarations.class Binary files differnew file mode 100644 index 00000000000..a62e3b42686 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/util/CppInterfaceInheritedDeclarations.class diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/util/CppInterfacePublicOperationsDeclaration.class b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/util/CppInterfacePublicOperationsDeclaration.class Binary files differnew file mode 100644 index 00000000000..3daf95616c4 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/util/CppInterfacePublicOperationsDeclaration.class diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/util/CppOperationDeclaration.class b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/util/CppOperationDeclaration.class Binary files differnew file mode 100644 index 00000000000..00f80fffc64 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/util/CppOperationDeclaration.class diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/util/CppOperationImplementation.class b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/util/CppOperationImplementation.class Binary files differnew file mode 100644 index 00000000000..416392036f1 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/util/CppOperationImplementation.class diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/util/CppOperationParameters.class b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/util/CppOperationParameters.class Binary files differnew file mode 100644 index 00000000000..82186852ac9 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/util/CppOperationParameters.class diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/util/CppOperationParametersWithoutDefaultValue.class b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/util/CppOperationParametersWithoutDefaultValue.class Binary files differnew file mode 100644 index 00000000000..6cabafabfd8 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/util/CppOperationParametersWithoutDefaultValue.class diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/util/CppOperationReturnType.class b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/util/CppOperationReturnType.class Binary files differnew file mode 100644 index 00000000000..04320573235 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/util/CppOperationReturnType.class diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/util/CppOperationTemplateImplementation.class b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/util/CppOperationTemplateImplementation.class Binary files differnew file mode 100644 index 00000000000..55fe92397d8 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/util/CppOperationTemplateImplementation.class diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/util/CppOwnerPackageIncludeDeclaration.class b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/util/CppOwnerPackageIncludeDeclaration.class Binary files differnew file mode 100644 index 00000000000..685a47c0a58 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/util/CppOwnerPackageIncludeDeclaration.class diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/util/CppParameter.class b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/util/CppParameter.class Binary files differnew file mode 100644 index 00000000000..7bf4a8a5eec --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/util/CppParameter.class diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/util/CppParameterWithoutDefaultValue.class b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/util/CppParameterWithoutDefaultValue.class Binary files differnew file mode 100644 index 00000000000..eab4f2e89e1 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/util/CppParameterWithoutDefaultValue.class diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/util/CppPrimitiveTypeDefinition.class b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/util/CppPrimitiveTypeDefinition.class Binary files differnew file mode 100644 index 00000000000..b7e4bb30436 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/util/CppPrimitiveTypeDefinition.class diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/util/CppStaticAttributeImplementation.class b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/util/CppStaticAttributeImplementation.class Binary files differnew file mode 100644 index 00000000000..ba1c5d81595 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/util/CppStaticAttributeImplementation.class diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/util/CppTemplateBindingParameter.class b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/util/CppTemplateBindingParameter.class Binary files differnew file mode 100644 index 00000000000..9301645da07 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/util/CppTemplateBindingParameter.class diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/util/CppTemplateDeclaration.class b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/util/CppTemplateDeclaration.class Binary files differnew file mode 100644 index 00000000000..9c8dd00fe1f --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/util/CppTemplateDeclaration.class diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/util/CppTemplateInlineOperationsImplementation.class b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/util/CppTemplateInlineOperationsImplementation.class Binary files differnew file mode 100644 index 00000000000..fc00099777c --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/util/CppTemplateInlineOperationsImplementation.class diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/util/CppTemplateParameter.class b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/util/CppTemplateParameter.class Binary files differnew file mode 100644 index 00000000000..10e799bb669 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/jet/util/CppTemplateParameter.class diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/preferences/CppCodeGenConstants.class b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/preferences/CppCodeGenConstants.class Binary files differnew file mode 100644 index 00000000000..c7e54c35fc3 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/preferences/CppCodeGenConstants.class diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/preferences/CppCodeGenPreferenceInitializer.class b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/preferences/CppCodeGenPreferenceInitializer.class Binary files differnew file mode 100644 index 00000000000..759cbd78bbb --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/preferences/CppCodeGenPreferenceInitializer.class diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/preferences/CppCodeGenUtils.class b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/preferences/CppCodeGenUtils.class Binary files differnew file mode 100644 index 00000000000..9564eba9315 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/preferences/CppCodeGenUtils.class diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/transformation/ModelElementsCreator.class b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/transformation/ModelElementsCreator.class Binary files differnew file mode 100644 index 00000000000..5da1f2416ee --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/transformation/ModelElementsCreator.class diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/utils/ClassUtils.class b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/utils/ClassUtils.class Binary files differnew file mode 100644 index 00000000000..09a58878d43 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/utils/ClassUtils.class diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/utils/GenUtils.class b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/utils/GenUtils.class Binary files differnew file mode 100644 index 00000000000..0f4e0ec63a2 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/utils/GenUtils.class diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/utils/Modifier.class b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/utils/Modifier.class Binary files differnew file mode 100644 index 00000000000..989898deb2f --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/bin/org/eclipse/papyrus/cpp/codegen/utils/Modifier.class diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/build.properties b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/build.properties new file mode 100644 index 00000000000..226e9b9f7cc --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/build.properties @@ -0,0 +1,9 @@ +source.. = src/,\
+ jetsrc/
+output.. = bin/
+bin.includes = META-INF/,\
+ .,\
+ plugin.xml,\
+ templates/,\
+ bin/,\
+ plugin.properties
diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/CppBindBody.java b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/CppBindBody.java new file mode 100644 index 00000000000..016a7d87da1 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/CppBindBody.java @@ -0,0 +1,167 @@ +/******************************************************************************* + * Copyright (c) 2006 CEA List. + * All rights reserved. This program and the accompanying materials + * are property of the CEA, their use is subject to specific agreement + * with the CEA. + * + * Contributors: + * CEA List - initial API and implementation + *******************************************************************************/ + +package org.eclipse.papyrus.cpp.codegen.jet; + +import org.eclipse.papyrus.cpp.codegen.Constants; +import org.eclipse.papyrus.cpp.codegen.utils.*; +import Cpp.CppInclude; +import org.eclipse.uml2.uml.Class; +import org.eclipse.uml2.uml.Package; +import org.eclipse.uml2.uml.*; +import org.eclipse.emf.common.util.EList; +import org.eclipse.papyrus.cpp.codegen.jet.util.*; +import java.util.*; +import org.eclipse.papyrus.cpp.codegen.Activator; + +public class CppBindBody +{ + protected static String nl; + public static synchronized CppBindBody create(String lineSeparator) + { + nl = lineSeparator; + CppBindBody result = new CppBindBody(); + nl = null; + return result; + } + + public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; + protected final String TEXT_1 = "#define "; + protected final String TEXT_2 = "_BODY" + NL + "" + NL + "/************************************************************"; + protected final String TEXT_3 = NL + " "; + protected final String TEXT_4 = " template binding body" + NL + " ************************************************************/" + NL; + protected final String TEXT_5 = NL; + protected final String TEXT_6 = NL; + protected final String TEXT_7 = NL; + protected final String TEXT_8 = NL; + protected final String TEXT_9 = NL; + protected final String TEXT_10 = NL + "#include <"; + protected final String TEXT_11 = "."; + protected final String TEXT_12 = ">" + NL; + protected final String TEXT_13 = NL; + protected final String TEXT_14 = NL; + protected final String TEXT_15 = NL; + protected final String TEXT_16 = NL; + protected final String TEXT_17 = NL; + protected final String TEXT_18 = NL; + protected final String TEXT_19 = NL; + protected final String TEXT_20 = NL; + protected final String TEXT_21 = NL + NL + "/************************************************************/" + NL + "template class "; + protected final String TEXT_22 = " <"; + protected final String TEXT_23 = ">;" + NL; + protected final String TEXT_24 = NL; + protected final String TEXT_25 = NL + NL + "/************************************************************" + NL + " End of "; + protected final String TEXT_26 = " template binding body" + NL + " ************************************************************/"; + protected final String TEXT_27 = NL; + + public String generate(Object argument) + { + final StringBuffer stringBuffer = new StringBuffer(); + +////////////////////////////////////////////////////////////////////////////////////////// +// Java preparation +////////////////////////////////////////////////////////////////////////////////////////// + + // Retrieve the class + Class currentClass = (Class) argument; + + // Get the package name + String className = currentClass.getName(); + String classFullName = GenUtils.getFullName (currentClass); + String classFULLNAME = classFullName.toUpperCase(); + String parentClass = ""; + String namespace = GenUtils.getNamespace (currentClass); + + // Retrieve header file suffix + String headerFileSuffix = Activator.getDefault().getPluginPreferences().getString("headSuffix"); + + // Retrieve owner Package + Package owner = currentClass.getPackage(); + String fullPath = ""; + + if (owner != null) { + fullPath = GenUtils.getFullPath(owner) + "/"; + } // else fullPath == "" + + TemplateBinding tb = GenUtils.getTemplateBindings(currentClass);; + + // prepare parent class declaration + EList<org.eclipse.uml2.uml.Element> templates = tb.getTargets(); + Class templateClass = (Class) ((TemplateSignature) templates.get(0)).getOwner(); + parentClass = GenUtils.qualifiedName (templateClass); + + // Prepare bindings parameter declaration + + String tParamDecl = ""; + Iterator<TemplateParameterSubstitution> tps = tb.getParameterSubstitutions().iterator(); + while(tps.hasNext()) { + TemplateParameterSubstitution paramSub = tps.next(); + + CppTemplateBindingParameter jetTParam = new CppTemplateBindingParameter(); + tParamDecl = tParamDecl+jetTParam.generate (paramSub); + + if (tps.hasNext()) { + tParamDecl = tParamDecl + ", "; + } + } + + +////////////////////////////////////////////////////////////////////////////////////////// +// The following part contains the template +////////////////////////////////////////////////////////////////////////////////////////// + stringBuffer.append(TEXT_1); + stringBuffer.append( classFULLNAME ); + stringBuffer.append(TEXT_2); + stringBuffer.append(TEXT_3); + stringBuffer.append( className ); + stringBuffer.append(TEXT_4); + stringBuffer.append(TEXT_5); + stringBuffer.append( Constants.cppIncPreBodyStart ); + stringBuffer.append(TEXT_6); + stringBuffer.append( ClassUtils.getCppIncludePreBody(currentClass) ); + stringBuffer.append(TEXT_7); + stringBuffer.append( Constants.cppIncPreBodyEnd ); + stringBuffer.append(TEXT_8); + stringBuffer.append(TEXT_9); + stringBuffer.append( Constants.includeHFile ); + stringBuffer.append(TEXT_10); + stringBuffer.append( fullPath ); + stringBuffer.append( className ); + stringBuffer.append(TEXT_11); + stringBuffer.append( headerFileSuffix ); + stringBuffer.append(TEXT_12); + stringBuffer.append(TEXT_13); + stringBuffer.append( Constants.cppIncBodyStart ); + stringBuffer.append(TEXT_14); + stringBuffer.append( ClassUtils.getCppIncludeBody(currentClass) ); + stringBuffer.append(TEXT_15); + stringBuffer.append( Constants.cppIncBodyEnd ); + stringBuffer.append(TEXT_16); + stringBuffer.append(TEXT_17); + stringBuffer.append( GenUtils.openNS(currentClass) ); + stringBuffer.append(TEXT_18); + stringBuffer.append(TEXT_19); + stringBuffer.append( Constants.derivedIncludes ); + stringBuffer.append(TEXT_20); + stringBuffer.append( ClassUtils.createIncludeDecl(currentClass) ); + stringBuffer.append(TEXT_21); + stringBuffer.append( parentClass ); + stringBuffer.append(TEXT_22); + stringBuffer.append( tParamDecl ); + stringBuffer.append(TEXT_23); + stringBuffer.append(TEXT_24); + stringBuffer.append( GenUtils.closeNS(currentClass) ); + stringBuffer.append(TEXT_25); + stringBuffer.append( className ); + stringBuffer.append(TEXT_26); + stringBuffer.append(TEXT_27); + return stringBuffer.toString(); + } +}
\ No newline at end of file diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/CppBindHeader.java b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/CppBindHeader.java new file mode 100644 index 00000000000..cd28f8d1210 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/CppBindHeader.java @@ -0,0 +1,186 @@ +/******************************************************************************* + * Copyright (c) 2006 CEA List. + * All rights reserved. This program and the accompanying materials + * are property of the CEA, their use is subject to specific agreement + * with the CEA. + * + * Contributors: + * CEA List - initial API and implementation + *******************************************************************************/ + +package org.eclipse.papyrus.cpp.codegen.jet; + +import org.eclipse.papyrus.cpp.codegen.utils.GenUtils; +import Cpp.CppInclude; +import org.eclipse.uml2.uml.Class; +import org.eclipse.emf.common.util.EList; +import org.eclipse.uml2.uml.Package; +import org.eclipse.uml2.uml.TemplateSignature; +import org.eclipse.uml2.uml.TemplateParameterSubstitution; +import org.eclipse.papyrus.cpp.codegen.jet.util.*; +import java.util.*; +import org.eclipse.papyrus.cpp.codegen.Activator; + +public class CppBindHeader +{ + protected static String nl; + public static synchronized CppBindHeader create(String lineSeparator) + { + nl = lineSeparator; + CppBindHeader result = new CppBindHeader(); + nl = null; + return result; + } + + public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; + protected final String TEXT_1 = "#ifndef "; + protected final String TEXT_2 = "_H" + NL + "#define "; + protected final String TEXT_3 = "_H" + NL + "" + NL + "/************************************************************"; + protected final String TEXT_4 = NL + " "; + protected final String TEXT_5 = " template binding header" + NL + " ************************************************************/" + NL; + protected final String TEXT_6 = NL; + protected final String TEXT_7 = NL; + protected final String TEXT_8 = NL; + protected final String TEXT_9 = NL; + protected final String TEXT_10 = NL; + protected final String TEXT_11 = NL + NL + "#include <"; + protected final String TEXT_12 = "."; + protected final String TEXT_13 = ">" + NL; + protected final String TEXT_14 = NL; + protected final String TEXT_15 = " " + NL + "/************************************************************/" + NL + "typedef "; + protected final String TEXT_16 = " <"; + protected final String TEXT_17 = "> "; + protected final String TEXT_18 = ";" + NL; + protected final String TEXT_19 = NL; + protected final String TEXT_20 = NL + NL + "/************************************************************" + NL + " End of "; + protected final String TEXT_21 = " template binding header" + NL + " ************************************************************/" + NL + "" + NL + "#endif"; + protected final String TEXT_22 = NL; + + public String generate(Object argument) + { + final StringBuffer stringBuffer = new StringBuffer(); + +////////////////////////////////////////////////////////////////////////////////////////// +// Java preparation +////////////////////////////////////////////////////////////////////////////////////////// + + // Retrieve the class + Class currentClass = (Class) argument; + + // Get the package name + String className = currentClass.getName(); + String classFullName = GenUtils.getFullName (currentClass); + String classFULLNAME = classFullName.toUpperCase(); + String classparent = ""; + String openNS = GenUtils.openNS (currentClass); + String closeNS = GenUtils.closeNS (currentClass); + + // Include declaration "CppInclude" + String headerDecl = ""; + CppInclude cppInclude = GenUtils.getApplication(currentClass, CppInclude.class); + if (cppInclude != null) { + headerDecl = "// Include from CppInclude declaration" + NL + cppInclude.getHeader() + NL; + } + + // Prepare owner package header include + Package ownerPackage = currentClass.getPackage(); + String ownerInclude = ""; + if (ownerPackage != null) { + // Create an util template to prepare the declaration + CppOwnerPackageIncludeDeclaration jetOwnerInclude + = new CppOwnerPackageIncludeDeclaration(); + // Execute the util template + ownerInclude = jetOwnerInclude.generate(ownerPackage); + } + + // Retrieve header file suffix + String headerFileSuffix = Activator.getDefault().getPluginPreferences().getString("headSuffix"); + + //find path for the package owning current class + String fullPath = ""; + String separ = ""; + + if (ownerPackage != null) { + fullPath = GenUtils.getFullPath (ownerPackage); + separ = "/"; + } // else fullPath == "" + + org.eclipse.uml2.uml.TemplateBinding tb = GenUtils.getTemplateBindings(currentClass); + + // prepare parent class declaration + EList<org.eclipse.uml2.uml.Element> templates = tb.getTargets(); + Class templateClass = (Class) ((TemplateSignature)templates.get(0)).getOwner(); + classparent = templateClass.getName(); + + // Prepare bindings parameter declaration + + String tParamDecl=""; + TemplateParameterSubstitution paramsub; + Iterator<TemplateParameterSubstitution> tps = tb.getParameterSubstitutions().iterator(); + while(tps.hasNext()) { + paramsub = (TemplateParameterSubstitution)tps.next(); + + CppTemplateBindingParameter jetTParam + = new CppTemplateBindingParameter(); + tParamDecl = tParamDecl+jetTParam.generate(paramsub); + + if (tps.hasNext()) { + tParamDecl = tParamDecl+", "; + } + } + + + // Prepare dependency includes + CppClassAllIncludesDeclaration jetClassIncludes + = new CppClassAllIncludesDeclaration(); + String classIncludes = jetClassIncludes.generate(argument); + if (!classIncludes.equals("")) { + classIncludes = "/* Structural includes (inheritance, dependencies... */"+NL+classIncludes; + } + + + +////////////////////////////////////////////////////////////////////////////////////////// +// The following part contains the template +////////////////////////////////////////////////////////////////////////////////////////// + stringBuffer.append(TEXT_1); + stringBuffer.append( classFULLNAME ); + stringBuffer.append(TEXT_2); + stringBuffer.append( classFULLNAME ); + stringBuffer.append(TEXT_3); + stringBuffer.append(TEXT_4); + stringBuffer.append( className ); + stringBuffer.append(TEXT_5); + stringBuffer.append(TEXT_6); + stringBuffer.append( ownerInclude ); + stringBuffer.append(TEXT_7); + stringBuffer.append(TEXT_8); + stringBuffer.append( classIncludes ); + stringBuffer.append(TEXT_9); + stringBuffer.append(TEXT_10); + stringBuffer.append( headerDecl ); + stringBuffer.append(TEXT_11); + stringBuffer.append( fullPath ); + stringBuffer.append( separ ); + stringBuffer.append( classparent ); + stringBuffer.append(TEXT_12); + stringBuffer.append( headerFileSuffix ); + stringBuffer.append(TEXT_13); + stringBuffer.append(TEXT_14); + stringBuffer.append( openNS ); + stringBuffer.append(TEXT_15); + stringBuffer.append( classparent ); + stringBuffer.append(TEXT_16); + stringBuffer.append( tParamDecl ); + stringBuffer.append(TEXT_17); + stringBuffer.append( className ); + stringBuffer.append(TEXT_18); + stringBuffer.append(TEXT_19); + stringBuffer.append( closeNS ); + stringBuffer.append(TEXT_20); + stringBuffer.append( className ); + stringBuffer.append(TEXT_21); + stringBuffer.append(TEXT_22); + return stringBuffer.toString(); + } +}
\ No newline at end of file diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/CppClassBody.java b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/CppClassBody.java new file mode 100644 index 00000000000..6d61bd37fe2 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/CppClassBody.java @@ -0,0 +1,147 @@ +/******************************************************************************* + * Copyright (c) 2006 CEA List. + * All rights reserved. This program and the accompanying materials + * are property of the CEA, their use is subject to specific agreement + * with the CEA. + * + * Contributors: + * CEA List - initial API and implementation + *******************************************************************************/ + +package org.eclipse.papyrus.cpp.codegen.jet; + +import org.eclipse.papyrus.cpp.codegen.Constants; +import org.eclipse.papyrus.cpp.codegen.utils.*; +import org.eclipse.emf.common.util.EList; +import Cpp.CppInclude; +import org.eclipse.uml2.uml.Classifier; +import org.eclipse.uml2.uml.Package; +import org.eclipse.papyrus.cpp.codegen.jet.util.*; +import org.eclipse.papyrus.cpp.codegen.Activator; + +public class CppClassBody +{ + protected static String nl; + public static synchronized CppClassBody create(String lineSeparator) + { + nl = lineSeparator; + CppClassBody result = new CppClassBody(); + nl = null; + return result; + } + + public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; + protected final String TEXT_1 = "#define "; + protected final String TEXT_2 = "_BODY" + NL + "" + NL + "/************************************************************"; + protected final String TEXT_3 = NL + " "; + protected final String TEXT_4 = " class body" + NL + " ************************************************************/" + NL; + protected final String TEXT_5 = NL; + protected final String TEXT_6 = NL; + protected final String TEXT_7 = NL; + protected final String TEXT_8 = NL; + protected final String TEXT_9 = NL + "#include <"; + protected final String TEXT_10 = "."; + protected final String TEXT_11 = ">" + NL; + protected final String TEXT_12 = NL; + protected final String TEXT_13 = NL; + protected final String TEXT_14 = NL; + protected final String TEXT_15 = NL; + protected final String TEXT_16 = NL; + protected final String TEXT_17 = NL; + protected final String TEXT_18 = NL; + protected final String TEXT_19 = NL; + protected final String TEXT_20 = NL; + protected final String TEXT_21 = NL; + protected final String TEXT_22 = NL + NL + "/************************************************************" + NL + " End of "; + protected final String TEXT_23 = " class body" + NL + " ************************************************************/"; + protected final String TEXT_24 = NL; + + public String generate(Object argument) + { + final StringBuffer stringBuffer = new StringBuffer(); + +////////////////////////////////////////////////////////////////////////////////////////// +// Java preparation +////////////////////////////////////////////////////////////////////////////////////////// + + // Retrieve the class + Classifier currentClass = (Classifier) argument; + + // Get the package name + String className = currentClass.getName(); + String classFullName= GenUtils.getFullName (currentClass); + String classFULLNAME= classFullName.toUpperCase(); + + // Retrieve header file suffix + String headerFileSuffix = Activator.getDefault().getPluginPreferences().getString("headSuffix"); + + // TODO - Prepare static attribute + String staticAttributes = ""; + + // Retrieve owner Package + Package owner = currentClass.getPackage(); + String fullPath = ""; + + if (owner != null) { + fullPath = GenUtils.getFullPath(owner) + "/"; + } // else fullPath == "" + + // Prepare attributes and Methods declarations + String allOperations = ""; + + // Methods + CppClassOperationsImplementation jetClassOp + = new CppClassOperationsImplementation(); + allOperations = jetClassOp.generate(currentClass); + +////////////////////////////////////////////////////////////////////////////////////////// +// The following part contains the template +////////////////////////////////////////////////////////////////////////////////////////// + stringBuffer.append(TEXT_1); + stringBuffer.append( classFULLNAME ); + stringBuffer.append(TEXT_2); + stringBuffer.append(TEXT_3); + stringBuffer.append( className ); + stringBuffer.append(TEXT_4); + stringBuffer.append(TEXT_5); + stringBuffer.append( Constants.cppIncPreBodyStart ); + stringBuffer.append(TEXT_6); + stringBuffer.append( ClassUtils.getCppIncludePreBody(currentClass) +); + stringBuffer.append( Constants.cppIncPreBodyEnd ); + stringBuffer.append(TEXT_7); + stringBuffer.append(TEXT_8); + stringBuffer.append( Constants.includeHFile ); + stringBuffer.append(TEXT_9); + stringBuffer.append( fullPath ); + stringBuffer.append( className ); + stringBuffer.append(TEXT_10); + stringBuffer.append( headerFileSuffix ); + stringBuffer.append(TEXT_11); + stringBuffer.append(TEXT_12); + stringBuffer.append( Constants.cppIncBodyStart ); + stringBuffer.append(TEXT_13); + stringBuffer.append( ClassUtils.getCppIncludeBody(currentClass) +); + stringBuffer.append( Constants.cppIncBodyEnd ); + stringBuffer.append(TEXT_14); + stringBuffer.append(TEXT_15); + stringBuffer.append( Constants.derivedIncludes ); + stringBuffer.append(TEXT_16); + stringBuffer.append( ClassUtils.createIncludeDecl(currentClass) ); + stringBuffer.append(TEXT_17); + stringBuffer.append(TEXT_18); + stringBuffer.append( GenUtils.openNS(currentClass) ); + stringBuffer.append(TEXT_19); + stringBuffer.append( ClassUtils.getStaticAttributes(currentClass) ); + stringBuffer.append(TEXT_20); + stringBuffer.append( allOperations ); + stringBuffer.append(TEXT_21); + stringBuffer.append( GenUtils.closeNS(currentClass) ); + stringBuffer.append(TEXT_22); + stringBuffer.append( className ); + stringBuffer.append(TEXT_23); + stringBuffer.append(TEXT_24); + return stringBuffer.toString(); + } +}
\ No newline at end of file diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/CppClassHeader.java b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/CppClassHeader.java new file mode 100644 index 00000000000..4497c4d9346 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/CppClassHeader.java @@ -0,0 +1,276 @@ +/******************************************************************************* + * Copyright (c) 2006 CEA List. + * All rights reserved. This program and the accompanying materials + * are property of the CEA, their use is subject to specific agreement + * with the CEA. + * + * Contributors: + * CEA List - initial API and implementation + *******************************************************************************/ + +package org.eclipse.papyrus.cpp.codegen.jet; + +import org.eclipse.papyrus.cpp.codegen.utils.GenUtils; +import Cpp.CppInclude; +import org.eclipse.papyrus.cpp.codegen.StdStereo; +import org.eclipse.uml2.uml.Package; +import org.eclipse.uml2.uml.*; +import org.eclipse.papyrus.cpp.codegen.jet.util.*; +import org.eclipse.papyrus.cpp.codegen.jet.doc.*; + +public class CppClassHeader +{ + protected static String nl; + public static synchronized CppClassHeader create(String lineSeparator) + { + nl = lineSeparator; + CppClassHeader result = new CppClassHeader(); + nl = null; + return result; + } + + public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; + protected final String TEXT_1 = "#ifndef "; + protected final String TEXT_2 = "_H" + NL + "#define "; + protected final String TEXT_3 = "_H" + NL + "" + NL + "/************************************************************"; + protected final String TEXT_4 = NL + " "; + protected final String TEXT_5 = " class header" + NL + " ************************************************************/" + NL; + protected final String TEXT_6 = NL; + protected final String TEXT_7 = NL; + protected final String TEXT_8 = NL; + protected final String TEXT_9 = NL; + protected final String TEXT_10 = NL; + protected final String TEXT_11 = NL; + protected final String TEXT_12 = " "; + protected final String TEXT_13 = NL; + protected final String TEXT_14 = NL + "/************************************************************/"; + protected final String TEXT_15 = NL; + protected final String TEXT_16 = NL; + protected final String TEXT_17 = " "; + protected final String TEXT_18 = " {"; + protected final String TEXT_19 = NL; + protected final String TEXT_20 = NL + NL + " public:"; + protected final String TEXT_21 = NL; + protected final String TEXT_22 = NL + NL + " protected:"; + protected final String TEXT_23 = NL; + protected final String TEXT_24 = NL + NL + " private:"; + protected final String TEXT_25 = NL; + protected final String TEXT_26 = NL + NL + "};" + NL + "/************************************************************/" + NL + "/* External declarations (package visibility) */"; + protected final String TEXT_27 = NL; + protected final String TEXT_28 = NL; + protected final String TEXT_29 = NL + "/************************************************************/" + NL + "/* Inline functions */"; + protected final String TEXT_30 = NL; + protected final String TEXT_31 = NL; + protected final String TEXT_32 = NL + NL + "/************************************************************" + NL + " End of "; + protected final String TEXT_33 = " class header" + NL + " ************************************************************/" + NL + "" + NL + "#endif"; + protected final String TEXT_34 = NL; + + public String generate(Object argument) + { + final StringBuffer stringBuffer = new StringBuffer(); + +////////////////////////////////////////////////////////////////////////////////////////// +// Java preparation +////////////////////////////////////////////////////////////////////////////////////////// + + + // Retrieve the class + Classifier currentClass = (Classifier) argument; + + // Get the package name + String className = currentClass.getName(); + String classFULLNAME = GenUtils.getFullName (currentClass).toUpperCase(); + String openNS = GenUtils.openNS (currentClass); + String closeNS = GenUtils.closeNS (currentClass); + String classDoc = ""; + String classOrStruct = (currentClass instanceof DataType) ? "struct" : "class"; + + // Doc for the class + CppElementDoc jDoc = new CppElementDoc(); + classDoc = jDoc.generate(currentClass); + + String includeProtection; + + // Include declaration "CppInclude" + String headerDecl = ""; + CppInclude cppInclude = GenUtils.getApplication(currentClass, CppInclude.class); + if (cppInclude != null) { + headerDecl = GenUtils.maskNull(cppInclude.getHeader()); + if (headerDecl.length() > 0) { + headerDecl = "// Include from CppInclude declaration" + NL + headerDecl.replace("HFILENAME", classFULLNAME) + NL; + } + } + + // Prepare owner package header include + Package ownerPackage = currentClass.getPackage(); + String ownerInclude = ""; + if (ownerPackage != null) { + // Create an util template to prepare the declaration + CppOwnerPackageIncludeDeclaration jetOwnerInclude + = new CppOwnerPackageIncludeDeclaration(); + // Execute the util template + ownerInclude = jetOwnerInclude.generate(ownerPackage); + } + + + // Prepare owned type and enum declaration + String typeEnumDefPackage = ""; + String typeEnumDef = ""; + + CppClassTypeAndEnum jetTE = new CppClassTypeAndEnum(); + typeEnumDef = jetTE.generate(currentClass); + + CppClassTypeAndEnumPackage jetTEp + = new CppClassTypeAndEnumPackage(); + typeEnumDefPackage = jetTEp.generate(currentClass); + + + // Prepare dependency includes + CppClassAllIncludesDeclaration jetClassIncludes + = new CppClassAllIncludesDeclaration(); + String classIncludes = jetClassIncludes.generate(argument); + if (!classIncludes.equals("")) { + classIncludes = "/* Structural includes (inheritance, dependencies... */"+NL+classIncludes; + } + + // Prepare friend dependency includes + CppClassIncludeFriendDeclaration jetClassFIncludes + = new CppClassIncludeFriendDeclaration(); + String friendIncludes = jetClassFIncludes.generate(argument); + if (!friendIncludes.equals("")) { + friendIncludes = "/* Friend class declaration */"+NL+friendIncludes; + } + + // Prepare attributes and Methods declarations + String publicAttributes = ""; + String publicOperations = ""; + String protectedAttributes = ""; + String protectedOperations = ""; + String privateAttributes = ""; + String privateOperations = ""; + String packageAttributes = ""; + String packageOperations = ""; + + // Attributes + CppClassAttributesDeclaration jetClassPAttr = new CppClassAttributesDeclaration(); + publicAttributes = jetClassPAttr.generate(currentClass, VisibilityKind.PUBLIC_LITERAL); + protectedAttributes = jetClassPAttr.generate(currentClass, VisibilityKind.PROTECTED_LITERAL); + privateAttributes = jetClassPAttr.generate(currentClass, VisibilityKind.PRIVATE_LITERAL); + packageAttributes = jetClassPAttr.generate(currentClass, VisibilityKind.PACKAGE_LITERAL); + + // Methods + CppClassOperationsDeclaration jetClassPOp = new CppClassOperationsDeclaration(); + publicOperations = jetClassPOp.generate(currentClass, VisibilityKind.PUBLIC_LITERAL); + protectedOperations = jetClassPOp.generate(currentClass, VisibilityKind.PROTECTED_LITERAL); + privateOperations = jetClassPOp.generate(currentClass, VisibilityKind.PRIVATE_LITERAL); + packageOperations = jetClassPOp.generate(currentClass, VisibilityKind.PACKAGE_LITERAL); + + boolean hasConstructor = false; + for (Operation operation : currentClass.getOperations ()) { + if (GenUtils.hasStereotype(operation, StdStereo.create)) { + hasConstructor = true; + break; + } + } + String defaultInitializer = ""; + for (Property attribute : currentClass.getAttributes ()) { + if (attribute.isStatic()) { + // static attributes are initialized differently + continue; + } + ValueSpecification vs = attribute.getDefaultValue (); + if ((vs != null) && (vs.stringValue() != null)) { + if (!defaultInitializer.equals("")) { + // not first attribute + defaultInitializer += ", "; + } + defaultInitializer += attribute.getName () + "(" + vs.stringValue() + ")"; + } + } + // no constructor, add it, if some properties have default values + if ((!hasConstructor) && (!defaultInitializer.equals (""))) { + defaultInitializer = className + "() : " + defaultInitializer + " {}"; + } + else { + defaultInitializer = ""; + } + + // Inline functions implementations + String inlineFunctionsImplementation = ""; + CppClassInlineOperationsImplementation jetInlineClassPOp + = new CppClassInlineOperationsImplementation(); + inlineFunctionsImplementation = jetInlineClassPOp.generate(currentClass); + + // Prepare inherited classes or implemented interfaces + String inheritedDeclarations = ""; + CppClassInheritedDeclarations jetInherited + = new CppClassInheritedDeclarations(); + inheritedDeclarations = jetInherited.generate(currentClass); + + +////////////////////////////////////////////////////////////////////////////////////////// +// The following part contains the template +////////////////////////////////////////////////////////////////////////////////////////// + stringBuffer.append(TEXT_1); + stringBuffer.append( classFULLNAME ); + stringBuffer.append(TEXT_2); + stringBuffer.append( classFULLNAME ); + stringBuffer.append(TEXT_3); + stringBuffer.append(TEXT_4); + stringBuffer.append( className ); + stringBuffer.append(TEXT_5); + stringBuffer.append(TEXT_6); + stringBuffer.append( ownerInclude ); + stringBuffer.append(TEXT_7); + stringBuffer.append(TEXT_8); + stringBuffer.append( classIncludes ); + stringBuffer.append(TEXT_9); + stringBuffer.append(TEXT_10); + stringBuffer.append( headerDecl ); + stringBuffer.append(TEXT_11); + stringBuffer.append( openNS ); + stringBuffer.append(TEXT_12); + stringBuffer.append(TEXT_13); + stringBuffer.append( typeEnumDefPackage ); + stringBuffer.append(TEXT_14); + stringBuffer.append(TEXT_15); + stringBuffer.append( classDoc ); + stringBuffer.append(TEXT_16); + stringBuffer.append( classOrStruct ); + stringBuffer.append(TEXT_17); + stringBuffer.append( className ); + stringBuffer.append( inheritedDeclarations ); + stringBuffer.append(TEXT_18); + stringBuffer.append(TEXT_19); + stringBuffer.append( friendIncludes ); + stringBuffer.append( typeEnumDef ); + stringBuffer.append(TEXT_20); + stringBuffer.append(TEXT_21); + stringBuffer.append( defaultInitializer ); + stringBuffer.append( publicAttributes ); + stringBuffer.append( publicOperations ); + stringBuffer.append(TEXT_22); + stringBuffer.append(TEXT_23); + stringBuffer.append( protectedAttributes ); + stringBuffer.append( protectedOperations ); + stringBuffer.append(TEXT_24); + stringBuffer.append(TEXT_25); + stringBuffer.append( privateAttributes ); + stringBuffer.append( privateOperations ); + stringBuffer.append(TEXT_26); + stringBuffer.append(TEXT_27); + stringBuffer.append( packageAttributes ); + stringBuffer.append(TEXT_28); + stringBuffer.append( packageOperations ); + stringBuffer.append(TEXT_29); + stringBuffer.append(TEXT_30); + stringBuffer.append( inlineFunctionsImplementation ); + stringBuffer.append(TEXT_31); + stringBuffer.append( closeNS ); + stringBuffer.append(TEXT_32); + stringBuffer.append( className ); + stringBuffer.append(TEXT_33); + stringBuffer.append(TEXT_34); + return stringBuffer.toString(); + } +}
\ No newline at end of file diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/CppInterfaceHeader.java b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/CppInterfaceHeader.java new file mode 100644 index 00000000000..933b4a00407 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/CppInterfaceHeader.java @@ -0,0 +1,160 @@ +/******************************************************************************* + * Copyright (c) 2006 CEA List. + * All rights reserved. This program and the accompanying materials + * are property of the CEA, their use is subject to specific agreement + * with the CEA. + * + * Contributors: + * CEA List - initial API and implementation + *******************************************************************************/ + +package org.eclipse.papyrus.cpp.codegen.jet; + +import org.eclipse.uml2.uml.Interface; +import org.eclipse.uml2.uml.Package; +import Cpp.CppInclude; +import org.eclipse.papyrus.cpp.codegen.utils.GenUtils; +import org.eclipse.papyrus.cpp.codegen.jet.util.*; +import org.eclipse.papyrus.cpp.codegen.jet.doc.*; + +public class CppInterfaceHeader +{ + protected static String nl; + public static synchronized CppInterfaceHeader create(String lineSeparator) + { + nl = lineSeparator; + CppInterfaceHeader result = new CppInterfaceHeader(); + nl = null; + return result; + } + + public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; + protected final String TEXT_1 = "#ifndef "; + protected final String TEXT_2 = "_H" + NL + "#define "; + protected final String TEXT_3 = "_H" + NL + "" + NL + "/************************************************************"; + protected final String TEXT_4 = NL + " "; + protected final String TEXT_5 = " interface header" + NL + " ************************************************************/" + NL; + protected final String TEXT_6 = NL; + protected final String TEXT_7 = NL; + protected final String TEXT_8 = NL; + protected final String TEXT_9 = NL; + protected final String TEXT_10 = NL; + protected final String TEXT_11 = NL; + protected final String TEXT_12 = NL + "/************************************************************/"; + protected final String TEXT_13 = NL; + protected final String TEXT_14 = NL + "class "; + protected final String TEXT_15 = " "; + protected final String TEXT_16 = "{" + NL + "" + NL + "/* Public declarations */" + NL + "public:"; + protected final String TEXT_17 = NL; + protected final String TEXT_18 = NL + NL + "};" + NL + "" + NL + "/************************************************************" + NL + " End of "; + protected final String TEXT_19 = " interface header" + NL + " ************************************************************/"; + protected final String TEXT_20 = NL; + protected final String TEXT_21 = NL + NL + "#endif"; + protected final String TEXT_22 = NL; + + public String generate(Object argument) + { + final StringBuffer stringBuffer = new StringBuffer(); + +////////////////////////////////////////////////////////////////////////////////////////// +// Java preparation +////////////////////////////////////////////////////////////////////////////////////////// + + // Retrieve the class + Interface currentInterface = (Interface) argument; + + // Get the package name + String interfaceName = currentInterface.getName(); + String interfaceFULLNAME = GenUtils.getFullNameUC (currentInterface); + + // For interface documentation + String iDoc = ""; + + // Retrieve enum doc + CppElementDoc jDoc = new CppElementDoc(); + iDoc = jDoc.generate(currentInterface); + + // Include declaration "CppInclude" + String headerDecl = ""; + CppInclude cppInclude = GenUtils.getApplication(currentInterface, CppInclude.class); + if (cppInclude != null) { + headerDecl = "// Include from CppInclude declaration" + NL + cppInclude.getHeader() + NL; + } + + // Prepare owner package header include + Package ownerPackage = currentInterface.getPackage(); + String ownerInclude = ""; + if (ownerPackage != null) { + // Create an util template to prepare the declaration + CppOwnerPackageIncludeDeclaration jetOwnerInclude + = new CppOwnerPackageIncludeDeclaration(); + // Execute the util template + ownerInclude = jetOwnerInclude.generate(ownerPackage); + } + + + // Prepare dependency includes + CppInterfaceAllIncludesDeclaration jetInterfaceIncludes + = new CppInterfaceAllIncludesDeclaration(); + String interfaceIncludes = jetInterfaceIncludes.generate(argument); + if (!interfaceIncludes.equals("")) { + interfaceIncludes = "/* Structural includes (inheritance, dependencies, ... */"+NL+interfaceIncludes; + } + + // Prepare Methods declarations + String publicOperations = ""; + + // Methods + CppInterfacePublicOperationsDeclaration jetPublicInterfacePOp + = new CppInterfacePublicOperationsDeclaration(); + publicOperations = jetPublicInterfacePOp.generate(currentInterface); + + + // Prepare inherited interfaces + String inheritedDeclarations = ""; + CppInterfaceInheritedDeclarations jetInherited + = new CppInterfaceInheritedDeclarations(); + inheritedDeclarations = jetInherited.generate(currentInterface); + + +////////////////////////////////////////////////////////////////////////////////////////// +// The following part contains the template +////////////////////////////////////////////////////////////////////////////////////////// + stringBuffer.append(TEXT_1); + stringBuffer.append( interfaceFULLNAME ); + stringBuffer.append(TEXT_2); + stringBuffer.append( interfaceFULLNAME ); + stringBuffer.append(TEXT_3); + stringBuffer.append(TEXT_4); + stringBuffer.append( interfaceName ); + stringBuffer.append(TEXT_5); + stringBuffer.append(TEXT_6); + stringBuffer.append( ownerInclude ); + stringBuffer.append(TEXT_7); + stringBuffer.append(TEXT_8); + stringBuffer.append( interfaceIncludes ); + stringBuffer.append(TEXT_9); + stringBuffer.append(TEXT_10); + stringBuffer.append( headerDecl ); + stringBuffer.append(TEXT_11); + stringBuffer.append( GenUtils.openNS(currentInterface) ); + stringBuffer.append(TEXT_12); + stringBuffer.append(TEXT_13); + stringBuffer.append( iDoc ); + stringBuffer.append(TEXT_14); + stringBuffer.append( interfaceName ); + stringBuffer.append(TEXT_15); + stringBuffer.append( inheritedDeclarations ); + stringBuffer.append(TEXT_16); + stringBuffer.append(TEXT_17); + stringBuffer.append( publicOperations ); + stringBuffer.append(TEXT_18); + stringBuffer.append( interfaceName ); + stringBuffer.append(TEXT_19); + stringBuffer.append(TEXT_20); + stringBuffer.append( GenUtils.closeNS(currentInterface) ); + stringBuffer.append(TEXT_21); + stringBuffer.append(TEXT_22); + return stringBuffer.toString(); + } +}
\ No newline at end of file diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/CppPackageHeader.java b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/CppPackageHeader.java new file mode 100644 index 00000000000..58865c8b294 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/CppPackageHeader.java @@ -0,0 +1,203 @@ +/******************************************************************************* + * Copyright (c) 2006 CEA List. + * All rights reserved. This program and the accompanying materials + * are property of the CEA, their use is subject to specific agreement + * with the CEA. + * + * Contributors: + * CEA List - initial API and implementation + *******************************************************************************/ + +package org.eclipse.papyrus.cpp.codegen.jet; + +import org.eclipse.papyrus.cpp.codegen.utils.GenUtils; +import Cpp.CppInclude; +import Cpp.CppNoCodeGen; +import org.eclipse.uml2.uml.*; +import org.eclipse.uml2.uml.Package; +import org.eclipse.emf.common.util.EList; +import org.eclipse.papyrus.cpp.codegen.jet.util.*; +import org.eclipse.papyrus.cpp.codegen.jet.doc.*; +import java.util.Iterator; +import java.util.Set; +import java.util.HashSet; +import org.eclipse.papyrus.cpp.codegen.Activator; + +public class CppPackageHeader +{ + protected static String nl; + public static synchronized CppPackageHeader create(String lineSeparator) + { + nl = lineSeparator; + CppPackageHeader result = new CppPackageHeader(); + nl = null; + return result; + } + + public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; + protected final String TEXT_1 = "#ifndef PKG_"; + protected final String TEXT_2 = NL + "#define PKG_"; + protected final String TEXT_3 = NL + NL + "/************************************************************" + NL + " Pkg_"; + protected final String TEXT_4 = " package header" + NL + " ************************************************************/" + NL; + protected final String TEXT_5 = NL; + protected final String TEXT_6 = NL + "\t" + NL + "/* Package dependency header include */"; + protected final String TEXT_7 = NL + "#include <"; + protected final String TEXT_8 = "."; + protected final String TEXT_9 = ">"; + protected final String TEXT_10 = NL + NL + "/* CppInclude header declarations insert */"; + protected final String TEXT_11 = NL; + protected final String TEXT_12 = NL; + protected final String TEXT_13 = NL; + protected final String TEXT_14 = NL + "/* Types Defined in the package */"; + protected final String TEXT_15 = NL; + protected final String TEXT_16 = NL; + protected final String TEXT_17 = NL; + protected final String TEXT_18 = NL + NL + "/************************************************************" + NL + " End of Pkg_"; + protected final String TEXT_19 = " package header" + NL + " ************************************************************/" + NL + "" + NL + "#endif"; + protected final String TEXT_20 = NL; + + public String generate(Object argument) + { + final StringBuffer stringBuffer = new StringBuffer(); + +////////////////////////////////////////////////////////////////////////////////////////// +// Java preparation +////////////////////////////////////////////////////////////////////////////////////////// + + // Retrieve the package + Package currentPackage = (Package) argument; + Package fatherPackage = currentPackage.getNestingPackage(); // return owner package + + // Get the package name + String packageName = currentPackage.getName(); + String packageFULLNAME = GenUtils.getFullName (currentPackage).toUpperCase(); + String openNS = GenUtils.openNS (currentPackage) + "namespace " + currentPackage.getName () + " {\n"; + String closeNS = "} // of namespace" + currentPackage.getName () + "\n" + GenUtils.closeNS (currentPackage); + + // Prepare the header declarations for this package + String headerDecl = ""; + CppInclude cppInclude = GenUtils.getApplication(currentPackage, CppInclude.class); + if (cppInclude != null) { + headerDecl = "// Include from CppInclude declaration" + NL + cppInclude.getHeader() + NL; + } + + // Retrieve header file suffix + String headerFileSuffix = Activator.getDefault().getPluginPreferences().getString("headSuffix"); + + + // Prepare Father include declaration + String fatherPkgInclude = ""; + if (fatherPackage != null) { + // Create an util template to prepare the declaration + CppOwnerPackageIncludeDeclaration jetPkgInclude + = new CppOwnerPackageIncludeDeclaration(); + // Execute the util template + fatherPkgInclude = jetPkgInclude.generate(fatherPackage); + } + + + // Prepare Dependency includes declarations ... + // Retrieve package used by current package (dependencies) + + String cFullName = ""; // used in java to contruct and in template to read list + + // Get packages linked by dependencies + EList<Package> usedPackages = GenUtils.getUsedPackages (currentPackage); + Set<String> usedPackagesNames = new HashSet<String>(); + // Add imported packages + usedPackages.addAll(currentPackage.getImportedPackages()); + + Iterator<Package> usedPackagesIt = usedPackages.iterator(); + Iterator<String> usedPackagesNamesIt; + + // Refactor as a new Set containing names to be declared for packages (with path) + while(usedPackagesIt.hasNext()) { + Package currentUsedPackage = usedPackagesIt.next(); + String cPackageName = currentUsedPackage.getName(); + String cPackagePath = GenUtils.getFullPath (currentUsedPackage); + + cFullName = cPackagePath+"/Pkg_"+cPackageName; + + // Add this name to the set if codegen stereotype is not applied + PackageImport packImport = currentPackage.getPackageImport(currentUsedPackage); + if(!GenUtils.hasStereotype(packImport, CppNoCodeGen.class)) { + if (!GenUtils.hasStereotype(currentUsedPackage, CppNoCodeGen.class)) { + usedPackagesNames.add(cFullName); + } + } + } + + // and prepare the Iterator for the template... + usedPackagesNamesIt = usedPackagesNames.iterator(); + + + + // Prepare owned type and enum declaration + String typeDef = ""; + String enumDef = ""; + + Iterator<Type> typeIt = currentPackage.getOwnedTypes().iterator(); + while (typeIt.hasNext()) { + Type currentElt = typeIt.next(); + if (!GenUtils.hasStereotype(currentElt, CppNoCodeGen.class)) { + if (currentElt instanceof org.eclipse.uml2.uml.PrimitiveType) { + + PrimitiveType currentType = (PrimitiveType) currentElt; + CppPrimitiveTypeDefinition jetPrimitiveType = new CppPrimitiveTypeDefinition(); + // Execute the util template + typeDef = typeDef+jetPrimitiveType.generate(currentType); + + } else if (currentElt instanceof org.eclipse.uml2.uml.Enumeration) { + + Enumeration currentEnum = (Enumeration) currentElt; + CppEnumerationDefinition jetEnum = new CppEnumerationDefinition(); + // Execute the util template + enumDef = enumDef+jetEnum.generate(currentEnum); + + } + } + } + + +////////////////////////////////////////////////////////////////////////////////////////// +// The following part contains the template +////////////////////////////////////////////////////////////////////////////////////////// + stringBuffer.append(TEXT_1); + stringBuffer.append( packageFULLNAME ); + stringBuffer.append(TEXT_2); + stringBuffer.append( packageFULLNAME ); + stringBuffer.append(TEXT_3); + stringBuffer.append( packageName ); + stringBuffer.append(TEXT_4); + stringBuffer.append(TEXT_5); + stringBuffer.append( fatherPkgInclude ); + stringBuffer.append(TEXT_6); + // For every depency linked package + while(usedPackagesNamesIt.hasNext()) { + cFullName = (String) usedPackagesNamesIt.next(); + stringBuffer.append(TEXT_7); + stringBuffer.append( cFullName ); + stringBuffer.append(TEXT_8); + stringBuffer.append( headerFileSuffix ); + stringBuffer.append(TEXT_9); + } + stringBuffer.append(TEXT_10); + stringBuffer.append(TEXT_11); + stringBuffer.append( headerDecl ); + stringBuffer.append(TEXT_12); + stringBuffer.append(TEXT_13); + stringBuffer.append( openNS ); + stringBuffer.append(TEXT_14); + stringBuffer.append(TEXT_15); + stringBuffer.append( typeDef ); + stringBuffer.append(TEXT_16); + stringBuffer.append( enumDef ); + stringBuffer.append(TEXT_17); + stringBuffer.append( closeNS ); + stringBuffer.append(TEXT_18); + stringBuffer.append( packageName ); + stringBuffer.append(TEXT_19); + stringBuffer.append(TEXT_20); + return stringBuffer.toString(); + } +}
\ No newline at end of file diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/CppTemplateHeader.java b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/CppTemplateHeader.java new file mode 100644 index 00000000000..4aad3809ba8 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/CppTemplateHeader.java @@ -0,0 +1,288 @@ +/******************************************************************************* + * Copyright (c) 2006 CEA List. + * All rights reserved. This program and the accompanying materials + * are property of the CEA, their use is subject to specific agreement + * with the CEA. + * + * Contributors: + * CEA List - initial API and implementation + *******************************************************************************/ + +package org.eclipse.papyrus.cpp.codegen.jet; + +import org.eclipse.papyrus.cpp.codegen.jet.doc.*; +import org.eclipse.uml2.uml.Package; +import org.eclipse.uml2.uml.Class; +import org.eclipse.uml2.uml.*; +import org.eclipse.papyrus.cpp.codegen.jet.util.*; +import Cpp.CppInclude; +import Cpp.CppNoCodeGen; +import Cpp.CppInline; +import org.eclipse.papyrus.cpp.codegen.utils.GenUtils; +import java.util.*; + +public class CppTemplateHeader +{ + protected static String nl; + public static synchronized CppTemplateHeader create(String lineSeparator) + { + nl = lineSeparator; + CppTemplateHeader result = new CppTemplateHeader(); + nl = null; + return result; + } + + public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; + protected final String TEXT_1 = "#ifndef "; + protected final String TEXT_2 = "_H" + NL + "#define "; + protected final String TEXT_3 = "_H" + NL + "" + NL + "/************************************************************"; + protected final String TEXT_4 = NL + " "; + protected final String TEXT_5 = " template class header" + NL + " ************************************************************/" + NL; + protected final String TEXT_6 = NL; + protected final String TEXT_7 = NL; + protected final String TEXT_8 = NL; + protected final String TEXT_9 = NL; + protected final String TEXT_10 = NL; + protected final String TEXT_11 = NL; + protected final String TEXT_12 = NL; + protected final String TEXT_13 = NL + "/************************************************************/" + NL + "template <"; + protected final String TEXT_14 = "> class "; + protected final String TEXT_15 = " "; + protected final String TEXT_16 = "{"; + protected final String TEXT_17 = NL; + protected final String TEXT_18 = NL + "/* Public declarations */" + NL + "public:"; + protected final String TEXT_19 = NL; + protected final String TEXT_20 = NL; + protected final String TEXT_21 = NL + NL + "/* Protected declarations */" + NL + "protected:"; + protected final String TEXT_22 = NL; + protected final String TEXT_23 = NL; + protected final String TEXT_24 = NL + NL + "/* Private declarations */" + NL + "private:"; + protected final String TEXT_25 = NL; + protected final String TEXT_26 = NL; + protected final String TEXT_27 = NL + NL + "};" + NL + "" + NL + "/************************************************************/" + NL + "/* Template functions */"; + protected final String TEXT_28 = NL; + protected final String TEXT_29 = NL; + protected final String TEXT_30 = NL; + protected final String TEXT_31 = NL + "/* Inline functions */"; + protected final String TEXT_32 = NL; + protected final String TEXT_33 = NL; + protected final String TEXT_34 = NL; + protected final String TEXT_35 = NL + NL + "/************************************************************" + NL + " End of "; + protected final String TEXT_36 = " template class header" + NL + " ************************************************************/" + NL + "" + NL + "#endif"; + protected final String TEXT_37 = NL; + + public String generate(Object argument) + { + final StringBuffer stringBuffer = new StringBuffer(); + +////////////////////////////////////////////////////////////////////////////////////////// +// Java preparation +////////////////////////////////////////////////////////////////////////////////////////// + + // Retrieve the class + Classifier currentClass = (Classifier) argument; + + // Get the package name + String className = currentClass.getName(); + String classFullName = GenUtils.getFullName(currentClass); + String classFULLNAME = classFullName.toUpperCase(); + String openNS = GenUtils.openNS (currentClass); + String closeNS = GenUtils.closeNS (currentClass); + + // Include declaration "CppInclude" + String headerDecl = ""; + CppInclude cppInclude = GenUtils.getApplication(currentClass, CppInclude.class); + if (cppInclude != null) { + headerDecl = "// Include from CppInclude declaration" + NL + cppInclude.getHeader() + NL; + } + + // Prepare owner package header include + Package ownerPackage = currentClass.getPackage(); + String ownerInclude = ""; + if (ownerPackage != null) { + // Create an util template to prepare the declaration + CppOwnerPackageIncludeDeclaration jetOwnerInclude = new CppOwnerPackageIncludeDeclaration(); + // Execute the util template + ownerInclude = jetOwnerInclude.generate(ownerPackage); + } + + // Prepare owned type and enum declaration + String typeEnumDefPackage = ""; + String typeEnumDef = ""; + + CppClassTypeAndEnum jetTE = new CppClassTypeAndEnum(); + typeEnumDef = jetTE.generate(currentClass); + + CppClassTypeAndEnumPackage jetTEp = new CppClassTypeAndEnumPackage(); + typeEnumDefPackage = jetTEp.generate(currentClass); + + // Prepare template parameter declaration + Iterator<org.eclipse.uml2.uml.TemplateParameter> tparam = + GenUtils.getTemplateParameters(currentClass).iterator(); + + String tParamDecl = ""; + String tDecl = ""; + + while (tparam.hasNext()) { + CppTemplateParameter jetTParam = new CppTemplateParameter(); + tParamDecl = tParamDecl + jetTParam.generate(tparam.next()); + + if (tparam.hasNext()) { + tParamDecl = tParamDecl + ", "; + } + } + + tDecl = "template <" + tParamDecl + ">" + NL; + + // Prepare dependency includes + CppClassAllIncludesDeclaration jetClassIncludes = new CppClassAllIncludesDeclaration(); + String classIncludes = jetClassIncludes.generate(argument); + if (!classIncludes.equals("")) { + classIncludes = "/* Structural includes (inheritance, dependencies... */" + + NL + classIncludes; + } + + // Prepare attributes and Methods declarations + String publicAttributes = ""; + String protectedAttributes = ""; + String privateAttributes = ""; + String publicOperations = "", publicOperationsImpl = ""; + String protectedOperations = "", protectedOperationsImpl = ""; + String privateOperations = "", privateOperationsImpl = ""; + + // Attributes + CppClassAttributesDeclaration jetClassPAttr = new CppClassAttributesDeclaration(); + publicAttributes = jetClassPAttr.generate(currentClass, VisibilityKind.PUBLIC_LITERAL); + protectedAttributes = jetClassPAttr.generate(currentClass, VisibilityKind.PROTECTED_LITERAL); + privateAttributes = jetClassPAttr.generate(currentClass, VisibilityKind.PRIVATE_LITERAL); + + // Methods implementation + String inlineFuncImpl = ""; + // String inlineFuncDecl = ""; + + // Implementation + CppOperationTemplateImplementation jetOpImpl = new CppOperationTemplateImplementation(); + // Declaration + CppOperationDeclaration jetOpDecl = new CppOperationDeclaration(); + + // Retrieve operations + Iterator<Operation> operations = currentClass.getOperations().iterator(); + while (operations.hasNext()) { + Operation currentOperation = operations.next(); + + if (GenUtils.hasStereotype(currentOperation, CppNoCodeGen.class) || + currentOperation.isAbstract()) { + continue; + } + if (GenUtils.hasStereotype(currentOperation, CppInline.class)) { + String opDoc = ""; + // Doc for the template + CppOperationDoc jDoc = new CppOperationDoc(); + opDoc = jDoc.generate(currentOperation); + // Inline declaration + if (currentOperation.getVisibility() == VisibilityKind.PUBLIC_LITERAL) { + publicOperations = publicOperations + + jetOpDecl.generate(currentOperation) + ";"; + } else if (currentOperation.getVisibility() == VisibilityKind.PRIVATE_LITERAL) { + privateOperations = privateOperations + + jetOpDecl.generate(currentOperation) + ";"; + } else if (currentOperation.getVisibility() == VisibilityKind.PROTECTED_LITERAL) { + protectedOperations = protectedOperations + + jetOpDecl.generate(currentOperation) + ";"; + } // else nothing + // Inline implementation + inlineFuncImpl = inlineFuncImpl + opDoc + NL + tDecl + + jetOpImpl.generate(currentOperation) + NL; + } else { + if (currentOperation.getVisibility() == VisibilityKind.PUBLIC_LITERAL) { + publicOperationsImpl = publicOperationsImpl + tDecl + + jetOpImpl.generate(currentOperation); + publicOperations = publicOperations + + jetOpDecl.generate(currentOperation) + ";"; + } else if (currentOperation.getVisibility() == VisibilityKind.PRIVATE_LITERAL) { + privateOperationsImpl = privateOperationsImpl + tDecl + + jetOpImpl.generate(currentOperation); + privateOperations = privateOperations + + jetOpDecl.generate(currentOperation) + ";"; + } else if (currentOperation.getVisibility() == VisibilityKind.PROTECTED_LITERAL) { + protectedOperationsImpl = protectedOperationsImpl + tDecl + + jetOpImpl.generate(currentOperation); + protectedOperations = protectedOperations + + jetOpDecl.generate(currentOperation) + ";"; + } // else nothing + } + } + + // Prepare inherited classes or implemented interfaces + String inheritedDeclarations = ""; + CppClassInheritedDeclarations jetInherited = new CppClassInheritedDeclarations(); + inheritedDeclarations = jetInherited.generate(currentClass); + + +////////////////////////////////////////////////////////////////////////////////////////// +// The following part contains the template +////////////////////////////////////////////////////////////////////////////////////////// + stringBuffer.append(TEXT_1); + stringBuffer.append( classFULLNAME ); + stringBuffer.append(TEXT_2); + stringBuffer.append( classFULLNAME ); + stringBuffer.append(TEXT_3); + stringBuffer.append(TEXT_4); + stringBuffer.append( className ); + stringBuffer.append(TEXT_5); + stringBuffer.append(TEXT_6); + stringBuffer.append( ownerInclude ); + stringBuffer.append(TEXT_7); + stringBuffer.append(TEXT_8); + stringBuffer.append( classIncludes ); + stringBuffer.append(TEXT_9); + stringBuffer.append(TEXT_10); + stringBuffer.append( headerDecl ); + stringBuffer.append(TEXT_11); + stringBuffer.append( openNS ); + stringBuffer.append(TEXT_12); + stringBuffer.append( typeEnumDefPackage ); + stringBuffer.append(TEXT_13); + stringBuffer.append( tParamDecl ); + stringBuffer.append(TEXT_14); + stringBuffer.append( className ); + stringBuffer.append(TEXT_15); + stringBuffer.append( inheritedDeclarations ); + stringBuffer.append(TEXT_16); + stringBuffer.append(TEXT_17); + stringBuffer.append( typeEnumDef ); + stringBuffer.append(TEXT_18); + stringBuffer.append(TEXT_19); + stringBuffer.append( publicAttributes ); + stringBuffer.append(TEXT_20); + stringBuffer.append( publicOperations ); + stringBuffer.append(TEXT_21); + stringBuffer.append(TEXT_22); + stringBuffer.append( protectedAttributes ); + stringBuffer.append(TEXT_23); + stringBuffer.append( protectedOperations ); + stringBuffer.append(TEXT_24); + stringBuffer.append(TEXT_25); + stringBuffer.append( privateAttributes ); + stringBuffer.append(TEXT_26); + stringBuffer.append( privateOperations ); + stringBuffer.append(TEXT_27); + stringBuffer.append(TEXT_28); + stringBuffer.append( publicOperationsImpl ); + stringBuffer.append(TEXT_29); + stringBuffer.append( protectedOperationsImpl ); + stringBuffer.append(TEXT_30); + stringBuffer.append( privateOperationsImpl ); + stringBuffer.append(TEXT_31); + stringBuffer.append(TEXT_32); + stringBuffer.append( inlineFuncImpl ); + stringBuffer.append(TEXT_33); + stringBuffer.append(TEXT_34); + stringBuffer.append( closeNS ); + stringBuffer.append(TEXT_35); + stringBuffer.append( className ); + stringBuffer.append(TEXT_36); + stringBuffer.append(TEXT_37); + return stringBuffer.toString(); + } +}
\ No newline at end of file diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/doc/CppElementDoc.java b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/doc/CppElementDoc.java new file mode 100644 index 00000000000..3b6157ccdb9 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/doc/CppElementDoc.java @@ -0,0 +1,58 @@ +/******************************************************************************* + * Copyright (c) 2006 CEA List. + * All rights reserved. This program and the accompanying materials + * are property of the CEA, their use is subject to specific agreement + * with the CEA. + * + * Contributors: + * CEA List - initial API and implementation + *******************************************************************************/ + +package org.eclipse.papyrus.cpp.codegen.jet.doc; + +import org.eclipse.uml2.uml.Element; +import org.eclipse.papyrus.cpp.codegen.utils.GenUtils; + +public class CppElementDoc +{ + protected static String nl; + public static synchronized CppElementDoc create(String lineSeparator) + { + nl = lineSeparator; + CppElementDoc result = new CppElementDoc(); + nl = null; + return result; + } + + public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; + protected final String TEXT_1 = "/**" + NL + " * "; + protected final String TEXT_2 = NL + " */"; + + public String generate(Object argument) + { + final StringBuffer stringBuffer = new StringBuffer(); + +////////////////////////////////////////////////////////////////////////////////////////// +// Java preparation +////////////////////////////////////////////////////////////////////////////////////////// + + // Retrieve the element + Element currentElt = (Element) argument; + String eltDoc = ""; + + + // Doc for the element + eltDoc = GenUtils.getComments(currentElt); + eltDoc = eltDoc.replaceAll(NL, NL+" * "); + + + +////////////////////////////////////////////////////////////////////////////////////////// +// The following part contains the template +////////////////////////////////////////////////////////////////////////////////////////// + stringBuffer.append(TEXT_1); + stringBuffer.append( eltDoc ); + stringBuffer.append(TEXT_2); + return stringBuffer.toString(); + } +}
\ No newline at end of file diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/doc/CppOperationDoc.java b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/doc/CppOperationDoc.java new file mode 100644 index 00000000000..b8fdbb83fb3 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/doc/CppOperationDoc.java @@ -0,0 +1,82 @@ +/******************************************************************************* + * Copyright (c) 2006 CEA List. + * All rights reserved. This program and the accompanying materials + * are property of the CEA, their use is subject to specific agreement + * with the CEA. + * + * Contributors: + * CEA List - initial API and implementation + *******************************************************************************/ + +package org.eclipse.papyrus.cpp.codegen.jet.doc; + +import org.eclipse.uml2.uml.Operation; +import org.eclipse.uml2.uml.Parameter; +import org.eclipse.papyrus.cpp.codegen.utils.GenUtils; +import java.util.Iterator; + +public class CppOperationDoc +{ + protected static String nl; + public static synchronized CppOperationDoc create(String lineSeparator) + { + nl = lineSeparator; + CppOperationDoc result = new CppOperationDoc(); + nl = null; + return result; + } + + public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; + protected final String TEXT_1 = "/**" + NL + " * "; + protected final String TEXT_2 = NL + " * "; + protected final String TEXT_3 = NL + " */"; + + public String generate(Object argument) + { + final StringBuffer stringBuffer = new StringBuffer(); + +////////////////////////////////////////////////////////////////////////////////////////// +// Java preparation +////////////////////////////////////////////////////////////////////////////////////////// + + // Retrieve the element + Operation currentOperation = (Operation) argument; + Parameter currentParameter; + + String opDoc = ""; + String opParams = ""; +// String opReturn = ""; +// TODO: return not handled? (or treated as any other parameter?) + + // Doc for the element + opDoc = GenUtils.getComments(currentOperation); + opDoc = opDoc.replaceAll(NL, NL+" * "); + + // Treat params + Iterator<Parameter> parameters = currentOperation.getOwnedParameters().iterator(); + while(parameters.hasNext()) { + currentParameter = (Parameter) parameters.next(); + + // Prepare parameters + CppParamDoc jetParam = new CppParamDoc(); + opParams = opParams+jetParam.generate(currentParameter); + + if (parameters.hasNext()){ + opParams = opParams+NL+" * "; + } + } + + // Treat return + + +////////////////////////////////////////////////////////////////////////////////////////// +// The following part contains the template +////////////////////////////////////////////////////////////////////////////////////////// + stringBuffer.append(TEXT_1); + stringBuffer.append( opDoc ); + stringBuffer.append(TEXT_2); + stringBuffer.append( opParams ); + stringBuffer.append(TEXT_3); + return stringBuffer.toString(); + } +}
\ No newline at end of file diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/doc/CppParamDoc.java b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/doc/CppParamDoc.java new file mode 100644 index 00000000000..398b823a7bb --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/doc/CppParamDoc.java @@ -0,0 +1,57 @@ +/******************************************************************************* + * Copyright (c) 2006 CEA List. + * All rights reserved. This program and the accompanying materials + * are property of the CEA, their use is subject to specific agreement + * with the CEA. + * + * Contributors: + * CEA List - initial API and implementation + *******************************************************************************/ + +package org.eclipse.papyrus.cpp.codegen.jet.doc; + +import org.eclipse.uml2.uml.Parameter; +import org.eclipse.papyrus.cpp.codegen.utils.GenUtils; + +public class CppParamDoc +{ + protected static String nl; + public static synchronized CppParamDoc create(String lineSeparator) + { + nl = lineSeparator; + CppParamDoc result = new CppParamDoc(); + nl = null; + return result; + } + + public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; + protected final String TEXT_1 = "@param "; + protected final String TEXT_2 = " "; + + public String generate(Object argument) + { + final StringBuffer stringBuffer = new StringBuffer(); + +////////////////////////////////////////////////////////////////////////////////////////// +// Java preparation +////////////////////////////////////////////////////////////////////////////////////////// + + // Retrieve the element + Parameter currentElt = (Parameter) argument; + + String paramName = currentElt.getName(); + String paramDoc = GenUtils.getComments(currentElt); + + paramDoc = paramDoc.replaceAll(NL, NL+" * "); + + +////////////////////////////////////////////////////////////////////////////////////////// +// The following part contains the template +////////////////////////////////////////////////////////////////////////////////////////// + stringBuffer.append(TEXT_1); + stringBuffer.append( paramName ); + stringBuffer.append(TEXT_2); + stringBuffer.append( paramDoc ); + return stringBuffer.toString(); + } +}
\ No newline at end of file diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppAttributeDeclaration.java b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppAttributeDeclaration.java new file mode 100644 index 00000000000..faad5c04422 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppAttributeDeclaration.java @@ -0,0 +1,124 @@ +/******************************************************************************* + * Copyright (c) 2006 CEA List. + * All rights reserved. This program and the accompanying materials + * are property of the CEA, their use is subject to specific agreement + * with the CEA. + * + * Contributors: + * CEA List - initial API and implementation + *******************************************************************************/ + +package org.eclipse.papyrus.cpp.codegen.jet.util; + +import org.eclipse.uml2.uml.Property; +import org.eclipse.papyrus.cpp.codegen.jet.doc.*; +import Cpp.*; +import org.eclipse.papyrus.cpp.codegen.utils.*; + +public class CppAttributeDeclaration +{ + protected static String nl; + public static synchronized CppAttributeDeclaration create(String lineSeparator) + { + nl = lineSeparator; + CppAttributeDeclaration result = new CppAttributeDeclaration(); + nl = null; + return result; + } + + public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; + protected final String TEXT_1 = NL + "\t"; + protected final String TEXT_2 = NL + "\t"; + protected final String TEXT_3 = " "; + protected final String TEXT_4 = ";"; + + public String generate(Object argument) + { + final StringBuffer stringBuffer = new StringBuffer(); + +////////////////////////////////////////////////////////////////////////////////////////// +// Java preparation +////////////////////////////////////////////////////////////////////////////////////////// + + // Retrieve the property + Property currentAttribute = (Property) argument; + + String attributeName = currentAttribute.getName(); + String typeName = ""; + String prefix = ""; + String suffix = ""; + String multiple = ""; + + // For property documentation + String propDoc = ""; + + // Retrieve enum doc + CppElementDoc jDoc = new CppElementDoc(); + propDoc = jDoc.generate(currentAttribute); + propDoc = propDoc.replaceAll(NL, NL+" "); + + if (currentAttribute.getType() == null) { + typeName = "undefined"; + } else { + typeName = GenUtils.qualifiedName (currentAttribute.getType()); + } + + // Static attribute + if (currentAttribute.isStatic()) { + prefix = "static"+" "; + } + + Modifier modifier = new Modifier(currentAttribute); + + // Treat multiplicity for association attributes + int multiplicity = currentAttribute.getUpper(); + if (multiplicity == 1) { + multiple = ""; + } else if (multiplicity == -1) { + multiple = "*"; + } else { + multiple = ""; + modifier.array = "[" + multiplicity + "]"; + } + + // If attribute is aggregation + if (GenUtils.isAggregation(currentAttribute)) { + // attributeName = "(*"+attributeName+")"; // this produce a pointer on a tab + attributeName = "*"+attributeName; // this produce a tab of pointers + } + + + if (GenUtils.hasStereotype(currentAttribute, CppConst.class) && currentAttribute.isStatic()) { + // const & static attributes may be initialized within class declaration + // check if initial value UML or profile + if (currentAttribute.getDefaultValue() != null) { + suffix = " = " + currentAttribute.getDefaultValue().stringValue(); + } + else { + CppDefault cppDefault = GenUtils.getApplication(currentAttribute, CppDefault.class); + if (cppDefault != null) { + suffix = " = " + cppDefault.getValue(); + } + } + } + +////////////////////////////////////////////////////////////////////////////////////////// +// The following part contains the template +////////////////////////////////////////////////////////////////////////////////////////// + stringBuffer.append(TEXT_1); + stringBuffer.append( propDoc ); + stringBuffer.append(TEXT_2); + stringBuffer.append( prefix ); + stringBuffer.append( modifier.isConst ); + stringBuffer.append( typeName ); + stringBuffer.append( multiple ); + stringBuffer.append( modifier.ptr ); + stringBuffer.append( modifier.ref ); + stringBuffer.append(TEXT_3); + stringBuffer.append( attributeName ); + stringBuffer.append( modifier.array ); + stringBuffer.append( suffix ); + stringBuffer.append(TEXT_4); + return stringBuffer.toString(); + } +}
\ No newline at end of file diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppAttributeImplementation.java b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppAttributeImplementation.java new file mode 100644 index 00000000000..ab85473afbc --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppAttributeImplementation.java @@ -0,0 +1,105 @@ +/******************************************************************************* + * Copyright (c) 2006 CEA List. + * All rights reserved. This program and the accompanying materials + * are property of the CEA, their use is subject to specific agreement + * with the CEA. + * + * Contributors: + * CEA List - initial API and implementation + *******************************************************************************/ + +package org.eclipse.papyrus.cpp.codegen.jet.util; + +import org.eclipse.uml2.uml.*; +import org.eclipse.papyrus.cpp.codegen.jet.doc.*; +import Cpp.*; +import org.eclipse.papyrus.cpp.codegen.utils.*; + +public class CppAttributeImplementation +{ + protected static String nl; + public static synchronized CppAttributeImplementation create(String lineSeparator) + { + nl = lineSeparator; + CppAttributeImplementation result = new CppAttributeImplementation(); + nl = null; + return result; + } + + public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; + protected final String TEXT_1 = "\t"; + protected final String TEXT_2 = NL + "\t"; + protected final String TEXT_3 = " "; + protected final String TEXT_4 = ";"; + protected final String TEXT_5 = NL; + + public String generate(Object argument) + { + final StringBuffer stringBuffer = new StringBuffer(); + +////////////////////////////////////////////////////////////////////////////////////////// +// Java preparation +////////////////////////////////////////////////////////////////////////////////////////// + + // Retrieve the property + Property currentAttribute = (Property) argument; + + String attributeName = currentAttribute.getName(); +// String className = currentAttribute.getOwner().getName(); + String typeName = ""; + String scopeName = ""; +// String prefix = ""; + String suffix = ""; + String multiple = ""; + + // For property documentation + String propDoc = ""; + + // Retrieve enum doc + CppElementDoc jDoc = new CppElementDoc(); + propDoc = jDoc.generate(currentAttribute); + propDoc = propDoc.replaceAll(NL, NL+" "); + + if (currentAttribute.getType() == null) { + typeName = "undefined"; + } + else { + Type type = currentAttribute.getType(); + typeName = GenUtils.qualifiedName (type); + /* + // If type is owned by a class add the scope + if (type.getOwner() instanceof Class) { + scopeName = ((Class) type.getOwner()).getName(); + typeName = scopeName+"::"+typeName; + } + */ + } + + // Multiple + // TODO? need to evaluate limitMultiplicity stereotype? + int upper = currentAttribute.getUpper(); + if ((upper == -1) || (upper > 1)) { + multiple = "*"; + } + + Modifier modifier = new Modifier(currentAttribute); + +////////////////////////////////////////////////////////////////////////////////////////// +// The following part contains the template +////////////////////////////////////////////////////////////////////////////////////////// + stringBuffer.append(TEXT_1); + stringBuffer.append( propDoc ); + stringBuffer.append(TEXT_2); + stringBuffer.append( typeName ); + stringBuffer.append( multiple ); + stringBuffer.append( modifier.ptr ); + stringBuffer.append( modifier.ref ); + stringBuffer.append(TEXT_3); + stringBuffer.append( attributeName ); + stringBuffer.append( modifier.array ); + stringBuffer.append( suffix ); + stringBuffer.append(TEXT_4); + stringBuffer.append(TEXT_5); + return stringBuffer.toString(); + } +}
\ No newline at end of file diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppClassAllIncludesDeclaration.java b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppClassAllIncludesDeclaration.java new file mode 100644 index 00000000000..acc9eb087fa --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppClassAllIncludesDeclaration.java @@ -0,0 +1,89 @@ +/******************************************************************************* + * Copyright (c) 2006 CEA List. + * All rights reserved. This program and the accompanying materials + * are property of the CEA, their use is subject to specific agreement + * with the CEA. + * + * Contributors: + * CEA List - initial API and implementation + *******************************************************************************/ + +package org.eclipse.papyrus.cpp.codegen.jet.util; + +import Cpp.*; +import org.eclipse.papyrus.cpp.codegen.utils.*; +import org.eclipse.uml2.uml.Class; +import org.eclipse.emf.common.util.EList; +import org.eclipse.uml2.uml.Package; +import org.eclipse.emf.common.util.UniqueEList; +import java.util.*; +import org.eclipse.uml2.uml.PrimitiveType; +import org.eclipse.uml2.uml.Enumeration; +import org.eclipse.uml2.uml.Classifier; + +public class CppClassAllIncludesDeclaration +{ + protected static String nl; + public static synchronized CppClassAllIncludesDeclaration create(String lineSeparator) + { + nl = lineSeparator; + CppClassAllIncludesDeclaration result = new CppClassAllIncludesDeclaration(); + nl = null; + return result; + } + + public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; + protected final String TEXT_1 = ""; + protected final String TEXT_2 = NL; + protected final String TEXT_3 = NL; + + public String generate(Object argument) + { + final StringBuffer stringBuffer = new StringBuffer(); + +////////////////////////////////////////////////////////////////////////////////////////// +// Java preparation +////////////////////////////////////////////////////////////////////////////////////////// + + // Retrieve the class + Classifier currentClass = (Classifier) argument; + + // Get the package name + // String className = currentClass.getName(); + + // Prepare Dependency includes declarations ... + // Retrieve package used by current package (dependencies) + // use a unique list to avoid duplicates + EList<Classifier> usedClasses = new UniqueEList<Classifier> (); + + String newInclude = ""; + + // 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)); + } + // 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)); + + Iterator<Classifier> usedClassesIt = usedClasses.iterator(); + // Parsing all as NamedElement + String includes = ClassUtils.createIncludeDecl (usedClasses, currentClass); + +////////////////////////////////////////////////////////////////////////////////////////// +// The following part contains the template +////////////////////////////////////////////////////////////////////////////////////////// + stringBuffer.append(TEXT_1); + stringBuffer.append( includes ); + stringBuffer.append(TEXT_2); + stringBuffer.append(TEXT_3); + return stringBuffer.toString(); + } +}
\ No newline at end of file diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppClassAttributesDeclaration.java b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppClassAttributesDeclaration.java new file mode 100644 index 00000000000..a0de92709c3 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppClassAttributesDeclaration.java @@ -0,0 +1,59 @@ +/******************************************************************************* + * Copyright (c) 2006 CEA List. + * All rights reserved. This program and the accompanying materials + * are property of the CEA, their use is subject to specific agreement + * with the CEA. + * + * Contributors: + * CEA List - initial API and implementation + *******************************************************************************/ + +package org.eclipse.papyrus.cpp.codegen.jet.util; + +import org.eclipse.uml2.uml.*; +import java.util.Iterator; + +public class CppClassAttributesDeclaration +{ + protected static String nl; + public static synchronized CppClassAttributesDeclaration create(String lineSeparator) + { + nl = lineSeparator; + CppClassAttributesDeclaration result = new CppClassAttributesDeclaration(); + nl = null; + return result; + } + + public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; + protected final String TEXT_1 = ""; + + public String generate(Object argument1, Object argument2) + { + final StringBuffer stringBuffer = new StringBuffer(); + +////////////////////////////////////////////////////////////////////////////////////////// +// Java preparation +////////////////////////////////////////////////////////////////////////////////////////// + + // Retrieve the class + Classifier currentClass = (Classifier) argument1; + String attrDecl = ""; + + // Retrieve public attributes + Iterator<Property> attributes = currentClass.getAttributes().iterator(); + while (attributes.hasNext()) { + Property attribute = attributes.next(); + if (attribute.getVisibility() == argument2) { + CppAttributeDeclaration jetAttDecl = new CppAttributeDeclaration(); + attrDecl = attrDecl+jetAttDecl.generate(attribute); + } + } + +////////////////////////////////////////////////////////////////////////////////////////// +// The following part contains the template +////////////////////////////////////////////////////////////////////////////////////////// + stringBuffer.append(TEXT_1); + stringBuffer.append( attrDecl ); + return stringBuffer.toString(); + } +}
\ No newline at end of file diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppClassAttributesImplementation.java b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppClassAttributesImplementation.java new file mode 100644 index 00000000000..4c30ed0bedd --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppClassAttributesImplementation.java @@ -0,0 +1,71 @@ +/******************************************************************************* + * Copyright (c) 2006 CEA List. + * All rights reserved. This program and the accompanying materials + * are property of the CEA, their use is subject to specific agreement + * with the CEA. + * + * Contributors: + * CEA List - initial API and implementation + *******************************************************************************/ + +package org.eclipse.papyrus.cpp.codegen.jet.util; + +import org.eclipse.uml2.uml.*; +import java.util.Iterator; +import Cpp.*; +import org.eclipse.papyrus.cpp.codegen.utils.GenUtils; + +public class CppClassAttributesImplementation +{ + protected static String nl; + public static synchronized CppClassAttributesImplementation create(String lineSeparator) + { + nl = lineSeparator; + CppClassAttributesImplementation result = new CppClassAttributesImplementation(); + nl = null; + return result; + } + + public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; + protected final String TEXT_1 = ""; + + public String generate(Object argument) + { + final StringBuffer stringBuffer = new StringBuffer(); + +////////////////////////////////////////////////////////////////////////////////////////// +// Java preparation +////////////////////////////////////////////////////////////////////////////////////////// + + // Retrieve the class + Classifier currentClass = (Classifier) argument; + String attrDecl = ""; + String attrSDecl = ""; + + CppAttributeImplementation jetAttDecl = new CppAttributeImplementation(); + CppStaticAttributeImplementation jetSAttDecl = new CppStaticAttributeImplementation(); + + Iterator<Property> attributesIt = currentClass.getAttributes().iterator(); + while (attributesIt.hasNext()) { + Property attribute = (Property) attributesIt.next(); + + // just check that this property is not a static const + // in that case it declared and defined in the header file + + // Static + if (attribute.isStatic()) { + attrSDecl = attrSDecl+jetSAttDecl.generate(attribute); + } else { + attrDecl = attrDecl+jetAttDecl.generate(attribute); + } + } + +////////////////////////////////////////////////////////////////////////////////////////// +// The following part contains the template +////////////////////////////////////////////////////////////////////////////////////////// + stringBuffer.append(TEXT_1); + stringBuffer.append( attrSDecl ); + stringBuffer.append( attrDecl ); + return stringBuffer.toString(); + } +}
\ No newline at end of file diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppClassFriendDeclaration.java b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppClassFriendDeclaration.java new file mode 100644 index 00000000000..030fae595ff --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppClassFriendDeclaration.java @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2006 CEA List. + * All rights reserved. This program and the accompanying materials + * are property of the CEA, their use is subject to specific agreement + * with the CEA. + * + * Contributors: + * CEA List - initial API and implementation + *******************************************************************************/ + +package org.eclipse.papyrus.cpp.codegen.jet.util; + +import org.eclipse.uml2.uml.NamedElement; + +public class CppClassFriendDeclaration +{ + protected static String nl; + public static synchronized CppClassFriendDeclaration create(String lineSeparator) + { + nl = lineSeparator; + CppClassFriendDeclaration result = new CppClassFriendDeclaration(); + nl = null; + return result; + } + + public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; + protected final String TEXT_1 = "friend class "; + protected final String TEXT_2 = ";"; + protected final String TEXT_3 = NL; + + public String generate(Object argument) + { + final StringBuffer stringBuffer = new StringBuffer(); + +////////////////////////////////////////////////////////////////////////////////////////// +// Java preparation +////////////////////////////////////////////////////////////////////////////////////////// + + // Retrieve the class + NamedElement currentNE = (NamedElement) argument; + String cClassName = currentNE.getName(); + +////////////////////////////////////////////////////////////////////////////////////////// +// The following part contains the template +////////////////////////////////////////////////////////////////////////////////////////// + stringBuffer.append(TEXT_1); + stringBuffer.append( cClassName ); + stringBuffer.append(TEXT_2); + stringBuffer.append(TEXT_3); + return stringBuffer.toString(); + } +}
\ No newline at end of file diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppClassIncludeClassDeclaration.java b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppClassIncludeClassDeclaration.java new file mode 100644 index 00000000000..e7fc0246e6e --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppClassIncludeClassDeclaration.java @@ -0,0 +1,72 @@ +/******************************************************************************* + * Copyright (c) 2006 CEA List. + * All rights reserved. This program and the accompanying materials + * are property of the CEA, their use is subject to specific agreement + * with the CEA. + * + * Contributors: + * CEA List - initial API and implementation + *******************************************************************************/ + +package org.eclipse.papyrus.cpp.codegen.jet.util; + +import org.eclipse.uml2.uml.NamedElement; +import org.eclipse.papyrus.cpp.codegen.utils.GenUtils; +import Cpp.*; + +public class CppClassIncludeClassDeclaration +{ + protected static String nl; + public static synchronized CppClassIncludeClassDeclaration create(String lineSeparator) + { + nl = lineSeparator; + CppClassIncludeClassDeclaration result = new CppClassIncludeClassDeclaration(); + nl = null; + return result; + } + + public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; + protected final String TEXT_1 = ""; + protected final String TEXT_2 = NL; + protected final String TEXT_3 = NL; + protected final String TEXT_4 = "class "; + protected final String TEXT_5 = ";"; + protected final String TEXT_6 = NL; + protected final String TEXT_7 = NL; + + public String generate(Object argument) + { + final StringBuffer stringBuffer = new StringBuffer(); + +////////////////////////////////////////////////////////////////////////////////////////// +// Java preparation +////////////////////////////////////////////////////////////////////////////////////////// + + // Retrieve the class + NamedElement currentNE = (NamedElement) argument; + String cClassName = currentNE.getName(); + String isTemplate = ""; + String openNS = GenUtils.openNS (currentNE); + String closeNS = GenUtils.closeNS (currentNE); + + if (GenUtils.hasStereotype(currentNE, CppTemplate.class)) { + isTemplate = "template "; + } + +////////////////////////////////////////////////////////////////////////////////////////// +// The following part contains the template +////////////////////////////////////////////////////////////////////////////////////////// + stringBuffer.append(TEXT_1); + stringBuffer.append(TEXT_2); + stringBuffer.append( openNS ); + stringBuffer.append(TEXT_3); + stringBuffer.append( isTemplate ); + stringBuffer.append(TEXT_4); + stringBuffer.append( cClassName ); + stringBuffer.append(TEXT_5); + stringBuffer.append(TEXT_6); + stringBuffer.append( closeNS ); + stringBuffer.append(TEXT_7); + return stringBuffer.toString(); + } +}
\ No newline at end of file diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppClassIncludeDeclaration.java b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppClassIncludeDeclaration.java new file mode 100644 index 00000000000..a10b49edd59 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppClassIncludeDeclaration.java @@ -0,0 +1,88 @@ +/******************************************************************************* + * Copyright (c) 2006 CEA List. + * All rights reserved. This program and the accompanying materials + * are property of the CEA, their use is subject to specific agreement + * with the CEA. + * + * Contributors: + * CEA List - initial API and implementation + *******************************************************************************/ + +package org.eclipse.papyrus.cpp.codegen.jet.util; + +import org.eclipse.uml2.uml.NamedElement; +import org.eclipse.uml2.uml.Package; +import org.eclipse.papyrus.cpp.codegen.Activator; +import org.eclipse.papyrus.cpp.codegen.utils.GenUtils; +import Cpp.*; + +public class CppClassIncludeDeclaration +{ + protected static String nl; + public static synchronized CppClassIncludeDeclaration create(String lineSeparator) + { + nl = lineSeparator; + CppClassIncludeDeclaration result = new CppClassIncludeDeclaration(); + nl = null; + return result; + } + + public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; + protected final String TEXT_1 = "#include <"; + protected final String TEXT_2 = ">"; + protected final String TEXT_3 = NL; + + public String generate(Object argument) + { + final StringBuffer stringBuffer = new StringBuffer(); + +////////////////////////////////////////////////////////////////////////////////////////// +// Java preparation +////////////////////////////////////////////////////////////////////////////////////////// + + + // Retrieve header file suffix + String headerFileSuffix = Activator.getDefault().getPluginPreferences().getString("headSuffix"); + + + // Retrieve the class + NamedElement currentNE = (NamedElement) argument; + String cClassPath = ""; + Package nearestPkg = currentNE.getNearestPackage(); + String cClassName = currentNE.getName(); + + if ( //!(nearestPkg.getUml2Package() instanceof org.eclipse.uml2.uml.Model) + /*&& */!(GenUtils.hasStereotype(nearestPkg, CppRoot.class))) { + cClassPath = GenUtils.getFullPath(nearestPkg)+"/"; + } + + + // If an external class is referred + CppExternClass extClass = GenUtils.getApplication(currentNE, CppExternClass.class); + CppTemplate template = GenUtils.getApplication(currentNE, CppTemplate.class); + if (extClass != null) { + cClassPath = ""; + cClassName = extClass.getName(); + if ((cClassName == null) || cClassName.equals ("")) { + // default value + cClassName = currentNE.getQualifiedName ().replace ("::", "/") + "." + headerFileSuffix; + // strip model name + cClassName = cClassName.substring (currentNE.getModel ().getName ().length () + 1); + } + } else if (template != null) { + cClassPath = ""; + cClassName = template.getDeclaration(); + } + else cClassName=cClassName+"."+headerFileSuffix; + +////////////////////////////////////////////////////////////////////////////////////////// +// The following part contains the template +////////////////////////////////////////////////////////////////////////////////////////// + stringBuffer.append(TEXT_1); + stringBuffer.append( cClassPath ); + stringBuffer.append( cClassName ); + stringBuffer.append(TEXT_2); + stringBuffer.append(TEXT_3); + return stringBuffer.toString(); + } +}
\ No newline at end of file diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppClassIncludeFriendDeclaration.java b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppClassIncludeFriendDeclaration.java new file mode 100644 index 00000000000..1b37bcb57aa --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppClassIncludeFriendDeclaration.java @@ -0,0 +1,71 @@ +/******************************************************************************* + * Copyright (c) 2006 CEA List. + * All rights reserved. This program and the accompanying materials + * are property of the CEA, their use is subject to specific agreement + * with the CEA. + * + * Contributors: + * CEA List - initial API and implementation + *******************************************************************************/ + +package org.eclipse.papyrus.cpp.codegen.jet.util; + +import org.eclipse.uml2.uml.*; +import java.util.*; +import org.eclipse.papyrus.cpp.codegen.utils.GenUtils; +import Cpp.*; + +public class CppClassIncludeFriendDeclaration +{ + protected static String nl; + public static synchronized CppClassIncludeFriendDeclaration create(String lineSeparator) + { + nl = lineSeparator; + CppClassIncludeFriendDeclaration result = new CppClassIncludeFriendDeclaration(); + nl = null; + return result; + } + + public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; + protected final String TEXT_1 = ""; + + public String generate(Object argument) + { + final StringBuffer stringBuffer = new StringBuffer(); + +////////////////////////////////////////////////////////////////////////////////////////// +// Java preparation +////////////////////////////////////////////////////////////////////////////////////////// + + // Retrieve the class + Classifier currentClass = (Classifier) argument; +// NamedElement currentElt = (NamedElement) argument; + + // Prepare Dependency includes declarations ... + // Retrieve package used by current package (dependencies) + Iterator<Classifier> friendClassesIt = GenUtils.getUsedClassifiers(currentClass).iterator(); + + // Parsing all as NamedElement + String friendClass = ""; + + while (friendClassesIt.hasNext()) { + Classifier cClass = friendClassesIt.next(); + + if (GenUtils.hasStereotype(cClass, CppFriend.class) && + (!GenUtils.hasStereotype(cClass, CppNoCodeGen.class))) { + + CppClassFriendDeclaration jetIDecl + = new CppClassFriendDeclaration(); + + friendClass = friendClass+jetIDecl.generate(cClass); + } + } + +////////////////////////////////////////////////////////////////////////////////////////// +// The following part contains the template +////////////////////////////////////////////////////////////////////////////////////////// + stringBuffer.append(TEXT_1); + stringBuffer.append( friendClass ); + return stringBuffer.toString(); + } +}
\ No newline at end of file diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppClassInheritedDeclarations.java b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppClassInheritedDeclarations.java new file mode 100644 index 00000000000..9081b1f7aaa --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppClassInheritedDeclarations.java @@ -0,0 +1,130 @@ +/******************************************************************************* + * Copyright (c) 2006 CEA List. + * All rights reserved. This program and the accompanying materials + * are property of the CEA, their use is subject to specific agreement + * with the CEA. + * + * Contributors: + * CEA List - initial API and implementation + *******************************************************************************/ + +package org.eclipse.papyrus.cpp.codegen.jet.util; + +import org.eclipse.uml2.uml.*; +import java.util.*; +import org.eclipse.papyrus.cpp.codegen.utils.GenUtils; +import Cpp.*; + +public class CppClassInheritedDeclarations +{ + protected static String nl; + public static synchronized CppClassInheritedDeclarations create(String lineSeparator) + { + nl = lineSeparator; + CppClassInheritedDeclarations result = new CppClassInheritedDeclarations(); + nl = null; + return result; + } + + public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; + protected final String TEXT_1 = ""; + + public String generate(Object argument) + { + final StringBuffer stringBuffer = new StringBuffer(); + +////////////////////////////////////////////////////////////////////////////////////////// +// Java preparation +////////////////////////////////////////////////////////////////////////////////////////// + + // Retrieve the class + Classifier currentClass = (Classifier) argument; + String targetName = ""; + String visibility = ""; + String decl = ""; + + // Get generalization and implementation relationships + Iterator<DirectedRelationship> relationshipIt = + currentClass.getSourceDirectedRelationships().iterator(); + // Iterator impIt = currentClass.getImplementations().iterator(); + + while (relationshipIt.hasNext()) { + + DirectedRelationship relationship = relationshipIt.next(); + + if ((relationship instanceof Generalization) || + (relationship instanceof InterfaceRealization)) + { + org.eclipse.uml2.uml.Classifier target = null; + if (relationship.getTargets ().size() > 0) { + // there should always be at least one element in the target + // list and it should be a classifier, but better check. + org.eclipse.uml2.uml.Element element = + relationship.getTargets().get(0); + if (element instanceof org.eclipse.uml2.uml.Classifier) { + target = (org.eclipse.uml2.uml.Classifier) element; + } + } + if (target != null) { + // If not <NoCodeGen> + if (!GenUtils.hasStereotype(target, CppNoCodeGen.class)) + { + CppVisibility cppVisibility = GenUtils.getApplication(relationship, CppVisibility.class); + if (cppVisibility != null) { + visibility = cppVisibility.getValue(); + } else { + visibility = "public"; + } + + targetName = GenUtils.qualifiedName (target); + if (!decl.equals("")) { + decl = decl + ", "; + } + decl = decl+visibility+" "+targetName; + } + } + } + } + + // Parse implementations + // RS: removed code: Implementation does not exist in UML2 v2. + // TODO: replace Implementation with new UML2 constructions? +// Implementation currentImp; +// +// while (impIt.hasNext()) { +// +// currentImp = (Implementation) impIt.next(); +// currentNE = (NamedElement) currentImp; +// +// // get visibility and target name +// visibility = currentNE.getVisibilityAsString(); +// +// // If not <NoCodeGen> +// if (!GenUtils.hasStereotype(currentImp.getTarget(), CppNoCodeGen.class)) { +// +// targetName = currentImp.getTarget().getName(); +// +// if (!decl.equals("")) { +// decl = decl + ", "; +// } +// decl = decl+visibility+" "+targetName; +// +// } +// } + + + // ":" if decl non empty + String prefix = ""; + if (!decl.equals("")) { + prefix = " : "; + } + +////////////////////////////////////////////////////////////////////////////////////////// +// The following part contains the template +////////////////////////////////////////////////////////////////////////////////////////// + stringBuffer.append(TEXT_1); + stringBuffer.append( prefix ); + stringBuffer.append( decl ); + return stringBuffer.toString(); + } +}
\ No newline at end of file diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppClassInlineOperationsImplementation.java b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppClassInlineOperationsImplementation.java new file mode 100644 index 00000000000..4ff043d4116 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppClassInlineOperationsImplementation.java @@ -0,0 +1,63 @@ +/******************************************************************************* + * Copyright (c) 2006 CEA List. + * All rights reserved. This program and the accompanying materials + * are property of the CEA, their use is subject to specific agreement + * with the CEA. + * + * Contributors: + * CEA List - initial API and implementation + *******************************************************************************/ + +package org.eclipse.papyrus.cpp.codegen.jet.util; + +import org.eclipse.uml2.uml.*; +import java.util.Iterator; +import org.eclipse.papyrus.cpp.codegen.utils.GenUtils; +import Cpp.*; + +public class CppClassInlineOperationsImplementation +{ + protected static String nl; + public static synchronized CppClassInlineOperationsImplementation create(String lineSeparator) + { + nl = lineSeparator; + CppClassInlineOperationsImplementation result = new CppClassInlineOperationsImplementation(); + nl = null; + return result; + } + + public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; + protected final String TEXT_1 = ""; + + public String generate(Object argument) + { + final StringBuffer stringBuffer = new StringBuffer(); + +////////////////////////////////////////////////////////////////////////////////////////// +// Java preparation +////////////////////////////////////////////////////////////////////////////////////////// + + // Retrieve the class + Classifier currentClass = (Classifier) argument; + String opDecl = ""; + + // Retrieve operations + Iterator<Operation> operations = currentClass.getOperations().iterator(); + while (operations.hasNext()) { + Operation currentOp = operations.next(); + if (GenUtils.hasStereotype (currentOp, CppInline.class) && + !GenUtils.hasStereotype (currentOp, CppNoCodeGen.class)) { + + CppOperationImplementation jetOpImpl = new CppOperationImplementation(); + opDecl = opDecl+jetOpImpl.generate(currentOp); + } + } + +////////////////////////////////////////////////////////////////////////////////////////// +// The following part contains the template +////////////////////////////////////////////////////////////////////////////////////////// + stringBuffer.append(TEXT_1); + stringBuffer.append( opDecl ); + return stringBuffer.toString(); + } +}
\ No newline at end of file diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppClassOperationsDeclaration.java b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppClassOperationsDeclaration.java new file mode 100644 index 00000000000..1ba52bc71f5 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppClassOperationsDeclaration.java @@ -0,0 +1,68 @@ +/******************************************************************************* + * Copyright (c) 2006 CEA List. + * All rights reserved. This program and the accompanying materials + * are property of the CEA, their use is subject to specific agreement + * with the CEA. + * + * Contributors: + * CEA List - initial API and implementation + *******************************************************************************/ + +package org.eclipse.papyrus.cpp.codegen.jet.util; + +import org.eclipse.uml2.uml.*; +import java.util.Iterator; +import org.eclipse.papyrus.cpp.codegen.utils.GenUtils; +import Cpp.*; + +public class CppClassOperationsDeclaration +{ + protected static String nl; + public static synchronized CppClassOperationsDeclaration create(String lineSeparator) + { + nl = lineSeparator; + CppClassOperationsDeclaration result = new CppClassOperationsDeclaration(); + nl = null; + return result; + } + + public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; + protected final String TEXT_1 = ""; + + public String generate(Object argument1, Object argument2) + { + final StringBuffer stringBuffer = new StringBuffer(); + +////////////////////////////////////////////////////////////////////////////////////////// +// Java preparation +////////////////////////////////////////////////////////////////////////////////////////// + + // Retrieve the class + Classifier currentClass = (Classifier) argument1; + String opDecl = ""; + + // Retrieve attributes + Iterator<Operation> operations = currentClass.getOperations().iterator(); + while (operations.hasNext()) { + Operation operation = operations.next(); + if (!GenUtils.hasStereotype (operation, CppNoCodeGen.class)) { + if (operation.getVisibility() == argument2) { + CppOperationDeclaration jetOpDecl = new CppOperationDeclaration(); + String cOpDecl = jetOpDecl.generate(operation); + + // if main cOpDecl = ""; + if (!cOpDecl.equals("")) { + opDecl = opDecl+NL+cOpDecl+";"; + } + } + } + } + +////////////////////////////////////////////////////////////////////////////////////////// +// The following part contains the template +////////////////////////////////////////////////////////////////////////////////////////// + stringBuffer.append(TEXT_1); + stringBuffer.append( opDecl ); + return stringBuffer.toString(); + } +}
\ No newline at end of file diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppClassOperationsImplementation.java b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppClassOperationsImplementation.java new file mode 100644 index 00000000000..377e7f579bf --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppClassOperationsImplementation.java @@ -0,0 +1,63 @@ +/******************************************************************************* + * Copyright (c) 2006 CEA List. + * All rights reserved. This program and the accompanying materials + * are property of the CEA, their use is subject to specific agreement + * with the CEA. + * + * Contributors: + * CEA List - initial API and implementation + *******************************************************************************/ + +package org.eclipse.papyrus.cpp.codegen.jet.util; + +import org.eclipse.uml2.uml.*; +import java.util.Iterator; +import org.eclipse.papyrus.cpp.codegen.utils.GenUtils; +import Cpp.*; + +public class CppClassOperationsImplementation +{ + protected static String nl; + public static synchronized CppClassOperationsImplementation create(String lineSeparator) + { + nl = lineSeparator; + CppClassOperationsImplementation result = new CppClassOperationsImplementation(); + nl = null; + return result; + } + + public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; + protected final String TEXT_1 = ""; + + public String generate(Object argument) + { + final StringBuffer stringBuffer = new StringBuffer(); + +////////////////////////////////////////////////////////////////////////////////////////// +// Java preparation +////////////////////////////////////////////////////////////////////////////////////////// + + // Retrieve the class + Classifier currentClass = (Classifier) argument; + String opDecl = ""; + + // Retrieve operations + Iterator<Operation> operations = currentClass.getOperations().iterator(); + while (operations.hasNext()) { + Operation currentOp = operations.next(); + if (!GenUtils.hasStereotype (currentOp, CppInline.class) && + !GenUtils.hasStereotype (currentOp, CppNoCodeGen.class) && + !currentOp.isAbstract()) { + CppOperationImplementation jetOpImpl = new CppOperationImplementation(); + opDecl = opDecl+jetOpImpl.generate(currentOp); + } + } + +////////////////////////////////////////////////////////////////////////////////////////// +// The following part contains the template +////////////////////////////////////////////////////////////////////////////////////////// + stringBuffer.append(TEXT_1); + stringBuffer.append( opDecl ); + return stringBuffer.toString(); + } +}
\ No newline at end of file diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppClassTypeAndEnum.java b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppClassTypeAndEnum.java new file mode 100644 index 00000000000..db433ffb881 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppClassTypeAndEnum.java @@ -0,0 +1,134 @@ +/******************************************************************************* + * Copyright (c) 2006 CEA List. + * All rights reserved. This program and the accompanying materials + * are property of the CEA, their use is subject to specific agreement + * with the CEA. + * + * Contributors: + * CEA List - initial API and implementation + *******************************************************************************/ + +package org.eclipse.papyrus.cpp.codegen.jet.util; + +import org.eclipse.papyrus.cpp.codegen.utils.GenUtils; +import org.eclipse.uml2.uml.*; + +public class CppClassTypeAndEnum +{ + protected static String nl; + public static synchronized CppClassTypeAndEnum create(String lineSeparator) + { + nl = lineSeparator; + CppClassTypeAndEnum result = new CppClassTypeAndEnum(); + nl = null; + return result; + } + + public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; + protected final String TEXT_1 = ""; + protected final String TEXT_2 = NL; + + public String generate(Object argument) + { + final StringBuffer stringBuffer = new StringBuffer(); + +////////////////////////////////////////////////////////////////////////////////////////// +// Java preparation +////////////////////////////////////////////////////////////////////////////////////////// + + // Retrieve the class + Classifier currentClass = (Classifier) argument; + + // Prepare owned type and enum declaration + String publicTypeDef = ""; + String privateTypeDef = ""; + String protectedTypeDef = ""; + String publicEnumDef = ""; + String privateEnumDef = ""; + String protectedEnumDef = ""; + String publicKeyword = "public:"; + String protectedKeyword = "protected:"; + String privateKeyword = "private:"; + + for (Element currentElt : currentClass.getOwnedElements()) { + if (!GenUtils.hasStereotype(currentElt, Cpp.CppNoCodeGen.class)) { + if (currentElt instanceof PrimitiveType) { + + org.eclipse.uml2.uml.PrimitiveType currentType = (org.eclipse.uml2.uml.PrimitiveType) currentElt; + CppPrimitiveTypeDefinition jetPrimitiveType = new CppPrimitiveTypeDefinition(); + // Execute the util template + if (currentType.getVisibility() == VisibilityKind.PUBLIC_LITERAL) { + publicTypeDef = publicTypeDef+jetPrimitiveType.generate(currentType); + } else if (currentType.getVisibility() == VisibilityKind.PROTECTED_LITERAL) { + protectedTypeDef = protectedTypeDef+jetPrimitiveType.generate(currentType); + } else if (currentType.getVisibility() == VisibilityKind.PRIVATE_LITERAL) { + privateTypeDef = privateTypeDef+jetPrimitiveType.generate(currentType); + } + } + else if (currentElt instanceof Enumeration) { + + Enumeration currentEnum = (Enumeration) currentElt; + CppEnumerationDefinition jetEnum = new CppEnumerationDefinition(); + // Execute the util template + if (currentEnum.getVisibility() == VisibilityKind.PUBLIC_LITERAL) { + publicEnumDef = publicEnumDef+jetEnum.generate(currentEnum); + } else if (currentEnum.getVisibility() == VisibilityKind.PROTECTED_LITERAL) { + protectedEnumDef = protectedEnumDef+jetEnum.generate(currentEnum); + } else if (currentEnum.getVisibility() == VisibilityKind.PRIVATE_LITERAL) { + privateEnumDef = privateEnumDef+jetEnum.generate(currentEnum); + } + } + } + } + + // If not "" add a comment before declarations + if (publicTypeDef.equals("") && publicEnumDef.equals("")) { + publicKeyword = ""; + } else { + if (!publicTypeDef.equals("")) { + publicTypeDef = "/* Public type definitions */"+NL+publicTypeDef+NL; + } + if (!publicEnumDef.equals("")) { + publicEnumDef = "/* Public enumeration definitions */"+NL+publicEnumDef+NL; + } + } + + if (protectedTypeDef.equals("") && protectedEnumDef.equals("")) { + protectedKeyword = ""; + } else { + if (!protectedTypeDef.equals("")) { + protectedTypeDef = "/* Protected type definitions */"+NL+protectedTypeDef+NL; + } + if (!protectedEnumDef.equals("")) { + protectedEnumDef = "/* Protected enumeration definitions */"+NL+protectedEnumDef+NL; + } + } + + if (privateTypeDef.equals("") && privateEnumDef.equals("")) { + privateKeyword = ""; + } else { + if (!privateTypeDef.equals("")) { + privateTypeDef = "/* Private type definitions */"+NL+privateTypeDef+NL; + } + if (!privateEnumDef.equals("")) { + privateEnumDef = "/* Private enumeration definitions */"+NL+privateEnumDef+NL; + } + } + +////////////////////////////////////////////////////////////////////////////////////////// +// The following part contains the template +////////////////////////////////////////////////////////////////////////////////////////// + stringBuffer.append(TEXT_1); + stringBuffer.append( publicKeyword ); + stringBuffer.append( publicTypeDef ); + stringBuffer.append( publicEnumDef ); + stringBuffer.append( protectedKeyword ); + stringBuffer.append( protectedTypeDef ); + stringBuffer.append( protectedEnumDef ); + stringBuffer.append( privateKeyword ); + stringBuffer.append( privateTypeDef ); + stringBuffer.append( privateEnumDef ); + stringBuffer.append(TEXT_2); + return stringBuffer.toString(); + } +}
\ No newline at end of file diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppClassTypeAndEnumPackage.java b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppClassTypeAndEnumPackage.java new file mode 100644 index 00000000000..4818c9dd823 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppClassTypeAndEnumPackage.java @@ -0,0 +1,97 @@ +/******************************************************************************* + * Copyright (c) 2006 CEA List. + * All rights reserved. This program and the accompanying materials + * are property of the CEA, their use is subject to specific agreement + * with the CEA. + * + * Contributors: + * CEA List - initial API and implementation + *******************************************************************************/ + +package org.eclipse.papyrus.cpp.codegen.jet.util; + +import org.eclipse.uml2.uml.Class; +import org.eclipse.uml2.uml.*; +import org.eclipse.papyrus.cpp.codegen.utils.GenUtils; +import java.util.Iterator; +import Cpp.*; + +public class CppClassTypeAndEnumPackage +{ + protected static String nl; + public static synchronized CppClassTypeAndEnumPackage create(String lineSeparator) + { + nl = lineSeparator; + CppClassTypeAndEnumPackage result = new CppClassTypeAndEnumPackage(); + nl = null; + return result; + } + + public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; + protected final String TEXT_1 = ""; + protected final String TEXT_2 = NL; + protected final String TEXT_3 = NL; + + public String generate(Object argument) + { + final StringBuffer stringBuffer = new StringBuffer(); + +////////////////////////////////////////////////////////////////////////////////////////// +// Java preparation +////////////////////////////////////////////////////////////////////////////////////////// + + // Retrieve the class + Classifier currentClass = (Classifier) argument; + + + // Prepare owned type and enum declaration + String packageTypeDef = ""; + String packageEnumDef = ""; + + Iterator<Element> typeIt = currentClass.getOwnedElements().iterator(); + while (typeIt.hasNext()) { + Element currentElt = typeIt.next(); + if (!GenUtils.hasStereotype(currentElt, CppNoCodeGen.class)) { + if (currentElt instanceof PrimitiveType) { + + PrimitiveType currentType = (PrimitiveType) currentElt; + CppPrimitiveTypeDefinition jetPrimitiveType = new CppPrimitiveTypeDefinition(); + // Execute the util template + if (currentType.getVisibility() == VisibilityKind.PACKAGE_LITERAL) { + packageTypeDef = packageTypeDef+jetPrimitiveType.generate(currentType); + } + + + } else if (currentElt instanceof Enumeration) { + + Enumeration currentEnum = (Enumeration) currentElt; + CppEnumerationDefinition jetEnum = new CppEnumerationDefinition(); + // Execute the util template + if (currentEnum.getVisibility() == VisibilityKind.PACKAGE_LITERAL) { + packageEnumDef = packageEnumDef+jetEnum.generate(currentEnum); + } + + } + } + } + + // If not "" add a comment before declarations + if (!packageEnumDef.equals("")) { + packageEnumDef = "/* Package enumeration definitions */"+NL+packageEnumDef; + } + if (!packageTypeDef.equals("")) { + packageTypeDef = "/* Package type definitions */"+NL+packageTypeDef; + } + + +////////////////////////////////////////////////////////////////////////////////////////// +// The following part contains the template +////////////////////////////////////////////////////////////////////////////////////////// + stringBuffer.append(TEXT_1); + stringBuffer.append( packageTypeDef ); + stringBuffer.append(TEXT_2); + stringBuffer.append( packageEnumDef ); + stringBuffer.append(TEXT_3); + return stringBuffer.toString(); + } +}
\ No newline at end of file diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppEnumerationDefinition.java b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppEnumerationDefinition.java new file mode 100644 index 00000000000..b3589b1a5fe --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppEnumerationDefinition.java @@ -0,0 +1,113 @@ +/******************************************************************************* + * Copyright (c) 2006 CEA List. + * All rights reserved. This program and the accompanying materials + * are property of the CEA, their use is subject to specific agreement + * with the CEA. + * + * Contributors: + * CEA List - initial API and implementation + *******************************************************************************/ + +package org.eclipse.papyrus.cpp.codegen.jet.util; + +import org.eclipse.uml2.uml.Enumeration; +import org.eclipse.uml2.uml.EnumerationLiteral; +import org.eclipse.papyrus.cpp.codegen.jet.doc.*; +import java.util.Iterator; +import org.eclipse.papyrus.cpp.codegen.utils.GenUtils; +import Cpp.*; + +public class CppEnumerationDefinition +{ + protected static String nl; + public static synchronized CppEnumerationDefinition create(String lineSeparator) + { + nl = lineSeparator; + CppEnumerationDefinition result = new CppEnumerationDefinition(); + nl = null; + return result; + } + + public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; + protected final String TEXT_1 = ""; + protected final String TEXT_2 = NL + "enum "; + protected final String TEXT_3 = " {" + NL + "\t"; + protected final String TEXT_4 = NL + "};" + NL; + protected final String TEXT_5 = NL; + + public String generate(Object argument) + { + final StringBuffer stringBuffer = new StringBuffer(); + +////////////////////////////////////////////////////////////////////////////////////////// +// Java preparation +////////////////////////////////////////////////////////////////////////////////////////// + + // This is an util template to prepare Enumeration definition + ///////////////////////////////////////////////////////////// + + + // Retrieve the enumeration + Enumeration currentEnumeration = (Enumeration) argument; + + // Get the package name + String enumName = currentEnumeration.getName(); + + // Doc + String enumDoc = ""; + String enumLitDoc = ""; + + // Retrieve enum doc + CppElementDoc jDoc = new CppElementDoc(); + enumDoc = jDoc.generate(currentEnumeration); + + // Retrieve literals + String enumLiterals = ""; + + Iterator<EnumerationLiteral> literalsIt = currentEnumeration.getOwnedLiterals().iterator(); + + while (literalsIt.hasNext()) { + + // retrieve current + EnumerationLiteral currentLiteral = literalsIt.next(); + + enumLiterals = enumLiterals+currentLiteral.getName(); + + // if current literal is initialised + CppInit cppInit = GenUtils.getApplication(currentLiteral, CppInit.class); + if (cppInit != null) { + // Add the initialisation value + int initValue = cppInit.getValue(); + enumLiterals = enumLiterals + " = " + initValue; + } + + // Retrieve doc + if (!GenUtils.getComments(currentLiteral).equals("")) { + enumLitDoc = " //< "+GenUtils.getComments(currentLiteral); + } else { + enumLitDoc = ""; + } + + // if more literal left prepare new line for next literal + if (literalsIt.hasNext()) { + enumLiterals = enumLiterals+" ,"+enumLitDoc+NL+"\t"; + } else { + enumLiterals = enumLiterals+enumLitDoc; + } + } + + +////////////////////////////////////////////////////////////////////////////////////////// +// The following part contains the template +////////////////////////////////////////////////////////////////////////////////////////// + stringBuffer.append(TEXT_1); + stringBuffer.append( enumDoc ); + stringBuffer.append(TEXT_2); + stringBuffer.append( enumName ); + stringBuffer.append(TEXT_3); + stringBuffer.append( enumLiterals ); + stringBuffer.append(TEXT_4); + stringBuffer.append(TEXT_5); + return stringBuffer.toString(); + } +}
\ No newline at end of file diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppInterfaceAllIncludesDeclaration.java b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppInterfaceAllIncludesDeclaration.java new file mode 100644 index 00000000000..ced6f6754b1 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppInterfaceAllIncludesDeclaration.java @@ -0,0 +1,113 @@ +/******************************************************************************* + * Copyright (c) 2006 CEA List. + * All rights reserved. This program and the accompanying materials + * are property of the CEA, their use is subject to specific agreement + * with the CEA. + * + * Contributors: + * CEA List - initial API and implementation + *******************************************************************************/ + +package org.eclipse.papyrus.cpp.codegen.jet.util; + +import Cpp.*; +import org.eclipse.papyrus.cpp.codegen.utils.GenUtils; +import org.eclipse.uml2.uml.Interface; +import org.eclipse.emf.common.util.EList; +import org.eclipse.uml2.uml.Package; +import org.eclipse.emf.common.util.UniqueEList; +import java.util.*; +import org.eclipse.uml2.uml.PrimitiveType; +import org.eclipse.uml2.uml.Enumeration; +import org.eclipse.uml2.uml.Classifier; + +public class CppInterfaceAllIncludesDeclaration +{ + protected static String nl; + public static synchronized CppInterfaceAllIncludesDeclaration create(String lineSeparator) + { + nl = lineSeparator; + CppInterfaceAllIncludesDeclaration result = new CppInterfaceAllIncludesDeclaration(); + nl = null; + return result; + } + + public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; + protected final String TEXT_1 = ""; + protected final String TEXT_2 = NL; + + public String generate(Object argument) + { + final StringBuffer stringBuffer = new StringBuffer(); + +////////////////////////////////////////////////////////////////////////////////////////// +// Java preparation +////////////////////////////////////////////////////////////////////////////////////////// + + // Retrieve the interface + Interface currentInterface = (Interface) argument; + + // Prepare Dependency includes declarations ... + // Retrieve package used by current package (dependencies) + // use a unique list to avoid duplicates + EList<Classifier> usedClasses = new UniqueEList<Classifier> (); + + String newInclude = ""; + + // class attributes dependencies + usedClasses.addAll (GenUtils.getOwnedAttributeTypes(currentInterface)); + // operation parameters dependencies + usedClasses.addAll (GenUtils.getIncludesFromOperations(currentInterface)); + // dependencies and associations + usedClasses.addAll (GenUtils.getRelationships(currentInterface)); + + Iterator<Classifier> usedClassesIt = usedClasses.iterator(); + // Parsing all as NamedElement + String includes = ""; + + while (usedClassesIt.hasNext()) + { + Classifier cl = usedClassesIt.next (); + + // Only add include if this is not for the current class + if (!currentInterface.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)) { + + 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 interface) + CppOwnerPackageIncludeDeclaration jetIDecl + = new CppOwnerPackageIncludeDeclaration(); + if (cl.getOwner() instanceof Package) { + newInclude = jetIDecl.generate (cl.getOwner ()); + } + else { + newInclude = ""; + } + } + else { + // include the file associated with the classifier + CppClassIncludeDeclaration jetIDecl + = new CppClassIncludeDeclaration(); + newInclude = jetIDecl.generate (cl); + } + + includes = includes+newInclude; + } + } + } + +////////////////////////////////////////////////////////////////////////////////////////// +// The following part contains the template +////////////////////////////////////////////////////////////////////////////////////////// + stringBuffer.append(TEXT_1); + stringBuffer.append( includes ); + stringBuffer.append(TEXT_2); + return stringBuffer.toString(); + } +}
\ No newline at end of file diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppInterfaceIncludeDeclaration.java b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppInterfaceIncludeDeclaration.java new file mode 100644 index 00000000000..63b3a5ebe72 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppInterfaceIncludeDeclaration.java @@ -0,0 +1,71 @@ +/******************************************************************************* + * Copyright (c) 2006 CEA List. + * All rights reserved. This program and the accompanying materials + * are property of the CEA, their use is subject to specific agreement + * with the CEA. + * + * Contributors: + * CEA List - initial API and implementation + *******************************************************************************/ + +package org.eclipse.papyrus.cpp.codegen.jet.util; + +import org.eclipse.uml2.uml.NamedElement; +import org.eclipse.uml2.uml.Package; +import org.eclipse.papyrus.cpp.codegen.Activator; +import Cpp.*; +import org.eclipse.papyrus.cpp.codegen.utils.GenUtils; + +public class CppInterfaceIncludeDeclaration +{ + protected static String nl; + public static synchronized CppInterfaceIncludeDeclaration create(String lineSeparator) + { + nl = lineSeparator; + CppInterfaceIncludeDeclaration result = new CppInterfaceIncludeDeclaration(); + nl = null; + return result; + } + + public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; + protected final String TEXT_1 = "#include <"; + protected final String TEXT_2 = "."; + protected final String TEXT_3 = ">"; + protected final String TEXT_4 = NL; + + public String generate(Object argument) + { + final StringBuffer stringBuffer = new StringBuffer(); + +////////////////////////////////////////////////////////////////////////////////////////// +// Java preparation +////////////////////////////////////////////////////////////////////////////////////////// + + + // Retrieve header file suffix + String headerFileSuffix = Activator.getDefault().getPluginPreferences().getString("headSuffix"); + + // Retrieve the interface + NamedElement currentNE = (NamedElement) argument; + String iInterfacePath = ""; + Package nearestPkg = currentNE.getNearestPackage(); + String iInterfaceName = currentNE.getName(); + + if ( //!(nearestPkg.getUml2Package() instanceof org.eclipse.uml2.uml.Model) + /*&&*/ !(GenUtils.hasStereotype(nearestPkg, CppRoot.class))) { + iInterfacePath = GenUtils.getFullPath (nearestPkg) + "/"; + } + +////////////////////////////////////////////////////////////////////////////////////////// +// The following part contains the template +////////////////////////////////////////////////////////////////////////////////////////// + stringBuffer.append(TEXT_1); + stringBuffer.append( iInterfacePath ); + stringBuffer.append( iInterfaceName ); + stringBuffer.append(TEXT_2); + stringBuffer.append( headerFileSuffix ); + stringBuffer.append(TEXT_3); + stringBuffer.append(TEXT_4); + return stringBuffer.toString(); + } +}
\ No newline at end of file diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppInterfaceInheritedDeclarations.java b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppInterfaceInheritedDeclarations.java new file mode 100644 index 00000000000..309f94f1d57 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppInterfaceInheritedDeclarations.java @@ -0,0 +1,84 @@ +/******************************************************************************* + * Copyright (c) 2006 CEA List. + * All rights reserved. This program and the accompanying materials + * are property of the CEA, their use is subject to specific agreement + * with the CEA. + * + * Contributors: + * CEA List - initial API and implementation + *******************************************************************************/ + +package org.eclipse.papyrus.cpp.codegen.jet.util; + +import org.eclipse.uml2.uml.Classifier; +import org.eclipse.uml2.uml.Generalization; +import java.util.Iterator; +import Cpp.*; +import org.eclipse.papyrus.cpp.codegen.utils.GenUtils; + +public class CppInterfaceInheritedDeclarations +{ + protected static String nl; + public static synchronized CppInterfaceInheritedDeclarations create(String lineSeparator) + { + nl = lineSeparator; + CppInterfaceInheritedDeclarations result = new CppInterfaceInheritedDeclarations(); + nl = null; + return result; + } + + public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; + protected final String TEXT_1 = ""; + + public String generate(Object argument) + { + final StringBuffer stringBuffer = new StringBuffer(); + +////////////////////////////////////////////////////////////////////////////////////////// +// Java preparation +////////////////////////////////////////////////////////////////////////////////////////// + + // Retrieve the interface + Classifier currentClass = (Classifier) argument; + String decl = ""; + String visibility = ""; + + // Get generalization and implementation relationships + Iterator<Generalization> genIt = currentClass.getGeneralizations().iterator(); + + // Parse generalizations + while (genIt.hasNext()) { + + Generalization currentGen = genIt.next(); + + visibility = GenUtils.getVisibility(currentGen); + + // If not <NoCodeGen> + Classifier tmpClassifier = currentGen.getGeneral(); + if (!GenUtils.hasStereotype(tmpClassifier, CppNoCodeGen.class)) { + + String targetName = tmpClassifier.getName(); + + if (!decl.equals("")) { + decl = decl + ", "; + } + decl = decl+visibility+" "+targetName; + } + } + + // ":" only if decl not empty + String prefix = ""; + if (!decl.equals("")) { + prefix = ": "; + visibility = "public "; + } + +////////////////////////////////////////////////////////////////////////////////////////// +// The following part contains the template +////////////////////////////////////////////////////////////////////////////////////////// + stringBuffer.append(TEXT_1); + stringBuffer.append( prefix ); + stringBuffer.append( decl ); + return stringBuffer.toString(); + } +}
\ No newline at end of file diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppInterfacePublicOperationsDeclaration.java b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppInterfacePublicOperationsDeclaration.java new file mode 100644 index 00000000000..84debe54ae5 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppInterfacePublicOperationsDeclaration.java @@ -0,0 +1,69 @@ +/******************************************************************************* + * Copyright (c) 2006 CEA List. + * All rights reserved. This program and the accompanying materials + * are property of the CEA, their use is subject to specific agreement + * with the CEA. + * + * Contributors: + * CEA List - initial API and implementation + *******************************************************************************/ + +package org.eclipse.papyrus.cpp.codegen.jet.util; + +import org.eclipse.uml2.uml.Interface; +import org.eclipse.uml2.uml.Operation; +import org.eclipse.uml2.uml.VisibilityKind; +import java.util.*; +import Cpp.*; +import org.eclipse.papyrus.cpp.codegen.utils.GenUtils; + +public class CppInterfacePublicOperationsDeclaration +{ + protected static String nl; + public static synchronized CppInterfacePublicOperationsDeclaration create(String lineSeparator) + { + nl = lineSeparator; + CppInterfacePublicOperationsDeclaration result = new CppInterfacePublicOperationsDeclaration(); + nl = null; + return result; + } + + public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; + protected final String TEXT_1 = ""; + + public String generate(Object argument) + { + final StringBuffer stringBuffer = new StringBuffer(); + +////////////////////////////////////////////////////////////////////////////////////////// +// Java preparation +////////////////////////////////////////////////////////////////////////////////////////// + + // Retrieve the class + Interface currentInterface = (Interface) argument; + String opDecl = ""; + + // Retrieve operations + Iterator<Operation> operations = currentInterface.getOwnedOperations().iterator(); + while (operations.hasNext()) { + Operation currentOperation = operations.next(); + if ((currentOperation.getVisibility() == VisibilityKind.PUBLIC_LITERAL) && + !GenUtils.hasStereotype (currentOperation, CppNoCodeGen.class)) { + CppOperationDeclaration jetOpDecl = new CppOperationDeclaration(); + String cOpDecl = jetOpDecl.generate(currentOperation); + + // if main cOpDecl = ""; + if (!cOpDecl.equals("")) { + opDecl = opDecl+"\t"+cOpDecl+";"; + } + } + } + +////////////////////////////////////////////////////////////////////////////////////////// +// The following part contains the template +////////////////////////////////////////////////////////////////////////////////////////// + stringBuffer.append(TEXT_1); + stringBuffer.append( opDecl ); + return stringBuffer.toString(); + } +}
\ No newline at end of file diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppOperationDeclaration.java b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppOperationDeclaration.java new file mode 100644 index 00000000000..28ff6878080 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppOperationDeclaration.java @@ -0,0 +1,142 @@ +/******************************************************************************* + * Copyright (c) 2006 CEA List. + * All rights reserved. This program and the accompanying materials + * are property of the CEA, their use is subject to specific agreement + * with the CEA. + * + * Contributors: + * CEA List - initial API and implementation + *******************************************************************************/ + +package org.eclipse.papyrus.cpp.codegen.jet.util; + +import org.eclipse.uml2.uml.*; +import org.eclipse.papyrus.cpp.codegen.jet.doc.*; +import Cpp.*; +import org.eclipse.papyrus.cpp.codegen.StdStereo; +import org.eclipse.papyrus.cpp.codegen.utils.GenUtils; + +public class CppOperationDeclaration +{ + protected static String nl; + public static synchronized CppOperationDeclaration create(String lineSeparator) + { + nl = lineSeparator; + CppOperationDeclaration result = new CppOperationDeclaration(); + nl = null; + return result; + } + + public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; + protected final String TEXT_1 = ""; + protected final String TEXT_2 = NL; + protected final String TEXT_3 = NL + "\t"; + protected final String TEXT_4 = "("; + protected final String TEXT_5 = ")"; + + public String generate(Object argument) + { + final StringBuffer stringBuffer = new StringBuffer(); + +////////////////////////////////////////////////////////////////////////////////////////// +// Java preparation +////////////////////////////////////////////////////////////////////////////////////////// + + // Retrieve the Operation + Operation currentOperation = (Operation) argument; + + String operationName = currentOperation.getName(); + + String opParameters = ""; + + String returnTypeName = "void"; + String pVirtualSuffix = ""; + String prefix = ""; + String constOp = ""; + + + String opDoc = ""; + + // Doc for the template + CppOperationDoc jDoc = new CppOperationDoc(); + opDoc = GenUtils.indent (jDoc.generate(currentOperation), "\t"); + + // Prepare return type + CppOperationReturnType jetRT = new CppOperationReturnType(); + returnTypeName = jetRT.generate(currentOperation); + if (!returnTypeName.equals ("")) { + returnTypeName += " "; + } + + boolean isInterface = currentOperation.getOwner () instanceof Interface; + + // Static attribute + if (currentOperation.isStatic()) { + prefix = prefix+"static"+" "; + } + + // Inline attribute + if (GenUtils.hasStereotype(currentOperation, CppInline.class)) { + prefix = prefix+"inline"+" "; + } + + // Creator / Destructor: use function within StdStereo + if (StdStereo.isApplied(currentOperation, StdStereo.create)) { + returnTypeName = ""; + } + if (StdStereo.isApplied(currentOperation, StdStereo.destroy)) { + returnTypeName = ""; + operationName = "~"+operationName; + } + + // Const attribute on operation + if (GenUtils.hasStereotype(currentOperation, CppConst.class)) { + constOp = " const"; + } + + // Virtual attribute on operation + if (GenUtils.hasStereotype(currentOperation, CppVirtual.class)) { + prefix = "virtual "+prefix; + } + + // Pure Virtual attribute on operation + if (isInterface || currentOperation.isAbstract ()) { + prefix = "virtual "+prefix; + pVirtualSuffix = " = 0"; + } + + // Friend attribute on operation + if (GenUtils.hasStereotype(currentOperation, CppFriend.class)) { + prefix = "friend "+prefix; + } + + // Prepare parameters + CppOperationParameters jetParams = new CppOperationParameters(); + opParameters = jetParams.generate(currentOperation); + +////////////////////////////////////////////////////////////////////////////////////////// +// The following part contains the template only if current operation is not main +// else nothing is return... +////////////////////////////////////////////////////////////////////////////////////////// + +if (!operationName.equals("main")) { + +////////////////////////////////////////////////////////////////////////////////////////// + stringBuffer.append(TEXT_1); + stringBuffer.append(TEXT_2); + stringBuffer.append( opDoc ); + stringBuffer.append(TEXT_3); + stringBuffer.append( prefix ); + stringBuffer.append( returnTypeName ); + stringBuffer.append( operationName ); + stringBuffer.append(TEXT_4); + stringBuffer.append( opParameters ); + stringBuffer.append(TEXT_5); + stringBuffer.append( constOp ); + stringBuffer.append( pVirtualSuffix ); + ////////////////////////////////////////////////////////////////////////////////////////// +} // else nothing done +////////////////////////////////////////////////////////////////////////////////////////// + return stringBuffer.toString(); + } +}
\ No newline at end of file diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppOperationImplementation.java b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppOperationImplementation.java new file mode 100644 index 00000000000..af6da84736b --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppOperationImplementation.java @@ -0,0 +1,171 @@ +/******************************************************************************* + * Copyright (c) 2006 CEA List. + * All rights reserved. This program and the accompanying materials + * are property of the CEA, their use is subject to specific agreement + * with the CEA. + * + * Contributors: + * CEA List - initial API and implementation + *******************************************************************************/ + +package org.eclipse.papyrus.cpp.codegen.jet.util; + +import org.eclipse.uml2.uml.*; +import org.eclipse.papyrus.cpp.codegen.jet.doc.*; +import Cpp.*; +import org.eclipse.papyrus.cpp.codegen.StdStereo; +import org.eclipse.papyrus.cpp.codegen.utils.GenUtils; + +public class CppOperationImplementation +{ + protected static String nl; + public static synchronized CppOperationImplementation create(String lineSeparator) + { + nl = lineSeparator; + CppOperationImplementation result = new CppOperationImplementation(); + nl = null; + return result; + } + + public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; + protected final String TEXT_1 = ""; + protected final String TEXT_2 = NL; + protected final String TEXT_3 = NL; + protected final String TEXT_4 = " "; + protected final String TEXT_5 = " ("; + protected final String TEXT_6 = ") {"; + protected final String TEXT_7 = NL; + protected final String TEXT_8 = NL + "}" + NL; + protected final String TEXT_9 = "\t" + NL; + protected final String TEXT_10 = NL; + protected final String TEXT_11 = NL; + protected final String TEXT_12 = " "; + protected final String TEXT_13 = "::"; + protected final String TEXT_14 = "("; + protected final String TEXT_15 = ")"; + protected final String TEXT_16 = " {"; + protected final String TEXT_17 = NL; + protected final String TEXT_18 = NL + "}" + NL; + protected final String TEXT_19 = "\t"; + + public String generate(Object argument) + { + final StringBuffer stringBuffer = new StringBuffer(); + +////////////////////////////////////////////////////////////////////////////////////////// +// Java preparation +////////////////////////////////////////////////////////////////////////////////////////// + + // Retrieve the Operation + Operation currentOperation = (Operation) argument; + + String body = ""; + String className = ""; + String operationName = currentOperation.getName(); + String opParameters = ""; + String returnTypeName = "void"; + String isInline = ""; + String isConst = ""; + String constInit = ""; + + String opDoc = ""; + + // Doc for the template + CppOperationDoc jDoc = new CppOperationDoc(); + opDoc = jDoc.generate(currentOperation); + + // Retrieve class name. Operation may belong to a class or datatype, thus use + // generic getOwner function + Element opOwner = currentOperation.getOwner(); + className = (opOwner instanceof NamedElement) ? ((NamedElement) opOwner).getName() : ""; + + // Retrieve body content + body = GenUtils.getBody (currentOperation, "C/C++"); + + // Prepare return type + CppOperationReturnType jetRT = new CppOperationReturnType(); + returnTypeName = jetRT.generate(currentOperation); + + // Creator / Destructor: use function within StdStereo + if (StdStereo.isApplied(currentOperation, StdStereo.create)) { + returnTypeName = ""; + } + if (StdStereo.isApplied(currentOperation, StdStereo.destroy)) { + returnTypeName = ""; + operationName = "~"+operationName; + } + + // If is inline operation + if (GenUtils.hasStereotype(currentOperation, CppInline.class)) { + isInline = "inline "; + } + + // Const op + if (GenUtils.hasStereotype(currentOperation, CppConst.class)) { + isConst = " const"; + } + + // Constructor init list + CppConstInit cppConstInit = GenUtils.getApplication(currentOperation, CppConstInit.class); + if ((cppConstInit != null) + && StdStereo.isApplied(currentOperation, StdStereo.create)) { + constInit = " : " + cppConstInit.getInitialisation(); + } + + // Prepare parameters + CppOperationParametersWithoutDefaultValue jetParams = new CppOperationParametersWithoutDefaultValue(); + opParameters = jetParams.generate(currentOperation); + +////////////////////////////////////////////////////////////////////////////////////////// +// The following part contains the template two cases main operation or classical +////////////////////////////////////////////////////////////////////////////////////////// + +// main + if (operationName.equals("main")) { + +////////////////////////////////////////////////////////////////////////////////////////// + stringBuffer.append(TEXT_1); + stringBuffer.append(TEXT_2); + stringBuffer.append( opDoc ); + stringBuffer.append(TEXT_3); + stringBuffer.append( returnTypeName ); + stringBuffer.append(TEXT_4); + stringBuffer.append( operationName ); + stringBuffer.append(TEXT_5); + stringBuffer.append( opParameters ); + stringBuffer.append(TEXT_6); + stringBuffer.append(TEXT_7); + stringBuffer.append( body ); + stringBuffer.append(TEXT_8); + ////////////////////////////////////////////////////////////////////////////////////////// + + } + else { + +////////////////////////////////////////////////////////////////////////////////////////// + stringBuffer.append(TEXT_9); + stringBuffer.append(TEXT_10); + stringBuffer.append( opDoc ); + stringBuffer.append(TEXT_11); + stringBuffer.append( isInline ); + stringBuffer.append( returnTypeName ); + stringBuffer.append(TEXT_12); + stringBuffer.append( className ); + stringBuffer.append(TEXT_13); + stringBuffer.append( operationName ); + stringBuffer.append(TEXT_14); + stringBuffer.append( opParameters ); + stringBuffer.append(TEXT_15); + stringBuffer.append( isConst ); + stringBuffer.append( constInit ); + stringBuffer.append(TEXT_16); + stringBuffer.append(TEXT_17); + stringBuffer.append( body ); + stringBuffer.append(TEXT_18); + ////////////////////////////////////////////////////////////////////////////////////////// + } +////////////////////////////////////////////////////////////////////////////////////////// + stringBuffer.append(TEXT_19); + return stringBuffer.toString(); + } +}
\ No newline at end of file diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppOperationParameters.java b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppOperationParameters.java new file mode 100644 index 00000000000..fc67d3ec185 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppOperationParameters.java @@ -0,0 +1,64 @@ +/******************************************************************************* + * Copyright (c) 2006 CEA List. + * All rights reserved. This program and the accompanying materials + * are property of the CEA, their use is subject to specific agreement + * with the CEA. + * + * Contributors: + * CEA List - initial API and implementation + *******************************************************************************/ + +package org.eclipse.papyrus.cpp.codegen.jet.util; + +import org.eclipse.uml2.uml.*; +import java.util.*; + +public class CppOperationParameters +{ + protected static String nl; + public static synchronized CppOperationParameters create(String lineSeparator) + { + nl = lineSeparator; + CppOperationParameters result = new CppOperationParameters(); + nl = null; + return result; + } + + public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; + public String generate(Object argument) + { + final StringBuffer stringBuffer = new StringBuffer(); + +////////////////////////////////////////////////////////////////////////////////////////// +// Java preparation +////////////////////////////////////////////////////////////////////////////////////////// + + // Retrieve the Operation + Operation currentOperation = (Operation) argument; + Parameter currentParameter; + + String paramDecl = ""; + + Iterator<Parameter> parameters = currentOperation.getOwnedParameters().iterator(); + while(parameters.hasNext()) { + currentParameter = parameters.next(); + if (currentParameter.getDirection () != ParameterDirectionKind.RETURN_LITERAL) { + // Prepare parameters + CppParameter jetParam = new CppParameter(); + if (!paramDecl.equals("")) { + paramDecl += ", "; + } + paramDecl = paramDecl+jetParam.generate(currentParameter); + } + } + + paramDecl.replaceAll(NL, ""); + +////////////////////////////////////////////////////////////////////////////////////////// +// The following part contains the template +////////////////////////////////////////////////////////////////////////////////////////// + + stringBuffer.append( paramDecl ); + return stringBuffer.toString(); + } +}
\ No newline at end of file diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppOperationParametersWithoutDefaultValue.java b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppOperationParametersWithoutDefaultValue.java new file mode 100644 index 00000000000..d3e0dc8d710 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppOperationParametersWithoutDefaultValue.java @@ -0,0 +1,62 @@ +/******************************************************************************* + * Copyright (c) 2006 CEA List. + * All rights reserved. This program and the accompanying materials + * are property of the CEA, their use is subject to specific agreement + * with the CEA. + * + * Contributors: + * CEA List - initial API and implementation + *******************************************************************************/ + +package org.eclipse.papyrus.cpp.codegen.jet.util; + +import org.eclipse.uml2.uml.*; +import java.util.*; + +public class CppOperationParametersWithoutDefaultValue +{ + protected static String nl; + public static synchronized CppOperationParametersWithoutDefaultValue create(String lineSeparator) + { + nl = lineSeparator; + CppOperationParametersWithoutDefaultValue result = new CppOperationParametersWithoutDefaultValue(); + nl = null; + return result; + } + + public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; + public String generate(Object argument) + { + final StringBuffer stringBuffer = new StringBuffer(); + +////////////////////////////////////////////////////////////////////////////////////////// +// Java preparation +////////////////////////////////////////////////////////////////////////////////////////// + + // Retrieve the Operation + Operation currentOperation = (Operation) argument; + Parameter currentParameter; + + String paramDecl = ""; + + Iterator<Parameter> parameters = currentOperation.getOwnedParameters().iterator(); + while(parameters.hasNext()) { + currentParameter = parameters.next(); + if (currentParameter.getDirection () != ParameterDirectionKind.RETURN_LITERAL) { + // Prepare parameters + CppParameterWithoutDefaultValue jetParam = new CppParameterWithoutDefaultValue(); + if (!paramDecl.equals("")) { + paramDecl += ", "; + } + paramDecl = paramDecl+jetParam.generate(currentParameter); + } + } + +////////////////////////////////////////////////////////////////////////////////////////// +// The following part contains the template +////////////////////////////////////////////////////////////////////////////////////////// + + stringBuffer.append( paramDecl ); + return stringBuffer.toString(); + } +}
\ No newline at end of file diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppOperationReturnType.java b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppOperationReturnType.java new file mode 100644 index 00000000000..5a75d7009e8 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppOperationReturnType.java @@ -0,0 +1,118 @@ +/******************************************************************************* + * Copyright (c) 2006 CEA List. + * All rights reserved. This program and the accompanying materials + * are property of the CEA, their use is subject to specific agreement + * with the CEA. + * + * Contributors: + * CEA List - initial API and implementation + *******************************************************************************/ + +package org.eclipse.papyrus.cpp.codegen.jet.util; + +import org.eclipse.uml2.uml.*; +import org.eclipse.uml2.uml.Class; +import Cpp.*; +import org.eclipse.papyrus.cpp.codegen.utils.*; + +public class CppOperationReturnType +{ + protected static String nl; + public static synchronized CppOperationReturnType create(String lineSeparator) + { + nl = lineSeparator; + CppOperationReturnType result = new CppOperationReturnType(); + nl = null; + return result; + } + + public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; + protected final String TEXT_1 = "::"; + + public String generate(Object argument) + { + final StringBuffer stringBuffer = new StringBuffer(); + +////////////////////////////////////////////////////////////////////////////////////////// +// Java preparation +////////////////////////////////////////////////////////////////////////////////////////// + + // Retrieve the Operation + Operation currentOperation = (Operation) argument; + + String returnTypeName = "void"; + String ownerName = ""; + Modifier modifier = new Modifier(); + + // Return type + if (currentOperation.getType() == null) { + returnTypeName = "void"; + } else { + if (currentOperation.getType() == null) { + returnTypeName = "undefined"; + } else { + // Treat the type if it is not "package visibility" and owned by a class + Type currentType = currentOperation.getType(); + returnTypeName = GenUtils.qualifiedName (currentType); + + if (currentType.getVisibility() != VisibilityKind.PACKAGE_LITERAL) { + if (currentType.getOwner() instanceof Class) { + ownerName = ((Class) currentType.getOwner()).getName(); + } + } + } + + // Treat pointer or ref on return parameter (only one return parameter should exists) + // retrieve return parameter +// RS: changed test: now getReturnResult returns only one param +// if (currentOperation.getUml2Operation().getReturnResults().size() == 1) { +// org.eclipse.uml2.uml.Parameter uml2Param +// = (org.eclipse.uml2.uml.Parameter) currentOperation.getUml2Operation().getReturnResults().get(0); +// Parameter currentRParameter +// = new Parameter(uml2Param); +// // case Pointer +// if (currentRParameter.hasStereotype(xy, CppPtr.class)) { +// isPointer = " "+currentRParameter.getTaggedValue(CppPtr.class, "declaration"); +// } +// if (currentRParameter.hasStereotype(xy, CppRef.class)) { +// isRef = " "+currentRParameter.getTaggedValue(CppRef.class, "declaration"); +// } +// if (currentRParameter.hasStereotype(xy, CppConst.class_)) { +// isConst = "const "; +// } +// } + if (currentOperation.getReturnResult() instanceof Parameter) { + Parameter uml2Param = (Parameter) currentOperation.getReturnResult(); + modifier = new Modifier(uml2Param); + } + } + + +////////////////////////////////////////////////////////////////////////////////////////// +// The following part contains the template two cases : scope required or not +////////////////////////////////////////////////////////////////////////////////////////// + +// No scope details + if (ownerName.equals("")) { +////////////////////////////////////////////////////////////////////////////////////////// + + stringBuffer.append( modifier.isConst ); + stringBuffer.append( returnTypeName ); + stringBuffer.append( modifier.ptr ); + stringBuffer.append( modifier.ref ); + ////////////////////////////////////////////////////////////////////////////////////////// +} else { +////////////////////////////////////////////////////////////////////////////////////////// + + stringBuffer.append( modifier.isConst ); + stringBuffer.append( ownerName ); + stringBuffer.append(TEXT_1); + stringBuffer.append( returnTypeName ); + stringBuffer.append( modifier.ptr ); + stringBuffer.append( modifier.ref ); + ////////////////////////////////////////////////////////////////////////////////////////// +} +////////////////////////////////////////////////////////////////////////////////////////// + return stringBuffer.toString(); + } +}
\ No newline at end of file diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppOperationTemplateImplementation.java b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppOperationTemplateImplementation.java new file mode 100644 index 00000000000..18487bed8a5 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppOperationTemplateImplementation.java @@ -0,0 +1,158 @@ +/******************************************************************************* + * Copyright (c) 2006 CEA List. + * All rights reserved. This program and the accompanying materials + * are property of the CEA, their use is subject to specific agreement + * with the CEA. + * + * Contributors: + * CEA List - initial API and implementation + *******************************************************************************/ + +package org.eclipse.papyrus.cpp.codegen.jet.util; + +import org.eclipse.uml2.uml.*; +import org.eclipse.uml2.uml.Class; +import Cpp.*; +import org.eclipse.papyrus.cpp.codegen.StdStereo; +import org.eclipse.papyrus.cpp.codegen.utils.GenUtils; + +public class CppOperationTemplateImplementation +{ + protected static String nl; + public static synchronized CppOperationTemplateImplementation create(String lineSeparator) + { + nl = lineSeparator; + CppOperationTemplateImplementation result = new CppOperationTemplateImplementation(); + nl = null; + return result; + } + + public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; + protected final String TEXT_1 = "("; + protected final String TEXT_2 = ")"; + protected final String TEXT_3 = " {"; + protected final String TEXT_4 = NL; + protected final String TEXT_5 = NL + "}"; + protected final String TEXT_6 = "<"; + protected final String TEXT_7 = ">::"; + protected final String TEXT_8 = "("; + protected final String TEXT_9 = ")"; + protected final String TEXT_10 = " {"; + protected final String TEXT_11 = NL; + protected final String TEXT_12 = NL + "}"; + + public String generate(Object argument) + { + final StringBuffer stringBuffer = new StringBuffer(); + +////////////////////////////////////////////////////////////////////////////////////////// +// Java preparation +////////////////////////////////////////////////////////////////////////////////////////// + + // Retrieve the Operation + Operation currentOperation = (Operation) argument; + + String operationName = currentOperation.getName(); + String opParameters = ""; + String returnTypeName = "void"; + String isConst = ""; + String isInline = ""; + + // Retrieve class & class name + Class currentClass = currentOperation.getClass_ (); + String className = currentClass.getName(); + + // Retrieve body content + String body = GenUtils.getBody (currentOperation, "C/C++"); + + // Prepare return type + CppOperationReturnType jetRT = new CppOperationReturnType(); + returnTypeName = jetRT.generate(currentOperation); + if (! "".equals(returnTypeName)) { + returnTypeName = returnTypeName + " "; + } + + // Creator / Destructor: use function within StdStereo + if (StdStereo.isApplied(currentOperation, StdStereo.create)) { + returnTypeName = ""; + } + if (StdStereo.isApplied(currentOperation, StdStereo.destroy)) { + returnTypeName = ""; + operationName = "~"+operationName; + } + + // If inline operation + if (GenUtils.hasStereotype(currentOperation, CppInline.class)) { + isInline = "inline "; + } + + // Const op + if (GenUtils.hasStereotype(currentOperation, CppConst.class)) { + isConst = " const"; + } + + // Prepare parameters + CppOperationParametersWithoutDefaultValue jetParams + = new CppOperationParametersWithoutDefaultValue(); + opParameters = jetParams.generate(currentOperation); + + + // Prepare template parameter declaration without type + String tparamWoType = ""; + + if (currentClass != null) { + tparamWoType = GenUtils.getTemplateParametersWoType(currentClass); + } + +////////////////////////////////////////////////////////////////////////////////////////// +// The following part contains the template +////////////////////////////////////////////////////////////////////////////////////////// +// Package visibility + if (currentOperation.getVisibility() == VisibilityKind.PACKAGE_LITERAL) { + +////////////////////////////////////////////////////////////////////////////////////////// + + + stringBuffer.append( isInline ); + stringBuffer.append( returnTypeName ); + stringBuffer.append( operationName ); + stringBuffer.append(TEXT_1); + stringBuffer.append( opParameters ); + stringBuffer.append(TEXT_2); + stringBuffer.append( isConst ); + stringBuffer.append(TEXT_3); + stringBuffer.append(TEXT_4); + stringBuffer.append( body ); + stringBuffer.append(TEXT_5); + + +////////////////////////////////////////////////////////////////////////////////////////// + + } else { // Default case + +////////////////////////////////////////////////////////////////////////////////////////// + + + stringBuffer.append( isInline ); + stringBuffer.append( returnTypeName ); + stringBuffer.append( className ); + stringBuffer.append(TEXT_6); + stringBuffer.append( tparamWoType ); + stringBuffer.append(TEXT_7); + stringBuffer.append( operationName ); + stringBuffer.append(TEXT_8); + stringBuffer.append( opParameters ); + stringBuffer.append(TEXT_9); + stringBuffer.append( isConst ); + stringBuffer.append(TEXT_10); + stringBuffer.append(TEXT_11); + stringBuffer.append( body ); + stringBuffer.append(TEXT_12); + + +////////////////////////////////////////////////////////////////////////////////////////// + } +////////////////////////////////////////////////////////////////////////////////////////// + return stringBuffer.toString(); + } +}
\ No newline at end of file diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppOwnerPackageIncludeDeclaration.java b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppOwnerPackageIncludeDeclaration.java new file mode 100644 index 00000000000..777e4798740 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppOwnerPackageIncludeDeclaration.java @@ -0,0 +1,82 @@ +/******************************************************************************* + * Copyright (c) 2006 CEA List. + * All rights reserved. This program and the accompanying materials + * are property of the CEA, their use is subject to specific agreement + * with the CEA. + * + * Contributors: + * CEA List - initial API and implementation + *******************************************************************************/ + +package org.eclipse.papyrus.cpp.codegen.jet.util; + +import org.eclipse.uml2.uml.Package; +import org.eclipse.papyrus.cpp.codegen.Activator; +import Cpp.*; +import org.eclipse.papyrus.cpp.codegen.utils.GenUtils; + +public class CppOwnerPackageIncludeDeclaration +{ + protected static String nl; + public static synchronized CppOwnerPackageIncludeDeclaration create(String lineSeparator) + { + nl = lineSeparator; + CppOwnerPackageIncludeDeclaration result = new CppOwnerPackageIncludeDeclaration(); + nl = null; + return result; + } + + public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; + protected final String TEXT_1 = " \t" + NL + "/* Owner package header include */" + NL + "#include <"; + protected final String TEXT_2 = "/Pkg_"; + protected final String TEXT_3 = "."; + protected final String TEXT_4 = ">"; + protected final String TEXT_5 = NL; + + public String generate(Object argument) + { + final StringBuffer stringBuffer = new StringBuffer(); + +////////////////////////////////////////////////////////////////////////////////////////// +// Java preparation +////////////////////////////////////////////////////////////////////////////////////////// + + // Retrieve the type passed as argument + Package currentPkg = (Package) argument; + String currentPkgName = currentPkg.getName(); + String currentPkgPath = GenUtils.getFullPath (currentPkg); + + // Retrieve header file suffix + String headerFileSuffix = Activator.getDefault().getPluginPreferences().getString("headSuffix"); + + // Prepare Father include declaration + boolean isRoot = false; + + // The currentElt has the CppRoot stereotype + if (GenUtils.hasStereotype(currentPkg, CppRoot.class)) { + isRoot = true; + } + // The currentPkg is the model root package + //if (currentPkg instanceof org.eclipse.uml2.uml.Model){ + // isRoot = true; + //} + + +////////////////////////////////////////////////////////////////////////////////////////// +// The following part contains the template +////////////////////////////////////////////////////////////////////////////////////////// + // if currentPkg is not root it is referenced here + if (!isRoot) { + stringBuffer.append(TEXT_1); + stringBuffer.append( currentPkgPath ); + stringBuffer.append(TEXT_2); + stringBuffer.append( currentPkgName ); + stringBuffer.append(TEXT_3); + stringBuffer.append( headerFileSuffix ); + stringBuffer.append(TEXT_4); + // endif + } + stringBuffer.append(TEXT_5); + return stringBuffer.toString(); + } +}
\ No newline at end of file diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppParameter.java b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppParameter.java new file mode 100644 index 00000000000..87ac2c0bfac --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppParameter.java @@ -0,0 +1,76 @@ +/******************************************************************************* + * Copyright (c) 2006 CEA List. + * All rights reserved. This program and the accompanying materials + * are property of the CEA, their use is subject to specific agreement + * with the CEA. + * + * Contributors: + * CEA List - initial API and implementation + *******************************************************************************/ + +package org.eclipse.papyrus.cpp.codegen.jet.util; + +import org.eclipse.uml2.uml.Parameter; +import Cpp.*; +import org.eclipse.papyrus.cpp.codegen.utils.Modifier; +import org.eclipse.papyrus.cpp.codegen.utils.GenUtils; + +public class CppParameter +{ + protected static String nl; + public static synchronized CppParameter create(String lineSeparator) + { + nl = lineSeparator; + CppParameter result = new CppParameter(); + nl = null; + return result; + } + + public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; + protected final String TEXT_1 = " "; + + public String generate(Object argument) + { + final StringBuffer stringBuffer = new StringBuffer(); + +////////////////////////////////////////////////////////////////////////////////////////// +// Java preparation +////////////////////////////////////////////////////////////////////////////////////////// + + // Retrieve the Parameter + Parameter currentParameter = (Parameter) argument; + + String parameterName = currentParameter.getName(); + + String typeName = ""; + String suffix = ""; + Modifier modifier = new Modifier(currentParameter); + + if (currentParameter.getType() == null) { + typeName = "undefined"; + } else { + typeName = GenUtils.qualifiedName (currentParameter.getType()); + } + + // Initial value + CppDefault cppDefault = GenUtils.getApplication(currentParameter, CppDefault.class); + if (cppDefault != null) { + suffix = " = " + cppDefault.getValue(); + } + + +////////////////////////////////////////////////////////////////////////////////////////// +// The following part contains the template +////////////////////////////////////////////////////////////////////////////////////////// + + stringBuffer.append( modifier.isConst ); + stringBuffer.append( typeName ); + stringBuffer.append( modifier.ptr ); + stringBuffer.append( modifier.ref ); + stringBuffer.append(TEXT_1); + stringBuffer.append( parameterName ); + stringBuffer.append( modifier.array ); + stringBuffer.append( suffix ); + return stringBuffer.toString(); + } +}
\ No newline at end of file diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppParameterWithoutDefaultValue.java b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppParameterWithoutDefaultValue.java new file mode 100644 index 00000000000..1bb92004f6d --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppParameterWithoutDefaultValue.java @@ -0,0 +1,111 @@ +/******************************************************************************* + * Copyright (c) 2006 CEA List. + * All rights reserved. This program and the accompanying materials + * are property of the CEA, their use is subject to specific agreement + * with the CEA. + * + * Contributors: + * CEA List - initial API and implementation + *******************************************************************************/ + +package org.eclipse.papyrus.cpp.codegen.jet.util; + +import org.eclipse.uml2.uml.Parameter; +import org.eclipse.uml2.uml.Classifier; +import Cpp.*; +import org.eclipse.papyrus.cpp.codegen.utils.Modifier; +import org.eclipse.papyrus.cpp.codegen.utils.GenUtils; + +public class CppParameterWithoutDefaultValue +{ + protected static String nl; + public static synchronized CppParameterWithoutDefaultValue create(String lineSeparator) + { + nl = lineSeparator; + CppParameterWithoutDefaultValue result = new CppParameterWithoutDefaultValue(); + nl = null; + return result; + } + + public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; + protected final String TEXT_1 = "<"; + protected final String TEXT_2 = ">"; + protected final String TEXT_3 = " "; + protected final String TEXT_4 = " "; + + public String generate(Object argument) + { + final StringBuffer stringBuffer = new StringBuffer(); + +////////////////////////////////////////////////////////////////////////////////////////// +// Java preparation +////////////////////////////////////////////////////////////////////////////////////////// + + // Retrieve the Parameter + Parameter currentParameter = (Parameter) argument; + + String parameterName = currentParameter.getName(); + + String typeName = ""; + Modifier modifier = new Modifier(currentParameter); + + // Prepare template parameter declaration without type + String tparamWoType = ""; + + if (currentParameter.getType() == null) { + typeName = "undefined"; + } + else if (currentParameter.getType() instanceof Classifier) { + Classifier classifier = (Classifier) currentParameter.getType(); + tparamWoType = GenUtils.getTemplateParametersWoType(classifier); + + typeName = GenUtils.qualifiedName (currentParameter.getType()); + } + else { + typeName = GenUtils.qualifiedName (currentParameter.getType()); + } + +////////////////////////////////////////////////////////////////////////////////////////// +// The following part contains the template +////////////////////////////////////////////////////////////////////////////////////////// +// Package visibility + if (!"".equals(tparamWoType)) { + +////////////////////////////////////////////////////////////////////////////////////////// + + + stringBuffer.append( modifier.isConst ); + stringBuffer.append( typeName ); + stringBuffer.append(TEXT_1); + stringBuffer.append( tparamWoType ); + stringBuffer.append(TEXT_2); + stringBuffer.append( modifier.ptr ); + stringBuffer.append( modifier.ref ); + stringBuffer.append(TEXT_3); + stringBuffer.append( parameterName ); + stringBuffer.append( modifier.array ); + + +////////////////////////////////////////////////////////////////////////////////////////// + + } else { // Default case + +////////////////////////////////////////////////////////////////////////////////////////// + + + stringBuffer.append( modifier.isConst ); + stringBuffer.append( typeName ); + stringBuffer.append( modifier.ptr ); + stringBuffer.append( modifier.ref ); + stringBuffer.append(TEXT_4); + stringBuffer.append( parameterName ); + stringBuffer.append( modifier.array ); + + + +////////////////////////////////////////////////////////////////////////////////////////// + } +////////////////////////////////////////////////////////////////////////////////////////// + return stringBuffer.toString(); + } +}
\ No newline at end of file diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppPrimitiveTypeDefinition.java b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppPrimitiveTypeDefinition.java new file mode 100644 index 00000000000..c014caf01d6 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppPrimitiveTypeDefinition.java @@ -0,0 +1,90 @@ +/******************************************************************************* + * Copyright (c) 2006 CEA List. + * All rights reserved. This program and the accompanying materials + * are property of the CEA, their use is subject to specific agreement + * with the CEA. + * + * Contributors: + * CEA List - initial API and implementation + *******************************************************************************/ + +package org.eclipse.papyrus.cpp.codegen.jet.util; + +import org.eclipse.uml2.uml.PrimitiveType; +import org.eclipse.papyrus.cpp.codegen.jet.doc.*; +import Cpp.*; +import org.eclipse.papyrus.cpp.codegen.utils.GenUtils; + +public class CppPrimitiveTypeDefinition +{ + protected static String nl; + public static synchronized CppPrimitiveTypeDefinition create(String lineSeparator) + { + nl = lineSeparator; + CppPrimitiveTypeDefinition result = new CppPrimitiveTypeDefinition(); + nl = null; + return result; + } + + public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; + protected final String TEXT_1 = ""; + protected final String TEXT_2 = NL; + protected final String TEXT_3 = NL; + + public String generate(Object argument) + { + final StringBuffer stringBuffer = new StringBuffer(); + +////////////////////////////////////////////////////////////////////////////////////////// +// Java preparation +////////////////////////////////////////////////////////////////////////////////////////// + + // Retrieve the type passed as argument + PrimitiveType currentPType = (PrimitiveType) argument; + String currentPTypeName = currentPType.getName(); + String definition = ""; + + // Doc + String typeDoc = ""; + + // Retrieve enum doc + CppElementDoc jDoc = new CppElementDoc(); + + /** + * 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) + */ + // Retrieve type definition + CppType cppType = GenUtils.getApplication(currentPType, CppType.class); + if (cppType != null) { + typeDoc = jDoc.generate(currentPType); + definition = "typedef " + cppType.getDefinition(); + + // If definition string contains "typeName" it should be replaced with type name... + if (definition.indexOf("typeName") != -1) { + definition = definition.replaceAll("typeName", currentPTypeName); + } else { + definition = definition + " " + currentPTypeName; + } + definition = definition + ";"; + } + else { + definition = GenUtils.getStdtypes(currentPType); + } + +////////////////////////////////////////////////////////////////////////////////////////// +// The following part contains the template +////////////////////////////////////////////////////////////////////////////////////////// + stringBuffer.append(TEXT_1); + stringBuffer.append( typeDoc ); + stringBuffer.append(TEXT_2); + stringBuffer.append( definition ); + stringBuffer.append(TEXT_3); + return stringBuffer.toString(); + } +}
\ No newline at end of file diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppStaticAttributeImplementation.java b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppStaticAttributeImplementation.java new file mode 100644 index 00000000000..e24233da4ab --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppStaticAttributeImplementation.java @@ -0,0 +1,102 @@ +/******************************************************************************* + * Copyright (c) 2006 CEA List. + * All rights reserved. This program and the accompanying materials + * are property of the CEA, their use is subject to specific agreement + * with the CEA. + * + * Contributors: + * CEA List - initial API and implementation + *******************************************************************************/ + +package org.eclipse.papyrus.cpp.codegen.jet.util; + +import org.eclipse.uml2.uml.*; +import Cpp.*; +import org.eclipse.papyrus.cpp.codegen.utils.*; + +public class CppStaticAttributeImplementation +{ + protected static String nl; + public static synchronized CppStaticAttributeImplementation create(String lineSeparator) + { + nl = lineSeparator; + CppStaticAttributeImplementation result = new CppStaticAttributeImplementation(); + nl = null; + return result; + } + + public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; + protected final String TEXT_1 = ""; + protected final String TEXT_2 = "::"; + protected final String TEXT_3 = ";"; + protected final String TEXT_4 = NL; + + public String generate(Object argument) + { + final StringBuffer stringBuffer = new StringBuffer(); + +////////////////////////////////////////////////////////////////////////////////////////// +// Java preparation +////////////////////////////////////////////////////////////////////////////////////////// + + // Retrieve the property + Property currentAttribute = (Property) argument; + + String attributeName = currentAttribute.getName(); + String className = GenUtils.qualifiedName (currentAttribute.getClass_()); + String typeName = ""; + String suffix = ""; + String multiple = ""; + String isAgg = ""; // attribute is an aggregation or association + + + if (currentAttribute.getType() == null) { + typeName = "undefined"+" "; + } else { + typeName = GenUtils.qualifiedName (currentAttribute.getType()) + " "; + } + + // Multiple + // if (currentAttribute.isMultiple()) { + // multiple = "*"; + // } + + // 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 + } + + Modifier modifier = new Modifier(currentAttribute); + + // Initial value + if (currentAttribute.getDefaultValue() != null) { + // via UML + suffix = " = " + currentAttribute.getDefaultValue().stringValue(); + } + else { + CppDefault cppDefault = GenUtils.getApplication(currentAttribute, CppDefault.class); + if (cppDefault != null) { + suffix = " = " + cppDefault.getValue(); + } + } + +////////////////////////////////////////////////////////////////////////////////////////// +// The following part contains the template +////////////////////////////////////////////////////////////////////////////////////////// + stringBuffer.append(TEXT_1); + stringBuffer.append( typeName ); + stringBuffer.append( multiple ); + stringBuffer.append( modifier.ptr ); + stringBuffer.append( isAgg ); + stringBuffer.append( modifier.ref ); + stringBuffer.append( className ); + stringBuffer.append(TEXT_2); + stringBuffer.append( attributeName ); + stringBuffer.append( modifier.array ); + stringBuffer.append( suffix ); + stringBuffer.append(TEXT_3); + stringBuffer.append(TEXT_4); + return stringBuffer.toString(); + } +}
\ No newline at end of file diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppTemplateBindingParameter.java b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppTemplateBindingParameter.java new file mode 100644 index 00000000000..09feb0868b5 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppTemplateBindingParameter.java @@ -0,0 +1,63 @@ +/******************************************************************************* + * Copyright (c) 2006 CEA List. + * All rights reserved. This program and the accompanying materials + * are property of the CEA, their use is subject to specific agreement + * with the CEA. + * + * Contributors: + * CEA List - initial API and implementation + *******************************************************************************/ + +package org.eclipse.papyrus.cpp.codegen.jet.util; + +import org.eclipse.uml2.uml.*; + +public class CppTemplateBindingParameter +{ + protected static String nl; + public static synchronized CppTemplateBindingParameter create(String lineSeparator) + { + nl = lineSeparator; + CppTemplateBindingParameter result = new CppTemplateBindingParameter(); + nl = null; + return result; + } + + public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; + public String generate(Object argument) + { + final StringBuffer stringBuffer = new StringBuffer(); + +////////////////////////////////////////////////////////////////////////////////////////// +// Java preparation +////////////////////////////////////////////////////////////////////////////////////////// + + + // Retrieve the TemplateParameter + // Retrieve the TemplateParameter + TemplateParameterSubstitution currentTParam = (TemplateParameterSubstitution) argument; + + String typeName = ""; + + if (currentTParam.getActual() == null) { + typeName ="param undefined"; + } + else { + ParameterableElement actual = currentTParam.getActual(); + + if (actual instanceof LiteralInteger) { + typeName = "" + ((LiteralInteger) currentTParam.getActual()).getValue(); + } + else { + typeName = ((NamedElement) currentTParam.getActual()).getName(); + } // value = currentTParam.getFormal().getParameteredElement().getName(); + } + +////////////////////////////////////////////////////////////////////////////////////////// +// The following part contains the template +////////////////////////////////////////////////////////////////////////////////////////// + + stringBuffer.append( typeName ); + return stringBuffer.toString(); + } +}
\ No newline at end of file diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppTemplateDeclaration.java b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppTemplateDeclaration.java new file mode 100644 index 00000000000..567a6ce365f --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppTemplateDeclaration.java @@ -0,0 +1,69 @@ +/******************************************************************************* + * Copyright (c) 2006 CEA List. + * All rights reserved. This program and the accompanying materials + * are property of the CEA, their use is subject to specific agreement + * with the CEA. + * + * Contributors: + * CEA List - initial API and implementation + *******************************************************************************/ + +package org.eclipse.papyrus.cpp.codegen.jet.util; + +import org.eclipse.uml2.uml.Class; +import org.eclipse.uml2.uml.TemplateParameter; +import java.util.*; +import org.eclipse.papyrus.cpp.codegen.utils.GenUtils; + +public class CppTemplateDeclaration +{ + protected static String nl; + public static synchronized CppTemplateDeclaration create(String lineSeparator) + { + nl = lineSeparator; + CppTemplateDeclaration result = new CppTemplateDeclaration(); + nl = null; + return result; + } + + public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; + protected final String TEXT_1 = "template <"; + protected final String TEXT_2 = ">"; + + public String generate(Object argument) + { + final StringBuffer stringBuffer = new StringBuffer(); + +////////////////////////////////////////////////////////////////////////////////////////// +// Java preparation +////////////////////////////////////////////////////////////////////////////////////////// + + // Retrieve the class + Class currentClass = (Class) argument; + + + // Prepare template parameter declaration + Iterator<TemplateParameter> tparam = GenUtils.getTemplateParameters(currentClass).iterator(); + String tParamDecl = ""; + + while(tparam.hasNext()) { + TemplateParameter currentTParam = tparam.next(); + + CppTemplateParameter jetTParam = new CppTemplateParameter(); + tParamDecl = tParamDecl+jetTParam.generate(currentTParam); + + if (tparam.hasNext()) { + tParamDecl = tParamDecl+", "; + } + } + +////////////////////////////////////////////////////////////////////////////////////////// +// The following part contains the template +////////////////////////////////////////////////////////////////////////////////////////// + + stringBuffer.append(TEXT_1); + stringBuffer.append( tParamDecl ); + stringBuffer.append(TEXT_2); + return stringBuffer.toString(); + } +}
\ No newline at end of file diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppTemplateInlineOperationsImplementation.java b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppTemplateInlineOperationsImplementation.java new file mode 100644 index 00000000000..999e3789ce1 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppTemplateInlineOperationsImplementation.java @@ -0,0 +1,75 @@ +/******************************************************************************* + * Copyright (c) 2006 CEA List. + * All rights reserved. This program and the accompanying materials + * are property of the CEA, their use is subject to specific agreement + * with the CEA. + * + * Contributors: + * CEA List - initial API and implementation + *******************************************************************************/ + +package org.eclipse.papyrus.cpp.codegen.jet.util; + +import org.eclipse.papyrus.cpp.codegen.jet.doc.*; +import org.eclipse.uml2.uml.Class; +import org.eclipse.uml2.uml.Operation; +import java.util.Iterator; +import Cpp.*; +import org.eclipse.papyrus.cpp.codegen.utils.GenUtils; + +public class CppTemplateInlineOperationsImplementation +{ + protected static String nl; + public static synchronized CppTemplateInlineOperationsImplementation create(String lineSeparator) + { + nl = lineSeparator; + CppTemplateInlineOperationsImplementation result = new CppTemplateInlineOperationsImplementation(); + nl = null; + return result; + } + + public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; + public String generate(Object argument) + { + final StringBuffer stringBuffer = new StringBuffer(); + +////////////////////////////////////////////////////////////////////////////////////////// +// Java preparation +////////////////////////////////////////////////////////////////////////////////////////// + + // Retrieve the class + Class currentClass = (Class) argument; + String opDecl = ""; + String tDecl = ""; + + // Retrieve template declaration + CppTemplateDeclaration jetTDecl = new CppTemplateDeclaration(); + // tDecl should contain something like "template <class x, class y>" + tDecl = jetTDecl.generate(currentClass) + " "; + + // Retrieve operations + Iterator<Operation> operations = currentClass.getOwnedOperations().iterator(); + while (operations.hasNext()) { + Operation currentOperation = operations.next(); + + if (GenUtils.hasStereotype (currentOperation, CppInline.class) && + !GenUtils.hasStereotype (currentOperation, CppNoCodeGen.class)) { + String opDoc = ""; + + // Doc for the template + CppOperationDoc jDoc = new CppOperationDoc(); + opDoc = jDoc.generate(currentOperation); + + CppOperationTemplateImplementation jetOpImpl = new CppOperationTemplateImplementation(); + opDecl = opDecl+opDoc+NL+tDecl+jetOpImpl.generate(currentOperation)+NL; + } + } + +////////////////////////////////////////////////////////////////////////////////////////// +// The following part contains the template +////////////////////////////////////////////////////////////////////////////////////////// + + stringBuffer.append( opDecl ); + return stringBuffer.toString(); + } +}
\ No newline at end of file diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppTemplateParameter.java b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppTemplateParameter.java new file mode 100644 index 00000000000..30e4dc8da32 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppTemplateParameter.java @@ -0,0 +1,68 @@ +/******************************************************************************* + * Copyright (c) 2006 CEA List. + * All rights reserved. This program and the accompanying materials + * are property of the CEA, their use is subject to specific agreement + * with the CEA. + * + * Contributors: + * CEA List - initial API and implementation + *******************************************************************************/ + +package org.eclipse.papyrus.cpp.codegen.jet.util; + +import Cpp.*; +import org.eclipse.papyrus.cpp.codegen.utils.GenUtils; +import org.eclipse.uml2.uml.TemplateParameter; + +public class CppTemplateParameter +{ + protected static String nl; + public static synchronized CppTemplateParameter create(String lineSeparator) + { + nl = lineSeparator; + CppTemplateParameter result = new CppTemplateParameter(); + nl = null; + return result; + } + + public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; + protected final String TEXT_1 = " "; + + public String generate(Object argument) + { + final StringBuffer stringBuffer = new StringBuffer(); + +////////////////////////////////////////////////////////////////////////////////////////// +// Java preparation +////////////////////////////////////////////////////////////////////////////////////////// + + + // Retrieve the TemplateParameter + TemplateParameter currentTParam = (TemplateParameter) argument; + + String parameterName = ""; + String typeName = ""; + + + if (GenUtils.getType(currentTParam) == "") { + typeName = "undefined"; + } else { + typeName = GenUtils.getType(currentTParam); //.getName(); + } + + // Retrieve name under stereotype CppTemplateParameter/name + Cpp.CppTemplateParameter ctp = GenUtils.getApplication(currentTParam, Cpp.CppTemplateParameter.class); + if (ctp != null) { + parameterName = ctp.getName(); + } + +////////////////////////////////////////////////////////////////////////////////////////// +// The following part contains the template +////////////////////////////////////////////////////////////////////////////////////////// + + stringBuffer.append( typeName ); + stringBuffer.append(TEXT_1); + stringBuffer.append( parameterName ); + return stringBuffer.toString(); + } +}
\ No newline at end of file diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/plugin.properties b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/plugin.properties new file mode 100644 index 00000000000..e69de29bb2d --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/plugin.properties diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/plugin.xml b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/plugin.xml new file mode 100644 index 00000000000..a8cab8ba2a5 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/plugin.xml @@ -0,0 +1,10 @@ +<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.2"?>
+<plugin>
+ <extension
+ point="org.eclipse.core.runtime.preferences">
+ <initializer
+ class="org.eclipse.papyrus.cpp.codegen.preferences.CppCodeGenPreferenceInitializer">
+ </initializer>
+ </extension>
+</plugin>
diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/Activator.java b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/Activator.java new file mode 100644 index 00000000000..83cc1860acf --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/Activator.java @@ -0,0 +1,65 @@ +/*******************************************************************************
+ * 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;
+
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.BundleContext;
+
+
+/**
+ * The activator class controls the plug-in life cycle
+ */
+public class Activator extends AbstractUIPlugin {
+
+ // The plug-in ID
+ public static final String PLUGIN_ID = "org.eclipse.papyrus.cpp.codegen"; //$NON-NLS-1$
+
+ // The shared instance
+ private static Activator plugin;
+
+ /**
+ * Returns the shared instance
+ *
+ * @return the shared instance
+ */
+ public static Activator getDefault() {
+ return plugin;
+ }
+
+ /**
+ * The constructor
+ */
+ public Activator() {
+ plugin = this;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
+ */
+ @Override
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
+ */
+ @Override
+ public void stop(BundleContext context) throws Exception {
+ plugin = null;
+ super.stop(context);
+ }
+
+}
diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/Constants.java b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/Constants.java new file mode 100644 index 00000000000..33e044a0323 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/Constants.java @@ -0,0 +1,36 @@ +/******************************************************************************* + * 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; + +/** + * String constants for the code generation + * + * @author ansgar + * + */ +public class Constants { + + public static final String includeHFile = "// include associated header file"; + + public static final String cppIncPreBodyStart = "// Include from CppInclude stereotype (pre-body)"; + + public static final String cppIncPreBodyEnd = "// End of CppInclude stereotype (pre-body)"; + + public static final String cppIncBodyStart = "// Include from CppInclude declaration (body)"; + + public static final String cppIncBodyEnd = "// End of CppInclude stereotype (body)"; + + public static final String derivedIncludes = "// Derived includes directives"; + + public static final String forwardDecl = "// forward declarations"; + + public static final String staticAttributes = "// static attributes (if any)"; +} diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/StdStereo.java b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/StdStereo.java new file mode 100644 index 00000000000..602960b6bf8 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/StdStereo.java @@ -0,0 +1,48 @@ +/******************************************************************************* + * 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; + +import org.eclipse.papyrus.cpp.codegen.utils.GenUtils; +import org.eclipse.uml2.uml.Element; + +public class StdStereo { + + public final static String create = "Create"; + + public final static String destroy = "Destroy"; + + /** + * In the UML 2.4 plugin, the Standard profile is split into an L2 and an L3 profile + */ + public final static String[] namespaces = { + "Standard", "StandardProfileL2" + }; + + /** + * Check whether a stereotype of the standard profile is applied + * + * @param element + * The element to check + * @param stdName + * the non qualified name of a stereotype within the standard + * profile + * @return + */ + public static boolean isApplied(Element element, String stdName) { + for(String namespace : namespaces) { + if(GenUtils.hasStereotype(element, namespace + "::" + stdName)) { + return true; + } + } + return false; + } +} diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/preferences/CppCodeGenConstants.java b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/preferences/CppCodeGenConstants.java new file mode 100644 index 00000000000..3e579c05b10 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/preferences/CppCodeGenConstants.java @@ -0,0 +1,31 @@ +/******************************************************************************* + * 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.preferences; + +public class CppCodeGenConstants { + + /** + * Suffix for generated header files + */ + public static final String P_HEADER_SUFFIX = "headSuffix"; + + /** + * Suffix for generated body/implementation files + */ + public static final String P_IMPLEM_SUFFIX = "implSuffix"; + + /** + * User defined comment header in generated files + */ + public static final String P_COMMENT_HEADER = "commentHeader"; + +} diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/preferences/CppCodeGenPreferenceInitializer.java b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/preferences/CppCodeGenPreferenceInitializer.java new file mode 100644 index 00000000000..607d79c3c2c --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/preferences/CppCodeGenPreferenceInitializer.java @@ -0,0 +1,40 @@ +/******************************************************************************* + * 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.preferences; + +import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer; +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.papyrus.cpp.codegen.Activator; + + +public class CppCodeGenPreferenceInitializer extends AbstractPreferenceInitializer { + + /* + * (non-Javadoc) + * + * @see org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer#initializeDefaultPreferences() + */ + public void initializeDefaultPreferences() { + IPreferenceStore store = Activator.getDefault().getPreferenceStore(); + store.setDefault(CppCodeGenConstants.P_HEADER_SUFFIX, "h"); + store.setDefault(CppCodeGenConstants.P_IMPLEM_SUFFIX, "cpp"); + + // Default value for P_COMMENT_HEADER + String NL = System.getProperties().getProperty("line.separator"); + String defaultValue = "" + + "// --------------------------------------------------------" + NL + + "// Code generated by Papyrus C++" + NL + + "// --------------------------------------------------------" + NL + + NL; + store.setDefault(CppCodeGenConstants.P_COMMENT_HEADER, defaultValue); + } +} diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/preferences/CppCodeGenUtils.java b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/preferences/CppCodeGenUtils.java new file mode 100644 index 00000000000..d7094ee9786 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/preferences/CppCodeGenUtils.java @@ -0,0 +1,48 @@ +/******************************************************************************* + * 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.preferences; + +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.papyrus.cpp.codegen.Activator; + +/** + * Utility class that returns the preference values + * + * @author ansgar + * + */ +public class CppCodeGenUtils { + + protected static IPreferenceStore preferenceStore = null; + + public static String getHeaderSuffix() { + initPreferenceStore(); + return preferenceStore.getString(CppCodeGenConstants.P_HEADER_SUFFIX); + } + + public static String getBodySuffix() { + initPreferenceStore(); + return preferenceStore.getString(CppCodeGenConstants.P_IMPLEM_SUFFIX); + } + + public static String getCommentHeader() { + initPreferenceStore(); + return preferenceStore.getString(CppCodeGenConstants.P_COMMENT_HEADER); + } + + public static void initPreferenceStore() { + if(preferenceStore == null) { + preferenceStore = Activator.getDefault().getPreferenceStore(); + } + } + +} diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/transformation/ModelElementsCreator.java b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/transformation/ModelElementsCreator.java new file mode 100644 index 00000000000..a966e85e5a0 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/transformation/ModelElementsCreator.java @@ -0,0 +1,476 @@ +/*******************************************************************************
+ * 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/cpp-codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/utils/ClassUtils.java b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/utils/ClassUtils.java new file mode 100644 index 00000000000..db60f1cb1d7 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/utils/ClassUtils.java @@ -0,0 +1,168 @@ +/******************************************************************************* + * 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.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.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; + +/** + * A set of utility functions related to classes. + * + * @author ansgar (ansgar.radermacher@cea.fr) + * + */ +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 + * + * @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); + } + } + if(attrSDecl.length() > 0) { + attrSDecl = Constants.staticAttributes + "\n" + attrSDecl; + } + return attrSDecl; + } +} diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/utils/GenUtils.java b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/utils/GenUtils.java new file mode 100644 index 00000000000..8f1aa18e816 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/utils/GenUtils.java @@ -0,0 +1,795 @@ +/******************************************************************************* + * 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.utils; + +import java.util.ArrayList; +import java.util.Collection; +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.EObject; +import org.eclipse.uml2.uml.AggregationKind; +import org.eclipse.uml2.uml.Behavior; +import org.eclipse.uml2.uml.Class; +import org.eclipse.uml2.uml.Classifier; +import org.eclipse.uml2.uml.ClassifierTemplateParameter; +import org.eclipse.uml2.uml.Comment; +import org.eclipse.uml2.uml.ConnectableElementTemplateParameter; +import org.eclipse.uml2.uml.Dependency; +import org.eclipse.uml2.uml.DirectedRelationship; +import org.eclipse.uml2.uml.Element; +import org.eclipse.uml2.uml.Interface; +import org.eclipse.uml2.uml.LiteralBoolean; +import org.eclipse.uml2.uml.LiteralInteger; +import org.eclipse.uml2.uml.LiteralString; +import org.eclipse.uml2.uml.LiteralUnlimitedNatural; +import org.eclipse.uml2.uml.NamedElement; +import org.eclipse.uml2.uml.Namespace; +import org.eclipse.uml2.uml.OpaqueBehavior; +import org.eclipse.uml2.uml.Operation; +import org.eclipse.uml2.uml.OperationTemplateParameter; +import org.eclipse.uml2.uml.Package; +import org.eclipse.uml2.uml.Parameter; +import org.eclipse.uml2.uml.ParameterableElement; +import org.eclipse.uml2.uml.PrimitiveType; +import org.eclipse.uml2.uml.Property; +import org.eclipse.uml2.uml.Stereotype; +import org.eclipse.uml2.uml.TemplateBinding; +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; + + + +/** + * Some utilities: a set of static method for C++ code generator + * Mainly "Template" related methods + * Should probably be put in com.cea.utils in next release + * + * @author wassim + * + */ +public class GenUtils { + + public static final String NL = System.getProperties().getProperty("line.separator"); + + /** + * Retrieve template bindings for the class passed as a Parameter + * only one template binding can exist for an element + * + * @param current + * Class on which the template binding is searched + * @return the template binding of current Class + */ + public static TemplateBinding getTemplateBindings(Class current) + { + TemplateBinding binding = null; + if(current.getTemplateBindings().size() == 1) { + binding = current.getTemplateBindings().get(0); + } + + return binding; + } + + public static boolean isTemplateBoundElement(Class uml2Class) { + boolean result = false; + EList<TemplateBinding> tb = uml2Class.getTemplateBindings(); + if(tb != null) { + Iterator<TemplateBinding> itb = tb.iterator(); + while(itb.hasNext()) { + TemplateBinding currentTb = itb.next(); + result = currentTb.getBoundElement() == uml2Class; + } + } + return result; + } + + public static Collection<TemplateParameter> getTemplateParameters( + Classifier classifier) + { + + Collection<TemplateParameter> params = new ArrayList<TemplateParameter>(); + TemplateSignature ts = classifier.getOwnedTemplateSignature(); + if(ts != null) { + params.addAll(ts.getOwnedParameters()); + } + + return params; + } + + public static Collection<ParameterableElement> getTemplateParameteredElements( + Classifier classifier) + { + + Collection<ParameterableElement> params = new ArrayList<ParameterableElement>(); + TemplateSignature ts = classifier.getOwnedTemplateSignature(); + if(ts != null) { + for(TemplateParameter tp : ts.getOwnedParameters()) { + if(tp != null) { + params.add(tp.getParameteredElement()); + } + } + } + + return params; + } + + /** + * Return a list of template parameters without type + * + * @param classifier + * @return + */ + public static String getTemplateParametersWoType(Classifier classifier) + { + String tparamWoType = ""; + + Iterator<TemplateParameter> it = GenUtils.getTemplateParameters( + classifier).iterator(); + + while(it.hasNext()) { + TemplateParameter currentTParam = it.next(); + tparamWoType = tparamWoType + GenUtils.getName(currentTParam); + + if(it.hasNext()) { + tparamWoType = tparamWoType + ", "; + } + } + return tparamWoType; + } + + /** + * The standard UML and MARTE libraries do not apply the cppType stereotype. Yet, we want to treat these + * types in an identical way, i.e. we use a typedef to the associated primitive C++ type + * + * @param type + * @return + */ + public static String getStdtypes(PrimitiveType type) { + Object owner = type.getOwner(); + String owningPkgName = ""; + if(owner instanceof Package) { + owningPkgName = ((Package)owner).getName(); + } + if(owningPkgName.equals("PrimitiveTypes") || // used in UML 2.4 + owningPkgName.equals("UMLPrimitiveTypes") || // used in UML < 2.4 + owningPkgName.equals("MARTE_PrimitivesTypes")) { + String td = null; + String name = type.getName(); + + if(name.equals("Boolean")) { + td = "bool"; + } + else if(name.equals("Integer")) { + td = "int"; + } + else if(name.equals("String")) { + td = "const char *"; + } + else if(name.equals("Unlimited Natural")) { + td = "unsigned long"; + } + if(td != null) { + return "typedef " + td + " " + name + ";"; + } + // else unknown within UMLPrimitiveTypes, treat in standard way + } + + return ""; + } + + /** + * Gives the type of the parameter or null for void. + * (used in particular in the context of template parameters + * TODO: redundant with qualifiedName??) + * + * @return the template type formated as string + */ + public static String getType(TemplateParameter templateParam) + { + String type = "", name = ""; + + // Retrieve name of the ParameteredElement (when possible = it is a NamedElement + ParameterableElement pElt = templateParam.getParameteredElement(); + if((pElt != null) && (pElt instanceof NamedElement)) { + name = ((NamedElement)pElt).getName(); + if(templateParam instanceof ClassifierTemplateParameter) { + type = "class"; + } + else if(templateParam instanceof OperationTemplateParameter) { + type = ""; + } + else if(templateParam instanceof ConnectableElementTemplateParameter) { + type = ""; + } + else {// uml2TemplateParameter instanceof TemplateParameter + if(pElt instanceof LiteralInteger) { + type = "int"; + } + else if(pElt instanceof LiteralString) { + type = "String"; + } else if(pElt instanceof LiteralBoolean) { + type = "Boolean"; + } else if(pElt instanceof LiteralUnlimitedNatural) { + type = "UnlimitedNatural"; + } else { + type = pElt.eClass().getName(); + } + } + } + else { + name = "undefined"; + } + + // Retrieve the name of the type + /* + * if (templateParam instanceof ClassifierTemplateParameter) { + * type = "class"; + * } else + * { + * if ((pElt != null) && (pElt instanceof LiteralInteger)) { + * type = "int"; + * } else { + * // Need test the other cases (LiteralBoolean ? LiteralString ?) + * type = "undefined"; + * } + * } + */ + + return (type + " " + name); + } + + public static String getName(TemplateParameter templateParam) + { + String name = ""; + ParameterableElement pElt = templateParam.getParameteredElement(); + if((pElt != null) && (pElt instanceof NamedElement)) { + name = ((NamedElement)pElt).getName(); + } else { + name = "undefined"; + } + + return name; + } + + /** + * Retrieve a list of types that belong to by a classifier in the current class + * + * @param current + * Class on which the attributes are searched + * @return collection of classes which are the type of the attributes + */ + public static EList<Classifier> getOwnedAttributeTypes(Classifier current) + { + EList<Classifier> result = new UniqueEList<Classifier>(); + + Iterator<Property> attributes; + attributes = current.getAttributes().iterator(); + while(attributes.hasNext()) { + Property currentAttribute = attributes.next(); + Type type = currentAttribute.getType(); + if(type instanceof Classifier) { + Classifier attrType = (Classifier)type; + result.add(attrType); + } + } + return result; + } + + /** + * Retrieve the operations in the current class then for each + * operation it finds the parameters that have a class type + * + * @param current + * Class on which the attributes are searched + * @return collection of classes which are the types of the operations parameters + */ + public static EList<Classifier> getIncludesFromOperations(Classifier current) + { + EList<Classifier> result = new UniqueEList<Classifier>(); + Iterator<Operation> operations = current.getOperations().iterator(); + while(operations.hasNext()) { + Operation op = operations.next(); + Iterator<Parameter> i = op.getOwnedParameters().iterator(); + while(i.hasNext()) { + Parameter param = i.next(); + Type type = param.getType(); + if(type instanceof Classifier) { + Classifier paramType = (Classifier)type; + result.add(paramType); + } + } + } + return result; + } + + public static EList<Interface> getImplementedInterfaces(Class current) + { + EList<Interface> interfaces = new UniqueEList<Interface>(); + Iterator<Interface> interfacesIt = current.getImplementedInterfaces().iterator(); + Interface currentInterface; + while(interfacesIt.hasNext()) { + currentInterface = (Interface)interfacesIt.next(); + interfaces.add(currentInterface); + } + return interfaces; + } + + /** + * Return a list of classifiers that are referenced by relationships, i.e. + * dependencies or associations + * + * @param current + * @return + */ + public static EList<Classifier> getRelationships(Classifier current) + { + EList<Classifier> classifiers = new UniqueEList<Classifier>(); + + for(DirectedRelationship relationship : current.getSourceDirectedRelationships()) { + + if(relationship.getTargets().size() > 0) { + // there should always be at least one element in the target + // list and it should be a classifier, but better check. + Element element = relationship.getTargets().get(0); + if(element instanceof Classifier) { + classifiers.add((Classifier)element); + } + } + } + return classifiers; + } + + /** + * Return a list of classifiers that are referenced via dependencies + * + * @param current + * @return + */ + public static EList<Classifier> getDependencies(Classifier current) + { + EList<Classifier> classifiers = new UniqueEList<Classifier>(); + + for(DirectedRelationship relationship : current.getSourceDirectedRelationships()) { + if(relationship instanceof Dependency) { + if(relationship.getTargets().size() > 0) { + // there should always be at least one element in the target + // list and it should be a classifier, but better check. + Element element = relationship.getTargets().get(0); + if(element instanceof Classifier) { + classifiers.add((Classifier)element); + } + } + } + } + return classifiers; + } + + /** + * Return a list of classifiers that are referenced via all kinds of relations except + * dependencies + * + * @param current + * @return + */ + public static EList<Classifier> getRelationshipsNoDeps(Classifier current) + { + EList<Classifier> classifiers = new UniqueEList<Classifier>(); + + for(DirectedRelationship relationship : current.getSourceDirectedRelationships()) { + if(!(relationship instanceof Dependency)) { + if(relationship.getTargets().size() > 0) { + // there should always be at least one element in the target + // list and it should be a classifier, but better check. + Element element = relationship.getTargets().get(0); + if(element instanceof Classifier) { + classifiers.add((Classifier)element); + } + } + } + } + return classifiers; + } + + /** + * Return the qualified name of a named element, but use "_" instead of "::" as separator + * + * @param ne + * a named element + * @return the fully qualified name with "_" as separator character + */ + public static String getFullName(NamedElement ne) { + return ne.getQualifiedName().replace("::", "_"); + } + + /** + * return the full name in upper case + * + * @param ne + * @return + */ + public static String getFullNameUC(NamedElement ne) { + return ne.getQualifiedName().replace("::", "_").toUpperCase(); + } + + /** + * Return a C++ namespace definition for a named element + * + * @param ne + * a named element + * @return a C++ namespace definition for a named element + */ + public static String getNamespace(NamedElement ne) { + String namespace = ""; + for(Namespace ns : ne.allNamespaces()) { + if(ns.getOwner() != null) { + String nsName = ns.getName(); + if(!namespace.equals("")) { + nsName += "::"; + } + namespace = nsName + namespace; + } + } + if(!namespace.equals("")) { + namespace = "\n" + + "using namespace " + namespace + ";\n"; + } + return namespace; + } + + /** + * Return a C++ open-namespace definition for a named element + * + * @param ne + * a named element + * @return a C++ open-namespace definition for a named element + */ + public static String openNS(NamedElement ne) { + String openNS = ""; + currentNS = ne.getNamespace(); + for(Namespace ns : ne.allNamespaces()) { + if(ns.getOwner() != null) { + openNS = "namespace " + ns.getName() + " {\n" + openNS; + } + } + return openNS; + } + + /** + * Return a C++ close-namespace definition for a named element + * + * @param ne + * a named element + * @return a C++ close-namespace definition for a named element + */ + public static String closeNS(NamedElement ne) { + String closeNS = ""; + for(Namespace ns : ne.allNamespaces()) { + if(ns.getOwner() != null) { + closeNS += "} // of namespace " + ns.getName() + "\n"; + } + } + return closeNS; + } + + public static String qualifiedName(NamedElement ne) { + Object owner = ne.getOwner(); + String owningPkgName = ""; + if(owner instanceof Package) { + owningPkgName = ((Package)owner).getName(); + } + if((hasStereotype(ne, CppExternClass.class)) || (hasStereotype(ne, CppNoCodeGen.class))) { + return ne.getName(); + } + else if(owningPkgName.equals("AnsiCLibrary")) { + // always use the short name for types within the ANSI C library + return ne.getName(); + } + + String qName = ne.getName(); + if(currentNS == ne.getNamespace()) { + // return simple name, if in current namespace + return qName; + } + if(ne instanceof PrimitiveType) { + if(!hasStereotype(ne, CppType.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; + } + } + + for(Namespace ns : ne.allNamespaces()) { + // don't add top-level + if(ns.getOwner() != null) { + qName = ns.getName() + "::" + qName; + } + } + if(qName.contains("::")) { + // is a qualified name => make path absolute + return "::" + qName; + } + else { + return qName; + } + } + + public static String getComments(Element element) { + String commentText = ""; + for(Comment comment : element.getOwnedComments()) { + commentText += comment.getBody(); + } + return commentText; + } + + /** + * Return a list of dependent package (the list of dependent + * elements filtered for packages) + * + * @param pkg + * @return + */ + public static EList<Package> getUsedPackages(Package pkg) { + EList<Package> result = new BasicEList<Package>(); + for(Element depElement : pkg.getClientDependencies()) { + if(depElement instanceof Package) { + result.add((Package)depElement); + } + } + return result; + } + + /** + * Return a list of dependent classes (the list of dependent + * elements filtered for classes) + * + * @param pkg + * @return + */ + public static EList<Classifier> getUsedClassifiers(Classifier cls) { + EList<Classifier> result = new BasicEList<Classifier>(); + for(Element depElement : cls.getClientDependencies()) { + if(depElement instanceof Classifier) { + result.add((Classifier)depElement); + } + } + return result; + } + + /** + * Return the qualified name of a package, but use "/" instead of "::" as separator + * + * @param pkg + * @return + */ + public static String getFullPath(Package pkg) { + return pkg.getQualifiedName().replace("::", "/"); + } + + /** + * Is a certain stereotype applied? + * + * @param element + * @param stereotype + * fully qualified stereotype name + * @return + */ + public static boolean hasStereotype(Element element, String stereotName) { + EList<Stereotype> list = element.getAppliedStereotypes(); + return element.getAppliedStereotype(stereotName) != null; + } + + /** + * Is a certain stereotype applied? + * + * @param element + * @param stereotype + * fully qualified stereotype name + * @return + */ + 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 + if(clazz.isAssignableFrom(stereoApplication.getClass())) { + return true; + } + } + return false; + } + + /** + * Return the stereotype application by passing an element of the static profile + * + * @param element + * the UML model element + * @param clazz + * the class of an element of a static profile. Compatible sub-types will be returned as well + * @return the stereotype application or null + */ + @SuppressWarnings("unchecked") + public static <T extends EObject> T getApplication(Element element, java.lang.Class<T> clazz) { + for(EObject stereoApplication : element.getStereotypeApplications()) { + // check whether the stereotype is an instance of the passed parameter clazz + if(clazz.isInstance(stereoApplication)) { + return (T)stereoApplication; + } + } + return null; + } + + /** + * Is a certain stereotype applied? + * + * @param element + * @param stereotype + * fully qualified stereotype name + * @return + */ + public static void setStereotype(Element element, String stereotName, boolean apply) { + Stereotype stereotype = element.getApplicableStereotype(stereotName); + if(stereotype != null) { + if(apply) { + if(!element.isStereotypeApplied(stereotype)) { + element.applyStereotype(stereotype); + } + } + else { + if(element.isStereotypeApplied(stereotype)) { + element.unapplyStereotype(stereotype); + } + } + } + } + + /** + * This method returns the stereotype applied to a certain element when given its name. + * Returns null, if a stereotype of that name does not exist. + * This function is quite similar to getAppliedStereotype, the difference is that it + * is not based on fully qualified name. + */ + public static String getTaggedValue(Element element, String stereo_name, String attrib_name) + { + Stereotype stereotype = element.getAppliedStereotype(stereo_name); + if(stereotype == null) { + return ""; + } + Object value = element.getValue(stereotype, attrib_name); + if(value == null) { + return ""; + } + + if(value instanceof NamedElement) { + return ((NamedElement)value).getName(); + } else if(value instanceof String) { + return (String)value; + } else { + return value.toString(); + } + } + + /** + * This method returns the stereotype applied to a certain element when given its name. + * Returns null, if a stereotype of that name does not exist. + * This function is quite similar to getAppliedStereotype, the difference is that it + * is not based on fully qualified name. + */ + public static void setTaggedValue(Element element, String stereo_name, String attrib_name, Object value) + { + Stereotype stereotype = element.getAppliedStereotype(stereo_name); + if(stereotype != null) { + element.setValue(stereotype, attrib_name, value); + } + } + + /** + * @param operation + * the operation + * @param selectedLanguage + * the selected language + * @return Return the first body of a selected language that is provided by + * one of the operation's methods + */ + public static String getBody(Operation operation, String selectedLanguage) { + for(Behavior behavior : operation.getMethods()) { + if(behavior instanceof OpaqueBehavior) { + OpaqueBehavior ob = (OpaqueBehavior)behavior; + Iterator<String> bodies = ob.getBodies().iterator(); + for(String language : ob.getLanguages()) { + String body = bodies.next(); + if(language.equals(selectedLanguage)) { + return indent(body, "\t"); + } + } + } + } + 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 + */ + public static boolean isAggregation(Property p) { + return /* (p.getAssociation() != null) && */ + (p.getAggregation() == AggregationKind.SHARED_LITERAL); + } + + public static String getVisibility(Element element) { + // get visibility and target name + CppVisibility cppVisibility = GenUtils.getApplication(element, CppVisibility.class); + if(cppVisibility != null) { + return cppVisibility.getValue(); + } else { + return "public"; + } + } + + /** + * Avoid null strings, i.e. replace null strings by empty strings + * + * @param str + * @return + */ + public static String maskNull(String str) { + if(str == null) { + return ""; + } + 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/cpp-codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/utils/Modifier.java b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/utils/Modifier.java new file mode 100644 index 00000000000..448657a6e47 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/utils/Modifier.java @@ -0,0 +1,84 @@ +/******************************************************************************* + * 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.utils; + +import org.eclipse.uml2.uml.Element; + +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 + * parameter or an attribute is a pointer, a reference, an array or constant. + * + * @author ansgar + * + */ +public class Modifier { + + public String ptr; + + public String ref; + + public String array; + + public String isConst; + + public Modifier() { + ptr = ""; + ref = ""; + array = ""; + isConst = ""; + } + + /** + * Create instance and initialize the ptr/ref/array/isConst attributes. + * + * @param currentParameter + */ + public Modifier(Element currentParameter) { + + // Pointer + CppPtr cppPtr = GenUtils.getApplication(currentParameter, CppPtr.class); + if(cppPtr != null) { + ptr = (cppPtr.getDeclaration() != null) ? + cppPtr.getDeclaration() : + "*"; + } + else { + ptr = ""; + } + + // Ref + ref = GenUtils.hasStereotype(currentParameter, CppRef.class) ? + "&" : + ""; + + // Array + CppArray cppArray = GenUtils.getApplication(currentParameter, CppArray.class); + if(cppArray != null) { + array = (cppArray.getDefinition() != null) ? + cppArray.getDefinition() : + "[]"; + } + else { + array = ""; + } + + // Const + isConst = GenUtils.hasStereotype(currentParameter, CppConst.class) ? + "const " : + ""; + } +} diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/CppBindBody.cpp.jet b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/CppBindBody.cpp.jet new file mode 100644 index 00000000000..04e92f6a6fd --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/CppBindBody.cpp.jet @@ -0,0 +1,87 @@ +<%@ jet package = "org.eclipse.papyrus.cpp.codegen.jet" + skeleton = "generator.skeleton" + imports = "org.eclipse.papyrus.cpp.codegen.Constants org.eclipse.papyrus.cpp.codegen.utils.* Cpp.CppInclude org.eclipse.uml2.uml.Class org.eclipse.uml2.uml.Package org.eclipse.uml2.uml.* org.eclipse.emf.common.util.EList org.eclipse.papyrus.cpp.codegen.jet.util.* java.util.* org.eclipse.papyrus.cpp.codegen.Activator" + class = "CppBindBody" + %> +<% +////////////////////////////////////////////////////////////////////////////////////////// +// Java preparation +////////////////////////////////////////////////////////////////////////////////////////// + + // Retrieve the class + Class currentClass = (Class) argument; + + // Get the package name + String className = currentClass.getName(); + String classFullName = GenUtils.getFullName (currentClass); + String classFULLNAME = classFullName.toUpperCase(); + String parentClass = ""; + String namespace = GenUtils.getNamespace (currentClass); + + // Retrieve header file suffix + String headerFileSuffix = Activator.getDefault().getPluginPreferences().getString("headSuffix"); + + // Retrieve owner Package + Package owner = currentClass.getPackage(); + String fullPath = ""; + + if (owner != null) { + fullPath = GenUtils.getFullPath(owner) + "/"; + } // else fullPath == "" + + TemplateBinding tb = GenUtils.getTemplateBindings(currentClass);; + + // prepare parent class declaration + EList<org.eclipse.uml2.uml.Element> templates = tb.getTargets(); + Class templateClass = (Class) ((TemplateSignature) templates.get(0)).getOwner(); + parentClass = GenUtils.qualifiedName (templateClass); + + // Prepare bindings parameter declaration + + String tParamDecl = ""; + Iterator<TemplateParameterSubstitution> tps = tb.getParameterSubstitutions().iterator(); + while(tps.hasNext()) { + TemplateParameterSubstitution paramSub = tps.next(); + + CppTemplateBindingParameter jetTParam = new CppTemplateBindingParameter(); + tParamDecl = tParamDecl+jetTParam.generate (paramSub); + + if (tps.hasNext()) { + tParamDecl = tParamDecl + ", "; + } + } + + +////////////////////////////////////////////////////////////////////////////////////////// +// The following part contains the template +//////////////////////////////////////////////////////////////////////////////////////////%> +#define <%= classFULLNAME %>_BODY + +/************************************************************ + <%= className %> template binding body + ************************************************************/ + +<%= Constants.cppIncPreBodyStart %> +<%= ClassUtils.getCppIncludePreBody(currentClass) %> +<%= Constants.cppIncPreBodyEnd %> + +<%= Constants.includeHFile %> +#include <<%= fullPath %><%= className %>.<%= headerFileSuffix %>> + +<%= Constants.cppIncBodyStart %> +<%= ClassUtils.getCppIncludeBody(currentClass) %> +<%= Constants.cppIncBodyEnd %> + +<%= GenUtils.openNS(currentClass) %> + +<%= Constants.derivedIncludes %> +<%= ClassUtils.createIncludeDecl(currentClass) %> + +/************************************************************/ +template class <%= parentClass %> <<%= tParamDecl %>>; + +<%= GenUtils.closeNS(currentClass) %> + +/************************************************************ + End of <%= className %> template binding body + ************************************************************/ diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/CppBindHeader.h.jet b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/CppBindHeader.h.jet new file mode 100644 index 00000000000..906567e511f --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/CppBindHeader.h.jet @@ -0,0 +1,115 @@ +<%@ jet package = "org.eclipse.papyrus.cpp.codegen.jet" + skeleton = "generator.skeleton" + imports = "org.eclipse.papyrus.cpp.codegen.utils.GenUtils Cpp.CppInclude org.eclipse.uml2.uml.Class org.eclipse.emf.common.util.EList org.eclipse.uml2.uml.Package org.eclipse.uml2.uml.TemplateSignature org.eclipse.uml2.uml.TemplateParameterSubstitution org.eclipse.papyrus.cpp.codegen.jet.util.* java.util.* org.eclipse.papyrus.cpp.codegen.Activator" + class = "CppBindHeader" + %> +<% +////////////////////////////////////////////////////////////////////////////////////////// +// Java preparation +////////////////////////////////////////////////////////////////////////////////////////// + + // Retrieve the class + Class currentClass = (Class) argument; + + // Get the package name + String className = currentClass.getName(); + String classFullName = GenUtils.getFullName (currentClass); + String classFULLNAME = classFullName.toUpperCase(); + String classparent = ""; + String openNS = GenUtils.openNS (currentClass); + String closeNS = GenUtils.closeNS (currentClass); + + // Include declaration "CppInclude" + String headerDecl = ""; + CppInclude cppInclude = GenUtils.getApplication(currentClass, CppInclude.class); + if (cppInclude != null) { + headerDecl = "// Include from CppInclude declaration" + NL + cppInclude.getHeader() + NL; + } + + // Prepare owner package header include + Package ownerPackage = currentClass.getPackage(); + String ownerInclude = ""; + if (ownerPackage != null) { + // Create an util template to prepare the declaration + CppOwnerPackageIncludeDeclaration jetOwnerInclude + = new CppOwnerPackageIncludeDeclaration(); + // Execute the util template + ownerInclude = jetOwnerInclude.generate(ownerPackage); + } + + // Retrieve header file suffix + String headerFileSuffix = Activator.getDefault().getPluginPreferences().getString("headSuffix"); + + //find path for the package owning current class + String fullPath = ""; + String separ = ""; + + if (ownerPackage != null) { + fullPath = GenUtils.getFullPath (ownerPackage); + separ = "/"; + } // else fullPath == "" + + org.eclipse.uml2.uml.TemplateBinding tb = GenUtils.getTemplateBindings(currentClass); + + // prepare parent class declaration + EList<org.eclipse.uml2.uml.Element> templates = tb.getTargets(); + Class templateClass = (Class) ((TemplateSignature)templates.get(0)).getOwner(); + classparent = templateClass.getName(); + + // Prepare bindings parameter declaration + + String tParamDecl=""; + TemplateParameterSubstitution paramsub; + Iterator<TemplateParameterSubstitution> tps = tb.getParameterSubstitutions().iterator(); + while(tps.hasNext()) { + paramsub = (TemplateParameterSubstitution)tps.next(); + + CppTemplateBindingParameter jetTParam + = new CppTemplateBindingParameter(); + tParamDecl = tParamDecl+jetTParam.generate(paramsub); + + if (tps.hasNext()) { + tParamDecl = tParamDecl+", "; + } + } + + + // Prepare dependency includes + CppClassAllIncludesDeclaration jetClassIncludes + = new CppClassAllIncludesDeclaration(); + String classIncludes = jetClassIncludes.generate(argument); + if (!classIncludes.equals("")) { + classIncludes = "/* Structural includes (inheritance, dependencies... */"+NL+classIncludes; + } + + + +////////////////////////////////////////////////////////////////////////////////////////// +// The following part contains the template +//////////////////////////////////////////////////////////////////////////////////////////%> +#ifndef <%= classFULLNAME %>_H +#define <%= classFULLNAME %>_H + +/************************************************************ + <%= className %> template binding header + ************************************************************/ + +<%= ownerInclude %> + +<%= classIncludes %> + +<%= headerDecl %> + +#include <<%= fullPath %><%= separ %><%= classparent %>.<%= headerFileSuffix %>> + +<%= openNS %> +/************************************************************/ +typedef <%= classparent %> <<%= tParamDecl %>> <%= className %>; + +<%= closeNS %> + +/************************************************************ + End of <%= className %> template binding header + ************************************************************/ + +#endif diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/CppClassBody.cpp.jet b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/CppClassBody.cpp.jet new file mode 100644 index 00000000000..13c3fe6ca9e --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/CppClassBody.cpp.jet @@ -0,0 +1,71 @@ +<%@ jet package = "org.eclipse.papyrus.cpp.codegen.jet"
+ skeleton = "generator.skeleton"
+ imports = "org.eclipse.papyrus.cpp.codegen.Constants org.eclipse.papyrus.cpp.codegen.utils.* org.eclipse.emf.common.util.EList Cpp.CppInclude org.eclipse.uml2.uml.Classifier org.eclipse.uml2.uml.Package org.eclipse.papyrus.cpp.codegen.jet.util.* org.eclipse.papyrus.cpp.codegen.Activator"
+ class = "CppClassBody"
+ %>
+<%
+//////////////////////////////////////////////////////////////////////////////////////////
+// Java preparation
+//////////////////////////////////////////////////////////////////////////////////////////
+
+ // Retrieve the class
+ Classifier currentClass = (Classifier) argument;
+
+ // Get the package name
+ String className = currentClass.getName();
+ String classFullName= GenUtils.getFullName (currentClass);
+ String classFULLNAME= classFullName.toUpperCase();
+
+ // Retrieve header file suffix
+ String headerFileSuffix = Activator.getDefault().getPluginPreferences().getString("headSuffix");
+
+ // TODO - Prepare static attribute
+ String staticAttributes = "";
+
+ // Retrieve owner Package
+ Package owner = currentClass.getPackage();
+ String fullPath = "";
+
+ if (owner != null) {
+ fullPath = GenUtils.getFullPath(owner) + "/";
+ } // else fullPath == ""
+
+ // Prepare attributes and Methods declarations
+ String allOperations = "";
+
+ // Methods
+ CppClassOperationsImplementation jetClassOp
+ = new CppClassOperationsImplementation();
+ allOperations = jetClassOp.generate(currentClass);
+
+//////////////////////////////////////////////////////////////////////////////////////////
+// The following part contains the template
+//////////////////////////////////////////////////////////////////////////////////////////%>
+#define <%= classFULLNAME %>_BODY
+
+/************************************************************
+ <%= className %> class body
+ ************************************************************/
+
+<%= Constants.cppIncPreBodyStart %>
+<%= ClassUtils.getCppIncludePreBody(currentClass)
+%><%= Constants.cppIncPreBodyEnd %>
+
+<%= Constants.includeHFile %>
+#include <<%= fullPath %><%= className %>.<%= headerFileSuffix %>>
+
+<%= Constants.cppIncBodyStart %>
+<%= ClassUtils.getCppIncludeBody(currentClass)
+%><%= Constants.cppIncBodyEnd %>
+
+<%= Constants.derivedIncludes %>
+<%= ClassUtils.createIncludeDecl(currentClass) %>
+
+<%= GenUtils.openNS(currentClass) %>
+<%= ClassUtils.getStaticAttributes(currentClass) %>
+<%= allOperations %>
+<%= GenUtils.closeNS(currentClass) %>
+
+/************************************************************
+ End of <%= className %> class body
+ ************************************************************/
diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/CppClassHeader.h.jet b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/CppClassHeader.h.jet new file mode 100644 index 00000000000..44e20527cd4 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/CppClassHeader.h.jet @@ -0,0 +1,191 @@ +<%@ jet package = "org.eclipse.papyrus.cpp.codegen.jet"
+ skeleton = "generator.skeleton"
+ imports = "org.eclipse.papyrus.cpp.codegen.utils.GenUtils Cpp.CppInclude org.eclipse.papyrus.cpp.codegen.StdStereo org.eclipse.uml2.uml.Package org.eclipse.uml2.uml.* org.eclipse.papyrus.cpp.codegen.jet.util.* org.eclipse.papyrus.cpp.codegen.jet.doc.*"
+ class = "CppClassHeader"
+ %>
+<%
+//////////////////////////////////////////////////////////////////////////////////////////
+// Java preparation
+//////////////////////////////////////////////////////////////////////////////////////////
+
+
+ // Retrieve the class
+ Classifier currentClass = (Classifier) argument;
+
+ // Get the package name
+ String className = currentClass.getName();
+ String classFULLNAME = GenUtils.getFullName (currentClass).toUpperCase();
+ String openNS = GenUtils.openNS (currentClass);
+ String closeNS = GenUtils.closeNS (currentClass);
+ String classDoc = "";
+ String classOrStruct = (currentClass instanceof DataType) ? "struct" : "class";
+
+ // Doc for the class
+ CppElementDoc jDoc = new CppElementDoc();
+ classDoc = jDoc.generate(currentClass);
+
+ String includeProtection;
+
+ // Include declaration "CppInclude"
+ String headerDecl = "";
+ CppInclude cppInclude = GenUtils.getApplication(currentClass, CppInclude.class);
+ if (cppInclude != null) {
+ headerDecl = GenUtils.maskNull(cppInclude.getHeader());
+ if (headerDecl.length() > 0) {
+ headerDecl = "// Include from CppInclude declaration" + NL + headerDecl.replace("HFILENAME", classFULLNAME) + NL;
+ }
+ }
+
+ // Prepare owner package header include
+ Package ownerPackage = currentClass.getPackage();
+ String ownerInclude = "";
+ if (ownerPackage != null) {
+ // Create an util template to prepare the declaration
+ CppOwnerPackageIncludeDeclaration jetOwnerInclude
+ = new CppOwnerPackageIncludeDeclaration();
+ // Execute the util template
+ ownerInclude = jetOwnerInclude.generate(ownerPackage);
+ }
+
+
+ // Prepare owned type and enum declaration
+ String typeEnumDefPackage = "";
+ String typeEnumDef = "";
+
+ CppClassTypeAndEnum jetTE = new CppClassTypeAndEnum();
+ typeEnumDef = jetTE.generate(currentClass);
+
+ CppClassTypeAndEnumPackage jetTEp
+ = new CppClassTypeAndEnumPackage();
+ typeEnumDefPackage = jetTEp.generate(currentClass);
+
+
+ // Prepare dependency includes
+ CppClassAllIncludesDeclaration jetClassIncludes
+ = new CppClassAllIncludesDeclaration();
+ String classIncludes = jetClassIncludes.generate(argument);
+ if (!classIncludes.equals("")) {
+ classIncludes = "/* Structural includes (inheritance, dependencies... */"+NL+classIncludes;
+ }
+
+ // Prepare friend dependency includes
+ CppClassIncludeFriendDeclaration jetClassFIncludes
+ = new CppClassIncludeFriendDeclaration();
+ String friendIncludes = jetClassFIncludes.generate(argument);
+ if (!friendIncludes.equals("")) {
+ friendIncludes = "/* Friend class declaration */"+NL+friendIncludes;
+ }
+
+ // Prepare attributes and Methods declarations
+ String publicAttributes = "";
+ String publicOperations = "";
+ String protectedAttributes = "";
+ String protectedOperations = "";
+ String privateAttributes = "";
+ String privateOperations = "";
+ String packageAttributes = "";
+ String packageOperations = "";
+
+ // Attributes
+ CppClassAttributesDeclaration jetClassPAttr = new CppClassAttributesDeclaration();
+ publicAttributes = jetClassPAttr.generate(currentClass, VisibilityKind.PUBLIC_LITERAL);
+ protectedAttributes = jetClassPAttr.generate(currentClass, VisibilityKind.PROTECTED_LITERAL);
+ privateAttributes = jetClassPAttr.generate(currentClass, VisibilityKind.PRIVATE_LITERAL);
+ packageAttributes = jetClassPAttr.generate(currentClass, VisibilityKind.PACKAGE_LITERAL);
+
+ // Methods
+ CppClassOperationsDeclaration jetClassPOp = new CppClassOperationsDeclaration();
+ publicOperations = jetClassPOp.generate(currentClass, VisibilityKind.PUBLIC_LITERAL);
+ protectedOperations = jetClassPOp.generate(currentClass, VisibilityKind.PROTECTED_LITERAL);
+ privateOperations = jetClassPOp.generate(currentClass, VisibilityKind.PRIVATE_LITERAL);
+ packageOperations = jetClassPOp.generate(currentClass, VisibilityKind.PACKAGE_LITERAL);
+
+ boolean hasConstructor = false;
+ for (Operation operation : currentClass.getOperations ()) {
+ if (GenUtils.hasStereotype(operation, StdStereo.create)) {
+ hasConstructor = true;
+ break;
+ }
+ }
+ String defaultInitializer = "";
+ for (Property attribute : currentClass.getAttributes ()) {
+ if (attribute.isStatic()) {
+ // static attributes are initialized differently
+ continue;
+ }
+ ValueSpecification vs = attribute.getDefaultValue ();
+ if ((vs != null) && (vs.stringValue() != null)) {
+ if (!defaultInitializer.equals("")) {
+ // not first attribute
+ defaultInitializer += ", ";
+ }
+ defaultInitializer += attribute.getName () + "(" + vs.stringValue() + ")";
+ }
+ }
+ // no constructor, add it, if some properties have default values
+ if ((!hasConstructor) && (!defaultInitializer.equals (""))) {
+ defaultInitializer = className + "() : " + defaultInitializer + " {}";
+ }
+ else {
+ defaultInitializer = "";
+ }
+
+ // Inline functions implementations
+ String inlineFunctionsImplementation = "";
+ CppClassInlineOperationsImplementation jetInlineClassPOp
+ = new CppClassInlineOperationsImplementation();
+ inlineFunctionsImplementation = jetInlineClassPOp.generate(currentClass);
+
+ // Prepare inherited classes or implemented interfaces
+ String inheritedDeclarations = "";
+ CppClassInheritedDeclarations jetInherited
+ = new CppClassInheritedDeclarations();
+ inheritedDeclarations = jetInherited.generate(currentClass);
+
+
+//////////////////////////////////////////////////////////////////////////////////////////
+// The following part contains the template
+//////////////////////////////////////////////////////////////////////////////////////////%>
+#ifndef <%= classFULLNAME %>_H
+#define <%= classFULLNAME %>_H
+
+/************************************************************
+ <%= className %> class header
+ ************************************************************/
+
+<%= ownerInclude %>
+
+<%= classIncludes %>
+
+<%= headerDecl %>
+<%= openNS %>
+<%= typeEnumDefPackage %>
+/************************************************************/
+<%= classDoc %>
+<%= classOrStruct %> <%= className %><%= inheritedDeclarations %> {
+<%= friendIncludes %><%= typeEnumDef %>
+
+ public:
+<%= defaultInitializer %><%= publicAttributes %><%= publicOperations %>
+
+ protected:
+<%= protectedAttributes %><%= protectedOperations %>
+
+ private:
+<%= privateAttributes %><%= privateOperations %>
+
+};
+/************************************************************/
+/* External declarations (package visibility) */
+<%= packageAttributes %>
+<%= packageOperations %>
+/************************************************************/
+/* Inline functions */
+<%= inlineFunctionsImplementation %>
+<%= closeNS %>
+
+/************************************************************
+ End of <%= className %> class header
+ ************************************************************/
+
+#endif
diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/CppInterfaceHeader.h.jet b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/CppInterfaceHeader.h.jet new file mode 100644 index 00000000000..29a627bfbdc --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/CppInterfaceHeader.h.jet @@ -0,0 +1,99 @@ +<%@ jet package = "org.eclipse.papyrus.cpp.codegen.jet"
+ skeleton = "generator.skeleton"
+ imports = "org.eclipse.uml2.uml.Interface org.eclipse.uml2.uml.Package Cpp.CppInclude org.eclipse.papyrus.cpp.codegen.utils.GenUtils org.eclipse.papyrus.cpp.codegen.jet.util.* org.eclipse.papyrus.cpp.codegen.jet.doc.*"
+ class = "CppInterfaceHeader"
+ %>
+<%
+//////////////////////////////////////////////////////////////////////////////////////////
+// Java preparation
+//////////////////////////////////////////////////////////////////////////////////////////
+
+ // Retrieve the class
+ Interface currentInterface = (Interface) argument;
+
+ // Get the package name
+ String interfaceName = currentInterface.getName();
+ String interfaceFULLNAME = GenUtils.getFullNameUC (currentInterface);
+
+ // For interface documentation
+ String iDoc = "";
+
+ // Retrieve enum doc
+ CppElementDoc jDoc = new CppElementDoc();
+ iDoc = jDoc.generate(currentInterface);
+
+ // Include declaration "CppInclude"
+ String headerDecl = "";
+ CppInclude cppInclude = GenUtils.getApplication(currentInterface, CppInclude.class);
+ if (cppInclude != null) {
+ headerDecl = "// Include from CppInclude declaration" + NL + cppInclude.getHeader() + NL;
+ }
+
+ // Prepare owner package header include
+ Package ownerPackage = currentInterface.getPackage();
+ String ownerInclude = "";
+ if (ownerPackage != null) {
+ // Create an util template to prepare the declaration
+ CppOwnerPackageIncludeDeclaration jetOwnerInclude
+ = new CppOwnerPackageIncludeDeclaration();
+ // Execute the util template
+ ownerInclude = jetOwnerInclude.generate(ownerPackage);
+ }
+
+
+ // Prepare dependency includes
+ CppInterfaceAllIncludesDeclaration jetInterfaceIncludes
+ = new CppInterfaceAllIncludesDeclaration();
+ String interfaceIncludes = jetInterfaceIncludes.generate(argument);
+ if (!interfaceIncludes.equals("")) {
+ interfaceIncludes = "/* Structural includes (inheritance, dependencies, ... */"+NL+interfaceIncludes;
+ }
+
+ // Prepare Methods declarations
+ String publicOperations = "";
+
+ // Methods
+ CppInterfacePublicOperationsDeclaration jetPublicInterfacePOp
+ = new CppInterfacePublicOperationsDeclaration();
+ publicOperations = jetPublicInterfacePOp.generate(currentInterface);
+
+
+ // Prepare inherited interfaces
+ String inheritedDeclarations = "";
+ CppInterfaceInheritedDeclarations jetInherited
+ = new CppInterfaceInheritedDeclarations();
+ inheritedDeclarations = jetInherited.generate(currentInterface);
+
+
+//////////////////////////////////////////////////////////////////////////////////////////
+// The following part contains the template
+//////////////////////////////////////////////////////////////////////////////////////////%>
+#ifndef <%= interfaceFULLNAME %>_H
+#define <%= interfaceFULLNAME %>_H
+
+/************************************************************
+ <%= interfaceName %> interface header
+ ************************************************************/
+
+<%= ownerInclude %>
+
+<%= interfaceIncludes %>
+
+<%= headerDecl %>
+<%= GenUtils.openNS(currentInterface) %>
+/************************************************************/
+<%= iDoc %>
+class <%= interfaceName %> <%= inheritedDeclarations %>{
+
+/* Public declarations */
+public:
+<%= publicOperations %>
+
+};
+
+/************************************************************
+ End of <%= interfaceName %> interface header
+ ************************************************************/
+<%= GenUtils.closeNS(currentInterface) %>
+
+#endif
diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/CppPackageHeader.h.jet b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/CppPackageHeader.h.jet new file mode 100644 index 00000000000..e0a61e00335 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/CppPackageHeader.h.jet @@ -0,0 +1,138 @@ +<%@ jet package = "org.eclipse.papyrus.cpp.codegen.jet"
+ skeleton = "generator.skeleton"
+ imports = "org.eclipse.papyrus.cpp.codegen.utils.GenUtils Cpp.CppInclude Cpp.CppNoCodeGen org.eclipse.uml2.uml.* org.eclipse.uml2.uml.Package org.eclipse.emf.common.util.EList org.eclipse.papyrus.cpp.codegen.jet.util.* org.eclipse.papyrus.cpp.codegen.jet.doc.* java.util.Iterator java.util.Set java.util.HashSet org.eclipse.papyrus.cpp.codegen.Activator"
+ class = "CppPackageHeader"
+%>
+<%
+//////////////////////////////////////////////////////////////////////////////////////////
+// Java preparation
+//////////////////////////////////////////////////////////////////////////////////////////
+
+ // Retrieve the package
+ Package currentPackage = (Package) argument;
+ Package fatherPackage = currentPackage.getNestingPackage(); // return owner package
+
+ // Get the package name
+ String packageName = currentPackage.getName();
+ String packageFULLNAME = GenUtils.getFullName (currentPackage).toUpperCase();
+ String openNS = GenUtils.openNS (currentPackage) + "namespace " + currentPackage.getName () + " {\n";
+ String closeNS = "} // of namespace" + currentPackage.getName () + "\n" + GenUtils.closeNS (currentPackage);
+
+ // Prepare the header declarations for this package
+ String headerDecl = "";
+ CppInclude cppInclude = GenUtils.getApplication(currentPackage, CppInclude.class);
+ if (cppInclude != null) {
+ headerDecl = "// Include from CppInclude declaration" + NL + cppInclude.getHeader() + NL;
+ }
+
+ // Retrieve header file suffix
+ String headerFileSuffix = Activator.getDefault().getPluginPreferences().getString("headSuffix");
+
+
+ // Prepare Father include declaration
+ String fatherPkgInclude = "";
+ if (fatherPackage != null) {
+ // Create an util template to prepare the declaration
+ CppOwnerPackageIncludeDeclaration jetPkgInclude
+ = new CppOwnerPackageIncludeDeclaration();
+ // Execute the util template
+ fatherPkgInclude = jetPkgInclude.generate(fatherPackage);
+ }
+
+
+ // Prepare Dependency includes declarations ...
+ // Retrieve package used by current package (dependencies)
+
+ String cFullName = ""; // used in java to contruct and in template to read list
+
+ // Get packages linked by dependencies
+ EList<Package> usedPackages = GenUtils.getUsedPackages (currentPackage);
+ Set<String> usedPackagesNames = new HashSet<String>();
+ // Add imported packages
+ usedPackages.addAll(currentPackage.getImportedPackages());
+
+ Iterator<Package> usedPackagesIt = usedPackages.iterator();
+ Iterator<String> usedPackagesNamesIt;
+
+ // Refactor as a new Set containing names to be declared for packages (with path)
+ while(usedPackagesIt.hasNext()) {
+ Package currentUsedPackage = usedPackagesIt.next();
+ String cPackageName = currentUsedPackage.getName();
+ String cPackagePath = GenUtils.getFullPath (currentUsedPackage);
+
+ cFullName = cPackagePath+"/Pkg_"+cPackageName;
+
+ // Add this name to the set if codegen stereotype is not applied
+ PackageImport packImport = currentPackage.getPackageImport(currentUsedPackage);
+ if(!GenUtils.hasStereotype(packImport, CppNoCodeGen.class)) {
+ if (!GenUtils.hasStereotype(currentUsedPackage, CppNoCodeGen.class)) {
+ usedPackagesNames.add(cFullName);
+ }
+ }
+ }
+
+ // and prepare the Iterator for the template...
+ usedPackagesNamesIt = usedPackagesNames.iterator();
+
+
+
+ // Prepare owned type and enum declaration
+ String typeDef = "";
+ String enumDef = "";
+
+ Iterator<Type> typeIt = currentPackage.getOwnedTypes().iterator();
+ while (typeIt.hasNext()) {
+ Type currentElt = typeIt.next();
+ if (!GenUtils.hasStereotype(currentElt, CppNoCodeGen.class)) {
+ if (currentElt instanceof org.eclipse.uml2.uml.PrimitiveType) {
+
+ PrimitiveType currentType = (PrimitiveType) currentElt;
+ CppPrimitiveTypeDefinition jetPrimitiveType = new CppPrimitiveTypeDefinition();
+ // Execute the util template
+ typeDef = typeDef+jetPrimitiveType.generate(currentType);
+
+ } else if (currentElt instanceof org.eclipse.uml2.uml.Enumeration) {
+
+ Enumeration currentEnum = (Enumeration) currentElt;
+ CppEnumerationDefinition jetEnum = new CppEnumerationDefinition();
+ // Execute the util template
+ enumDef = enumDef+jetEnum.generate(currentEnum);
+
+ }
+ }
+ }
+
+
+//////////////////////////////////////////////////////////////////////////////////////////
+// The following part contains the template
+//////////////////////////////////////////////////////////////////////////////////////////%>
+#ifndef PKG_<%= packageFULLNAME %>
+#define PKG_<%= packageFULLNAME %>
+
+/************************************************************
+ Pkg_<%= packageName %> package header
+ ************************************************************/
+
+<%= fatherPkgInclude %>
+
+/* Package dependency header include */
+<% // For every depency linked package
+ while(usedPackagesNamesIt.hasNext()) {
+ cFullName = (String) usedPackagesNamesIt.next(); %>
+#include <<%= cFullName %>.<%= headerFileSuffix %>>
+<% } %>
+
+/* CppInclude header declarations insert */
+<%= headerDecl %>
+
+<%= openNS %>
+/* Types Defined in the package */
+<%= typeDef %>
+<%= enumDef %>
+<%= closeNS %>
+
+/************************************************************
+ End of Pkg_<%= packageName %> package header
+ ************************************************************/
+
+#endif
diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/CppTemplateHeader.h.jet b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/CppTemplateHeader.h.jet new file mode 100644 index 00000000000..4b72e7c51c0 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/CppTemplateHeader.h.jet @@ -0,0 +1,202 @@ +<%@ jet package = "org.eclipse.papyrus.cpp.codegen.jet"
+ skeleton = "generator.skeleton"
+ imports = "org.eclipse.papyrus.cpp.codegen.jet.doc.* org.eclipse.uml2.uml.Package org.eclipse.uml2.uml.Class org.eclipse.uml2.uml.* org.eclipse.papyrus.cpp.codegen.jet.util.* Cpp.CppInclude Cpp.CppNoCodeGen Cpp.CppInline org.eclipse.papyrus.cpp.codegen.utils.GenUtils java.util.*"
+ class = "CppTemplateHeader"
+ %>
+<%
+//////////////////////////////////////////////////////////////////////////////////////////
+// Java preparation
+//////////////////////////////////////////////////////////////////////////////////////////
+
+ // Retrieve the class
+ Classifier currentClass = (Classifier) argument;
+
+ // Get the package name
+ String className = currentClass.getName();
+ String classFullName = GenUtils.getFullName(currentClass);
+ String classFULLNAME = classFullName.toUpperCase();
+ String openNS = GenUtils.openNS (currentClass);
+ String closeNS = GenUtils.closeNS (currentClass);
+
+ // Include declaration "CppInclude"
+ String headerDecl = "";
+ CppInclude cppInclude = GenUtils.getApplication(currentClass, CppInclude.class);
+ if (cppInclude != null) {
+ headerDecl = "// Include from CppInclude declaration" + NL + cppInclude.getHeader() + NL;
+ }
+
+ // Prepare owner package header include
+ Package ownerPackage = currentClass.getPackage();
+ String ownerInclude = "";
+ if (ownerPackage != null) {
+ // Create an util template to prepare the declaration
+ CppOwnerPackageIncludeDeclaration jetOwnerInclude = new CppOwnerPackageIncludeDeclaration();
+ // Execute the util template
+ ownerInclude = jetOwnerInclude.generate(ownerPackage);
+ }
+
+ // Prepare owned type and enum declaration
+ String typeEnumDefPackage = "";
+ String typeEnumDef = "";
+
+ CppClassTypeAndEnum jetTE = new CppClassTypeAndEnum();
+ typeEnumDef = jetTE.generate(currentClass);
+
+ CppClassTypeAndEnumPackage jetTEp = new CppClassTypeAndEnumPackage();
+ typeEnumDefPackage = jetTEp.generate(currentClass);
+
+ // Prepare template parameter declaration
+ Iterator<org.eclipse.uml2.uml.TemplateParameter> tparam =
+ GenUtils.getTemplateParameters(currentClass).iterator();
+
+ String tParamDecl = "";
+ String tDecl = "";
+
+ while (tparam.hasNext()) {
+ CppTemplateParameter jetTParam = new CppTemplateParameter();
+ tParamDecl = tParamDecl + jetTParam.generate(tparam.next());
+
+ if (tparam.hasNext()) {
+ tParamDecl = tParamDecl + ", ";
+ }
+ }
+
+ tDecl = "template <" + tParamDecl + ">" + NL;
+
+ // Prepare dependency includes
+ CppClassAllIncludesDeclaration jetClassIncludes = new CppClassAllIncludesDeclaration();
+ String classIncludes = jetClassIncludes.generate(argument);
+ if (!classIncludes.equals("")) {
+ classIncludes = "/* Structural includes (inheritance, dependencies... */"
+ + NL + classIncludes;
+ }
+
+ // Prepare attributes and Methods declarations
+ String publicAttributes = "";
+ String protectedAttributes = "";
+ String privateAttributes = "";
+ String publicOperations = "", publicOperationsImpl = "";
+ String protectedOperations = "", protectedOperationsImpl = "";
+ String privateOperations = "", privateOperationsImpl = "";
+
+ // Attributes
+ CppClassAttributesDeclaration jetClassPAttr = new CppClassAttributesDeclaration();
+ publicAttributes = jetClassPAttr.generate(currentClass, VisibilityKind.PUBLIC_LITERAL);
+ protectedAttributes = jetClassPAttr.generate(currentClass, VisibilityKind.PROTECTED_LITERAL);
+ privateAttributes = jetClassPAttr.generate(currentClass, VisibilityKind.PRIVATE_LITERAL);
+
+ // Methods implementation
+ String inlineFuncImpl = "";
+ // String inlineFuncDecl = "";
+
+ // Implementation
+ CppOperationTemplateImplementation jetOpImpl = new CppOperationTemplateImplementation();
+ // Declaration
+ CppOperationDeclaration jetOpDecl = new CppOperationDeclaration();
+
+ // Retrieve operations
+ Iterator<Operation> operations = currentClass.getOperations().iterator();
+ while (operations.hasNext()) {
+ Operation currentOperation = operations.next();
+
+ if (GenUtils.hasStereotype(currentOperation, CppNoCodeGen.class) ||
+ currentOperation.isAbstract()) {
+ continue;
+ }
+ if (GenUtils.hasStereotype(currentOperation, CppInline.class)) {
+ String opDoc = "";
+ // Doc for the template
+ CppOperationDoc jDoc = new CppOperationDoc();
+ opDoc = jDoc.generate(currentOperation);
+ // Inline declaration
+ if (currentOperation.getVisibility() == VisibilityKind.PUBLIC_LITERAL) {
+ publicOperations = publicOperations
+ + jetOpDecl.generate(currentOperation) + ";";
+ } else if (currentOperation.getVisibility() == VisibilityKind.PRIVATE_LITERAL) {
+ privateOperations = privateOperations
+ + jetOpDecl.generate(currentOperation) + ";";
+ } else if (currentOperation.getVisibility() == VisibilityKind.PROTECTED_LITERAL) {
+ protectedOperations = protectedOperations
+ + jetOpDecl.generate(currentOperation) + ";";
+ } // else nothing
+ // Inline implementation
+ inlineFuncImpl = inlineFuncImpl + opDoc + NL + tDecl
+ + jetOpImpl.generate(currentOperation) + NL;
+ } else {
+ if (currentOperation.getVisibility() == VisibilityKind.PUBLIC_LITERAL) {
+ publicOperationsImpl = publicOperationsImpl + tDecl
+ + jetOpImpl.generate(currentOperation);
+ publicOperations = publicOperations
+ + jetOpDecl.generate(currentOperation) + ";";
+ } else if (currentOperation.getVisibility() == VisibilityKind.PRIVATE_LITERAL) {
+ privateOperationsImpl = privateOperationsImpl + tDecl
+ + jetOpImpl.generate(currentOperation);
+ privateOperations = privateOperations
+ + jetOpDecl.generate(currentOperation) + ";";
+ } else if (currentOperation.getVisibility() == VisibilityKind.PROTECTED_LITERAL) {
+ protectedOperationsImpl = protectedOperationsImpl + tDecl
+ + jetOpImpl.generate(currentOperation);
+ protectedOperations = protectedOperations
+ + jetOpDecl.generate(currentOperation) + ";";
+ } // else nothing
+ }
+ }
+
+ // Prepare inherited classes or implemented interfaces
+ String inheritedDeclarations = "";
+ CppClassInheritedDeclarations jetInherited = new CppClassInheritedDeclarations();
+ inheritedDeclarations = jetInherited.generate(currentClass);
+
+
+//////////////////////////////////////////////////////////////////////////////////////////
+// The following part contains the template
+//////////////////////////////////////////////////////////////////////////////////////////%>
+#ifndef <%= classFULLNAME %>_H
+#define <%= classFULLNAME %>_H
+
+/************************************************************
+ <%= className %> template class header
+ ************************************************************/
+
+<%= ownerInclude %>
+
+<%= classIncludes %>
+
+<%= headerDecl %>
+<%= openNS %>
+<%= typeEnumDefPackage %>
+/************************************************************/
+template <<%= tParamDecl %>> class <%= className %> <%= inheritedDeclarations %>{
+<%= typeEnumDef %>
+/* Public declarations */
+public:
+<%= publicAttributes %>
+<%= publicOperations %>
+
+/* Protected declarations */
+protected:
+<%= protectedAttributes %>
+<%= protectedOperations %>
+
+/* Private declarations */
+private:
+<%= privateAttributes %>
+<%= privateOperations %>
+
+};
+
+/************************************************************/
+/* Template functions */
+<%= publicOperationsImpl %>
+<%= protectedOperationsImpl %>
+<%= privateOperationsImpl %>
+/* Inline functions */
+<%= inlineFuncImpl %>
+
+<%= closeNS %>
+
+/************************************************************
+ End of <%= className %> template class header
+ ************************************************************/
+
+#endif
diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/doc/CppElementDoc.doc.jet b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/doc/CppElementDoc.doc.jet new file mode 100644 index 00000000000..2a0e5b591c7 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/doc/CppElementDoc.doc.jet @@ -0,0 +1,27 @@ +<%@ jet package = "org.eclipse.papyrus.cpp.codegen.jet.doc"
+ skeleton = "../generator.skeleton"
+ imports = "org.eclipse.uml2.uml.Element org.eclipse.papyrus.cpp.codegen.utils.GenUtils"
+ class = "CppElementDoc"
+ %>
+<%
+//////////////////////////////////////////////////////////////////////////////////////////
+// Java preparation
+//////////////////////////////////////////////////////////////////////////////////////////
+
+ // Retrieve the element
+ Element currentElt = (Element) argument;
+ String eltDoc = "";
+
+
+ // Doc for the element
+ eltDoc = GenUtils.getComments(currentElt);
+ eltDoc = eltDoc.replaceAll(NL, NL+" * ");
+
+
+
+//////////////////////////////////////////////////////////////////////////////////////////
+// The following part contains the template
+//////////////////////////////////////////////////////////////////////////////////////////%>
+/**
+ * <%= eltDoc %>
+ */
\ No newline at end of file diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/doc/CppOperationDoc.doc.jet b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/doc/CppOperationDoc.doc.jet new file mode 100644 index 00000000000..de8ebf7cc19 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/doc/CppOperationDoc.doc.jet @@ -0,0 +1,47 @@ +<%@ jet package = "org.eclipse.papyrus.cpp.codegen.jet.doc"
+ skeleton = "../generator.skeleton"
+ imports = "org.eclipse.uml2.uml.Operation org.eclipse.uml2.uml.Parameter org.eclipse.papyrus.cpp.codegen.utils.GenUtils java.util.Iterator"
+ class = "CppOperationDoc"
+ %>
+<%
+//////////////////////////////////////////////////////////////////////////////////////////
+// Java preparation
+//////////////////////////////////////////////////////////////////////////////////////////
+
+ // Retrieve the element
+ Operation currentOperation = (Operation) argument;
+ Parameter currentParameter;
+
+ String opDoc = "";
+ String opParams = "";
+// String opReturn = "";
+// TODO: return not handled? (or treated as any other parameter?)
+
+ // Doc for the element
+ opDoc = GenUtils.getComments(currentOperation);
+ opDoc = opDoc.replaceAll(NL, NL+" * ");
+
+ // Treat params
+ Iterator<Parameter> parameters = currentOperation.getOwnedParameters().iterator();
+ while(parameters.hasNext()) {
+ currentParameter = (Parameter) parameters.next();
+
+ // Prepare parameters
+ CppParamDoc jetParam = new CppParamDoc();
+ opParams = opParams+jetParam.generate(currentParameter);
+
+ if (parameters.hasNext()){
+ opParams = opParams+NL+" * ";
+ }
+ }
+
+ // Treat return
+
+
+//////////////////////////////////////////////////////////////////////////////////////////
+// The following part contains the template
+//////////////////////////////////////////////////////////////////////////////////////////%>
+/**
+ * <%= opDoc %>
+ * <%= opParams %>
+ */
\ No newline at end of file diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/doc/CppParamDoc.doc.jet b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/doc/CppParamDoc.doc.jet new file mode 100644 index 00000000000..4e8e2ee3fda --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/doc/CppParamDoc.doc.jet @@ -0,0 +1,23 @@ +<%@ jet package = "org.eclipse.papyrus.cpp.codegen.jet.doc"
+ skeleton = "../generator.skeleton"
+ imports = "org.eclipse.uml2.uml.Parameter org.eclipse.papyrus.cpp.codegen.utils.GenUtils"
+ class = "CppParamDoc"
+ %>
+<%
+//////////////////////////////////////////////////////////////////////////////////////////
+// Java preparation
+//////////////////////////////////////////////////////////////////////////////////////////
+
+ // Retrieve the element
+ Parameter currentElt = (Parameter) argument;
+
+ String paramName = currentElt.getName();
+ String paramDoc = GenUtils.getComments(currentElt);
+
+ paramDoc = paramDoc.replaceAll(NL, NL+" * ");
+
+
+//////////////////////////////////////////////////////////////////////////////////////////
+// The following part contains the template
+//////////////////////////////////////////////////////////////////////////////////////////%>
+@param <%= paramName %> <%= paramDoc %>
\ No newline at end of file diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/generator.skeleton b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/generator.skeleton new file mode 100644 index 00000000000..aa011c805d5 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/generator.skeleton @@ -0,0 +1,19 @@ +/*******************************************************************************
+ * Copyright (c) 2006 CEA List.
+ * All rights reserved. This program and the accompanying materials
+ * are property of the CEA, their use is subject to specific agreement
+ * with the CEA.
+ *
+ * Contributors:
+ * CEA List - initial API and implementation
+ *******************************************************************************/
+
+package PACKAGE;
+
+public class CLASS
+{
+ public String generate(Object argument)
+ {
+ return "";
+ }
+}
\ No newline at end of file diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/generatorTwoArgs.skeleton b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/generatorTwoArgs.skeleton new file mode 100644 index 00000000000..1e268756e0c --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/generatorTwoArgs.skeleton @@ -0,0 +1,19 @@ +/*******************************************************************************
+ * Copyright (c) 2006 CEA List.
+ * All rights reserved. This program and the accompanying materials
+ * are property of the CEA, their use is subject to specific agreement
+ * with the CEA.
+ *
+ * Contributors:
+ * CEA List - initial API and implementation
+ *******************************************************************************/
+
+package PACKAGE;
+
+public class CLASS
+{
+ public String generate(Object argument1, Object argument2)
+ {
+ return "";
+ }
+}
\ No newline at end of file diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/util/class/CppClassAllIncludesDeclaration.util.jet b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/util/class/CppClassAllIncludesDeclaration.util.jet new file mode 100644 index 00000000000..b872a010e91 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/util/class/CppClassAllIncludesDeclaration.util.jet @@ -0,0 +1,47 @@ +<%@ jet package = "org.eclipse.papyrus.cpp.codegen.jet.util"
+ skeleton = "../../generator.skeleton"
+ imports = "Cpp.* org.eclipse.papyrus.cpp.codegen.utils.* org.eclipse.uml2.uml.Class org.eclipse.emf.common.util.EList org.eclipse.uml2.uml.Package org.eclipse.emf.common.util.UniqueEList java.util.* org.eclipse.uml2.uml.PrimitiveType org.eclipse.uml2.uml.Enumeration org.eclipse.uml2.uml.Classifier"
+ class = "CppClassAllIncludesDeclaration"
+%>
+<%
+//////////////////////////////////////////////////////////////////////////////////////////
+// Java preparation
+//////////////////////////////////////////////////////////////////////////////////////////
+
+ // Retrieve the class
+ Classifier currentClass = (Classifier) argument;
+
+ // Get the package name
+ // String className = currentClass.getName();
+
+ // Prepare Dependency includes declarations ...
+ // Retrieve package used by current package (dependencies)
+ // use a unique list to avoid duplicates
+ EList<Classifier> usedClasses = new UniqueEList<Classifier> ();
+
+ String newInclude = "";
+
+ // 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));
+ }
+ // 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));
+
+ Iterator<Classifier> usedClassesIt = usedClasses.iterator();
+ // Parsing all as NamedElement
+ String includes = ClassUtils.createIncludeDecl (usedClasses, currentClass);
+
+//////////////////////////////////////////////////////////////////////////////////////////
+// The following part contains the template
+//////////////////////////////////////////////////////////////////////////////////////////%>
+<%= includes %>
+
diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/util/class/CppClassAttributesDeclaration.util.jet b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/util/class/CppClassAttributesDeclaration.util.jet new file mode 100644 index 00000000000..a1c1ebc1f4a --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/util/class/CppClassAttributesDeclaration.util.jet @@ -0,0 +1,28 @@ +<%@ jet package = "org.eclipse.papyrus.cpp.codegen.jet.util"
+ skeleton = "../../generatorTwoArgs.skeleton"
+ imports = "org.eclipse.uml2.uml.* java.util.Iterator"
+ class = "CppClassAttributesDeclaration"
+%>
+<%
+//////////////////////////////////////////////////////////////////////////////////////////
+// Java preparation
+//////////////////////////////////////////////////////////////////////////////////////////
+
+ // Retrieve the class
+ Classifier currentClass = (Classifier) argument1;
+ String attrDecl = "";
+
+ // Retrieve public attributes
+ Iterator<Property> attributes = currentClass.getAttributes().iterator();
+ while (attributes.hasNext()) {
+ Property attribute = attributes.next();
+ if (attribute.getVisibility() == argument2) {
+ CppAttributeDeclaration jetAttDecl = new CppAttributeDeclaration();
+ attrDecl = attrDecl+jetAttDecl.generate(attribute);
+ }
+ }
+
+//////////////////////////////////////////////////////////////////////////////////////////
+// The following part contains the template
+//////////////////////////////////////////////////////////////////////////////////////////%>
+<%= attrDecl %>
\ No newline at end of file diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/util/class/CppClassFriendDeclaration.util.jet b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/util/class/CppClassFriendDeclaration.util.jet new file mode 100644 index 00000000000..ddfb72badfc --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/util/class/CppClassFriendDeclaration.util.jet @@ -0,0 +1,18 @@ +<%@ jet package = "org.eclipse.papyrus.cpp.codegen.jet.util"
+ skeleton = "../../generator.skeleton"
+ imports = "org.eclipse.uml2.uml.NamedElement"
+ class = "CppClassFriendDeclaration"
+%>
+<%
+//////////////////////////////////////////////////////////////////////////////////////////
+// Java preparation
+//////////////////////////////////////////////////////////////////////////////////////////
+
+ // Retrieve the class
+ NamedElement currentNE = (NamedElement) argument;
+ String cClassName = currentNE.getName();
+
+//////////////////////////////////////////////////////////////////////////////////////////
+// The following part contains the template
+//////////////////////////////////////////////////////////////////////////////////////////%>
+friend class <%= cClassName %>;
diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/util/class/CppClassIncludeClassDeclaration.util.jet b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/util/class/CppClassIncludeClassDeclaration.util.jet new file mode 100644 index 00000000000..41949a00117 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/util/class/CppClassIncludeClassDeclaration.util.jet @@ -0,0 +1,28 @@ +<%@ jet package = "org.eclipse.papyrus.cpp.codegen.jet.util"
+ skeleton = "../../generator.skeleton"
+ imports = "org.eclipse.uml2.uml.NamedElement org.eclipse.papyrus.cpp.codegen.utils.GenUtils Cpp.*"
+ class = "CppClassIncludeClassDeclaration"
+%>
+<%
+//////////////////////////////////////////////////////////////////////////////////////////
+// Java preparation
+//////////////////////////////////////////////////////////////////////////////////////////
+
+ // Retrieve the class
+ NamedElement currentNE = (NamedElement) argument;
+ String cClassName = currentNE.getName();
+ String isTemplate = "";
+ String openNS = GenUtils.openNS (currentNE);
+ String closeNS = GenUtils.closeNS (currentNE);
+
+ if (GenUtils.hasStereotype(currentNE, CppTemplate.class)) {
+ isTemplate = "template ";
+ }
+
+//////////////////////////////////////////////////////////////////////////////////////////
+// The following part contains the template
+//////////////////////////////////////////////////////////////////////////////////////////%>
+
+<%= openNS %>
+<%= isTemplate %>class <%= cClassName %>;
+<%= closeNS %>
diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/util/class/CppClassIncludeDeclaration.util.jet b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/util/class/CppClassIncludeDeclaration.util.jet new file mode 100644 index 00000000000..e00089131b3 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/util/class/CppClassIncludeDeclaration.util.jet @@ -0,0 +1,49 @@ +<%@ jet package = "org.eclipse.papyrus.cpp.codegen.jet.util"
+ skeleton = "../../generator.skeleton"
+ imports = "org.eclipse.uml2.uml.NamedElement org.eclipse.uml2.uml.Package org.eclipse.papyrus.cpp.codegen.Activator org.eclipse.papyrus.cpp.codegen.utils.GenUtils Cpp.*"
+ class = "CppClassIncludeDeclaration"
+%>
+<%
+//////////////////////////////////////////////////////////////////////////////////////////
+// Java preparation
+//////////////////////////////////////////////////////////////////////////////////////////
+
+
+ // Retrieve header file suffix
+ String headerFileSuffix = Activator.getDefault().getPluginPreferences().getString("headSuffix");
+
+
+ // Retrieve the class
+ NamedElement currentNE = (NamedElement) argument;
+ String cClassPath = "";
+ Package nearestPkg = currentNE.getNearestPackage();
+ String cClassName = currentNE.getName();
+
+ if ( //!(nearestPkg.getUml2Package() instanceof org.eclipse.uml2.uml.Model)
+ /*&& */!(GenUtils.hasStereotype(nearestPkg, CppRoot.class))) {
+ cClassPath = GenUtils.getFullPath(nearestPkg)+"/";
+ }
+
+
+ // If an external class is referred
+ CppExternClass extClass = GenUtils.getApplication(currentNE, CppExternClass.class);
+ CppTemplate template = GenUtils.getApplication(currentNE, CppTemplate.class);
+ if (extClass != null) {
+ cClassPath = "";
+ cClassName = extClass.getName();
+ if ((cClassName == null) || cClassName.equals ("")) {
+ // default value
+ cClassName = currentNE.getQualifiedName ().replace ("::", "/") + "." + headerFileSuffix;
+ // strip model name
+ cClassName = cClassName.substring (currentNE.getModel ().getName ().length () + 1);
+ }
+ } else if (template != null) {
+ cClassPath = "";
+ cClassName = template.getDeclaration();
+ }
+ else cClassName=cClassName+"."+headerFileSuffix;
+
+//////////////////////////////////////////////////////////////////////////////////////////
+// The following part contains the template
+//////////////////////////////////////////////////////////////////////////////////////////%>
+#include <<%= cClassPath %><%= cClassName %>>
diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/util/class/CppClassIncludeFriendDeclaration.util.jet b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/util/class/CppClassIncludeFriendDeclaration.util.jet new file mode 100644 index 00000000000..ab1941de515 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/util/class/CppClassIncludeFriendDeclaration.util.jet @@ -0,0 +1,38 @@ +<%@ jet package = "org.eclipse.papyrus.cpp.codegen.jet.util"
+ skeleton = "../../generator.skeleton"
+ imports = "org.eclipse.uml2.uml.* java.util.* org.eclipse.papyrus.cpp.codegen.utils.GenUtils Cpp.*"
+ class = "CppClassIncludeFriendDeclaration"
+%>
+<%
+//////////////////////////////////////////////////////////////////////////////////////////
+// Java preparation
+//////////////////////////////////////////////////////////////////////////////////////////
+
+ // Retrieve the class
+ Classifier currentClass = (Classifier) argument;
+// NamedElement currentElt = (NamedElement) argument;
+
+ // Prepare Dependency includes declarations ...
+ // Retrieve package used by current package (dependencies)
+ Iterator<Classifier> friendClassesIt = GenUtils.getUsedClassifiers(currentClass).iterator();
+
+ // Parsing all as NamedElement
+ String friendClass = "";
+
+ while (friendClassesIt.hasNext()) {
+ Classifier cClass = friendClassesIt.next();
+
+ if (GenUtils.hasStereotype(cClass, CppFriend.class) &&
+ (!GenUtils.hasStereotype(cClass, CppNoCodeGen.class))) {
+
+ CppClassFriendDeclaration jetIDecl
+ = new CppClassFriendDeclaration();
+
+ friendClass = friendClass+jetIDecl.generate(cClass);
+ }
+ }
+
+//////////////////////////////////////////////////////////////////////////////////////////
+// The following part contains the template
+//////////////////////////////////////////////////////////////////////////////////////////%>
+<%= friendClass %>
\ No newline at end of file diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/util/class/CppClassInheritedDeclarations.util.jet b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/util/class/CppClassInheritedDeclarations.util.jet new file mode 100644 index 00000000000..4ed12621cb3 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/util/class/CppClassInheritedDeclarations.util.jet @@ -0,0 +1,96 @@ +<%@ jet package = "org.eclipse.papyrus.cpp.codegen.jet.util"
+ skeleton = "../../generator.skeleton"
+ imports = "org.eclipse.uml2.uml.* java.util.* org.eclipse.papyrus.cpp.codegen.utils.GenUtils Cpp.*"
+ class = "CppClassInheritedDeclarations"
+%>
+<%
+//////////////////////////////////////////////////////////////////////////////////////////
+// Java preparation
+//////////////////////////////////////////////////////////////////////////////////////////
+
+ // Retrieve the class
+ Classifier currentClass = (Classifier) argument;
+ String targetName = "";
+ String visibility = "";
+ String decl = "";
+
+ // Get generalization and implementation relationships
+ Iterator<DirectedRelationship> relationshipIt =
+ currentClass.getSourceDirectedRelationships().iterator();
+ // Iterator impIt = currentClass.getImplementations().iterator();
+
+ while (relationshipIt.hasNext()) {
+
+ DirectedRelationship relationship = relationshipIt.next();
+
+ if ((relationship instanceof Generalization) ||
+ (relationship instanceof InterfaceRealization))
+ {
+ org.eclipse.uml2.uml.Classifier target = null;
+ if (relationship.getTargets ().size() > 0) {
+ // there should always be at least one element in the target
+ // list and it should be a classifier, but better check.
+ org.eclipse.uml2.uml.Element element =
+ relationship.getTargets().get(0);
+ if (element instanceof org.eclipse.uml2.uml.Classifier) {
+ target = (org.eclipse.uml2.uml.Classifier) element;
+ }
+ }
+ if (target != null) {
+ // If not <NoCodeGen>
+ if (!GenUtils.hasStereotype(target, CppNoCodeGen.class))
+ {
+ CppVisibility cppVisibility = GenUtils.getApplication(relationship, CppVisibility.class);
+ if (cppVisibility != null) {
+ visibility = cppVisibility.getValue();
+ } else {
+ visibility = "public";
+ }
+
+ targetName = GenUtils.qualifiedName (target);
+ if (!decl.equals("")) {
+ decl = decl + ", ";
+ }
+ decl = decl+visibility+" "+targetName;
+ }
+ }
+ }
+ }
+
+ // Parse implementations
+ // RS: removed code: Implementation does not exist in UML2 v2.
+ // TODO: replace Implementation with new UML2 constructions?
+// Implementation currentImp;
+//
+// while (impIt.hasNext()) {
+//
+// currentImp = (Implementation) impIt.next();
+// currentNE = (NamedElement) currentImp;
+//
+// // get visibility and target name
+// visibility = currentNE.getVisibilityAsString();
+//
+// // If not <NoCodeGen>
+// if (!GenUtils.hasStereotype(currentImp.getTarget(), CppNoCodeGen.class)) {
+//
+// targetName = currentImp.getTarget().getName();
+//
+// if (!decl.equals("")) {
+// decl = decl + ", ";
+// }
+// decl = decl+visibility+" "+targetName;
+//
+// }
+// }
+
+
+ // ":" if decl non empty
+ String prefix = "";
+ if (!decl.equals("")) {
+ prefix = " : ";
+ }
+
+//////////////////////////////////////////////////////////////////////////////////////////
+// The following part contains the template
+//////////////////////////////////////////////////////////////////////////////////////////%>
+<%= prefix %><%= decl %>
\ No newline at end of file diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/util/class/CppClassInlineOperationsImplementation.util.jet b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/util/class/CppClassInlineOperationsImplementation.util.jet new file mode 100644 index 00000000000..1c8f5382870 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/util/class/CppClassInlineOperationsImplementation.util.jet @@ -0,0 +1,30 @@ +<%@ jet package = "org.eclipse.papyrus.cpp.codegen.jet.util"
+ skeleton = "../../generator.skeleton"
+ imports = "org.eclipse.uml2.uml.* java.util.Iterator org.eclipse.papyrus.cpp.codegen.utils.GenUtils Cpp.*"
+ class = "CppClassInlineOperationsImplementation"
+%>
+<%
+//////////////////////////////////////////////////////////////////////////////////////////
+// Java preparation
+//////////////////////////////////////////////////////////////////////////////////////////
+
+ // Retrieve the class
+ Classifier currentClass = (Classifier) argument;
+ String opDecl = "";
+
+ // Retrieve operations
+ Iterator<Operation> operations = currentClass.getOperations().iterator();
+ while (operations.hasNext()) {
+ Operation currentOp = operations.next();
+ if (GenUtils.hasStereotype (currentOp, CppInline.class) &&
+ !GenUtils.hasStereotype (currentOp, CppNoCodeGen.class)) {
+
+ CppOperationImplementation jetOpImpl = new CppOperationImplementation();
+ opDecl = opDecl+jetOpImpl.generate(currentOp);
+ }
+ }
+
+//////////////////////////////////////////////////////////////////////////////////////////
+// The following part contains the template
+//////////////////////////////////////////////////////////////////////////////////////////%>
+<%= opDecl %>
\ No newline at end of file diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/util/class/CppClassOperationsDeclaration.util.jet b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/util/class/CppClassOperationsDeclaration.util.jet new file mode 100644 index 00000000000..a05242cb999 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/util/class/CppClassOperationsDeclaration.util.jet @@ -0,0 +1,35 @@ +<%@ jet package = "org.eclipse.papyrus.cpp.codegen.jet.util"
+ skeleton = "../../generatorTwoArgs.skeleton"
+ imports = "org.eclipse.uml2.uml.* java.util.Iterator org.eclipse.papyrus.cpp.codegen.utils.GenUtils Cpp.*"
+ class = "CppClassOperationsDeclaration"
+%>
+<%
+//////////////////////////////////////////////////////////////////////////////////////////
+// Java preparation
+//////////////////////////////////////////////////////////////////////////////////////////
+
+ // Retrieve the class
+ Classifier currentClass = (Classifier) argument1;
+ String opDecl = "";
+
+ // Retrieve attributes
+ Iterator<Operation> operations = currentClass.getOperations().iterator();
+ while (operations.hasNext()) {
+ Operation operation = operations.next();
+ if (!GenUtils.hasStereotype (operation, CppNoCodeGen.class)) {
+ if (operation.getVisibility() == argument2) {
+ CppOperationDeclaration jetOpDecl = new CppOperationDeclaration();
+ String cOpDecl = jetOpDecl.generate(operation);
+
+ // if main cOpDecl = "";
+ if (!cOpDecl.equals("")) {
+ opDecl = opDecl+NL+cOpDecl+";";
+ }
+ }
+ }
+ }
+
+//////////////////////////////////////////////////////////////////////////////////////////
+// The following part contains the template
+//////////////////////////////////////////////////////////////////////////////////////////%>
+<%= opDecl %>
\ No newline at end of file diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/util/class/CppClassOperationsImplementation.util.jet b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/util/class/CppClassOperationsImplementation.util.jet new file mode 100644 index 00000000000..0ca8426587b --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/util/class/CppClassOperationsImplementation.util.jet @@ -0,0 +1,30 @@ +<%@ jet package = "org.eclipse.papyrus.cpp.codegen.jet.util"
+ skeleton = "../../generator.skeleton"
+ imports = "org.eclipse.uml2.uml.* java.util.Iterator org.eclipse.papyrus.cpp.codegen.utils.GenUtils Cpp.*"
+ class = "CppClassOperationsImplementation"
+%>
+<%
+//////////////////////////////////////////////////////////////////////////////////////////
+// Java preparation
+//////////////////////////////////////////////////////////////////////////////////////////
+
+ // Retrieve the class
+ Classifier currentClass = (Classifier) argument;
+ String opDecl = "";
+
+ // Retrieve operations
+ Iterator<Operation> operations = currentClass.getOperations().iterator();
+ while (operations.hasNext()) {
+ Operation currentOp = operations.next();
+ if (!GenUtils.hasStereotype (currentOp, CppInline.class) &&
+ !GenUtils.hasStereotype (currentOp, CppNoCodeGen.class) &&
+ !currentOp.isAbstract()) {
+ CppOperationImplementation jetOpImpl = new CppOperationImplementation();
+ opDecl = opDecl+jetOpImpl.generate(currentOp);
+ }
+ }
+
+//////////////////////////////////////////////////////////////////////////////////////////
+// The following part contains the template
+//////////////////////////////////////////////////////////////////////////////////////////%>
+<%= opDecl %>
\ No newline at end of file diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/util/class/CppClassTypeAndEnum.util.jet b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/util/class/CppClassTypeAndEnum.util.jet new file mode 100644 index 00000000000..8901678c6d4 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/util/class/CppClassTypeAndEnum.util.jet @@ -0,0 +1,93 @@ +<%@ jet package = "org.eclipse.papyrus.cpp.codegen.jet.util"
+ skeleton = "../../generator.skeleton"
+ imports = "org.eclipse.papyrus.cpp.codegen.utils.GenUtils org.eclipse.uml2.uml.*"
+ class = "CppClassTypeAndEnum"
+ %>
+<%
+//////////////////////////////////////////////////////////////////////////////////////////
+// Java preparation
+//////////////////////////////////////////////////////////////////////////////////////////
+
+ // Retrieve the class
+ Classifier currentClass = (Classifier) argument;
+
+ // Prepare owned type and enum declaration
+ String publicTypeDef = "";
+ String privateTypeDef = "";
+ String protectedTypeDef = "";
+ String publicEnumDef = "";
+ String privateEnumDef = "";
+ String protectedEnumDef = "";
+ String publicKeyword = "public:";
+ String protectedKeyword = "protected:";
+ String privateKeyword = "private:";
+
+ for (Element currentElt : currentClass.getOwnedElements()) {
+ if (!GenUtils.hasStereotype(currentElt, Cpp.CppNoCodeGen.class)) {
+ if (currentElt instanceof PrimitiveType) {
+
+ org.eclipse.uml2.uml.PrimitiveType currentType = (org.eclipse.uml2.uml.PrimitiveType) currentElt;
+ CppPrimitiveTypeDefinition jetPrimitiveType = new CppPrimitiveTypeDefinition();
+ // Execute the util template
+ if (currentType.getVisibility() == VisibilityKind.PUBLIC_LITERAL) {
+ publicTypeDef = publicTypeDef+jetPrimitiveType.generate(currentType);
+ } else if (currentType.getVisibility() == VisibilityKind.PROTECTED_LITERAL) {
+ protectedTypeDef = protectedTypeDef+jetPrimitiveType.generate(currentType);
+ } else if (currentType.getVisibility() == VisibilityKind.PRIVATE_LITERAL) {
+ privateTypeDef = privateTypeDef+jetPrimitiveType.generate(currentType);
+ }
+ }
+ else if (currentElt instanceof Enumeration) {
+
+ Enumeration currentEnum = (Enumeration) currentElt;
+ CppEnumerationDefinition jetEnum = new CppEnumerationDefinition();
+ // Execute the util template
+ if (currentEnum.getVisibility() == VisibilityKind.PUBLIC_LITERAL) {
+ publicEnumDef = publicEnumDef+jetEnum.generate(currentEnum);
+ } else if (currentEnum.getVisibility() == VisibilityKind.PROTECTED_LITERAL) {
+ protectedEnumDef = protectedEnumDef+jetEnum.generate(currentEnum);
+ } else if (currentEnum.getVisibility() == VisibilityKind.PRIVATE_LITERAL) {
+ privateEnumDef = privateEnumDef+jetEnum.generate(currentEnum);
+ }
+ }
+ }
+ }
+
+ // If not "" add a comment before declarations
+ if (publicTypeDef.equals("") && publicEnumDef.equals("")) {
+ publicKeyword = "";
+ } else {
+ if (!publicTypeDef.equals("")) {
+ publicTypeDef = "/* Public type definitions */"+NL+publicTypeDef+NL;
+ }
+ if (!publicEnumDef.equals("")) {
+ publicEnumDef = "/* Public enumeration definitions */"+NL+publicEnumDef+NL;
+ }
+ }
+
+ if (protectedTypeDef.equals("") && protectedEnumDef.equals("")) {
+ protectedKeyword = "";
+ } else {
+ if (!protectedTypeDef.equals("")) {
+ protectedTypeDef = "/* Protected type definitions */"+NL+protectedTypeDef+NL;
+ }
+ if (!protectedEnumDef.equals("")) {
+ protectedEnumDef = "/* Protected enumeration definitions */"+NL+protectedEnumDef+NL;
+ }
+ }
+
+ if (privateTypeDef.equals("") && privateEnumDef.equals("")) {
+ privateKeyword = "";
+ } else {
+ if (!privateTypeDef.equals("")) {
+ privateTypeDef = "/* Private type definitions */"+NL+privateTypeDef+NL;
+ }
+ if (!privateEnumDef.equals("")) {
+ privateEnumDef = "/* Private enumeration definitions */"+NL+privateEnumDef+NL;
+ }
+ }
+
+//////////////////////////////////////////////////////////////////////////////////////////
+// The following part contains the template
+//////////////////////////////////////////////////////////////////////////////////////////%>
+<%= publicKeyword %><%= publicTypeDef %><%= publicEnumDef %><%= protectedKeyword %><%= protectedTypeDef %><%= protectedEnumDef %><%= privateKeyword %><%= privateTypeDef %><%= privateEnumDef %>
diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/util/class/CppClassTypeAndEnumPackage.util.jet b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/util/class/CppClassTypeAndEnumPackage.util.jet new file mode 100644 index 00000000000..52feb87b245 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/util/class/CppClassTypeAndEnumPackage.util.jet @@ -0,0 +1,59 @@ +<%@ jet package = "org.eclipse.papyrus.cpp.codegen.jet.util"
+ skeleton = "../../generator.skeleton"
+ imports = "org.eclipse.uml2.uml.Class org.eclipse.uml2.uml.* org.eclipse.papyrus.cpp.codegen.utils.GenUtils java.util.Iterator Cpp.*"
+ class = "CppClassTypeAndEnumPackage"
+ %>
+<%
+//////////////////////////////////////////////////////////////////////////////////////////
+// Java preparation
+//////////////////////////////////////////////////////////////////////////////////////////
+
+ // Retrieve the class
+ Classifier currentClass = (Classifier) argument;
+
+
+ // Prepare owned type and enum declaration
+ String packageTypeDef = "";
+ String packageEnumDef = "";
+
+ Iterator<Element> typeIt = currentClass.getOwnedElements().iterator();
+ while (typeIt.hasNext()) {
+ Element currentElt = typeIt.next();
+ if (!GenUtils.hasStereotype(currentElt, CppNoCodeGen.class)) {
+ if (currentElt instanceof PrimitiveType) {
+
+ PrimitiveType currentType = (PrimitiveType) currentElt;
+ CppPrimitiveTypeDefinition jetPrimitiveType = new CppPrimitiveTypeDefinition();
+ // Execute the util template
+ if (currentType.getVisibility() == VisibilityKind.PACKAGE_LITERAL) {
+ packageTypeDef = packageTypeDef+jetPrimitiveType.generate(currentType);
+ }
+
+
+ } else if (currentElt instanceof Enumeration) {
+
+ Enumeration currentEnum = (Enumeration) currentElt;
+ CppEnumerationDefinition jetEnum = new CppEnumerationDefinition();
+ // Execute the util template
+ if (currentEnum.getVisibility() == VisibilityKind.PACKAGE_LITERAL) {
+ packageEnumDef = packageEnumDef+jetEnum.generate(currentEnum);
+ }
+
+ }
+ }
+ }
+
+ // If not "" add a comment before declarations
+ if (!packageEnumDef.equals("")) {
+ packageEnumDef = "/* Package enumeration definitions */"+NL+packageEnumDef;
+ }
+ if (!packageTypeDef.equals("")) {
+ packageTypeDef = "/* Package type definitions */"+NL+packageTypeDef;
+ }
+
+
+//////////////////////////////////////////////////////////////////////////////////////////
+// The following part contains the template
+//////////////////////////////////////////////////////////////////////////////////////////%>
+<%= packageTypeDef %>
+<%= packageEnumDef %>
diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/util/enum/CppEnumerationDefinition.util.jet b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/util/enum/CppEnumerationDefinition.util.jet new file mode 100644 index 00000000000..469b0a3d723 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/util/enum/CppEnumerationDefinition.util.jet @@ -0,0 +1,72 @@ +<%@ jet package = "org.eclipse.papyrus.cpp.codegen.jet.util"
+ skeleton = "../../generator.skeleton"
+ imports = "org.eclipse.uml2.uml.Enumeration org.eclipse.uml2.uml.EnumerationLiteral org.eclipse.papyrus.cpp.codegen.jet.doc.* java.util.Iterator org.eclipse.papyrus.cpp.codegen.utils.GenUtils Cpp.*"
+ class = "CppEnumerationDefinition"
+%>
+<%
+//////////////////////////////////////////////////////////////////////////////////////////
+// Java preparation
+//////////////////////////////////////////////////////////////////////////////////////////
+
+ // This is an util template to prepare Enumeration definition
+ /////////////////////////////////////////////////////////////
+
+
+ // Retrieve the enumeration
+ Enumeration currentEnumeration = (Enumeration) argument;
+
+ // Get the package name
+ String enumName = currentEnumeration.getName();
+
+ // Doc
+ String enumDoc = "";
+ String enumLitDoc = "";
+
+ // Retrieve enum doc
+ CppElementDoc jDoc = new CppElementDoc();
+ enumDoc = jDoc.generate(currentEnumeration);
+
+ // Retrieve literals
+ String enumLiterals = "";
+
+ Iterator<EnumerationLiteral> literalsIt = currentEnumeration.getOwnedLiterals().iterator();
+
+ while (literalsIt.hasNext()) {
+
+ // retrieve current
+ EnumerationLiteral currentLiteral = literalsIt.next();
+
+ enumLiterals = enumLiterals+currentLiteral.getName();
+
+ // if current literal is initialised
+ CppInit cppInit = GenUtils.getApplication(currentLiteral, CppInit.class);
+ if (cppInit != null) {
+ // Add the initialisation value
+ int initValue = cppInit.getValue();
+ enumLiterals = enumLiterals + " = " + initValue;
+ }
+
+ // Retrieve doc
+ if (!GenUtils.getComments(currentLiteral).equals("")) {
+ enumLitDoc = " //< "+GenUtils.getComments(currentLiteral);
+ } else {
+ enumLitDoc = "";
+ }
+
+ // if more literal left prepare new line for next literal
+ if (literalsIt.hasNext()) {
+ enumLiterals = enumLiterals+" ,"+enumLitDoc+NL+"\t";
+ } else {
+ enumLiterals = enumLiterals+enumLitDoc;
+ }
+ }
+
+
+//////////////////////////////////////////////////////////////////////////////////////////
+// The following part contains the template
+//////////////////////////////////////////////////////////////////////////////////////////%>
+<%= enumDoc %>
+enum <%= enumName %> {
+ <%= enumLiterals %>
+};
+
diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/util/interface/CppInterfaceAllIncludesDeclaration.util.jet b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/util/interface/CppInterfaceAllIncludesDeclaration.util.jet new file mode 100644 index 00000000000..fdffc73bde7 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/util/interface/CppInterfaceAllIncludesDeclaration.util.jet @@ -0,0 +1,72 @@ +<%@ jet package = "org.eclipse.papyrus.cpp.codegen.jet.util"
+ skeleton = "../../generator.skeleton"
+ imports = "Cpp.* org.eclipse.papyrus.cpp.codegen.utils.GenUtils org.eclipse.uml2.uml.Interface org.eclipse.emf.common.util.EList org.eclipse.uml2.uml.Package org.eclipse.emf.common.util.UniqueEList java.util.* org.eclipse.uml2.uml.PrimitiveType org.eclipse.uml2.uml.Enumeration org.eclipse.uml2.uml.Classifier"
+ class = "CppInterfaceAllIncludesDeclaration"
+%>
+<%
+//////////////////////////////////////////////////////////////////////////////////////////
+// Java preparation
+//////////////////////////////////////////////////////////////////////////////////////////
+
+ // Retrieve the interface
+ Interface currentInterface = (Interface) argument;
+
+ // Prepare Dependency includes declarations ...
+ // Retrieve package used by current package (dependencies)
+ // use a unique list to avoid duplicates
+ EList<Classifier> usedClasses = new UniqueEList<Classifier> ();
+
+ String newInclude = "";
+
+ // class attributes dependencies
+ usedClasses.addAll (GenUtils.getOwnedAttributeTypes(currentInterface));
+ // operation parameters dependencies
+ usedClasses.addAll (GenUtils.getIncludesFromOperations(currentInterface));
+ // dependencies and associations
+ usedClasses.addAll (GenUtils.getRelationships(currentInterface));
+
+ Iterator<Classifier> usedClassesIt = usedClasses.iterator();
+ // Parsing all as NamedElement
+ String includes = "";
+
+ while (usedClassesIt.hasNext())
+ {
+ Classifier cl = usedClassesIt.next ();
+
+ // Only add include if this is not for the current class
+ if (!currentInterface.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)) {
+
+ 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 interface)
+ CppOwnerPackageIncludeDeclaration jetIDecl
+ = new CppOwnerPackageIncludeDeclaration();
+ if (cl.getOwner() instanceof Package) {
+ newInclude = jetIDecl.generate (cl.getOwner ());
+ }
+ else {
+ newInclude = "";
+ }
+ }
+ else {
+ // include the file associated with the classifier
+ CppClassIncludeDeclaration jetIDecl
+ = new CppClassIncludeDeclaration();
+ newInclude = jetIDecl.generate (cl);
+ }
+
+ includes = includes+newInclude;
+ }
+ }
+ }
+
+//////////////////////////////////////////////////////////////////////////////////////////
+// The following part contains the template
+//////////////////////////////////////////////////////////////////////////////////////////%>
+<%= includes %>
diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/util/interface/CppInterfaceIncludeDeclaration.util.jet b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/util/interface/CppInterfaceIncludeDeclaration.util.jet new file mode 100644 index 00000000000..3984fdbb0f3 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/util/interface/CppInterfaceIncludeDeclaration.util.jet @@ -0,0 +1,29 @@ +<%@ jet package = "org.eclipse.papyrus.cpp.codegen.jet.util"
+ skeleton = "../../generator.skeleton"
+ imports = "org.eclipse.uml2.uml.NamedElement org.eclipse.uml2.uml.Package org.eclipse.papyrus.cpp.codegen.Activator Cpp.* org.eclipse.papyrus.cpp.codegen.utils.GenUtils"
+ class = "CppInterfaceIncludeDeclaration"
+%>
+<%
+//////////////////////////////////////////////////////////////////////////////////////////
+// Java preparation
+//////////////////////////////////////////////////////////////////////////////////////////
+
+
+ // Retrieve header file suffix
+ String headerFileSuffix = Activator.getDefault().getPluginPreferences().getString("headSuffix");
+
+ // Retrieve the interface
+ NamedElement currentNE = (NamedElement) argument;
+ String iInterfacePath = "";
+ Package nearestPkg = currentNE.getNearestPackage();
+ String iInterfaceName = currentNE.getName();
+
+ if ( //!(nearestPkg.getUml2Package() instanceof org.eclipse.uml2.uml.Model)
+ /*&&*/ !(GenUtils.hasStereotype(nearestPkg, CppRoot.class))) {
+ iInterfacePath = GenUtils.getFullPath (nearestPkg) + "/";
+ }
+
+//////////////////////////////////////////////////////////////////////////////////////////
+// The following part contains the template
+//////////////////////////////////////////////////////////////////////////////////////////%>
+#include <<%= iInterfacePath %><%= iInterfaceName %>.<%= headerFileSuffix %>>
diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/util/interface/CppInterfaceInheritedDeclarations.util.jet b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/util/interface/CppInterfaceInheritedDeclarations.util.jet new file mode 100644 index 00000000000..b2528ccac0f --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/util/interface/CppInterfaceInheritedDeclarations.util.jet @@ -0,0 +1,49 @@ +<%@ jet package = "org.eclipse.papyrus.cpp.codegen.jet.util"
+ skeleton = "../../generator.skeleton"
+ imports = "org.eclipse.uml2.uml.Classifier org.eclipse.uml2.uml.Generalization java.util.Iterator Cpp.* org.eclipse.papyrus.cpp.codegen.utils.GenUtils"
+ class = "CppInterfaceInheritedDeclarations"
+%>
+<%
+//////////////////////////////////////////////////////////////////////////////////////////
+// Java preparation
+//////////////////////////////////////////////////////////////////////////////////////////
+
+ // Retrieve the interface
+ Classifier currentClass = (Classifier) argument;
+ String decl = "";
+ String visibility = "";
+
+ // Get generalization and implementation relationships
+ Iterator<Generalization> genIt = currentClass.getGeneralizations().iterator();
+
+ // Parse generalizations
+ while (genIt.hasNext()) {
+
+ Generalization currentGen = genIt.next();
+
+ visibility = GenUtils.getVisibility(currentGen);
+
+ // If not <NoCodeGen>
+ Classifier tmpClassifier = currentGen.getGeneral();
+ if (!GenUtils.hasStereotype(tmpClassifier, CppNoCodeGen.class)) {
+
+ String targetName = tmpClassifier.getName();
+
+ if (!decl.equals("")) {
+ decl = decl + ", ";
+ }
+ decl = decl+visibility+" "+targetName;
+ }
+ }
+
+ // ":" only if decl not empty
+ String prefix = "";
+ if (!decl.equals("")) {
+ prefix = ": ";
+ visibility = "public ";
+ }
+
+//////////////////////////////////////////////////////////////////////////////////////////
+// The following part contains the template
+//////////////////////////////////////////////////////////////////////////////////////////%>
+<%= prefix %><%= decl %>
\ No newline at end of file diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/util/interface/CppInterfacePublicOperationsDeclaration.util.jet b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/util/interface/CppInterfacePublicOperationsDeclaration.util.jet new file mode 100644 index 00000000000..0867efce3b5 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/util/interface/CppInterfacePublicOperationsDeclaration.util.jet @@ -0,0 +1,34 @@ +<%@ jet package = "org.eclipse.papyrus.cpp.codegen.jet.util"
+ skeleton = "../../generator.skeleton"
+ imports = "org.eclipse.uml2.uml.Interface org.eclipse.uml2.uml.Operation org.eclipse.uml2.uml.VisibilityKind java.util.* Cpp.* org.eclipse.papyrus.cpp.codegen.utils.GenUtils"
+ class = "CppInterfacePublicOperationsDeclaration"
+%>
+<%
+//////////////////////////////////////////////////////////////////////////////////////////
+// Java preparation
+//////////////////////////////////////////////////////////////////////////////////////////
+
+ // Retrieve the class
+ Interface currentInterface = (Interface) argument;
+ String opDecl = "";
+
+ // Retrieve operations
+ Iterator<Operation> operations = currentInterface.getOwnedOperations().iterator();
+ while (operations.hasNext()) {
+ Operation currentOperation = operations.next();
+ if ((currentOperation.getVisibility() == VisibilityKind.PUBLIC_LITERAL) &&
+ !GenUtils.hasStereotype (currentOperation, CppNoCodeGen.class)) {
+ CppOperationDeclaration jetOpDecl = new CppOperationDeclaration();
+ String cOpDecl = jetOpDecl.generate(currentOperation);
+
+ // if main cOpDecl = "";
+ if (!cOpDecl.equals("")) {
+ opDecl = opDecl+"\t"+cOpDecl+";";
+ }
+ }
+ }
+
+//////////////////////////////////////////////////////////////////////////////////////////
+// The following part contains the template
+//////////////////////////////////////////////////////////////////////////////////////////%>
+<%= opDecl %>
\ No newline at end of file diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/util/operation/CppOperationDeclaration.util.jet b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/util/operation/CppOperationDeclaration.util.jet new file mode 100644 index 00000000000..0498b6ddd1c --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/util/operation/CppOperationDeclaration.util.jet @@ -0,0 +1,96 @@ +<%@ jet package = "org.eclipse.papyrus.cpp.codegen.jet.util"
+ skeleton = "../../generator.skeleton"
+ imports = "org.eclipse.uml2.uml.* org.eclipse.papyrus.cpp.codegen.jet.doc.* Cpp.* org.eclipse.papyrus.cpp.codegen.StdStereo org.eclipse.papyrus.cpp.codegen.utils.GenUtils"
+ class = "CppOperationDeclaration"
+%>
+<%
+//////////////////////////////////////////////////////////////////////////////////////////
+// Java preparation
+//////////////////////////////////////////////////////////////////////////////////////////
+
+ // Retrieve the Operation
+ Operation currentOperation = (Operation) argument;
+
+ String operationName = currentOperation.getName();
+
+ String opParameters = "";
+
+ String returnTypeName = "void";
+ String pVirtualSuffix = "";
+ String prefix = "";
+ String constOp = "";
+
+
+ String opDoc = "";
+
+ // Doc for the template
+ CppOperationDoc jDoc = new CppOperationDoc();
+ opDoc = GenUtils.indent (jDoc.generate(currentOperation), "\t");
+
+ // Prepare return type
+ CppOperationReturnType jetRT = new CppOperationReturnType();
+ returnTypeName = jetRT.generate(currentOperation);
+ if (!returnTypeName.equals ("")) {
+ returnTypeName += " ";
+ }
+
+ boolean isInterface = currentOperation.getOwner () instanceof Interface;
+
+ // Static attribute
+ if (currentOperation.isStatic()) {
+ prefix = prefix+"static"+" ";
+ }
+
+ // Inline attribute
+ if (GenUtils.hasStereotype(currentOperation, CppInline.class)) {
+ prefix = prefix+"inline"+" ";
+ }
+
+ // Creator / Destructor: use function within StdStereo
+ if (StdStereo.isApplied(currentOperation, StdStereo.create)) {
+ returnTypeName = "";
+ }
+ if (StdStereo.isApplied(currentOperation, StdStereo.destroy)) {
+ returnTypeName = "";
+ operationName = "~"+operationName;
+ }
+
+ // Const attribute on operation
+ if (GenUtils.hasStereotype(currentOperation, CppConst.class)) {
+ constOp = " const";
+ }
+
+ // Virtual attribute on operation
+ if (GenUtils.hasStereotype(currentOperation, CppVirtual.class)) {
+ prefix = "virtual "+prefix;
+ }
+
+ // Pure Virtual attribute on operation
+ if (isInterface || currentOperation.isAbstract ()) {
+ prefix = "virtual "+prefix;
+ pVirtualSuffix = " = 0";
+ }
+
+ // Friend attribute on operation
+ if (GenUtils.hasStereotype(currentOperation, CppFriend.class)) {
+ prefix = "friend "+prefix;
+ }
+
+ // Prepare parameters
+ CppOperationParameters jetParams = new CppOperationParameters();
+ opParameters = jetParams.generate(currentOperation);
+
+//////////////////////////////////////////////////////////////////////////////////////////
+// The following part contains the template only if current operation is not main
+// else nothing is return...
+//////////////////////////////////////////////////////////////////////////////////////////
+
+if (!operationName.equals("main")) {
+
+//////////////////////////////////////////////////////////////////////////////////////////%>
+
+<%= opDoc %>
+ <%= prefix %><%= returnTypeName %><%= operationName %>(<%= opParameters %>)<%= constOp %><%= pVirtualSuffix %>
+<%//////////////////////////////////////////////////////////////////////////////////////////
+} // else nothing done
+//////////////////////////////////////////////////////////////////////////////////////////%>
\ No newline at end of file diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/util/operation/CppOperationImplementation.util.jet b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/util/operation/CppOperationImplementation.util.jet new file mode 100644 index 00000000000..b7761341a77 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/util/operation/CppOperationImplementation.util.jet @@ -0,0 +1,99 @@ +<%@ jet package = "org.eclipse.papyrus.cpp.codegen.jet.util"
+ skeleton = "../../generator.skeleton"
+ imports = "org.eclipse.uml2.uml.* org.eclipse.papyrus.cpp.codegen.jet.doc.* Cpp.* org.eclipse.papyrus.cpp.codegen.StdStereo org.eclipse.papyrus.cpp.codegen.utils.GenUtils"
+ class = "CppOperationImplementation"
+%>
+<%
+//////////////////////////////////////////////////////////////////////////////////////////
+// Java preparation
+//////////////////////////////////////////////////////////////////////////////////////////
+
+ // Retrieve the Operation
+ Operation currentOperation = (Operation) argument;
+
+ String body = "";
+ String className = "";
+ String operationName = currentOperation.getName();
+ String opParameters = "";
+ String returnTypeName = "void";
+ String isInline = "";
+ String isConst = "";
+ String constInit = "";
+
+ String opDoc = "";
+
+ // Doc for the template
+ CppOperationDoc jDoc = new CppOperationDoc();
+ opDoc = jDoc.generate(currentOperation);
+
+ // Retrieve class name. Operation may belong to a class or datatype, thus use
+ // generic getOwner function
+ Element opOwner = currentOperation.getOwner();
+ className = (opOwner instanceof NamedElement) ? ((NamedElement) opOwner).getName() : "";
+
+ // Retrieve body content
+ body = GenUtils.getBody (currentOperation, "C/C++");
+
+ // Prepare return type
+ CppOperationReturnType jetRT = new CppOperationReturnType();
+ returnTypeName = jetRT.generate(currentOperation);
+
+ // Creator / Destructor: use function within StdStereo
+ if (StdStereo.isApplied(currentOperation, StdStereo.create)) {
+ returnTypeName = "";
+ }
+ if (StdStereo.isApplied(currentOperation, StdStereo.destroy)) {
+ returnTypeName = "";
+ operationName = "~"+operationName;
+ }
+
+ // If is inline operation
+ if (GenUtils.hasStereotype(currentOperation, CppInline.class)) {
+ isInline = "inline ";
+ }
+
+ // Const op
+ if (GenUtils.hasStereotype(currentOperation, CppConst.class)) {
+ isConst = " const";
+ }
+
+ // Constructor init list
+ CppConstInit cppConstInit = GenUtils.getApplication(currentOperation, CppConstInit.class);
+ if ((cppConstInit != null)
+ && StdStereo.isApplied(currentOperation, StdStereo.create)) {
+ constInit = " : " + cppConstInit.getInitialisation();
+ }
+
+ // Prepare parameters
+ CppOperationParametersWithoutDefaultValue jetParams = new CppOperationParametersWithoutDefaultValue();
+ opParameters = jetParams.generate(currentOperation);
+
+//////////////////////////////////////////////////////////////////////////////////////////
+// The following part contains the template two cases main operation or classical
+//////////////////////////////////////////////////////////////////////////////////////////
+
+// main
+ if (operationName.equals("main")) {
+
+//////////////////////////////////////////////////////////////////////////////////////////%>
+
+<%= opDoc %>
+<%= returnTypeName %> <%= operationName %> (<%= opParameters %>) {
+<%= body %>
+}
+
+<%//////////////////////////////////////////////////////////////////////////////////////////
+
+ }
+ else {
+
+//////////////////////////////////////////////////////////////////////////////////////////%>
+
+<%= opDoc %>
+<%= isInline %><%= returnTypeName %> <%= className %>::<%= operationName %>(<%= opParameters %>)<%= isConst %><%= constInit %> {
+<%= body %>
+}
+
+<%//////////////////////////////////////////////////////////////////////////////////////////
+ }
+//////////////////////////////////////////////////////////////////////////////////////////%>
\ No newline at end of file diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/util/operation/CppOperationParameters.util.jet b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/util/operation/CppOperationParameters.util.jet new file mode 100644 index 00000000000..00858e02574 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/util/operation/CppOperationParameters.util.jet @@ -0,0 +1,35 @@ +<%@ jet package = "org.eclipse.papyrus.cpp.codegen.jet.util"
+ skeleton = "../../generator.skeleton"
+ imports = "org.eclipse.uml2.uml.* java.util.*"
+ class = "CppOperationParameters"
+%>
+<%
+//////////////////////////////////////////////////////////////////////////////////////////
+// Java preparation
+//////////////////////////////////////////////////////////////////////////////////////////
+
+ // Retrieve the Operation
+ Operation currentOperation = (Operation) argument;
+ Parameter currentParameter;
+
+ String paramDecl = "";
+
+ Iterator<Parameter> parameters = currentOperation.getOwnedParameters().iterator();
+ while(parameters.hasNext()) {
+ currentParameter = parameters.next();
+ if (currentParameter.getDirection () != ParameterDirectionKind.RETURN_LITERAL) {
+ // Prepare parameters
+ CppParameter jetParam = new CppParameter();
+ if (!paramDecl.equals("")) {
+ paramDecl += ", ";
+ }
+ paramDecl = paramDecl+jetParam.generate(currentParameter);
+ }
+ }
+
+ paramDecl.replaceAll(NL, "");
+
+//////////////////////////////////////////////////////////////////////////////////////////
+// The following part contains the template
+//////////////////////////////////////////////////////////////////////////////////////////
+%><%= paramDecl %>
\ No newline at end of file diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/util/operation/CppOperationParametersWithoutDefaultValue.util.jet b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/util/operation/CppOperationParametersWithoutDefaultValue.util.jet new file mode 100644 index 00000000000..9cc336e09c7 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/util/operation/CppOperationParametersWithoutDefaultValue.util.jet @@ -0,0 +1,33 @@ +<%@ jet package = "org.eclipse.papyrus.cpp.codegen.jet.util"
+ skeleton = "../../generator.skeleton"
+ imports = "org.eclipse.uml2.uml.* java.util.*"
+ class = "CppOperationParametersWithoutDefaultValue"
+%>
+<%
+//////////////////////////////////////////////////////////////////////////////////////////
+// Java preparation
+//////////////////////////////////////////////////////////////////////////////////////////
+
+ // Retrieve the Operation
+ Operation currentOperation = (Operation) argument;
+ Parameter currentParameter;
+
+ String paramDecl = "";
+
+ Iterator<Parameter> parameters = currentOperation.getOwnedParameters().iterator();
+ while(parameters.hasNext()) {
+ currentParameter = parameters.next();
+ if (currentParameter.getDirection () != ParameterDirectionKind.RETURN_LITERAL) {
+ // Prepare parameters
+ CppParameterWithoutDefaultValue jetParam = new CppParameterWithoutDefaultValue();
+ if (!paramDecl.equals("")) {
+ paramDecl += ", ";
+ }
+ paramDecl = paramDecl+jetParam.generate(currentParameter);
+ }
+ }
+
+//////////////////////////////////////////////////////////////////////////////////////////
+// The following part contains the template
+//////////////////////////////////////////////////////////////////////////////////////////
+%><%= paramDecl %>
\ No newline at end of file diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/util/operation/CppOperationReturnType.util.jet b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/util/operation/CppOperationReturnType.util.jet new file mode 100644 index 00000000000..5c776417ef8 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/util/operation/CppOperationReturnType.util.jet @@ -0,0 +1,76 @@ +<%@ jet package = "org.eclipse.papyrus.cpp.codegen.jet.util"
+ skeleton = "../../generator.skeleton"
+ imports = "org.eclipse.uml2.uml.* org.eclipse.uml2.uml.Class Cpp.* org.eclipse.papyrus.cpp.codegen.utils.*"
+ class = "CppOperationReturnType"
+%>
+<%
+//////////////////////////////////////////////////////////////////////////////////////////
+// Java preparation
+//////////////////////////////////////////////////////////////////////////////////////////
+
+ // Retrieve the Operation
+ Operation currentOperation = (Operation) argument;
+
+ String returnTypeName = "void";
+ String ownerName = "";
+ Modifier modifier = new Modifier();
+
+ // Return type
+ if (currentOperation.getType() == null) {
+ returnTypeName = "void";
+ } else {
+ if (currentOperation.getType() == null) {
+ returnTypeName = "undefined";
+ } else {
+ // Treat the type if it is not "package visibility" and owned by a class
+ Type currentType = currentOperation.getType();
+ returnTypeName = GenUtils.qualifiedName (currentType);
+
+ if (currentType.getVisibility() != VisibilityKind.PACKAGE_LITERAL) {
+ if (currentType.getOwner() instanceof Class) {
+ ownerName = ((Class) currentType.getOwner()).getName();
+ }
+ }
+ }
+
+ // Treat pointer or ref on return parameter (only one return parameter should exists)
+ // retrieve return parameter
+// RS: changed test: now getReturnResult returns only one param
+// if (currentOperation.getUml2Operation().getReturnResults().size() == 1) {
+// org.eclipse.uml2.uml.Parameter uml2Param
+// = (org.eclipse.uml2.uml.Parameter) currentOperation.getUml2Operation().getReturnResults().get(0);
+// Parameter currentRParameter
+// = new Parameter(uml2Param);
+// // case Pointer
+// if (currentRParameter.hasStereotype(xy, CppPtr.class)) {
+// isPointer = " "+currentRParameter.getTaggedValue(CppPtr.class, "declaration");
+// }
+// if (currentRParameter.hasStereotype(xy, CppRef.class)) {
+// isRef = " "+currentRParameter.getTaggedValue(CppRef.class, "declaration");
+// }
+// if (currentRParameter.hasStereotype(xy, CppConst.class_)) {
+// isConst = "const ";
+// }
+// }
+ if (currentOperation.getReturnResult() instanceof Parameter) {
+ Parameter uml2Param = (Parameter) currentOperation.getReturnResult();
+ modifier = new Modifier(uml2Param);
+ }
+ }
+
+
+//////////////////////////////////////////////////////////////////////////////////////////
+// The following part contains the template two cases : scope required or not
+//////////////////////////////////////////////////////////////////////////////////////////
+
+// No scope details
+ if (ownerName.equals("")) {
+//////////////////////////////////////////////////////////////////////////////////////////
+%><%= modifier.isConst %><%= returnTypeName %><%= modifier.ptr %><%= modifier.ref %>
+<%//////////////////////////////////////////////////////////////////////////////////////////
+} else {
+//////////////////////////////////////////////////////////////////////////////////////////
+%><%= modifier.isConst %><%= ownerName %>::<%= returnTypeName %><%= modifier.ptr %><%= modifier.ref %>
+<%//////////////////////////////////////////////////////////////////////////////////////////
+}
+//////////////////////////////////////////////////////////////////////////////////////////%>
\ No newline at end of file diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/util/operation/CppOperationTemplateImplementation.util.jet b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/util/operation/CppOperationTemplateImplementation.util.jet new file mode 100644 index 00000000000..a7dde0e50da --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/util/operation/CppOperationTemplateImplementation.util.jet @@ -0,0 +1,90 @@ +<%@ jet package = "org.eclipse.papyrus.cpp.codegen.jet.util"
+ skeleton = "../../generator.skeleton"
+ imports = "org.eclipse.uml2.uml.* org.eclipse.uml2.uml.Class Cpp.* org.eclipse.papyrus.cpp.codegen.StdStereo org.eclipse.papyrus.cpp.codegen.utils.GenUtils"
+ class = "CppOperationTemplateImplementation"
+%>
+<%
+//////////////////////////////////////////////////////////////////////////////////////////
+// Java preparation
+//////////////////////////////////////////////////////////////////////////////////////////
+
+ // Retrieve the Operation
+ Operation currentOperation = (Operation) argument;
+
+ String operationName = currentOperation.getName();
+ String opParameters = "";
+ String returnTypeName = "void";
+ String isConst = "";
+ String isInline = "";
+
+ // Retrieve class & class name
+ Class currentClass = currentOperation.getClass_ ();
+ String className = currentClass.getName();
+
+ // Retrieve body content
+ String body = GenUtils.getBody (currentOperation, "C/C++");
+
+ // Prepare return type
+ CppOperationReturnType jetRT = new CppOperationReturnType();
+ returnTypeName = jetRT.generate(currentOperation);
+ if (! "".equals(returnTypeName)) {
+ returnTypeName = returnTypeName + " ";
+ }
+
+ // Creator / Destructor: use function within StdStereo
+ if (StdStereo.isApplied(currentOperation, StdStereo.create)) {
+ returnTypeName = "";
+ }
+ if (StdStereo.isApplied(currentOperation, StdStereo.destroy)) {
+ returnTypeName = "";
+ operationName = "~"+operationName;
+ }
+
+ // If inline operation
+ if (GenUtils.hasStereotype(currentOperation, CppInline.class)) {
+ isInline = "inline ";
+ }
+
+ // Const op
+ if (GenUtils.hasStereotype(currentOperation, CppConst.class)) {
+ isConst = " const";
+ }
+
+ // Prepare parameters
+ CppOperationParametersWithoutDefaultValue jetParams
+ = new CppOperationParametersWithoutDefaultValue();
+ opParameters = jetParams.generate(currentOperation);
+
+
+ // Prepare template parameter declaration without type
+ String tparamWoType = "";
+
+ if (currentClass != null) {
+ tparamWoType = GenUtils.getTemplateParametersWoType(currentClass);
+ }
+
+//////////////////////////////////////////////////////////////////////////////////////////
+// The following part contains the template
+//////////////////////////////////////////////////////////////////////////////////////////
+// Package visibility
+ if (currentOperation.getVisibility() == VisibilityKind.PACKAGE_LITERAL) {
+
+//////////////////////////////////////////////////////////////////////////////////////////
+
+%><%= isInline %><%= returnTypeName %><%= operationName %>(<%= opParameters %>)<%= isConst %> {
+<%= body %>
+}<%
+
+//////////////////////////////////////////////////////////////////////////////////////////
+
+ } else { // Default case
+
+//////////////////////////////////////////////////////////////////////////////////////////
+
+%><%= isInline %><%= returnTypeName %><%= className %><<%= tparamWoType %>>::<%= operationName %>(<%= opParameters %>)<%= isConst %> {
+<%= body %>
+}<%
+
+//////////////////////////////////////////////////////////////////////////////////////////
+ }
+//////////////////////////////////////////////////////////////////////////////////////////%>
\ No newline at end of file diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/util/package/CppOwnerPackageIncludeDeclaration.util.jet b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/util/package/CppOwnerPackageIncludeDeclaration.util.jet new file mode 100644 index 00000000000..bd5a5d8dfb0 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/util/package/CppOwnerPackageIncludeDeclaration.util.jet @@ -0,0 +1,40 @@ +<%@ jet package = "org.eclipse.papyrus.cpp.codegen.jet.util"
+ skeleton = "../../generator.skeleton"
+ imports = "org.eclipse.uml2.uml.Package org.eclipse.papyrus.cpp.codegen.Activator Cpp.* org.eclipse.papyrus.cpp.codegen.utils.GenUtils"
+ class = "CppOwnerPackageIncludeDeclaration"
+%>
+<%
+//////////////////////////////////////////////////////////////////////////////////////////
+// Java preparation
+//////////////////////////////////////////////////////////////////////////////////////////
+
+ // Retrieve the type passed as argument
+ Package currentPkg = (Package) argument;
+ String currentPkgName = currentPkg.getName();
+ String currentPkgPath = GenUtils.getFullPath (currentPkg);
+
+ // Retrieve header file suffix
+ String headerFileSuffix = Activator.getDefault().getPluginPreferences().getString("headSuffix");
+
+ // Prepare Father include declaration
+ boolean isRoot = false;
+
+ // The currentElt has the CppRoot stereotype
+ if (GenUtils.hasStereotype(currentPkg, CppRoot.class)) {
+ isRoot = true;
+ }
+ // The currentPkg is the model root package
+ //if (currentPkg instanceof org.eclipse.uml2.uml.Model){
+ // isRoot = true;
+ //}
+
+
+//////////////////////////////////////////////////////////////////////////////////////////
+// The following part contains the template
+//////////////////////////////////////////////////////////////////////////////////////////%>
+<% // if currentPkg is not root it is referenced here
+ if (!isRoot) { %>
+/* Owner package header include */
+#include <<%= currentPkgPath %>/Pkg_<%= currentPkgName %>.<%= headerFileSuffix %>>
+<% // endif
+ } %>
diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/util/parameter/CppParameter.util.jet b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/util/parameter/CppParameter.util.jet new file mode 100644 index 00000000000..78d0d60c020 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/util/parameter/CppParameter.util.jet @@ -0,0 +1,36 @@ +<%@ jet package = "org.eclipse.papyrus.cpp.codegen.jet.util"
+ skeleton = "../../generator.skeleton"
+ imports = "org.eclipse.uml2.uml.Parameter Cpp.* org.eclipse.papyrus.cpp.codegen.utils.Modifier org.eclipse.papyrus.cpp.codegen.utils.GenUtils"
+ class = "CppParameter"
+%>
+<%
+//////////////////////////////////////////////////////////////////////////////////////////
+// Java preparation
+//////////////////////////////////////////////////////////////////////////////////////////
+
+ // Retrieve the Parameter
+ Parameter currentParameter = (Parameter) argument;
+
+ String parameterName = currentParameter.getName();
+
+ String typeName = "";
+ String suffix = "";
+ Modifier modifier = new Modifier(currentParameter);
+
+ if (currentParameter.getType() == null) {
+ typeName = "undefined";
+ } else {
+ typeName = GenUtils.qualifiedName (currentParameter.getType());
+ }
+
+ // Initial value
+ CppDefault cppDefault = GenUtils.getApplication(currentParameter, CppDefault.class);
+ if (cppDefault != null) {
+ suffix = " = " + cppDefault.getValue();
+ }
+
+
+//////////////////////////////////////////////////////////////////////////////////////////
+// The following part contains the template
+//////////////////////////////////////////////////////////////////////////////////////////
+%><%= modifier.isConst %><%= typeName %><%= modifier.ptr %><%= modifier.ref %> <%= parameterName %><%= modifier.array %><%= suffix %>
\ No newline at end of file diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/util/parameter/CppParameterWithoutDefaultValue.util.jet b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/util/parameter/CppParameterWithoutDefaultValue.util.jet new file mode 100644 index 00000000000..95862d64632 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/util/parameter/CppParameterWithoutDefaultValue.util.jet @@ -0,0 +1,56 @@ +<%@ jet package = "org.eclipse.papyrus.cpp.codegen.jet.util"
+ skeleton = "../../generator.skeleton"
+ imports = "org.eclipse.uml2.uml.Parameter org.eclipse.uml2.uml.Classifier Cpp.* org.eclipse.papyrus.cpp.codegen.utils.Modifier org.eclipse.papyrus.cpp.codegen.utils.GenUtils"
+ class = "CppParameterWithoutDefaultValue"
+%>
+<%
+//////////////////////////////////////////////////////////////////////////////////////////
+// Java preparation
+//////////////////////////////////////////////////////////////////////////////////////////
+
+ // Retrieve the Parameter
+ Parameter currentParameter = (Parameter) argument;
+
+ String parameterName = currentParameter.getName();
+
+ String typeName = "";
+ Modifier modifier = new Modifier(currentParameter);
+
+ // Prepare template parameter declaration without type
+ String tparamWoType = "";
+
+ if (currentParameter.getType() == null) {
+ typeName = "undefined";
+ }
+ else if (currentParameter.getType() instanceof Classifier) {
+ Classifier classifier = (Classifier) currentParameter.getType();
+ tparamWoType = GenUtils.getTemplateParametersWoType(classifier);
+
+ typeName = GenUtils.qualifiedName (currentParameter.getType());
+ }
+ else {
+ typeName = GenUtils.qualifiedName (currentParameter.getType());
+ }
+
+//////////////////////////////////////////////////////////////////////////////////////////
+// The following part contains the template
+//////////////////////////////////////////////////////////////////////////////////////////
+// Package visibility
+ if (!"".equals(tparamWoType)) {
+
+//////////////////////////////////////////////////////////////////////////////////////////
+
+%><%= modifier.isConst %><%= typeName %><<%= tparamWoType %>><%= modifier.ptr %><%= modifier.ref %> <%= parameterName %><%= modifier.array %><%
+
+//////////////////////////////////////////////////////////////////////////////////////////
+
+ } else { // Default case
+
+//////////////////////////////////////////////////////////////////////////////////////////
+
+%><%= modifier.isConst %><%= typeName %><%= modifier.ptr %><%= modifier.ref %> <%= parameterName %><%= modifier.array %><%
+
+
+//////////////////////////////////////////////////////////////////////////////////////////
+ }
+//////////////////////////////////////////////////////////////////////////////////////////%>
\ No newline at end of file diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/util/property/CppAttributeDeclaration.util.jet b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/util/property/CppAttributeDeclaration.util.jet new file mode 100644 index 00000000000..58c5fc97a71 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/util/property/CppAttributeDeclaration.util.jet @@ -0,0 +1,78 @@ +<%@ jet package = "org.eclipse.papyrus.cpp.codegen.jet.util"
+ skeleton = "../../generator.skeleton"
+ imports = "org.eclipse.uml2.uml.Property org.eclipse.papyrus.cpp.codegen.jet.doc.* Cpp.* org.eclipse.papyrus.cpp.codegen.utils.*"
+ class = "CppAttributeDeclaration"
+%>
+<%
+//////////////////////////////////////////////////////////////////////////////////////////
+// Java preparation
+//////////////////////////////////////////////////////////////////////////////////////////
+
+ // Retrieve the property
+ Property currentAttribute = (Property) argument;
+
+ String attributeName = currentAttribute.getName();
+ String typeName = "";
+ String prefix = "";
+ String suffix = "";
+ String multiple = "";
+
+ // For property documentation
+ String propDoc = "";
+
+ // Retrieve enum doc
+ CppElementDoc jDoc = new CppElementDoc();
+ propDoc = jDoc.generate(currentAttribute);
+ propDoc = propDoc.replaceAll(NL, NL+" ");
+
+ if (currentAttribute.getType() == null) {
+ typeName = "undefined";
+ } else {
+ typeName = GenUtils.qualifiedName (currentAttribute.getType());
+ }
+
+ // Static attribute
+ if (currentAttribute.isStatic()) {
+ prefix = "static"+" ";
+ }
+
+ Modifier modifier = new Modifier(currentAttribute);
+
+ // Treat multiplicity for association attributes
+ int multiplicity = currentAttribute.getUpper();
+ if (multiplicity == 1) {
+ multiple = "";
+ } else if (multiplicity == -1) {
+ multiple = "*";
+ } else {
+ multiple = "";
+ modifier.array = "[" + multiplicity + "]";
+ }
+
+ // If attribute is aggregation
+ if (GenUtils.isAggregation(currentAttribute)) {
+ // attributeName = "(*"+attributeName+")"; // this produce a pointer on a tab
+ attributeName = "*"+attributeName; // this produce a tab of pointers
+ }
+
+
+ if (GenUtils.hasStereotype(currentAttribute, CppConst.class) && currentAttribute.isStatic()) {
+ // const & static attributes may be initialized within class declaration
+ // check if initial value UML or profile
+ if (currentAttribute.getDefaultValue() != null) {
+ suffix = " = " + currentAttribute.getDefaultValue().stringValue();
+ }
+ else {
+ CppDefault cppDefault = GenUtils.getApplication(currentAttribute, CppDefault.class);
+ if (cppDefault != null) {
+ suffix = " = " + cppDefault.getValue();
+ }
+ }
+ }
+
+//////////////////////////////////////////////////////////////////////////////////////////
+// The following part contains the template
+//////////////////////////////////////////////////////////////////////////////////////////%>
+
+ <%= propDoc %>
+ <%= prefix %><%= modifier.isConst %><%= typeName %><%= multiple %><%= modifier.ptr %><%= modifier.ref %> <%= attributeName %><%= modifier.array %><%= suffix %>;
\ No newline at end of file diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/util/property/CppAttributeImplementation.util.jet b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/util/property/CppAttributeImplementation.util.jet new file mode 100644 index 00000000000..2980c4fee83 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/util/property/CppAttributeImplementation.util.jet @@ -0,0 +1,58 @@ +<%@ jet package = "org.eclipse.papyrus.cpp.codegen.jet.util"
+ skeleton = "../../generator.skeleton"
+ imports = "org.eclipse.uml2.uml.* org.eclipse.papyrus.cpp.codegen.jet.doc.* Cpp.* org.eclipse.papyrus.cpp.codegen.utils.*"
+ class = "CppAttributeImplementation"
+%>
+<%
+//////////////////////////////////////////////////////////////////////////////////////////
+// Java preparation
+//////////////////////////////////////////////////////////////////////////////////////////
+
+ // Retrieve the property
+ Property currentAttribute = (Property) argument;
+
+ String attributeName = currentAttribute.getName();
+// String className = currentAttribute.getOwner().getName();
+ String typeName = "";
+ String scopeName = "";
+// String prefix = "";
+ String suffix = "";
+ String multiple = "";
+
+ // For property documentation
+ String propDoc = "";
+
+ // Retrieve enum doc
+ CppElementDoc jDoc = new CppElementDoc();
+ propDoc = jDoc.generate(currentAttribute);
+ propDoc = propDoc.replaceAll(NL, NL+" ");
+
+ if (currentAttribute.getType() == null) {
+ typeName = "undefined";
+ }
+ else {
+ Type type = currentAttribute.getType();
+ typeName = GenUtils.qualifiedName (type);
+ /*
+ // If type is owned by a class add the scope
+ if (type.getOwner() instanceof Class) {
+ scopeName = ((Class) type.getOwner()).getName();
+ typeName = scopeName+"::"+typeName;
+ }
+ */
+ }
+
+ // Multiple
+ // TODO? need to evaluate limitMultiplicity stereotype?
+ int upper = currentAttribute.getUpper();
+ if ((upper == -1) || (upper > 1)) {
+ multiple = "*";
+ }
+
+ Modifier modifier = new Modifier(currentAttribute);
+
+//////////////////////////////////////////////////////////////////////////////////////////
+// The following part contains the template
+//////////////////////////////////////////////////////////////////////////////////////////%>
+ <%= propDoc %>
+ <%= typeName %><%= multiple %><%= modifier.ptr %><%= modifier.ref %> <%= attributeName %><%= modifier.array %><%= suffix %>;
diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/util/property/CppClassAttributesImplementation.util.jet b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/util/property/CppClassAttributesImplementation.util.jet new file mode 100644 index 00000000000..634b097bbb1 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/util/property/CppClassAttributesImplementation.util.jet @@ -0,0 +1,37 @@ +<%@ jet package = "org.eclipse.papyrus.cpp.codegen.jet.util"
+ skeleton = "../../generator.skeleton"
+ imports = "org.eclipse.uml2.uml.* java.util.Iterator Cpp.* org.eclipse.papyrus.cpp.codegen.utils.GenUtils"
+ class = "CppClassAttributesImplementation"
+%>
+<%
+//////////////////////////////////////////////////////////////////////////////////////////
+// Java preparation
+//////////////////////////////////////////////////////////////////////////////////////////
+
+ // Retrieve the class
+ Classifier currentClass = (Classifier) argument;
+ String attrDecl = "";
+ String attrSDecl = "";
+
+ CppAttributeImplementation jetAttDecl = new CppAttributeImplementation();
+ CppStaticAttributeImplementation jetSAttDecl = new CppStaticAttributeImplementation();
+
+ Iterator<Property> attributesIt = currentClass.getAttributes().iterator();
+ while (attributesIt.hasNext()) {
+ Property attribute = (Property) attributesIt.next();
+
+ // just check that this property is not a static const
+ // in that case it declared and defined in the header file
+
+ // Static
+ if (attribute.isStatic()) {
+ attrSDecl = attrSDecl+jetSAttDecl.generate(attribute);
+ } else {
+ attrDecl = attrDecl+jetAttDecl.generate(attribute);
+ }
+ }
+
+//////////////////////////////////////////////////////////////////////////////////////////
+// The following part contains the template
+//////////////////////////////////////////////////////////////////////////////////////////%>
+<%= attrSDecl %><%= attrDecl %>
\ No newline at end of file diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/util/property/CppStaticAttributeImplementation.util.jet b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/util/property/CppStaticAttributeImplementation.util.jet new file mode 100644 index 00000000000..aafed1f9c64 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/util/property/CppStaticAttributeImplementation.util.jet @@ -0,0 +1,56 @@ +<%@ jet package = "org.eclipse.papyrus.cpp.codegen.jet.util"
+ skeleton = "../../generator.skeleton"
+ imports = "org.eclipse.uml2.uml.* Cpp.* org.eclipse.papyrus.cpp.codegen.utils.*"
+ class = "CppStaticAttributeImplementation"
+%>
+<%
+//////////////////////////////////////////////////////////////////////////////////////////
+// Java preparation
+//////////////////////////////////////////////////////////////////////////////////////////
+
+ // Retrieve the property
+ Property currentAttribute = (Property) argument;
+
+ String attributeName = currentAttribute.getName();
+ String className = GenUtils.qualifiedName (currentAttribute.getClass_());
+ String typeName = "";
+ String suffix = "";
+ String multiple = "";
+ String isAgg = ""; // attribute is an aggregation or association
+
+
+ if (currentAttribute.getType() == null) {
+ typeName = "undefined"+" ";
+ } else {
+ typeName = GenUtils.qualifiedName (currentAttribute.getType()) + " ";
+ }
+
+ // Multiple
+ // if (currentAttribute.isMultiple()) {
+ // multiple = "*";
+ // }
+
+ // 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
+ }
+
+ Modifier modifier = new Modifier(currentAttribute);
+
+ // Initial value
+ if (currentAttribute.getDefaultValue() != null) {
+ // via UML
+ suffix = " = " + currentAttribute.getDefaultValue().stringValue();
+ }
+ else {
+ CppDefault cppDefault = GenUtils.getApplication(currentAttribute, CppDefault.class);
+ if (cppDefault != null) {
+ suffix = " = " + cppDefault.getValue();
+ }
+ }
+
+//////////////////////////////////////////////////////////////////////////////////////////
+// The following part contains the template
+//////////////////////////////////////////////////////////////////////////////////////////%>
+<%= typeName %><%= multiple %><%= modifier.ptr %><%= isAgg %><%= modifier.ref %><%= className %>::<%= attributeName %><%= modifier.array %><%= suffix %>;
diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/util/template/CppTemplateBindingParameter.util.jet b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/util/template/CppTemplateBindingParameter.util.jet new file mode 100644 index 00000000000..ed41e210f5c --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/util/template/CppTemplateBindingParameter.util.jet @@ -0,0 +1,35 @@ +<%@ jet package = "org.eclipse.papyrus.cpp.codegen.jet.util" + skeleton = "../../generator.skeleton" + imports = "org.eclipse.uml2.uml.*" + class = "CppTemplateBindingParameter" +%> +<% +////////////////////////////////////////////////////////////////////////////////////////// +// Java preparation +////////////////////////////////////////////////////////////////////////////////////////// + + + // Retrieve the TemplateParameter + // Retrieve the TemplateParameter + TemplateParameterSubstitution currentTParam = (TemplateParameterSubstitution) argument; + + String typeName = ""; + + if (currentTParam.getActual() == null) { + typeName ="param undefined"; + } + else { + ParameterableElement actual = currentTParam.getActual(); + + if (actual instanceof LiteralInteger) { + typeName = "" + ((LiteralInteger) currentTParam.getActual()).getValue(); + } + else { + typeName = ((NamedElement) currentTParam.getActual()).getName(); + } // value = currentTParam.getFormal().getParameteredElement().getName(); + } + +////////////////////////////////////////////////////////////////////////////////////////// +// The following part contains the template +////////////////////////////////////////////////////////////////////////////////////////// +%><%= typeName %>
\ No newline at end of file diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/util/template/CppTemplateDeclaration.h.jet b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/util/template/CppTemplateDeclaration.h.jet new file mode 100644 index 00000000000..c76b40afb08 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/util/template/CppTemplateDeclaration.h.jet @@ -0,0 +1,33 @@ +<%@ jet package = "org.eclipse.papyrus.cpp.codegen.jet.util"
+ skeleton = "../../generator.skeleton"
+ imports = "org.eclipse.uml2.uml.Class org.eclipse.uml2.uml.TemplateParameter java.util.* org.eclipse.papyrus.cpp.codegen.utils.GenUtils"
+ class = "CppTemplateDeclaration"
+ %>
+<%
+//////////////////////////////////////////////////////////////////////////////////////////
+// Java preparation
+//////////////////////////////////////////////////////////////////////////////////////////
+
+ // Retrieve the class
+ Class currentClass = (Class) argument;
+
+
+ // Prepare template parameter declaration
+ Iterator<TemplateParameter> tparam = GenUtils.getTemplateParameters(currentClass).iterator();
+ String tParamDecl = "";
+
+ while(tparam.hasNext()) {
+ TemplateParameter currentTParam = tparam.next();
+
+ CppTemplateParameter jetTParam = new CppTemplateParameter();
+ tParamDecl = tParamDecl+jetTParam.generate(currentTParam);
+
+ if (tparam.hasNext()) {
+ tParamDecl = tParamDecl+", ";
+ }
+ }
+
+//////////////////////////////////////////////////////////////////////////////////////////
+// The following part contains the template
+//////////////////////////////////////////////////////////////////////////////////////////
+%>template <<%= tParamDecl %>>
\ No newline at end of file diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/util/template/CppTemplateInlineOperationsImplementation.util.jet b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/util/template/CppTemplateInlineOperationsImplementation.util.jet new file mode 100644 index 00000000000..146deefca76 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/util/template/CppTemplateInlineOperationsImplementation.util.jet @@ -0,0 +1,42 @@ +<%@ jet package = "org.eclipse.papyrus.cpp.codegen.jet.util"
+ skeleton = "../../generator.skeleton"
+ imports = "org.eclipse.papyrus.cpp.codegen.jet.doc.* org.eclipse.uml2.uml.Class org.eclipse.uml2.uml.Operation java.util.Iterator Cpp.* org.eclipse.papyrus.cpp.codegen.utils.GenUtils"
+ class = "CppTemplateInlineOperationsImplementation"
+%>
+<%
+//////////////////////////////////////////////////////////////////////////////////////////
+// Java preparation
+//////////////////////////////////////////////////////////////////////////////////////////
+
+ // Retrieve the class
+ Class currentClass = (Class) argument;
+ String opDecl = "";
+ String tDecl = "";
+
+ // Retrieve template declaration
+ CppTemplateDeclaration jetTDecl = new CppTemplateDeclaration();
+ // tDecl should contain something like "template <class x, class y>"
+ tDecl = jetTDecl.generate(currentClass) + " ";
+
+ // Retrieve operations
+ Iterator<Operation> operations = currentClass.getOwnedOperations().iterator();
+ while (operations.hasNext()) {
+ Operation currentOperation = operations.next();
+
+ if (GenUtils.hasStereotype (currentOperation, CppInline.class) &&
+ !GenUtils.hasStereotype (currentOperation, CppNoCodeGen.class)) {
+ String opDoc = "";
+
+ // Doc for the template
+ CppOperationDoc jDoc = new CppOperationDoc();
+ opDoc = jDoc.generate(currentOperation);
+
+ CppOperationTemplateImplementation jetOpImpl = new CppOperationTemplateImplementation();
+ opDecl = opDecl+opDoc+NL+tDecl+jetOpImpl.generate(currentOperation)+NL;
+ }
+ }
+
+//////////////////////////////////////////////////////////////////////////////////////////
+// The following part contains the template
+//////////////////////////////////////////////////////////////////////////////////////////
+%><%= opDecl %>
\ No newline at end of file diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/util/template/CppTemplateParameter.util.jet b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/util/template/CppTemplateParameter.util.jet new file mode 100644 index 00000000000..925439208bb --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/util/template/CppTemplateParameter.util.jet @@ -0,0 +1,34 @@ +<%@ jet package = "org.eclipse.papyrus.cpp.codegen.jet.util" + skeleton = "../../generator.skeleton" + imports = "Cpp.* org.eclipse.papyrus.cpp.codegen.utils.GenUtils org.eclipse.uml2.uml.TemplateParameter" + class = "CppTemplateParameter" +%> +<% +////////////////////////////////////////////////////////////////////////////////////////// +// Java preparation +////////////////////////////////////////////////////////////////////////////////////////// + + + // Retrieve the TemplateParameter + TemplateParameter currentTParam = (TemplateParameter) argument; + + String parameterName = ""; + String typeName = ""; + + + if (GenUtils.getType(currentTParam) == "") { + typeName = "undefined"; + } else { + typeName = GenUtils.getType(currentTParam); //.getName(); + } + + // Retrieve name under stereotype CppTemplateParameter/name + Cpp.CppTemplateParameter ctp = GenUtils.getApplication(currentTParam, Cpp.CppTemplateParameter.class); + if (ctp != null) { + parameterName = ctp.getName(); + } + +////////////////////////////////////////////////////////////////////////////////////////// +// The following part contains the template +////////////////////////////////////////////////////////////////////////////////////////// +%><%= typeName %> <%= parameterName %>
\ No newline at end of file diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/util/type/CppPrimitiveTypeDefinition.util.jet b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/util/type/CppPrimitiveTypeDefinition.util.jet new file mode 100644 index 00000000000..ce6419b204f --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/templates/util/type/CppPrimitiveTypeDefinition.util.jet @@ -0,0 +1,53 @@ +<%@ jet package = "org.eclipse.papyrus.cpp.codegen.jet.util"
+ skeleton = "../../generator.skeleton"
+ imports = "org.eclipse.uml2.uml.PrimitiveType org.eclipse.papyrus.cpp.codegen.jet.doc.* Cpp.* org.eclipse.papyrus.cpp.codegen.utils.GenUtils"
+ class = "CppPrimitiveTypeDefinition"
+%>
+<%
+//////////////////////////////////////////////////////////////////////////////////////////
+// Java preparation
+//////////////////////////////////////////////////////////////////////////////////////////
+
+ // Retrieve the type passed as argument
+ PrimitiveType currentPType = (PrimitiveType) argument;
+ String currentPTypeName = currentPType.getName();
+ String definition = "";
+
+ // Doc
+ String typeDoc = "";
+
+ // Retrieve enum doc
+ CppElementDoc jDoc = new CppElementDoc();
+
+ /**
+ * 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)
+ */
+ // Retrieve type definition
+ CppType cppType = GenUtils.getApplication(currentPType, CppType.class);
+ if (cppType != null) {
+ typeDoc = jDoc.generate(currentPType);
+ definition = "typedef " + cppType.getDefinition();
+
+ // If definition string contains "typeName" it should be replaced with type name...
+ if (definition.indexOf("typeName") != -1) {
+ definition = definition.replaceAll("typeName", currentPTypeName);
+ } else {
+ definition = definition + " " + currentPTypeName;
+ }
+ definition = definition + ";";
+ }
+ else {
+ definition = GenUtils.getStdtypes(currentPType);
+ }
+
+//////////////////////////////////////////////////////////////////////////////////////////
+// The following part contains the template
+//////////////////////////////////////////////////////////////////////////////////////////%>
+<%= typeDoc %>
+<%= definition %>
|