diff options
author | Ed Seidewitz | 2015-05-22 05:05:15 +0000 |
---|---|---|
committer | Camille Letavernier | 2015-05-26 08:27:11 +0000 |
commit | 6653e3b70ed3d6f81931a1546a80a53c1250b7af (patch) | |
tree | b8c8f4dd8e28b7d76778a391caa8274cf9ef02fe | |
parent | b744b51598da15e837e2f1d14e571fad87bf5a8b (diff) | |
download | org.eclipse.papyrus-6653e3b70ed3d6f81931a1546a80a53c1250b7af.tar.gz org.eclipse.papyrus-6653e3b70ed3d6f81931a1546a80a53c1250b7af.tar.xz org.eclipse.papyrus-6653e3b70ed3d6f81931a1546a80a53c1250b7af.zip |
Bug 466454 - Corrected mapping to properly handle "stub"
classifierBehaviors.
Change-Id: Ibf1b4893a8aeaabd4de518c256be96f6e59d8ae2
Signed-off-by: Ed Seidewitz <ed-s@modeldriven.com>
Reviewed-on: https://git.eclipse.org/r/48471
Tested-by: Hudson CI
Reviewed-by: Jeremie Tatibouet <jeremie.tatibouet@cea.fr>
Reviewed-by: Camille Letavernier <camille.letavernier@cea.fr>
4 files changed, 52 insertions, 10 deletions
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 007cb7de705..fe44b8e75e9 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 @@ -880,11 +880,17 @@ mapping ActiveClassDefinition::toClass() : Class ownedReception := self.ownedMember->map toNamedElement()[Reception]; ownedReception += self.ownedMember[definition.oclIsKindOf(SignalReceptionDefinition)]->map toReception(); if self.classifierBehavior <> null then { - classifierBehavior := self.classifierBehavior.map toActivity(); - classifierBehavior.name := uniqueName(result.name + "$behavior", result); - classifierBehavior.visibility := VisibilityKind::private; - ownedBehavior += classifierBehavior; // Eclipse implementation only - // addDefinition(classifierBehavior.oclAsType(Activity), self.classifierBehavior.body); + // NOTE: The Xtext grammar currently does not set isStub = true for a stub classifierBehavior. + if self.classifierBehavior.isStub or self.classifierBehavior.body = null then { + classifierBehavior := new Activity(Sequence{}); + classifierBehavior.name := self.classifierBehavior.actualName() + "$stub"; + } else { + classifierBehavior := self.classifierBehavior.map toActivity(); + classifierBehavior.name := uniqueName(result.name + "$behavior", result); + classifierBehavior.visibility := VisibilityKind::private; + ownedBehavior += classifierBehavior; // Because classifierBehavior is not a member in the Ecore metamodel. + // addDefinition(classifierBehavior.oclAsType(Activity), self.classifierBehavior.body); + } endif; } endif; } endif; } diff --git a/plugins/uml/alf/org.eclipse.papyrus.uml.alf/src/org/eclipse/papyrus/uml/alf/Alf.xtext b/plugins/uml/alf/org.eclipse.papyrus.uml.alf/src/org/eclipse/papyrus/uml/alf/Alf.xtext index 5b9936db02a..729197eefe5 100644 --- a/plugins/uml/alf/org.eclipse.papyrus.uml.alf/src/org/eclipse/papyrus/uml/alf/Alf.xtext +++ b/plugins/uml/alf/org.eclipse.papyrus.uml.alf/src/org/eclipse/papyrus/uml/alf/Alf.xtext @@ -212,7 +212,7 @@ ActiveClassDefinitionOrStub returns ActiveClassDefinition : ;
BehaviorClause returns ActivityDefinition :
- body = Block | name = Name // TODO: isStub = true
+ body = Block | name = Name // NOTE: Does not set isStub = true.
;
ActiveClassMember returns Member :
diff --git a/tests/junit/plugins/uml/alf/org.eclipse.papyrus.uml.alf.tests/src/org/eclipse/papyrus/uml/alf/tests/mapper/AlfCompiler.java b/tests/junit/plugins/uml/alf/org.eclipse.papyrus.uml.alf.tests/src/org/eclipse/papyrus/uml/alf/tests/mapper/AlfCompiler.java index 1cea8635fc5..8f3fcd38e89 100644 --- a/tests/junit/plugins/uml/alf/org.eclipse.papyrus.uml.alf.tests/src/org/eclipse/papyrus/uml/alf/tests/mapper/AlfCompiler.java +++ b/tests/junit/plugins/uml/alf/org.eclipse.papyrus.uml.alf.tests/src/org/eclipse/papyrus/uml/alf/tests/mapper/AlfCompiler.java @@ -60,17 +60,22 @@ public class AlfCompiler extends AlfMapper { return result.getRootASTElement(); } } - - public String getTextualRepresentation(Element element) { + + public Comment getTextualRepresentationComment(Element element) { for (Comment comment : element.getOwnedComments()) { if (comment.isStereotypeApplied(this.textualRepresentationStereotype) && "Alf".equals(comment.getValue(this.textualRepresentationStereotype, "language"))) { - return comment.getBody(); + return comment; } } return null; } + public String getTextualRepresentation(Element element) { + Comment comment = this.getTextualRepresentationComment(element); + return comment == null? null: comment.getBody(); + } + public void addTextualRepresentation(Element element, String textualRepresentation) { Comment comment = UMLFactory.eINSTANCE.createComment(); comment.setBody(textualRepresentation); @@ -82,6 +87,15 @@ public class AlfCompiler extends AlfMapper { comment.applyStereotype(this.textualRepresentationStereotype); comment.setValue(this.textualRepresentationStereotype, "language", "Alf"); } + + public void updateTextualRepresentation(Element element, String textualRepresentation) { + Comment comment = this.getTextualRepresentationComment(element); + if (comment == null) { + this.addTextualRepresentation(element, textualRepresentation); + } else { + comment.setBody(textualRepresentation); + } + } public void compile(NamedElement contextElement) throws ParsingError, MappingError { String textualRepresentation = this.getTextualRepresentation(contextElement); @@ -97,7 +111,7 @@ public class AlfCompiler extends AlfMapper { alf.add(this.parse(textualRepresentation)); this.map(contextElement, alf); - this.addTextualRepresentation(contextElement, textualRepresentation); + this.updateTextualRepresentation(contextElement, textualRepresentation); } } diff --git a/tests/junit/plugins/uml/alf/org.eclipse.papyrus.uml.alf.tests/src/org/eclipse/papyrus/uml/alf/tests/mapper/CompilerTests.java b/tests/junit/plugins/uml/alf/org.eclipse.papyrus.uml.alf.tests/src/org/eclipse/papyrus/uml/alf/tests/mapper/CompilerTests.java index 18e2bc45f15..47e6cdd8c61 100644 --- a/tests/junit/plugins/uml/alf/org.eclipse.papyrus.uml.alf.tests/src/org/eclipse/papyrus/uml/alf/tests/mapper/CompilerTests.java +++ b/tests/junit/plugins/uml/alf/org.eclipse.papyrus.uml.alf.tests/src/org/eclipse/papyrus/uml/alf/tests/mapper/CompilerTests.java @@ -540,6 +540,7 @@ public class CompilerTests { Behavior classifierBehavior = testClass.getClassifierBehavior(); assertNotNull(classifierBehavior); + assertTrue(testClass.getOwnedBehaviors().contains(classifierBehavior)); assertEquals(testClass.getName() + "$behavior$1", classifierBehavior.getName()); assertEquals(VisibilityKind.PRIVATE_LITERAL, classifierBehavior.getVisibility()); assertTrue(classifierBehavior instanceof Activity); @@ -578,4 +579,25 @@ public class CompilerTests { assertNotNull(action); assertEquals(operation, action.getOperation()); } + + public static String TEST_ACTIVE_CLASS_TEXT = "active class Test { public p() { } } do 'Test$behavior$1'"; + + @Test + public void testActiveClassRecompile() throws ParsingError, MappingError { + Class testClass = compileTestClassifierBehavior(); + + Behavior classifierBehavior = testClass.getClassifierBehavior(); + assertTextualRepresentation(classifierBehavior, CLASSIFIER_BEHAVIOR_ACTIVITY_TEXT); + + compiler.compile(testClass, TEST_ACTIVE_CLASS_TEXT); + + assertTextualRepresentation(testClass, TEST_ACTIVE_CLASS_TEXT); + assertEquals(classifierBehavior, testClass.getClassifierBehavior()); + assertTrue(testClass.getOwnedBehaviors().contains(classifierBehavior)); + assertEquals(testClass.getName() + "$behavior$1", classifierBehavior.getName()); + assertEquals(VisibilityKind.PRIVATE_LITERAL, classifierBehavior.getVisibility()); + assertTextualRepresentation(classifierBehavior, CLASSIFIER_BEHAVIOR_ACTIVITY_TEXT); + assertTrue(classifierBehavior instanceof Activity); + assertTrue(((Activity)classifierBehavior).getNodes().size() > 0); + } } |