Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKenn Hussey2012-03-19 01:15:37 +0000
committerKenn Hussey2012-03-19 01:15:37 +0000
commita96a6894bff375ff20890fedb0333ba8db328abc (patch)
tree758088f18cf7746982ff7bf80b01e5b578437093 /plugins/org.eclipse.uml2.uml
parent3ea4c101ee474c6cac2d07a94a8d9927f480f257 (diff)
downloadorg.eclipse.uml2.test-a96a6894bff375ff20890fedb0333ba8db328abc.tar.gz
org.eclipse.uml2.test-a96a6894bff375ff20890fedb0333ba8db328abc.tar.xz
org.eclipse.uml2.test-a96a6894bff375ff20890fedb0333ba8db328abc.zip
[366350] Adding support for conversion of default literal values from
Ecore to UML.
Diffstat (limited to 'plugins/org.eclipse.uml2.uml')
-rw-r--r--plugins/org.eclipse.uml2.uml/src/org/eclipse/uml2/uml/util/UMLUtil.java171
1 files changed, 161 insertions, 10 deletions
diff --git a/plugins/org.eclipse.uml2.uml/src/org/eclipse/uml2/uml/util/UMLUtil.java b/plugins/org.eclipse.uml2.uml/src/org/eclipse/uml2/uml/util/UMLUtil.java
index 5302b748..e95cc0bf 100644
--- a/plugins/org.eclipse.uml2.uml/src/org/eclipse/uml2/uml/util/UMLUtil.java
+++ b/plugins/org.eclipse.uml2.uml/src/org/eclipse/uml2/uml/util/UMLUtil.java
@@ -10,7 +10,7 @@
* Kenn Hussey (Embarcadero Technologies) - 199624, 184249, 204406, 208125, 204200, 213218, 213903, 220669, 208016, 226396, 271470
* Nicolas Rouquette (JPL) - 260120, 313837
* Kenn Hussey - 286329, 313601, 314971, 344907, 236184
- * Kenn Hussey (CEA) - 327039, 358792, 364419
+ * Kenn Hussey (CEA) - 327039, 358792, 364419, 366350
* Yann Tanguy (CEA) - 350402
*
*/
@@ -3307,16 +3307,12 @@ public class UMLUtil
if (default_ != null) {
- if (type instanceof PrimitiveType
- && safeEquals(
- "PrimitiveTypes::UnlimitedNatural", type.getQualifiedName())) {//$NON-NLS-1$
-
- default_ = TypesFactory.eINSTANCE
- .createFromString(
- TypesPackage.Literals.UNLIMITED_NATURAL,
- default_).toString();
-
+ if (isUnlimitedNatural(type)) {
+ default_ = TypesFactory.eINSTANCE.createFromString(
+ TypesPackage.Literals.UNLIMITED_NATURAL,
+ default_).toString();
}
+
eAttribute.setDefaultValueLiteral(default_);
}
@@ -6632,6 +6628,33 @@ public class UMLUtil
caseETypedElement(eAttribute);
+ String defaultValueLiteral = eAttribute
+ .getDefaultValueLiteral();
+
+ if (defaultValueLiteral != null) {
+ Type type = property.getType();
+ EClass eClass = null;
+
+ if (type instanceof Enumeration) {
+ eClass = UMLPackage.Literals.INSTANCE_VALUE;
+ } else if (isBoolean(type)) {
+ eClass = UMLPackage.Literals.LITERAL_BOOLEAN;
+ } else if (isInteger(type)) {
+ eClass = UMLPackage.Literals.LITERAL_INTEGER;
+ } else if (isReal(type)) {
+ eClass = UMLPackage.Literals.LITERAL_REAL;
+ } else if (isString(type)) {
+ eClass = UMLPackage.Literals.LITERAL_STRING;
+ } else if (isUnlimitedNatural(type)) {
+ eClass = UMLPackage.Literals.LITERAL_UNLIMITED_NATURAL;
+ }
+
+ if (eClass != null) {
+ property.createDefaultValue(null, type, eClass);
+ property.setDefault(defaultValueLiteral);
+ }
+ }
+
defaultCase(eAttribute);
return property;
@@ -10345,4 +10368,132 @@ public class UMLUtil
return resourceSet;
}
+ /**
+ * Determines whether the specified type is a primitive type that classifies
+ * Boolean values.
+ *
+ * @param type
+ * The type in question.
+ * @return <code>true</code> if the type is a Boolean primitive type;
+ * <code>false</code> otherwise.
+ *
+ * @since 4.0
+ */
+ public static boolean isBoolean(Type type) {
+
+ if (type instanceof PrimitiveType) {
+ String qualifiedName = type.getQualifiedName();
+
+ return "JavaPrimitiveTypes::boolean".equals(qualifiedName) //$NON-NLS-1$
+ || "EcorePrimitiveTypes::EBoolean".equals(qualifiedName) //$NON-NLS-1$
+ || "EcorePrimitiveTypes::EBooleanObject".equals(qualifiedName) //$NON-NLS-1$
+ || "PrimitiveTypes::Boolean".equals(qualifiedName) //$NON-NLS-1$
+ || "XMLPrimitiveTypes::Boolean".equals(qualifiedName) //$NON-NLS-1$
+ || "XMLPrimitiveTypes::BooleanObject".equals(qualifiedName); //$NON-NLS-1$
+ }
+
+ return false;
+ }
+
+ /**
+ * Determines whether the specified type is a primitive type that classifies
+ * integer values.
+ *
+ * @param type
+ * The type in question.
+ * @return <code>true</code> if the type is an integer primitive type;
+ * <code>false</code> otherwise.
+ *
+ * @since 4.0
+ */
+ public static boolean isInteger(Type type) {
+
+ if (type instanceof PrimitiveType) {
+ String qualifiedName = type.getQualifiedName();
+
+ return "JavaPrimitiveTypes::int".equals(qualifiedName) //$NON-NLS-1$
+ || "EcorePrimitiveTypes::EInt".equals(qualifiedName) //$NON-NLS-1$
+ || "EcorePrimitiveTypes::EIntegerObject".equals(qualifiedName) //$NON-NLS-1$
+ || "PrimitiveTypes::Integer".equals(qualifiedName) //$NON-NLS-1$
+ || "XMLPrimitiveTypes::Int".equals(qualifiedName) //$NON-NLS-1$
+ || "XMLPrimitiveTypes::Integer".equals(qualifiedName) //$NON-NLS-1$
+ || "XMLPrimitiveTypes::IntObject".equals(qualifiedName); //$NON-NLS-1$
+ }
+
+ return false;
+ }
+
+ /**
+ * Determines whether the specified type is a primitive type that classifies
+ * real values.
+ *
+ * @param type
+ * The type in question.
+ * @return <code>true</code> if the type is a real primitive type;
+ * <code>false</code> otherwise.
+ *
+ * @since 4.0
+ */
+ public static boolean isReal(Type type) {
+
+ if (type instanceof PrimitiveType) {
+ String qualifiedName = type.getQualifiedName();
+
+ return "JavaPrimitiveTypes::double".equals(qualifiedName) //$NON-NLS-1$
+ || "EcorePrimitiveTypes::EDouble".equals(qualifiedName) //$NON-NLS-1$
+ || "EcorePrimitiveTypes::EDoubleObject".equals(qualifiedName) //$NON-NLS-1$
+ || "PrimitiveTypes::Real".equals(qualifiedName) //$NON-NLS-1$
+ || "XMLPrimitiveTypes::Double".equals(qualifiedName) //$NON-NLS-1$
+ || "XMLPrimitiveTypes::DoubleObject".equals(qualifiedName); //$NON-NLS-1$
+ }
+
+ return false;
+ }
+
+ /**
+ * Determines whether the specified type is a primitive type that classifies
+ * string values.
+ *
+ * @param type
+ * The type in question.
+ * @return <code>true</code> if the type is a string primitive type;
+ * <code>false</code> otherwise.
+ *
+ * @since 4.0
+ */
+ public static boolean isString(Type type) {
+
+ if (type instanceof PrimitiveType) {
+ String qualifiedName = type.getQualifiedName();
+
+ return "EcorePrimitiveTypes::EString".equals(qualifiedName) //$NON-NLS-1$
+ || "PrimitiveTypes::String".equals(qualifiedName) //$NON-NLS-1$
+ || "XMLPrimitiveTypes::String".equals(qualifiedName); //$NON-NLS-1$
+ }
+
+ return false;
+ }
+
+ /**
+ * Determines whether the specified type is a primitive type that classifies
+ * unlimited natural values.
+ *
+ * @param type
+ * The type in question.
+ * @return <code>true</code> if the type is an unlimited natural primitive
+ * type; <code>false</code> otherwise.
+ *
+ * @since 4.0
+ */
+ public static boolean isUnlimitedNatural(Type type) {
+
+ if (type instanceof PrimitiveType) {
+ String qualifiedName = type.getQualifiedName();
+
+ return "PrimitiveTypes::UnlimitedNatural".equals(qualifiedName); //$NON-NLS-1$
+ }
+
+ return false;
+ }
+
}

Back to the top