Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEd Seidewitz2015-07-21 00:57:01 +0000
committerGerrit Code Review @ Eclipse.org2015-11-26 15:35:28 +0000
commit8d0b38ea11bd162e146c547f7a195138d6ab3f2e (patch)
tree0fe679cb2524b165fb5835e10732d808610b9322
parent903058defac517e8693b6a14ed9482577b784813 (diff)
downloadorg.eclipse.papyrus-8d0b38ea11bd162e146c547f7a195138d6ab3f2e.tar.gz
org.eclipse.papyrus-8d0b38ea11bd162e146c547f7a195138d6ab3f2e.tar.xz
org.eclipse.papyrus-8d0b38ea11bd162e146c547f7a195138d6ab3f2e.zip
Bug 472232 - Improved handling of default values.
- Updated Alf2UML to save default value text in body of OpaqueExpression. - Updated UML2Alf to re-parse default value from body text. Change-Id: I4b073fa77ca132867be8c42c8a765fae80d9ff6b Signed-off-by: Ed Seidewitz <ed-s@modeldriven.com>
-rw-r--r--plugins/uml/alf/org.eclipse.papyrus.uml.alf.to.fuml/src/org/eclipse/papyrus/uml/alf/to/fuml/qvt/QVTLibrary.java21
-rw-r--r--plugins/uml/alf/org.eclipse.papyrus.uml.alf.to.fuml/transformation/Alf2UML.qvto19
-rw-r--r--plugins/uml/alf/org.eclipse.papyrus.uml.alf.to.fuml/transformation/UML2Alf.qvto23
3 files changed, 45 insertions, 18 deletions
diff --git a/plugins/uml/alf/org.eclipse.papyrus.uml.alf.to.fuml/src/org/eclipse/papyrus/uml/alf/to/fuml/qvt/QVTLibrary.java b/plugins/uml/alf/org.eclipse.papyrus.uml.alf.to.fuml/src/org/eclipse/papyrus/uml/alf/to/fuml/qvt/QVTLibrary.java
index 0c3548663d5..e969563a95e 100644
--- a/plugins/uml/alf/org.eclipse.papyrus.uml.alf.to.fuml/src/org/eclipse/papyrus/uml/alf/to/fuml/qvt/QVTLibrary.java
+++ b/plugins/uml/alf/org.eclipse.papyrus.uml.alf.to.fuml/src/org/eclipse/papyrus/uml/alf/to/fuml/qvt/QVTLibrary.java
@@ -1,5 +1,5 @@
/*****************************************************************************
- * Copyright (c) 2013, 2014 CEA LIST.
+ * Copyright (c) 2013-2015 CEA LIST.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -7,18 +7,24 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * IJI - Initial implementation
- * MDS - Updated for Luna
+ * Ed Seidewitz (IJI/MDS)
*
*****************************************************************************/
package org.eclipse.papyrus.uml.alf.to.fuml.qvt;
+import java.io.StringReader;
+
import org.eclipse.m2m.qvt.oml.blackbox.java.Module;
import org.eclipse.m2m.qvt.oml.blackbox.java.Operation;
import org.eclipse.m2m.qvt.oml.blackbox.java.Operation.Kind;
import org.eclipse.papyrus.uml.alf.AlfStandaloneSetup;
+import org.eclipse.papyrus.uml.alf.Expression;
import org.eclipse.papyrus.uml.alf.SyntaxElement;
+import org.eclipse.papyrus.uml.alf.services.AlfGrammarAccess;
+import org.eclipse.xtext.IGrammarAccess;
+import org.eclipse.xtext.parser.IParseResult;
+import org.eclipse.xtext.parser.IParser;
import org.eclipse.xtext.resource.SaveOptions;
import org.eclipse.xtext.serializer.ISerializer;
@@ -38,5 +44,14 @@ public class QVTLibrary {
SaveOptions options = SaveOptions.newBuilder().format().noValidation().getOptions();
return serializer.serialize(element, options);
}
+
+ @Operation(contextual = true, kind = Kind.QUERY)
+ public static Expression parseExpression(String text) {
+ Injector injector = new AlfStandaloneSetup().createInjectorAndDoEMFRegistration();
+ IParser parser = injector.getInstance(IParser.class);
+ AlfGrammarAccess grammar = (AlfGrammarAccess) injector.getInstance(IGrammarAccess.class);
+ IParseResult result = parser.parse(grammar.getExpressionRule(), new StringReader(text));
+ return result.hasSyntaxErrors()? null: (Expression)result.getRootASTElement();
+ }
}
diff --git a/plugins/uml/alf/org.eclipse.papyrus.uml.alf.to.fuml/transformation/Alf2UML.qvto b/plugins/uml/alf/org.eclipse.papyrus.uml.alf.to.fuml/transformation/Alf2UML.qvto
index 01d50a19f1c..7bc7c678ce7 100644
--- a/plugins/uml/alf/org.eclipse.papyrus.uml.alf.to.fuml/transformation/Alf2UML.qvto
+++ b/plugins/uml/alf/org.eclipse.papyrus.uml.alf.to.fuml/transformation/Alf2UML.qvto
@@ -471,14 +471,12 @@ mapping ClassDefinition::toClass() : Class
ownedAttribute := members[Property];
ownedOperation := members[Operation];
- ownedBehavior := result.ownedOperation.method;
nestedClassifier := members[Classifier];
- ownedAttribute[defaultValue <> null]->forEach(p) {
- var behavior := p.defaultValue.oclAsType(OpaqueExpression).behavior;
- behavior.name := uniqueName(p.name + "$defaultValue", result);
- ownedBehavior += behavior;
- };
+ ownedBehavior := result.ownedOperation.method;
+ ownedBehavior += ownedAttribute[defaultValue <> null].
+ defaultValue.oclAsType(OpaqueExpression).behavior;
+
ownedOperation.method->forEach(m) {
m.name := uniqueName(m.specification.name + "$method", result);
if m.specification.invresolveone(OperationDefinition).isStub then {
@@ -870,13 +868,20 @@ mapping PropertyDefinition::toProperty() : Property
else AggregationKind::none endif;
if self.initializer <> null then {
var expression := self.initializer.map toOpaqueExpression();
+ expression.behavior.name := name + "$defaultValue$1";
defaultValue := expression;
} endif;
}
mapping Expression::toOpaqueExpression() : OpaqueExpression {
behavior := self.map toActivity();
- addDefinition(behavior.oclAsType(Activity), self);
+ language += "Alf";
+ var text := self.serialize();
+ if text.startsWith("=") then {
+ text := text.substring(2, text.length());
+ } endif;
+ body += text;
+// addDefinition(behavior.oclAsType(Activity), self);
}
// Operation Definitions
diff --git a/plugins/uml/alf/org.eclipse.papyrus.uml.alf.to.fuml/transformation/UML2Alf.qvto b/plugins/uml/alf/org.eclipse.papyrus.uml.alf.to.fuml/transformation/UML2Alf.qvto
index 9703d6c5d05..ea498f7aa44 100644
--- a/plugins/uml/alf/org.eclipse.papyrus.uml.alf.to.fuml/transformation/UML2Alf.qvto
+++ b/plugins/uml/alf/org.eclipse.papyrus.uml.alf.to.fuml/transformation/UML2Alf.qvto
@@ -11,6 +11,7 @@
* Ed Seidewitz (MDS)
*
*****************************************************************************/
+import org.eclipse.papyrus.uml.alf.to.fuml.qvt.QVTLibrary;
import UML2AlfLibrary;
modeltype Alf uses "http://www.omg.org/spec/ALF/20120827";
@@ -200,7 +201,7 @@ mapping uml::ClassifierTemplateParameter::toTemplateParameter() : Member {
abstract mapping Class::toClassDefinition() : ClassDefinition
inherits Classifier::toClassifierDefinition {
ownedMember += self.nestedClassifier->map toMember();
- ownedMember += self.ownedBehavior->select(isDefaultValue())->map toMember(); // TODO: Remove
+// ownedMember += self.ownedBehavior->select(isDefaultValue())->map toMember(); // TODO: Remove
ownedMember += self.ownedAttribute->reject(isInitializationFlag(self.name))->
map toMember();
// TODO: Filter out default constructor and destructor operations.
@@ -394,14 +395,20 @@ mapping Property::toPropertyDefinition() : PropertyDefinition
mapping OpaqueExpression::toExpression(context : NamedElement) : Expression {
init {
- result := object BehaviorInvocationExpression {
- target := self.behavior.alfQualifiedName(context);
- tuple := object PositionalTuple {
- expression := OrderedSet{};
- }
- };
+ if self.language->exists(language | language = "Alf") then {
+ var i := self.language->indexOf("Alf");
+ result := self.body->at(i).parseExpression();
+ } else if self.behavior <> null then {
+ result := object BehaviorInvocationExpression {
+ target := self.behavior.alfQualifiedName(context);
+ tuple := object PositionalTuple {
+ expression := OrderedSet{};
+ }
+ };
+ } else {
+ result := null;
+ } endif endif;
}
- // TODO: Map default values to true initializer expressions.
}
// Operations

Back to the top