Merge branch 'master' into bugs/405065
diff --git a/examples/org.eclipse.uml2.examples.uml.ui/src/org/eclipse/uml2/examples/uml/ui/dialogs/UML2EcoreConverterOptionsDialog.java b/examples/org.eclipse.uml2.examples.uml.ui/src/org/eclipse/uml2/examples/uml/ui/dialogs/UML2EcoreConverterOptionsDialog.java
index 5fcc9b6..3294eef 100644
--- a/examples/org.eclipse.uml2.examples.uml.ui/src/org/eclipse/uml2/examples/uml/ui/dialogs/UML2EcoreConverterOptionsDialog.java
+++ b/examples/org.eclipse.uml2.examples.uml.ui/src/org/eclipse/uml2/examples/uml/ui/dialogs/UML2EcoreConverterOptionsDialog.java
@@ -9,7 +9,7 @@
* IBM - initial API and implementation
* Kenn Hussey (Embarcadero Technologies) - 213218
* Kenn Hussey (CEA) - 322715
- * Christian W. Damus (CEA) - 409396, 403374, 420338
+ * Christian W. Damus (CEA) - 409396, 403374, 420338, 405065
*
*/
package org.eclipse.uml2.examples.uml.ui.dialogs;
@@ -168,6 +168,14 @@
createOptionArea(
parent,
+ UMLExamplesUIPlugin.INSTANCE
+ .getString("_UI_PropertyDefaultExpressions_label"), //$NON-NLS-1$
+ UMLUtil.UML2EcoreConverter.OPTION__PROPERTY_DEFAULT_EXPRESSIONS,
+ new String[]{ignoreChoiceLabel, reportChoiceLabel,
+ processChoiceLabel}, processChoiceLabel);
+
+ createOptionArea(
+ parent,
UMLExamplesUIPlugin.INSTANCE.getString("_UI_Comments_label"), //$NON-NLS-1$
UMLUtil.UML2EcoreConverter.OPTION__COMMENTS, new String[]{
ignoreChoiceLabel, reportChoiceLabel, processChoiceLabel},
diff --git a/plugins/org.eclipse.uml2.ant/src/org/eclipse/uml2/ant/app/DefineProfileApplication.java b/plugins/org.eclipse.uml2.ant/src/org/eclipse/uml2/ant/app/DefineProfileApplication.java
index ecca433..d87ce17 100644
--- a/plugins/org.eclipse.uml2.ant/src/org/eclipse/uml2/ant/app/DefineProfileApplication.java
+++ b/plugins/org.eclipse.uml2.ant/src/org/eclipse/uml2/ant/app/DefineProfileApplication.java
@@ -10,6 +10,7 @@
* Kenn Hussey (Embarcadero Technologies) - 213218
* Kenn Hussey (CEA) - 322715
* Christian W. Damus (CEA) - 286404 (adapted from UMLImporterApplication)
+ * Christian W. Damus (CEA) - 405065
*
*/
package org.eclipse.uml2.ant.app;
@@ -211,6 +212,7 @@
result.append(" -SUPER_CLASS_ORDER | -ANNOTATION_DETAILS |" ).append(nl); //$NON-NLS-1$
result.append(" -INVARIANT_CONSTRAINTS | -VALIDATION_DELEGATES | -NON_API_INVARIANTS |" ).append(nl); //$NON-NLS-1$
result.append(" -OPERATION_BODIES | -INVOCATION_DELEGATES |" ).append(nl); //$NON-NLS-1$
+ result.append(" -PROPERTY_DEFAULT_EXPRESSIONS |" ).append(nl); //$NON-NLS-1$
result.append(" -COMMENTS | -CAMEL_CASE_NAMES |" ).append(nl); //$NON-NLS-1$
result.append(" -FOREIGN_DEFINITIONS >" ).append(nl); //$NON-NLS-1$
result.append(" < PROCESS | IGNORE | REPORT | DISCARD >").append(nl); //$NON-NLS-1$
@@ -297,6 +299,8 @@
.equalsIgnoreCase(strippedKey)
|| UMLUtil.UML2EcoreConverter.OPTION__INVOCATION_DELEGATES
.equalsIgnoreCase(strippedKey)
+ || UMLUtil.UML2EcoreConverter.OPTION__PROPERTY_DEFAULT_EXPRESSIONS
+ .equalsIgnoreCase(strippedKey)
|| UMLUtil.UML2EcoreConverter.OPTION__COMMENTS
.equalsIgnoreCase(strippedKey)
|| UMLUtil.UML2EcoreConverter.OPTION__CAMEL_CASE_NAMES
diff --git a/plugins/org.eclipse.uml2.common/src/org/eclipse/uml2/common/util/UML2Util.java b/plugins/org.eclipse.uml2.common/src/org/eclipse/uml2/common/util/UML2Util.java
index ed3ee13..98a1081 100644
--- a/plugins/org.eclipse.uml2.common/src/org/eclipse/uml2/common/util/UML2Util.java
+++ b/plugins/org.eclipse.uml2.common/src/org/eclipse/uml2/common/util/UML2Util.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2005, 2013 IBM Corporation, Embarcadero Technologies, CEA, and others.
+ * Copyright (c) 2005, 2014 IBM Corporation, Embarcadero Technologies, CEA, and others.
* 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
@@ -10,6 +10,7 @@
* Kenn Hussey (Embarcadero Technologies) - 204200, 247980
* Keith Campbell (IBM) - 343783
* Kenn Hussey (CEA) - 316165, 322715, 212765, 421756
+ * Christian W. Damus (CEA) - 405065
*
*/
package org.eclipse.uml2.common.util;
@@ -1302,6 +1303,41 @@
return result;
}
+ /**
+ * Adds the specified setting delegate to a package, if it is not already
+ * present.
+ *
+ * @param ePackage
+ * a package
+ * @param settingDelegate
+ * a setting delegate to ensure is recorded for this package
+ *
+ * @return {@code false} if the {@code settingDelegate} is {@code null} or
+ * empty, or was already present; {@code true} if the setting
+ * delegate was added to the package
+ *
+ * @since 5.0
+ */
+ protected static boolean addSettingDelegate(EPackage ePackage,
+ String settingDelegate) {
+
+ boolean result = false;
+
+ if (!isEmpty(settingDelegate)) {
+ List<String> settingDelegates = EcoreUtil
+ .getSettingDelegates(ePackage);
+
+ if (!settingDelegates.contains(settingDelegate)) {
+ result = (settingDelegates = new ArrayList<String>(
+ settingDelegates)).add(settingDelegate);
+
+ EcoreUtil.setSettingDelegates(ePackage, settingDelegates);
+ }
+ }
+
+ return result;
+ }
+
protected static boolean addValidationDelegate(EPackage ePackage,
String validationDelegate) {
boolean result = false;
diff --git a/plugins/org.eclipse.uml2.uml.ecore.importer/src/org/eclipse/uml2/uml/ecore/importer/UMLImporterApplication.java b/plugins/org.eclipse.uml2.uml.ecore.importer/src/org/eclipse/uml2/uml/ecore/importer/UMLImporterApplication.java
index 5cb03ff..0cb2310 100644
--- a/plugins/org.eclipse.uml2.uml.ecore.importer/src/org/eclipse/uml2/uml/ecore/importer/UMLImporterApplication.java
+++ b/plugins/org.eclipse.uml2.uml.ecore.importer/src/org/eclipse/uml2/uml/ecore/importer/UMLImporterApplication.java
@@ -9,7 +9,7 @@
* IBM - initial API and implementation
* Kenn Hussey (Embarcadero Technologies) - 213218
* Kenn Hussey (CEA) - 322715
- * Christian W. Damus (CEA) - 403374, 420338
+ * Christian W. Damus (CEA) - 403374, 420338, 405065
*
*/
package org.eclipse.uml2.uml.ecore.importer;
@@ -106,6 +106,7 @@
appendLine(result," -SUPER_CLASS_ORDER | -ANNOTATION_DETAILS |" ); //$NON-NLS-1$
appendLine(result," -INVARIANT_CONSTRAINTS | -VALIDATION_DELEGATES | -NON_API_INVARIANTS |" ); //$NON-NLS-1$
appendLine(result," -OPERATION_BODIES | -INVOCATION_DELEGATES |" ); //$NON-NLS-1$
+ appendLine(result," -PROPERTY_DEFAULT_EXPRESSIONS |"); //$NON-NLS-1$
appendLine(result," -COMMENTS | -CAMEL_CASE_NAMES >" ); //$NON-NLS-1$
appendLine(result," < PROCESS | IGNORE | REPORT | DISCARD >"); //$NON-NLS-1$
appendLine(result, "<CACHE-ADAPTER-SUPPORT> ::= -cacheAdapterSupport"); //$NON-NLS-1$
@@ -197,6 +198,8 @@
.equalsIgnoreCase(strippedKey)
|| UMLUtil.UML2EcoreConverter.OPTION__INVOCATION_DELEGATES
.equalsIgnoreCase(strippedKey)
+ || UMLUtil.UML2EcoreConverter.OPTION__PROPERTY_DEFAULT_EXPRESSIONS
+ .equalsIgnoreCase(strippedKey)
|| UMLUtil.UML2EcoreConverter.OPTION__COMMENTS
.equalsIgnoreCase(strippedKey)
|| UMLUtil.UML2EcoreConverter.OPTION__CAMEL_CASE_NAMES
diff --git a/plugins/org.eclipse.uml2.uml.ecore.importer/src/org/eclipse/uml2/uml/ecore/importer/ui/UMLImporterDetailPage.java b/plugins/org.eclipse.uml2.uml.ecore.importer/src/org/eclipse/uml2/uml/ecore/importer/ui/UMLImporterDetailPage.java
index aafc551..2f763e9 100644
--- a/plugins/org.eclipse.uml2.uml.ecore.importer/src/org/eclipse/uml2/uml/ecore/importer/ui/UMLImporterDetailPage.java
+++ b/plugins/org.eclipse.uml2.uml.ecore.importer/src/org/eclipse/uml2/uml/ecore/importer/ui/UMLImporterDetailPage.java
@@ -9,7 +9,7 @@
* IBM - initial API and implementation
* Kenn Hussey (Embarcadero Technologies) - 213218
* Kenn Hussey (CEA) - 322715
- * Christian W. Damus (CEA) - 409396, 403374, 420338
+ * Christian W. Damus (CEA) - 409396, 403374, 420338, 405065
*
*/
package org.eclipse.uml2.uml.ecore.importer.ui;
@@ -252,6 +252,13 @@
ignoreChoiceLabel);
addOptionControl(
optionsComposite,
+ UMLImporterPlugin.INSTANCE
+ .getString("_UI_PropertyDefaultExpressions_label"), //$NON-NLS-1$
+ UMLUtil.UML2EcoreConverter.OPTION__PROPERTY_DEFAULT_EXPRESSIONS,
+ new String[]{ignoreChoiceLabel, reportChoiceLabel,
+ processChoiceLabel}, ignoreChoiceLabel);
+ addOptionControl(
+ optionsComposite,
UMLImporterPlugin.INSTANCE.getString("_UI_Comments_label"), //$NON-NLS-1$
UMLUtil.UML2EcoreConverter.OPTION__COMMENTS, new String[]{
ignoreChoiceLabel, reportChoiceLabel, processChoiceLabel},
diff --git a/plugins/org.eclipse.uml2.uml.editor/src/org/eclipse/uml2/uml/editor/dialogs/Profile2EPackageConverterOptionsDialog.java b/plugins/org.eclipse.uml2.uml.editor/src/org/eclipse/uml2/uml/editor/dialogs/Profile2EPackageConverterOptionsDialog.java
index 71fdc1b..bcebace 100644
--- a/plugins/org.eclipse.uml2.uml.editor/src/org/eclipse/uml2/uml/editor/dialogs/Profile2EPackageConverterOptionsDialog.java
+++ b/plugins/org.eclipse.uml2.uml.editor/src/org/eclipse/uml2/uml/editor/dialogs/Profile2EPackageConverterOptionsDialog.java
@@ -8,7 +8,7 @@
* Contributors:
* IBM - initial API and implementation
* Kenn Hussey (CEA) - 322715, 163556
- * Christian W. Damus (CEA) - 409396, 403374, 420338
+ * Christian W. Damus (CEA) - 409396, 403374, 420338, 405065
*
*/
package org.eclipse.uml2.uml.editor.dialogs;
@@ -159,6 +159,14 @@
createOptionArea(
parent,
+ UMLEditorPlugin.INSTANCE
+ .getString("_UI_PropertyDefaultExpressions_label"), //$NON-NLS-1$
+ UMLUtil.UML2EcoreConverter.OPTION__PROPERTY_DEFAULT_EXPRESSIONS,
+ new String[]{ignoreChoiceLabel, reportChoiceLabel,
+ processChoiceLabel}, ignoreChoiceLabel);
+
+ createOptionArea(
+ parent,
UMLEditorPlugin.INSTANCE.getString("_UI_Comments_label"), //$NON-NLS-1$
UMLUtil.UML2EcoreConverter.OPTION__COMMENTS, new String[]{
ignoreChoiceLabel, reportChoiceLabel, processChoiceLabel},
diff --git a/plugins/org.eclipse.uml2.uml/model/UML.genmodel b/plugins/org.eclipse.uml2.uml/model/UML.genmodel
index 4b84ceb..0ec964e 100644
--- a/plugins/org.eclipse.uml2.uml/model/UML.genmodel
+++ b/plugins/org.eclipse.uml2.uml/model/UML.genmodel
@@ -33,6 +33,7 @@
<details key="UNTYPED_PROPERTIES" value="REPORT"/>
<details key="NON_API_INVARIANTS" value="IGNORE"/>
<details key="OPPOSITE_ROLE_NAMES" value="IGNORE"/>
+ <details key="PROPERTY_DEFAULT_EXPRESSIONS" value="IGNORE"/>
</genAnnotations>
<foreignModel>UML.merged.uml</foreignModel>
<genPackages xsi:type="genmodel:GenPackage" prefix="UML" basePackage="org.eclipse.uml2"
diff --git a/plugins/org.eclipse.uml2.uml/plugin.properties b/plugins/org.eclipse.uml2.uml/plugin.properties
index 4527a74..bdb9492 100644
--- a/plugins/org.eclipse.uml2.uml/plugin.properties
+++ b/plugins/org.eclipse.uml2.uml/plugin.properties
@@ -8,7 +8,7 @@
# IBM - initial API and implementation
# Kenn Hussey (Embarcadero Technologies) - 156879, 215488, 213218, 204200
# Kenn Hussey (CEA) - 327039, 351774, 373709, 388636, 295864, 397140, 316165, 322715, 80307, 416833
-# Christian W. Damus (CEA) - 373643, 374012, 163556, 409396, 180744, 403374, 420338
+# Christian W. Damus (CEA) - 373643, 374012, 163556, 409396, 180744, 403374, 420338, 405065
#
# NLS_MESSAGEFORMAT_VAR
@@ -58,6 +58,7 @@
_UI_UML2EcoreConverter_ProcessSuperClassOrder_diagnostic = Re-ordered the super classes of class ''{0}'' for optimal code generation.
_UI_UML2EcoreConverter_ProcessAnnotationDetails_diagnostic = Annotated model element ''{0}'' with details from source ''{1}''.
_UI_UML2EcoreConverter_ProcessUntypedProperty_diagnostic = Feature ''{0}'' has no type specified and is assigned ''{1}'' by default.
+_UI_UML2EcoreConverter_ProcessOppositeRoleName_diagnostic = Reference ''{0}'' has been annotated with opposite role name ''{1}''.
_UI_UML2EcoreConverter_DiscardDuplicateOperation_diagnostic = Discarded operation ''{0}'' because it is a duplicate of inherited operation ''{1}''.
_UI_UML2EcoreConverter_DiscardDuplicateOperationInheritance_diagnostic = Discarded inheritance of operation ''{2}'' by class ''{0}'' because it is a duplicate of operation ''{1}''.
@@ -78,20 +79,19 @@
_UI_UML2EcoreConverter_ReportSuperClassOrder_diagnostic = The super classes of class ''{0}'' should be re-ordered for optimal code generation.
_UI_UML2EcoreConverter_ReportAnnotationDetails_diagnostic = Model element ''{0}'' should be annotated with details from source ''{1}''.
_UI_UML2EcoreConverter_ReportUntypedProperty_diagnostic = Feature ''{0}'' has no type specified.
-_UI_UML2EcoreConverter_ProcessOppositeRoleName_diagnostic = Reference ''{0}'' has been annotated with opposite role name ''{1}''.
_UI_Ecore2UMLConverter_ProcessEcoreTaggedValue_diagnostic = Applied Ecore tag ''{1}'' with value of ''{2}'' to element ''{0}''.
_UI_Ecore2UMLConverter_ProcessRedefinesAnnotation_diagnostic = Made ''{0}'' redefine ''{1}'' based on an annotation.
_UI_Ecore2UMLConverter_ProcessSubsetsAnnotation_diagnostic = Made ''{0}'' subset ''{1}'' based on an annotation.
_UI_Ecore2UMLConverter_ProcessUnionAnnotation_diagnostic = Made ''{0}'' a union based on an annotation.
_UI_Ecore2UMLConverter_ProcessAnnotationDetails_diagnostic = Annotated element ''{0}'' with details from source ''{1}''.
+_UI_Ecore2UMLConverter_ProcessOppositeRoleName_diagnostic = Property ''{0}'' association-owned opposite has been named ''{1}''.
_UI_Ecore2UMLConverter_ReportEcoreTaggedValue_diagnostic = Element ''{0}'' should have an Ecore tag ''{1}'' with value of ''{2}''.
_UI_Ecore2UMLConverter_ReportRedefinesAnnotation_diagnostic = ''{0}'' should redefine ''{1}'' based on an annotation.
_UI_Ecore2UMLConverter_ReportSubsetsAnnotation_diagnostic = ''{0}'' should subset ''{1}'' based on an annotation.
_UI_Ecore2UMLConverter_ReportUnionAnnotation_diagnostic = ''{0}'' should be a union based on an annotation.
_UI_Ecore2UMLConverter_ReportAnnotationDetails_diagnostic = Element ''{0}'' should be annotated with details from source ''{1}''.
-_UI_Ecore2UMLConverter_ProcessOppositeRoleName_diagnostic = Property ''{0}'' association-owned opposite has been named ''{1}''.
_UI_Classifier_NoCyclesInGeneralization_diagnostic = Classifier ''{0}'' is both a transitively general and transitively specific classifier of the same classifier.
_UI_Classifier_SpecializeType_diagnostic = Classifier ''{0}'' specializes classifier ''{1}'' of invalid type.
@@ -167,10 +167,12 @@
_UI_UML2EcoreConverter_ReportInvariantConstraint_diagnostic = Classifier ''{0}'' should have an invariant constraint for ''{1}''.
_UI_UML2EcoreConverter_ReportOperationBody_diagnostic = Operation ''{0}'' should be annotated with a(n) ''{1}'' body.
+_UI_UML2EcoreConverter_ReportPropertyDefaultExpression_diagnostic = Feature ''{0}'' should be annotated with a(n) ''{1}'' derivation/initial value.
_UI_UML2EcoreConverter_ReportComment_diagnostic = Model element ''{0}'' should be annotated with documentation.
_UI_UML2EcoreConverter_ProcessInvariantConstraint_diagnostic = Added an invariant constraint for ''{1}'' to classifier ''{0}''.
_UI_UML2EcoreConverter_ProcessOperationBody_diagnostic = Annotated operation ''{0}'' with a(n) ''{1}'' body.
+_UI_UML2EcoreConverter_ProcessPropertyDefaultExpression_diagnostic = Annotated feature ''{0}'' with a(n) ''{1}'' derivation/initial value.
_UI_UML2EcoreConverter_ProcessComment_diagnostic = Annotated model element ''{0}'' with documentation.
_UI_Ecore2UMLConverter_ReportBodyAnnotation_diagnostic = Operation ''{0}'' should have a(n) ''{1}'' body constraint based on a body annotation.
@@ -205,6 +207,7 @@
_UI_AnnotationDetails_label = Annotation Details
_UI_InvariantConstraints_label = Invariant Constraints
_UI_OperationBodies_label = Operation Bodies
+_UI_PropertyDefaultExpressions_label = Property Default Expressions
_UI_Comments_label = Comments
_UI_UntypedProperties_label = Untyped Properties
_UI_OppositeRoleNames_label = Opposite Role Names
diff --git a/plugins/org.eclipse.uml2.uml/src/org/eclipse/uml2/uml/internal/operations/ProfileOperations.java b/plugins/org.eclipse.uml2.uml/src/org/eclipse/uml2/uml/internal/operations/ProfileOperations.java
index 899ec5b..4cf1f06 100644
--- a/plugins/org.eclipse.uml2.uml/src/org/eclipse/uml2/uml/internal/operations/ProfileOperations.java
+++ b/plugins/org.eclipse.uml2.uml/src/org/eclipse/uml2/uml/internal/operations/ProfileOperations.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2005, 2013 IBM Corporation, CEA, and others.
+ * Copyright (c) 2005, 2014 IBM Corporation, CEA, and others.
* 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
@@ -9,6 +9,7 @@
* IBM - initial API and implementation
* Kenn Hussey - 323181, 354452
* Kenn Hussey (CEA) - 327039, 392833, 163556
+ * Christian W. Damus (CEA) - 405065
*
*/
package org.eclipse.uml2.uml.internal.operations;
@@ -246,6 +247,8 @@
OPTION__IGNORE);
options
.put(UML2EcoreConverter.OPTION__OPERATION_BODIES, OPTION__IGNORE);
+ options.put(UML2EcoreConverter.OPTION__PROPERTY_DEFAULT_EXPRESSIONS,
+ OPTION__IGNORE);
options.put(UML2EcoreConverter.OPTION__COMMENTS, OPTION__IGNORE);
return profile.define(options, null, null);
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 bc1a892..ed10d7f 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
@@ -12,7 +12,7 @@
* Kenn Hussey - 286329, 313601, 314971, 344907, 236184, 335125
* Kenn Hussey (CEA) - 327039, 358792, 364419, 366350, 307343, 382637, 273949, 389542, 389495, 316165, 392833, 399544, 322715, 163556, 212765, 397324, 204658, 408612, 411731, 269598, 422000, 416833
* Yann Tanguy (CEA) - 350402
- * Christian W. Damus (CEA) - 392833, 251963, 405061, 409396, 176998, 180744, 403374, 416833, 420338
+ * Christian W. Damus (CEA) - 392833, 251963, 405061, 409396, 176998, 180744, 403374, 416833, 420338, 405065
* E.D.Willink - 420338
*
*/
@@ -3837,6 +3837,17 @@
*/
public static final String OPTION__OPPOSITE_ROLE_NAMES = "OPPOSITE_ROLE_NAMES"; //$NON-NLS-1$
+ /**
+ * The option for handling cases where property default value
+ * expressions are encountered. These generate setting delegate
+ * annotations in the Ecore model. Supported choices are
+ * <code>OPTION__IGNORE</code>, <code>OPTION__REPORT</code>, and
+ * <code>OPTION__PROCESS</code>.
+ *
+ * @since 5.0
+ */
+ public static final String OPTION__PROPERTY_DEFAULT_EXPRESSIONS = "PROPERTY_DEFAULT_EXPRESSIONS"; //$NON-NLS-1$
+
private static final int DIAGNOSTIC_CODE_OFFSET = 2000;
/**
@@ -3945,6 +3956,14 @@
*/
public static final int OPPOSITE_ROLE_NAME = DIAGNOSTIC_CODE_OFFSET + 18;
+ /**
+ * The diagnostic code for cases where property default expression
+ * details are encountered.
+ *
+ * @since 5.0
+ */
+ public static final int PROPERTY_DEFAULT_EXPRESSION = DIAGNOSTIC_CODE_OFFSET + 19;
+
protected static final Pattern ANNOTATION_PATTERN = Pattern
.compile("\\G\\s*((?>\\\\.|\\S)+)((?:\\s+(?>\\\\.|\\S)+\\s*+=\\s*(['\"])((?>\\\\.|.)*?)\\3)*)"); //$NON-NLS-1$
@@ -4915,17 +4934,25 @@
.createEAttribute());
elementToEModelElementMap.put(property, eAttribute);
- String default_ = property.getDefault();
+ // only set the default literal if the default value is
+ // not an expression when we are using setting delegates
+ if (!((property.getDefaultValue() instanceof OpaqueExpression) && OPTION__PROCESS
+ .equals(options
+ .get(OPTION__PROPERTY_DEFAULT_EXPRESSIONS)))) {
- if (default_ != null) {
+ String default_ = property.getDefault();
- if (isUnlimitedNatural(type)) {
- default_ = TypesFactory.eINSTANCE.createFromString(
- TypesPackage.Literals.UNLIMITED_NATURAL,
- default_).toString();
+ if (default_ != null) {
+
+ if (isUnlimitedNatural(type)) {
+ default_ = TypesFactory.eINSTANCE
+ .createFromString(
+ TypesPackage.Literals.UNLIMITED_NATURAL,
+ default_).toString();
+ }
+
+ eAttribute.setDefaultValueLiteral(default_);
}
-
- eAttribute.setDefaultValueLiteral(default_);
}
eAttribute.setID(property.isID());
@@ -7524,6 +7551,122 @@
return eClassifier;
}
+ /**
+ * Reports or processes (as requested) default-value opaque expressions
+ * of properties to generate Ecore setting delegate annotations (or
+ * report that they should be generated).
+ *
+ * @since 5.0
+ */
+ protected void processPropertyDefaultExpressions(
+ Map<String, String> options, DiagnosticChain diagnostics,
+ Map<Object, Object> context) {
+
+ for (Map.Entry<Element, EModelElement> entry : elementToEModelElementMap
+ .entrySet()) {
+
+ Element key = entry.getKey();
+ EModelElement value = entry.getValue();
+
+ if (key instanceof Property
+ && value instanceof EStructuralFeature) {
+ Property property = (Property) key;
+ EStructuralFeature eFeature = (EStructuralFeature) value;
+
+ ValueSpecification specification = property
+ .getDefaultValue();
+
+ if (specification instanceof OpaqueExpression) {
+ OpaqueExpression expr = (OpaqueExpression) specification;
+
+ processPropertyDefaultExpression(eFeature,
+ expr.getLanguages(), expr.getBodies(), options,
+ diagnostics, context);
+ }
+ }
+ }
+ }
+
+ /**
+ * Reports or processes (as requested) the default-value opaque
+ * expression of a property to generate Ecore setting delegate
+ * annotations (or report that they should be generated).
+ *
+ * @since 5.0
+ */
+ protected void processPropertyDefaultExpression(
+ EStructuralFeature eFeature, EList<String> languages,
+ EList<String> bodies, Map<String, String> options,
+ DiagnosticChain diagnostics, Map<Object, Object> context) {
+
+ int languagesSize = languages.size();
+ int bodiesSize = bodies.size();
+
+ for (int i = 0; i < (languagesSize == bodiesSize
+ ? bodiesSize
+ : (bodiesSize == 1
+ ? 1
+ : 0)); i++) {
+
+ String language = i < languagesSize
+ ? languages.get(i)
+ : LANGUAGE__OCL;
+
+ if (OPTION__PROCESS.equals(options
+ .get(OPTION__PROPERTY_DEFAULT_EXPRESSIONS))) {
+
+ if (diagnostics != null) {
+ diagnostics
+ .add(new BasicDiagnostic(
+ Diagnostic.INFO,
+ UMLValidator.DIAGNOSTIC_SOURCE,
+ PROPERTY_DEFAULT_EXPRESSION,
+ UMLPlugin.INSTANCE
+ .getString(
+ "_UI_UML2EcoreConverter_ProcessPropertyDefaultExpression_diagnostic", //$NON-NLS-1$
+ getMessageSubstitutions(context,
+ eFeature, language)),
+ new Object[]{eFeature}));
+
+ }
+
+ String source = UML2_GEN_MODEL_PACKAGE_1_1_NS_URI;
+ String detailKey = ANNOTATION_DETAIL__DERIVATION;
+
+ if (LANGUAGE__OCL.equals(language)) {
+ addSettingDelegate(
+ (EPackage) getContainingEObject(eFeature,
+ EcorePackage.Literals.EPACKAGE, true),
+ OCL_DELEGATE_URI);
+
+ source = OCL_DELEGATE_URI;
+ }
+
+ if (eFeature.isChangeable() || !eFeature.isDerived()) {
+ // it's an initial-value specification, not a derivation
+ detailKey = ANNOTATION_DETAIL__INITIAL;
+ }
+
+ EcoreUtil.setAnnotation(eFeature, source, detailKey,
+ bodies.get(i));
+ } else if (OPTION__REPORT.equals(options
+ .get(OPTION__PROPERTY_DEFAULT_EXPRESSIONS))
+ && diagnostics != null) {
+
+ diagnostics
+ .add(new BasicDiagnostic(
+ Diagnostic.WARNING,
+ UMLValidator.DIAGNOSTIC_SOURCE,
+ PROPERTY_DEFAULT_EXPRESSION,
+ UMLPlugin.INSTANCE
+ .getString(
+ "_UI_UML2EcoreConverter_ReportPropertyDefaultExpression_diagnostic", //$NON-NLS-1$
+ getMessageSubstitutions(context, eFeature,
+ language)), new Object[]{eFeature}));
+ }
+ }
+ }
+
protected void processAnnotationDetails(
final Map<String, String> options,
final DiagnosticChain diagnostics,
@@ -7813,6 +7956,12 @@
processOperationBodies(options, diagnostics, context);
}
+ if (!OPTION__IGNORE.equals(options
+ .get(OPTION__PROPERTY_DEFAULT_EXPRESSIONS))) {
+
+ processPropertyDefaultExpressions(options, diagnostics, context);
+ }
+
if (!OPTION__IGNORE.equals(options.get(OPTION__UNTYPED_PROPERTIES))) {
processUntypedProperties(options, diagnostics, context);
}
@@ -10519,6 +10668,10 @@
protected static final String ANNOTATION_DETAIL__BODY = "body"; //$NON-NLS-1$
+ protected static final String ANNOTATION_DETAIL__DERIVATION = "derivation"; //$NON-NLS-1$
+
+ protected static final String ANNOTATION_DETAIL__INITIAL = "initial"; //$NON-NLS-1$
+
protected static final String ANNOTATION_DETAIL__URI = "URI"; //$NON-NLS-1$
public static final String ENUMERATION_LITERAL__ATTRIBUTE = "Attribute"; //$NON-NLS-1$
@@ -12091,6 +12244,14 @@
OPTION__IGNORE);
}
+ if (!options
+ .containsKey(UML2EcoreConverter.OPTION__PROPERTY_DEFAULT_EXPRESSIONS)) {
+
+ options.put(
+ UML2EcoreConverter.OPTION__PROPERTY_DEFAULT_EXPRESSIONS,
+ OPTION__IGNORE);
+ }
+
return convertToEcore(package_, options, null, null);
}
@@ -12232,6 +12393,14 @@
OPTION__REPORT);
}
+ if (!options
+ .containsKey(UML2EcoreConverter.OPTION__PROPERTY_DEFAULT_EXPRESSIONS)) {
+
+ options.put(
+ UML2EcoreConverter.OPTION__PROPERTY_DEFAULT_EXPRESSIONS,
+ OPTION__REPORT);
+ }
+
@SuppressWarnings("unchecked")
Collection<EPackage> ePackages = (Collection<EPackage>) new UML2EcoreConverter()
.convert(Collections.singletonList(package_), options, diagnostics,
@@ -12362,6 +12531,14 @@
OPTION__IGNORE);
}
+ if (!options
+ .containsKey(UML2EcoreConverter.OPTION__PROPERTY_DEFAULT_EXPRESSIONS)) {
+
+ options.put(
+ UML2EcoreConverter.OPTION__PROPERTY_DEFAULT_EXPRESSIONS,
+ OPTION__IGNORE);
+ }
+
return convertToEcore(profile, options, null, null);
}
@@ -12486,6 +12663,14 @@
OPTION__REPORT);
}
+ if (!options
+ .containsKey(UML2EcoreConverter.OPTION__PROPERTY_DEFAULT_EXPRESSIONS)) {
+
+ options.put(
+ UML2EcoreConverter.OPTION__PROPERTY_DEFAULT_EXPRESSIONS,
+ OPTION__REPORT);
+ }
+
@SuppressWarnings("unchecked")
Collection<EPackage> ePackages = (Collection<EPackage>) new Profile2EPackageConverter()
.convert(Collections.singleton(profile), options, diagnostics,
diff --git a/tests/org.eclipse.uml2.uml.tests/src/org/eclipse/uml2/uml/bug/tests/Bug405065.uml b/tests/org.eclipse.uml2.uml.tests/src/org/eclipse/uml2/uml/bug/tests/Bug405065.uml
new file mode 100644
index 0000000..b1827e6
--- /dev/null
+++ b/tests/org.eclipse.uml2.uml.tests/src/org/eclipse/uml2/uml/bug/tests/Bug405065.uml
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<uml:Package xmi:version="20110701" xmlns:xmi="http://www.omg.org/spec/XMI/20110701" xmlns:uml="http://www.eclipse.org/uml2/4.0.0/UML" xmi:id="_yboL0HrWEeOmgIVCTlT7jw" name="initials" URI="http://www.eclipse.org/uml2/schemas/tests/bugs/405065">
+ <elementImport xmi:id="_ExyDwHrXEeOmgIVCTlT7jw">
+ <importedElement xmi:type="uml:PrimitiveType" href="pathmap://UML_LIBRARIES/UMLPrimitiveTypes.library.uml#Real"/>
+ </elementImport>
+ <packagedElement xmi:type="uml:Class" xmi:id="_4Z_AoHrWEeOmgIVCTlT7jw" name="Thing">
+ <ownedAttribute xmi:id="__ApLkHrWEeOmgIVCTlT7jw" name="cost">
+ <type xmi:type="uml:PrimitiveType" href="pathmap://UML_LIBRARIES/UMLPrimitiveTypes.library.uml#Real"/>
+ </ownedAttribute>
+ <ownedAttribute xmi:id="_J7sj4HrXEeOmgIVCTlT7jw" name="tax">
+ <type xmi:type="uml:PrimitiveType" href="pathmap://UML_LIBRARIES/UMLPrimitiveTypes.library.uml#Real"/>
+ <defaultValue xmi:type="uml:LiteralReal" xmi:id="_a5vRAHrlEeOU_OLbrrQL2A" value="0.08"/>
+ </ownedAttribute>
+ <ownedAttribute xmi:id="_LbQ5MHrXEeOmgIVCTlT7jw" name="discount">
+ <type xmi:type="uml:PrimitiveType" href="pathmap://UML_LIBRARIES/UMLPrimitiveTypes.library.uml#Real"/>
+ <defaultValue xmi:type="uml:OpaqueExpression" xmi:id="_V51J0HrXEeOmgIVCTlT7jw">
+ <language>OCL</language>
+ <body>self.cost / 10.0</body>
+ </defaultValue>
+ </ownedAttribute>
+ <ownedAttribute xmi:id="_NLQQIHrXEeOmgIVCTlT7jw" name="price" isReadOnly="true" isDerived="true">
+ <type xmi:type="uml:PrimitiveType" href="pathmap://UML_LIBRARIES/UMLPrimitiveTypes.library.uml#Real"/>
+ <defaultValue xmi:type="uml:OpaqueExpression" xmi:id="_W2ei0HrYEeOmgIVCTlT7jw">
+ <language>OCL</language>
+ <body>(self.cost - self.discount) * (1.0 + self.tax)</body>
+ </defaultValue>
+ </ownedAttribute>
+ </packagedElement>
+</uml:Package>
diff --git a/tests/org.eclipse.uml2.uml.tests/src/org/eclipse/uml2/uml/bug/tests/Bug405065Test.java b/tests/org.eclipse.uml2.uml.tests/src/org/eclipse/uml2/uml/bug/tests/Bug405065Test.java
new file mode 100644
index 0000000..f217346
--- /dev/null
+++ b/tests/org.eclipse.uml2.uml.tests/src/org/eclipse/uml2/uml/bug/tests/Bug405065Test.java
@@ -0,0 +1,217 @@
+/*
+ * Copyright (c) 2014 CEA and others.
+ *
+ * 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:
+ * Christian W. Damus (CEA) - Initial API and implementation
+ *
+ */
+package org.eclipse.uml2.uml.bug.tests;
+
+import java.net.URL;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.regex.Pattern;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EAnnotation;
+import org.eclipse.emf.ecore.EAttribute;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EClassifier;
+import org.eclipse.emf.ecore.EDataType;
+import org.eclipse.emf.ecore.EModelElement;
+import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.uml2.common.util.UML2Util;
+import org.eclipse.uml2.uml.Package;
+import org.eclipse.uml2.uml.UMLPackage;
+import org.eclipse.uml2.uml.tests.util.StandaloneSupport;
+import org.eclipse.uml2.uml.util.UMLUtil;
+
+/**
+ * Tests the support for non-API constraints in classifiers that convert to
+ * Ecore EClasses.
+ *
+ * @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=405065
+ */
+public class Bug405065Test
+ extends TestCase {
+
+ private static final String ECORE_ANNOTATION_URI = "http://www.eclipse.org/emf/2002/Ecore";
+
+ private static final String OCL_ANNOTATION_URI = ECORE_ANNOTATION_URI
+ + "/OCL";
+
+ private ResourceSet rset;
+
+ private Package fixture;
+
+ public Bug405065Test() {
+ super();
+ }
+
+ public Bug405065Test(String name) {
+ super(name);
+ }
+
+ public static Test suite() {
+ return new TestSuite(Bug405065Test.class, "Bug 405065 tests"); //$NON-NLS-1$
+ }
+
+ public void testControl() {
+ // a control test for features that should not be annotated
+ EPackage ePackage = convert();
+
+ EAttribute cost = getEAttribute(getEClass(ePackage, "Thing"), "cost");
+ assertNoOCLAnnotation(cost);
+ assertFalse(cost.isDerived());
+ assertTrue(cost.isChangeable());
+ }
+
+ public void testDerivedFeature() {
+ EPackage ePackage = convert();
+
+ EAttribute price = getEAttribute(getEClass(ePackage, "Thing"), "price");
+ assertOCLAnnotation(price, "derivation",
+ "(self.cost - self.discount) * (1.0 + self.tax)");
+ assertTrue(price.isDerived());
+ assertFalse(price.isChangeable());
+ }
+
+ public void testInitialValueFeature() {
+ EPackage ePackage = convert();
+
+ EAttribute discount = getEAttribute(getEClass(ePackage, "Thing"),
+ "discount");
+ assertOCLAnnotation(discount, "initial", "self.cost / 10.0");
+ assertFalse(discount.isDerived());
+ assertTrue(discount.isChangeable());
+ }
+
+ //
+ // Test framework
+ //
+
+ @Override
+ protected void setUp()
+ throws Exception {
+
+ rset = new ResourceSetImpl();
+ if (StandaloneSupport.isStandalone()) {
+ StandaloneSupport.init(rset);
+ }
+
+ fixture = getTestModel();
+ }
+
+ @Override
+ protected void tearDown()
+ throws Exception {
+
+ fixture = null;
+
+ // clean up the CacheAdapter as well as we can
+ for (Resource next : rset.getResources()) {
+ next.unload();
+ next.eAdapters().clear();
+ }
+
+ rset.getResources().clear();
+ rset.eAdapters().clear();
+ }
+
+ Package getTestModel() {
+ URL url = getClass().getResource("Bug405065.uml"); //$NON-NLS-1$
+ return (Package) UML2Util.load(rset,
+ URI.createURI(url.toExternalForm()), UMLPackage.Literals.PACKAGE);
+ }
+
+ EPackage convert() {
+ return convert(fixture);
+ }
+
+ EPackage convert(Package package_) {
+ Map<String, String> options = new HashMap<String, String>();
+ options.put(
+ UMLUtil.UML2EcoreConverter.OPTION__PROPERTY_DEFAULT_EXPRESSIONS,
+ UMLUtil.OPTION__PROCESS);
+ options.put(UMLUtil.UML2EcoreConverter.OPTION__DERIVED_FEATURES,
+ UMLUtil.OPTION__PROCESS);
+
+ Collection<EPackage> ecores = UMLUtil.convertToEcore(package_, options);
+
+ assertNotNull(ecores);
+ assertTrue(ecores.size() > 0);
+
+ EPackage result = ecores.iterator().next();
+ assertEquals("initials", result.getName());
+
+ assertEcoreAnnotation(result, "settingDelegates", OCL_ANNOTATION_URI);
+
+ return result;
+ }
+
+ EClass getEClass(EPackage ePackage, String name) {
+ return getEClassifier(ePackage, name, EClass.class);
+ }
+
+ EDataType getEDataType(EPackage ePackage, String name) {
+ return getEClassifier(ePackage, name, EDataType.class);
+ }
+
+ <T extends EClassifier> T getEClassifier(EPackage ePackage, String name,
+ Class<T> metaclass) {
+ EClassifier result = ePackage.getEClassifier(name);
+ assertTrue(metaclass.isInstance(result));
+ return metaclass.cast(result);
+ }
+
+ EAttribute getEAttribute(EClass eClass, String name) {
+ EStructuralFeature result = eClass.getEStructuralFeature(name);
+
+ assertTrue("EAttribute not found: " + name,
+ result instanceof EAttribute);
+ return (EAttribute) result;
+ }
+
+ void assertEcoreAnnotation(EModelElement element, String key, String value) {
+ assertAnnotation(element, ECORE_ANNOTATION_URI, key, value);
+ }
+
+ void assertOCLAnnotation(EModelElement element, String key, String value) {
+ assertAnnotation(element, OCL_ANNOTATION_URI, key, value);
+ }
+
+ void assertAnnotation(EModelElement element, String source, String key,
+ String value) {
+ String annotation = EcoreUtil.getAnnotation(element, source, key);
+ assertNotNull("Annotation key not found", annotation);
+ assertTrue(Pattern
+ .compile(
+ String.format("(?:^|\\s)%s(?:$|\\s)", Pattern.quote(value)))
+ .matcher(annotation).find());
+ }
+
+ void assertNoOCLAnnotation(EModelElement element) {
+ assertNoAnnotation(element, OCL_ANNOTATION_URI);
+ }
+
+ void assertNoAnnotation(EModelElement element, String source) {
+ EAnnotation annotation = element.getEAnnotation(source);
+ assertNull("Found annotation", annotation);
+ }
+
+}
diff --git a/tests/org.eclipse.uml2.uml.tests/src/org/eclipse/uml2/uml/bug/tests/UMLBugTests.java b/tests/org.eclipse.uml2.uml.tests/src/org/eclipse/uml2/uml/bug/tests/UMLBugTests.java
index b3c807d..e21585d 100644
--- a/tests/org.eclipse.uml2.uml.tests/src/org/eclipse/uml2/uml/bug/tests/UMLBugTests.java
+++ b/tests/org.eclipse.uml2.uml.tests/src/org/eclipse/uml2/uml/bug/tests/UMLBugTests.java
@@ -7,7 +7,7 @@
*
* Contributors:
* Christian W. Damus (CEA) - initial API and implementation
- * Christian W. Damus (CEA) - 409396, 403365, 300957, 405061, 401682, 176998, 180744, 403374, 420338
+ * Christian W. Damus (CEA) - 409396, 403365, 300957, 405061, 401682, 176998, 180744, 403374, 420338, 405065
* Manuel Bork <bork@yatta.de> (Yatta Solutions GmbH) - 421756, 422000
*
*/
@@ -53,6 +53,7 @@
result.addTest(Bug403374Test.suite());
result.addTest(Bug416833Test.suite());
result.addTest(Bug420338Test.suite());
+ result.addTest(Bug405065Test.suite());
return result;
}