Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnsgar Radermacher2014-11-07 09:52:42 +0000
committerAnsgar Radermacher2014-11-07 09:55:40 +0000
commitae9cef1d1086a6b353d33329c97805edaa29da5a (patch)
treeff9141f2cd66fcc9f3b4347b5d71a0e8e869d937 /extraplugins/codegen
parentffea654b6fd4bd8519c7fc47558307036baf04d3 (diff)
downloadorg.eclipse.papyrus-ae9cef1d1086a6b353d33329c97805edaa29da5a.tar.gz
org.eclipse.papyrus-ae9cef1d1086a6b353d33329c97805edaa29da5a.tar.xz
org.eclipse.papyrus-ae9cef1d1086a6b353d33329c97805edaa29da5a.zip
449026 - C++ code generation from class operation not happening
Diffstat (limited to 'extraplugins/codegen')
-rw-r--r--extraplugins/codegen/org.eclipse.papyrus.acceleo/src/org/eclipse/papyrus/acceleo/GenUtils.java13
-rw-r--r--extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/Constants.java6
-rw-r--r--extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/xtend/CppOperations.xtend7
-rw-r--r--extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/xtend-gen/org/eclipse/papyrus/cpp/codegen/xtend/CppOperations.java7
4 files changed, 21 insertions, 12 deletions
diff --git a/extraplugins/codegen/org.eclipse.papyrus.acceleo/src/org/eclipse/papyrus/acceleo/GenUtils.java b/extraplugins/codegen/org.eclipse.papyrus.acceleo/src/org/eclipse/papyrus/acceleo/GenUtils.java
index 7d8c9df6f54..d43a23a6104 100644
--- a/extraplugins/codegen/org.eclipse.papyrus.acceleo/src/org/eclipse/papyrus/acceleo/GenUtils.java
+++ b/extraplugins/codegen/org.eclipse.papyrus.acceleo/src/org/eclipse/papyrus/acceleo/GenUtils.java
@@ -14,6 +14,8 @@ package org.eclipse.papyrus.acceleo;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
import org.eclipse.emf.common.util.BasicEList;
import org.eclipse.emf.common.util.EList;
@@ -556,10 +558,10 @@ public class GenUtils {
* @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) {
+ public static String getBody(Operation operation, Pattern selectedLanguages) {
for (Behavior behavior : operation.getMethods()) {
if (behavior instanceof OpaqueBehavior) {
- return getBodyFromOB((OpaqueBehavior) behavior, selectedLanguage);
+ return getBodyFromOB((OpaqueBehavior) behavior, selectedLanguages);
}
}
return ""; //$NON-NLS-1$
@@ -570,18 +572,19 @@ public class GenUtils {
* @param ob
* an opaque behavior
* @param selectedLanguage
- * the selected language
+ * the selected language, this may be a regular expression
* @return Return the first body of a selected language that is provided by
* one of the operation's methods
*/
- public static String getBodyFromOB(OpaqueBehavior ob, String selectedLanguage) {
+ public static String getBodyFromOB(OpaqueBehavior ob, Pattern selectedLanguages) {
Iterator<String> bodies = ob.getBodies().iterator();
for (String language : ob.getLanguages()) {
// additional sanity check: number of languages and number of bodies should be synchronized,
// but there is no guarantee that this is the case
if (bodies.hasNext()) {
String body = bodies.next();
- if (language.equals(selectedLanguage)) {
+ Matcher matcher = selectedLanguages.matcher(language);
+ if (matcher.matches()) {
// additional "\r" confuses Acceleo
return cleanCR(body);
}
diff --git a/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/Constants.java b/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/Constants.java
index 562ef1394e3..f4c257d11f9 100644
--- a/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/Constants.java
+++ b/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/Constants.java
@@ -10,6 +10,8 @@
*******************************************************************************/
package org.eclipse.papyrus.cpp.codegen;
+import java.util.regex.Pattern;
+
/**
* String constants for the code generation
*
@@ -35,5 +37,7 @@ public class Constants {
public static final String staticAttributes = "// static attributes (if any)"; //$NON-NLS-1$
public static final String undefinedType = "undefined"; //$NON-NLS-1$
-
+
+ // support the languages "C++", "C/C++" as well as "cpp". The '+' needs to be escaped in a regular epression
+ public static final Pattern supportedLanguages = Pattern.compile("C\\+\\+|C/C\\+\\+|cpp"); //$NON-NLS-1$
}
diff --git a/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/xtend/CppOperations.xtend b/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/xtend/CppOperations.xtend
index 53b4625212e..439feac17ab 100644
--- a/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/xtend/CppOperations.xtend
+++ b/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/xtend/CppOperations.xtend
@@ -17,17 +17,18 @@ import org.eclipse.uml2.uml.profile.standard.Create
import org.eclipse.uml2.uml.profile.standard.Destroy
import org.eclipse.papyrus.C_Cpp.ConstInit
import org.eclipse.uml2.uml.util.UMLUtil
+import org.eclipse.papyrus.cpp.codegen.Constants
class CppOperations {
static def CppOperationImplementation(Operation operation) '''
«CppDocumentation.CppOperationDoc(operation)»
«IF (operation.name == 'main')»
«CppReturnSpec(operation)»«operation.name»(«CppParameter.CppOperationParameters(operation,false)») {
- «GenUtils.getBody(operation, 'C/C++')»
+ «GenUtils.getBody(operation, Constants.supportedLanguages)»
}
«ELSE»
«CppTemplates.templateSignature(operation)»«InlineTxt(operation)»«CppReturnSpec(operation)»«operation.featuringClassifiers.get(0).name»«CppTemplates.templateShortSignature(operation)»::«destructor(operation)»«operation.name»(«CppParameter.CppOperationParameters(operation, false)»)«throwss(operation)»«Modifier.modCVQualifier(operation)»«CppConstInit(operation)» {
- «GenUtils.getBody(operation, 'C/C++')»
+ «GenUtils.getBody(operation, Constants.supportedLanguages)»
}
«ENDIF»
'''
@@ -88,7 +89,7 @@ class CppOperations {
static def CppBehaviorImplementation(OpaqueBehavior behavior) '''
«CppDocumentation.CppBehaviorDoc(behavior)»
«CppReturnSpec(behavior)»«behavior.context.name»::«behavior.name»(«CppParameter.CppBehaviorParameters(behavior, false)»)«Modifier.modCVQualifier(behavior)» {
- «GenUtils.getBodyFromOB(behavior, 'C/C++')»
+ «GenUtils.getBodyFromOB(behavior, Constants.supportedLanguages)»
}
'''
diff --git a/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/xtend-gen/org/eclipse/papyrus/cpp/codegen/xtend/CppOperations.java b/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/xtend-gen/org/eclipse/papyrus/cpp/codegen/xtend/CppOperations.java
index ab5b34f8be7..e9b9fa91722 100644
--- a/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/xtend-gen/org/eclipse/papyrus/cpp/codegen/xtend/CppOperations.java
+++ b/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/xtend-gen/org/eclipse/papyrus/cpp/codegen/xtend/CppOperations.java
@@ -6,6 +6,7 @@ import org.eclipse.papyrus.C_Cpp.ConstInit;
import org.eclipse.papyrus.C_Cpp.Inline;
import org.eclipse.papyrus.C_Cpp.Virtual;
import org.eclipse.papyrus.acceleo.GenUtils;
+import org.eclipse.papyrus.cpp.codegen.Constants;
import org.eclipse.papyrus.cpp.codegen.utils.CppGenUtils;
import org.eclipse.papyrus.cpp.codegen.utils.Modifier;
import org.eclipse.papyrus.cpp.codegen.xtend.CppDocumentation;
@@ -48,7 +49,7 @@ public class CppOperations {
_builder.append(") {");
_builder.newLineIfNotEmpty();
_builder.append("\t");
- String _body = GenUtils.getBody(operation, "C/C++");
+ String _body = GenUtils.getBody(operation, Constants.supportedLanguages);
_builder.append(_body, "\t");
_builder.newLineIfNotEmpty();
_builder.append("} ");
@@ -84,7 +85,7 @@ public class CppOperations {
_builder.append(" {");
_builder.newLineIfNotEmpty();
_builder.append("\t");
- String _body_1 = GenUtils.getBody(operation, "C/C++");
+ String _body_1 = GenUtils.getBody(operation, Constants.supportedLanguages);
_builder.append(_body_1, "\t");
_builder.newLineIfNotEmpty();
_builder.append("}");
@@ -265,7 +266,7 @@ public class CppOperations {
_builder.append(" {");
_builder.newLineIfNotEmpty();
_builder.append("\t");
- String _bodyFromOB = GenUtils.getBodyFromOB(behavior, "C/C++");
+ String _bodyFromOB = GenUtils.getBodyFromOB(behavior, Constants.supportedLanguages);
_builder.append(_bodyFromOB, "\t");
_builder.newLineIfNotEmpty();
_builder.append("}");

Back to the top