Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShuai Li2016-01-18 16:38:08 +0000
committerShuai Li2016-01-27 12:21:28 +0000
commit2a57d574039b38e83849c466e717273976179144 (patch)
treef7c44ded292683adea823e58ef8ae6ecc3089170 /extraplugins
parent4686eadb0d9a0484a680020bce01e72a09d8c10a (diff)
downloadorg.eclipse.papyrus-2a57d574039b38e83849c466e717273976179144.tar.gz
org.eclipse.papyrus-2a57d574039b38e83849c466e717273976179144.tar.xz
org.eclipse.papyrus-2a57d574039b38e83849c466e717273976179144.zip
Bug 486047 - [Codegen C++] Shared aggregation pointer
- When computing types to include, we skip shared aggregation attribute types - When computing types to declare, we add shared aggregation attribute types (unless they are already included, this hasn't changed) - Fix double pointer when an attribute is of shared aggregation kind, and it is also stereotyped <<Ptr>> Change-Id: I580c25ee304861498522b437128f1329208ffe4d Signed-off-by: Shuai Li <shuai.li@cea.fr>
Diffstat (limited to 'extraplugins')
-rw-r--r--extraplugins/qompass/codegen/cpp/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/utils/ClassUtils.java44
-rw-r--r--extraplugins/qompass/codegen/cpp/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/utils/Modifier.java13
-rw-r--r--extraplugins/qompass/codegen/org.eclipse.papyrus.codegen.base/src/org/eclipse/papyrus/codegen/base/GenUtils.java78
3 files changed, 104 insertions, 31 deletions
diff --git a/extraplugins/qompass/codegen/cpp/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/utils/ClassUtils.java b/extraplugins/qompass/codegen/cpp/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/utils/ClassUtils.java
index 6450635c0f6..8a37ce5cc46 100644
--- a/extraplugins/qompass/codegen/cpp/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/utils/ClassUtils.java
+++ b/extraplugins/qompass/codegen/cpp/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/utils/ClassUtils.java
@@ -11,6 +11,7 @@
package org.eclipse.papyrus.cpp.codegen.utils;
+import java.util.Iterator;
import java.util.List;
import org.eclipse.emf.common.util.BasicEList;
@@ -22,6 +23,7 @@ import org.eclipse.papyrus.C_Cpp.NoCodeGen;
import org.eclipse.papyrus.C_Cpp.Ptr;
import org.eclipse.papyrus.C_Cpp.Ref;
import org.eclipse.papyrus.codegen.base.GenUtils;
+import org.eclipse.uml2.uml.AggregationKind;
import org.eclipse.uml2.uml.Classifier;
import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.Enumeration;
@@ -29,6 +31,8 @@ import org.eclipse.uml2.uml.Interface;
import org.eclipse.uml2.uml.Operation;
import org.eclipse.uml2.uml.Package;
import org.eclipse.uml2.uml.PrimitiveType;
+import org.eclipse.uml2.uml.Property;
+import org.eclipse.uml2.uml.Type;
/**
* A set of utility functions related to classes.
@@ -96,7 +100,7 @@ public class ClassUtils {
noCodeGenStereotypes.add(NoCodeGen.class);
// class attributes dependencies (non-ptr and non-ref)
- usedClasses.addAll(GenUtils.getTypesViaAttributes(currentClass, ptrRefStereotypes, null, true));
+ usedClasses.addAll(GenUtils.getTypesViaAttributes(currentClass, ptrRefStereotypes, null, true, true));
addEnumerationsAndPrimitiveTypes(usedClasses, GenUtils.getTypesViaAttributes(currentClass));
// class inline operation parameters dependencies (non-ptr and non-ref)
@@ -104,7 +108,7 @@ public class ClassUtils {
addEnumerationsAndPrimitiveTypes(usedClasses, GenUtils.getTypesViaOperations(currentClass));
// inner classifier attribute dependencies (non-ptr and non-ref)
- usedClasses.addAll(GenUtils.getInnerClassifierTypesViaAttributes(currentClass, ptrRefStereotypes, null, true));
+ usedClasses.addAll(GenUtils.getInnerClassifierTypesViaAttributes(currentClass, ptrRefStereotypes, null, true, true));
addEnumerationsAndPrimitiveTypes(usedClasses, GenUtils.getInnerClassifierTypesViaAttributes(currentClass));
// inner classifier operation parameters dependencies (non-ptr and non-ref)
@@ -169,19 +173,6 @@ public class ClassUtils {
return usedClasses;
}
- private static void addEnumerationsAndPrimitiveTypes(List<Classifier> usedClasses, List<Classifier> unfilteredClasses) {
- if (usedClasses != null && unfilteredClasses != null) {
- for (Classifier classifier : unfilteredClasses) {
- if ((classifier instanceof Enumeration) || (classifier instanceof PrimitiveType)) {
- if (classifier.getOwner() instanceof Package) {
- usedClasses.add(classifier);
- }
- }
- }
- }
-
- }
-
/**
* Calculate the list of classifiers that needs to be declared in a header file
*
@@ -202,16 +193,18 @@ public class ClassUtils {
EList<Class<? extends EObject>> noCodeGenStereotypes = new BasicEList<Class<? extends EObject>>();
noCodeGenStereotypes.add(NoCodeGen.class);
- // class attributes dependencies (only ptr and ref)
- usedClasses.addAll(GenUtils.getTypesViaAttributes(currentClass, null, ptrRefStereotypes, true));
+ // class attributes dependencies (only ptr and ref and shared aggregation)
+ usedClasses.addAll(GenUtils.getTypesViaAttributes(currentClass, null, ptrRefStereotypes, true, false));
+ usedClasses.addAll(GenUtils.getTypesViaSharedAggregationAttributes(currentClass));
// operation parameters dependencies
usedClasses.addAll(GenUtils.getTypesViaOperations(currentClass));
usedClasses.removeAll(GenUtils.getTypesViaOperations(currentClass, noCodeGenStereotypes, inlineStereotypes, ptrRefStereotypes, null, false)); // Remove inline operation parameter types that have been included previously
// no-specification opaque behavior dependencies
usedClasses.addAll(GenUtils.getTypesViaOpaqueBehaviors(currentClass));
- // inner classifier attribute dependencies (only ptr and ref)
- usedClasses.addAll(GenUtils.getInnerClassifierTypesViaAttributes(currentClass, null, ptrRefStereotypes, false));
+ // inner classifier attribute dependencies (only ptr and ref and shared aggregation)
+ usedClasses.addAll(GenUtils.getInnerClassifierTypesViaAttributes(currentClass, null, ptrRefStereotypes, false, false));
+ usedClasses.addAll(GenUtils.getInnerClassifierTypesViaSharedAggregationAttributes(currentClass));
// inner classifier parameters dependencies
usedClasses.addAll(GenUtils.getInnerClassifierTypesViaOperations(currentClass));
usedClasses.removeAll(GenUtils.getInnerClassifierTypesViaOperations(currentClass, noCodeGenStereotypes, inlineStereotypes, ptrRefStereotypes, null, false)); // Remove inner classifier inline operation parameter types that have been included previously
@@ -256,4 +249,17 @@ public class ClassUtils {
return nestedOperations;
}
+
+ private static void addEnumerationsAndPrimitiveTypes(List<Classifier> usedClasses, List<Classifier> unfilteredClasses) {
+ if (usedClasses != null && unfilteredClasses != null) {
+ for (Classifier classifier : unfilteredClasses) {
+ if ((classifier instanceof Enumeration) || (classifier instanceof PrimitiveType)) {
+ if (classifier.getOwner() instanceof Package) {
+ usedClasses.add(classifier);
+ }
+ }
+ }
+ }
+
+ }
}
diff --git a/extraplugins/qompass/codegen/cpp/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/utils/Modifier.java b/extraplugins/qompass/codegen/cpp/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/utils/Modifier.java
index a55f4f6c0a0..05daf9e3965 100644
--- a/extraplugins/qompass/codegen/cpp/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/utils/Modifier.java
+++ b/extraplugins/qompass/codegen/cpp/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/utils/Modifier.java
@@ -41,18 +41,19 @@ public class Modifier {
public static String modPtr(Element propertyOrParameter) {
// Pointer
- String ptr = ""; //$NON-NLS-1$
+ String ptr; //$NON-NLS-1$
Ptr cppPtr = UMLUtil.getStereotypeApplication(propertyOrParameter, Ptr.class);
if (cppPtr != null) {
ptr = (cppPtr.getDeclaration() != null) ? cppPtr.getDeclaration() : "*"; //$NON-NLS-1$
} else {
- ptr = ""; //$NON-NLS-1$
- }
- if (propertyOrParameter instanceof Property) {
- if (((Property) propertyOrParameter).getAggregation() == AggregationKind.SHARED_LITERAL) {
- ptr += "*"; //$NON-NLS-1$
+ if (propertyOrParameter instanceof Property
+ && ((Property) propertyOrParameter).getAggregation() == AggregationKind.SHARED_LITERAL) {
+ ptr = "*"; //$NON-NLS-1$
+ } else {
+ ptr = ""; //$NON-NLS-1$
}
}
+
boolean ptrOrRef = GenUtils.hasStereotype(propertyOrParameter, Ref.class)
|| GenUtils.hasStereotype(propertyOrParameter, Ptr.class);
diff --git a/extraplugins/qompass/codegen/org.eclipse.papyrus.codegen.base/src/org/eclipse/papyrus/codegen/base/GenUtils.java b/extraplugins/qompass/codegen/org.eclipse.papyrus.codegen.base/src/org/eclipse/papyrus/codegen/base/GenUtils.java
index 426db4fe8de..93b1c43a059 100644
--- a/extraplugins/qompass/codegen/org.eclipse.papyrus.codegen.base/src/org/eclipse/papyrus/codegen/base/GenUtils.java
+++ b/extraplugins/qompass/codegen/org.eclipse.papyrus.codegen.base/src/org/eclipse/papyrus/codegen/base/GenUtils.java
@@ -22,6 +22,7 @@ import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.common.util.UniqueEList;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
+import org.eclipse.uml2.uml.AggregationKind;
import org.eclipse.uml2.uml.Behavior;
import org.eclipse.uml2.uml.Classifier;
import org.eclipse.uml2.uml.Comment;
@@ -174,9 +175,13 @@ public class GenUtils {
* List of ALL stereotypes that must no be applied
* @param includedStereotypes
* List of ANY stereotype that must no be applied (at least one)
+ * @param bypassForInnerClassifiers
+ * Always include inner classifier types or not
+ * @param noSharedAggregation
+ * Always exclude attributes with a shared aggregation kind
* @return Collection of classifiers which are the types of the attributes
*/
- public static EList<Classifier> getTypesViaAttributes(Classifier current, EList<Class<? extends EObject>> excludedStereotypes, EList<Class<? extends EObject>> includedStereotypes, boolean bypassForInnerClassifiers) {
+ public static EList<Classifier> getTypesViaAttributes(Classifier current, EList<Class<? extends EObject>> excludedStereotypes, EList<Class<? extends EObject>> includedStereotypes, boolean bypassForInnerClassifiers, boolean noSharedAggregation) {
EList<Classifier> result = new UniqueEList<Classifier>();
Iterator<Property> attributes;
@@ -186,14 +191,24 @@ public class GenUtils {
Type type = currentAttribute.getType();
if (type != null) {
+ // Check type is inner classifier
if (bypassForInnerClassifiers && !(type.getOwner() instanceof Package)) { // if we force inner class types to be processed
addFarthestOwnerType(type, result);
} else {
- // Check stereotypes
+ // Check other conditions
boolean ok = true;
- if (excludedStereotypes != null && GenUtils.hasAnyStereotype(currentAttribute, excludedStereotypes)) {
+
+ // Check attribute is shared aggregation
+ if (noSharedAggregation && currentAttribute.getAggregation() == AggregationKind.SHARED_LITERAL) {
ok = false;
}
+ // Check attribute does not have an excluded stereotype
+ if (ok) {
+ if (excludedStereotypes != null && GenUtils.hasAnyStereotype(currentAttribute, excludedStereotypes)) {
+ ok = false;
+ }
+ }
+ // Check attribute has an included stereotype
if (ok) {
if (includedStereotypes != null && !GenUtils.hasAnyStereotype(currentAttribute, includedStereotypes)) {
ok = false;
@@ -212,6 +227,32 @@ public class GenUtils {
}
/**
+ * Retrieve a list of types of attributes, with SHARED aggregation, that belong to the current classifier.
+ *
+ * @param current
+ * Class on which the attributes are searched
+ * @return Collection of classifiers which are the types of the attributes
+ */
+ public static EList<Classifier> getTypesViaSharedAggregationAttributes(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 != null) {
+ if (currentAttribute.getAggregation() == AggregationKind.SHARED_LITERAL) {
+ addFarthestOwnerType(type, result);
+ }
+ }
+ }
+
+ return result;
+ }
+
+ /**
* Retrieve the operations in the current classifier. For each
* operation, collect types of its parameters.
* This method thus finds types, on
@@ -249,6 +290,8 @@ public class GenUtils {
* List of ALL stereotypes that must not be applied to a parameter
* @param includedParameterStereotypes
* List of ANY stereotype that must be applied to a parameter (at least one)
+ * @param bypassForInnerClassifiers
+ * Always include types that are inner classifiers
* @return Collection of classifiers which are the types of the operation parameters
*/
public static EList<Classifier> getTypesViaOperations(Classifier current,
@@ -342,6 +385,8 @@ public class GenUtils {
* List of ALL stereotypes that must not be applied to a parameter
* @param includedParameterStereotypes
* List of ANY stereotype that must be applied to a parameter (at least one)
+ * @param bypassForInnerClassifiers
+ * Always include types that are inner classifiers
* @return Collection of classifiers which are the types of the opaque behavior parameters
*/
public static EList<Classifier> getTypesViaOpaqueBehaviors(Classifier current,
@@ -437,13 +482,34 @@ public class GenUtils {
* List of ALL stereotypes that must no be applied
* @param includedStereotypes
* List of ANY stereotype that must no be applied (at least one)
+ * @param bypassForInnerClassifiers
+ * Always include types that are inner classifiers
+ * @param noSharedAggregation
+ * Always exclude attributes with a shared aggregation kind
+ * @return Collection of classifiers which are the types of the attributes of inner classifiers
+ */
+ public static EList<Classifier> getInnerClassifierTypesViaAttributes(Classifier current, EList<Class<? extends EObject>> excludedStereotypes, EList<Class<? extends EObject>> includedStereotypes, boolean bypassForInnerClassifiers, boolean noSharedAggregation) {
+ EList<Classifier> result = new UniqueEList<Classifier>();
+ for (Element ownedElement : current.allOwnedElements()) {
+ if (ownedElement instanceof Classifier) {
+ result.addAll(getTypesViaAttributes((Classifier) ownedElement, excludedStereotypes, includedStereotypes, bypassForInnerClassifiers, noSharedAggregation));
+ }
+ }
+ return result;
+ }
+
+ /**
+ * Retrieve a list of types of attributes, of shared aggregation, of inner classifiers that belong to the current classifier.
+ *
+ * @param current
+ * Class on which the attributes are searched
* @return Collection of classifiers which are the types of the attributes of inner classifiers
*/
- public static EList<Classifier> getInnerClassifierTypesViaAttributes(Classifier current, EList<Class<? extends EObject>> excludedStereotypes, EList<Class<? extends EObject>> includedStereotypes, boolean bypassForInnerClassifiers) {
+ public static EList<Classifier> getInnerClassifierTypesViaSharedAggregationAttributes(Classifier current) {
EList<Classifier> result = new UniqueEList<Classifier>();
for (Element ownedElement : current.allOwnedElements()) {
if (ownedElement instanceof Classifier) {
- result.addAll(getTypesViaAttributes((Classifier) ownedElement, excludedStereotypes, includedStereotypes, bypassForInnerClassifiers));
+ result.addAll(getTypesViaSharedAggregationAttributes((Classifier) ownedElement));
}
}
return result;
@@ -712,7 +778,7 @@ public class GenUtils {
* @param classifier
* @return
*/
- private static void addFarthestOwnerType(Element element, EList<Classifier> result) {
+ public static void addFarthestOwnerType(Element element, EList<Classifier> result) {
if (element == null || result == null) {
return;
}

Back to the top