diff options
author | Ed Seidewitz | 2015-06-10 04:39:21 +0000 |
---|---|---|
committer | Arnaud Cuccuru | 2015-06-10 08:06:08 +0000 |
commit | c7095ebf10e9b9eb60e1be67fa35288d540cddd6 (patch) | |
tree | 917aa8745f785796962054c18ea87f6656ad1b69 | |
parent | db0f92e171a6d04f1caffab603ee917718258772 (diff) | |
download | org.eclipse.papyrus-c7095ebf10e9b9eb60e1be67fa35288d540cddd6.tar.gz org.eclipse.papyrus-c7095ebf10e9b9eb60e1be67fa35288d540cddd6.tar.xz org.eclipse.papyrus-c7095ebf10e9b9eb60e1be67fa35288d540cddd6.zip |
Added a library element lookup cache.
Change-Id: Icf8b6c83e1a51b5ddd332338d9786d2a70f87ff8
Signed-off-by: Ed Seidewitz <ed-s@modeldriven.com>
Reviewed-on: https://git.eclipse.org/r/49885
Tested-by: Hudson CI
Reviewed-by: Arnaud Cuccuru <arnaud.cuccuru@cea.fr>
Tested-by: Arnaud Cuccuru <arnaud.cuccuru@cea.fr>
4 files changed, 76 insertions, 37 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 ba8592d112f..01d50a19f1c 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 @@ -611,7 +611,7 @@ helper ClassDefinition::createInitializationMethod(class_ : Class, initializatio }; // Add action to set initialization to true. - initializationNode.node += var valueAction ::= new ValueSpecificationAction(new LiteralBoolean(true, self.booleanType().toType())); + initializationNode.node += var valueAction ::= new ValueSpecificationAction(self.literalBoolean(true)); initializationNode.node += var writeAction ::= new AddStructuralFeatureValueAction(initializationFlag, true, null); new ObjectFlow(method, selfFork, writeAction._'object'); new ObjectFlow(initializationNode, valueAction.result, writeAction.value); @@ -626,8 +626,8 @@ helper ClassDefinition::createInitializationMethod(class_ : Class, initializatio method.ownedNode += var sizeAction ::= new CallBehaviorAction(self.functionSize()); new ObjectFlow(method, readAction.result, sizeAction.argument->at(1)); - method.ownedNode += valueAction := new ValueSpecificationAction(new LiteralInteger(0, self.integerType().toType())); - method.ownedNode += var testAction ::= new TestIdentityAction("Size==0", self.booleanType().toType()); + method.ownedNode += valueAction := new ValueSpecificationAction(self.literalInteger(0)); + method.ownedNode += var testAction ::= new TestIdentityAction("Size==0", self.typeBoolean()); new ObjectFlow(method, sizeAction.result->at(1), testAction.first); new ObjectFlow(method, valueAction.result, testAction.second); @@ -1075,8 +1075,8 @@ helper OperationDefinition::mapConstructor(initializationFlag : Property, initia method.ownedNode += var sizeAction ::= new CallBehaviorAction(self.functionSize()); new ObjectFlow(method, readAction.result, sizeAction.argument->at(1)); - method.ownedNode += var valueAction ::= new ValueSpecificationAction(new LiteralInteger(0, self.integerType().toType())); - method.ownedNode += var testAction ::= new TestIdentityAction("Size==0", self.booleanType().toType()); + method.ownedNode += var valueAction ::= new ValueSpecificationAction(self.literalInteger(0)); + method.ownedNode += var testAction ::= new TestIdentityAction("Size==0", self.typeBoolean()); new ObjectFlow(method, sizeAction.result->at(1), testAction.first); new ObjectFlow(method, valueAction.result, testAction.second); diff --git a/plugins/uml/alf/org.eclipse.papyrus.uml.alf.to.fuml/transformation/AlfCommon2UML.qvto b/plugins/uml/alf/org.eclipse.papyrus.uml.alf.to.fuml/transformation/AlfCommon2UML.qvto index be348d59f4c..37efa54f957 100644 --- a/plugins/uml/alf/org.eclipse.papyrus.uml.alf.to.fuml/transformation/AlfCommon2UML.qvto +++ b/plugins/uml/alf/org.eclipse.papyrus.uml.alf.to.fuml/transformation/AlfCommon2UML.qvto @@ -20,10 +20,27 @@ transformation AlfCommon2UML(in alf : Alf, inout uml : UML); abstract mapping SyntaxElement::toUml() : Element; +property libraryCache : Dict(String, ElementReference); + +helper SyntaxElement::libraryElement(path : String) : ElementReference { + var referent := libraryCache->get(path); + if referent = null then { + referent := self.resolveInLibrary(path)![true]; + if referent <> null then { + libraryCache->put(path, referent); + } endif; + } endif; + return referent; +} + +helper SyntaxElement::collectionFunctionsPackage() : ElementReference { + return self.libraryElement("CollectionFunctions"); +} + helper SyntaxElement::libraryFunction(path : String) : Behavior { - var referent := self.resolveInLibrary(path)![isBehavior()]; + var referent := self.libraryElement(path); return - if referent->isEmpty() then null + if referent = null then null else referent.toUml().oclAsType(Behavior) endif; } @@ -124,24 +141,52 @@ helper SyntaxElement::functionIntegerToBitString() : Behavior { return self.libraryFunction("PrimitiveBehaviors::BitStringFunctions::ToBitString"); } +helper SyntaxElement::libraryType(name : String) : Type { + return self.libraryElement("PrimitiveTypes::" + name).toType(); +} + +helper SyntaxElement::typeBoolean() : Type { + return self.libraryType("Boolean"); +} + +helper SyntaxElement::typeNatural() : Type { + return self.libraryType("Natural"); +} + +helper SyntaxElement::typeInteger() : Type { + return self.libraryType("Integer"); +} + +helper SyntaxElement::typeString() : Type { + return self.libraryType("String"); +} + +helper SyntaxElement::typeUnlimitedNatural() : Type { + return self.libraryType("UnlimitedNatural"); +} + +helper SyntaxElement::typeBitString() : Type { + return self.libraryType("BitString"); +} + helper SyntaxElement::literalBoolean(b : Boolean) : LiteralBoolean { - return new LiteralBoolean(b, self.booleanType().toType()); + return new LiteralBoolean(b, self.typeBoolean()); } helper SyntaxElement::literalNatural(n : Integer) : LiteralInteger { - return new LiteralInteger(n, self.naturalType().toType()); + return new LiteralInteger(n, self.typeNatural()); } helper SyntaxElement::literalInteger(i : Integer) : LiteralInteger { - return new LiteralInteger(i, self.integerType().toType()); + return new LiteralInteger(i, self.typeInteger()); } helper SyntaxElement::literalString(s : String) : LiteralString { - return new LiteralString(s, self.stringType().toType()); + return new LiteralString(s, self.typeString()); } helper SyntaxElement::literalUnlimited() : LiteralUnlimitedNatural { - return new LiteralUnlimitedNatural(self.unlimitedNaturalType().toType()); + return new LiteralUnlimitedNatural(self.typeUnlimitedNatural()); } // Documented Elements diff --git a/plugins/uml/alf/org.eclipse.papyrus.uml.alf.to.fuml/transformation/AlfExpression2UML.qvto b/plugins/uml/alf/org.eclipse.papyrus.uml.alf.to.fuml/transformation/AlfExpression2UML.qvto index 5e7f8f3c690..bfe872b96d3 100644 --- a/plugins/uml/alf/org.eclipse.papyrus.uml.alf.to.fuml/transformation/AlfExpression2UML.qvto +++ b/plugins/uml/alf/org.eclipse.papyrus.uml.alf.to.fuml/transformation/AlfExpression2UML.qvto @@ -459,10 +459,8 @@ helper InvocationExpression::InvocationExpression_mapTarget(inout graph : Expres helper InvocationExpression::isCollectionFunctionInvocation() : Boolean { var referent := self.referent; - var template := referent.template(); - return referent.isTemplateBinding() and - template.namespace() <> null and - template.namespace().equals(self.collectionFunctionsPackage()); + return referent.isTemplateBinding() and + self.collectionFunctionsPackage().equals(referent.template().namespace()); } query InvocationExpression::sequenceFunction() : Behavior { @@ -491,10 +489,6 @@ query InvocationExpression::sequenceFunction() : Behavior { return behavior; } -helper InvocationExpression::collectionFunctionsPackage() : ElementReference { - return self.resolveInLibrary("CollectionFunctions")![isPackage()]; -} - helper InvocationExpression::mapTuple(inout graph : ExpressionGraph, action : Action) : ActivityGraph { return self.tuple.map toActivityGraph(graph, action, null, null); } @@ -589,7 +583,7 @@ query InvocationExpression::isSequenceFeatureInvocation() : Boolean { // and conditioning the destroy action on that. helper InvocationExpression::addDestroyCheck(inout graph : ActivityGraph, targetNode : ActivityNode, targetPin : ActivityNode) { graph.nodes += var readSelfAction ::= new ReadSelfAction(null); - graph.nodes += var testAction ::= new TestIdentityAction("self==" + nameOf(targetNode), self.booleanType().toType()); + graph.nodes += var testAction ::= new TestIdentityAction("self==" + nameOf(targetNode), self.typeBoolean()); graph.edges += new ObjectFlow(readSelfAction.result, testAction.first); graph.edges += new ObjectFlow(targetNode, testAction.second); createObjectDecisionGraph("destroy check", targetNode, testAction.result, targetPin, null).addTo(graph); @@ -872,7 +866,7 @@ helper InstanceCreationExpression::mapTarget(inout graph : ExpressionGraph) : Ac helper LinkOperationExpression::mapTarget(inout graph : ActivityGraph) : Action { var association := self.referent.toUml().oclAsType(Association); - var unlimitedNaturalType := self.unlimitedNaturalType().toType(); + var unlimitedNaturalType := self.typeUnlimitedNatural(); graph.nodes += var action ::= if self.isClear then new ClearAssociationAction(association) else if self.isCreation then new CreateLinkAction(association, unlimitedNaturalType) @@ -1055,7 +1049,7 @@ query SequenceRange::isEmpty() : Boolean { helper SyntaxElement::mapSequenceRangeLoop( resultSource1 : ActivityNode, resultSource2 : ActivityNode, label : String) : ExpressionGraph { - var integerType := self.integerType().toType(); + var integerType := self.typeInteger(); var rangeLowerInputPin := new InputPin("rangeLower", integerType, 1, 1); var rangeUpperInputPin := new InputPin("rangeUpper", integerType, 1, 1); var accumulatorInputPin := new InputPin("range", integerType, 0, -1); @@ -1283,7 +1277,7 @@ mapping ForAllOrExistsOrOneExpression::toActivityGraph() : ExpressionGraph case(self.operation = "one") { addBehavior(result, self.functionSize()); nodes += var valueAction ::= new ValueSpecificationAction(self.literalInteger(1)); - nodes += var testAction ::= new TestIdentityAction("=1", self.booleanType().toType()); + nodes += var testAction ::= new TestIdentityAction("=1", self.typeBoolean()); edges += new ObjectFlow(resultSource, testAction.first); edges += new ObjectFlow(valueAction.result, testAction.second); resultSource := testAction.result; @@ -1327,7 +1321,7 @@ mapping IsUniqueExpression::toActivityGraph() : ExpressionGraph nestedGraph.nodes += var variableSource ::= new ForkNode("each"); nestedGraph.nodes += var callAction := new CallBehaviorAction(self.functionCount()); nestedGraph.nodes += var valueAction := new ValueSpecificationAction(self.literalInteger(1)); - nestedGraph.nodes += var testAction := new TestIdentityAction("=1", self.booleanType().toType()); + nestedGraph.nodes += var testAction := new TestIdentityAction("=1", self.typeBoolean()); nestedGraph.edges += new ObjectFlow(forkNode, callAction.argument->at(1)); nestedGraph.edges += new ObjectFlow(variableSource, callAction.argument->at(2)); nestedGraph.edges += new ObjectFlow(callAction.result->at(1), testAction.first); @@ -1520,12 +1514,12 @@ helper CastExpression::mapNestedGraph(inout nestedGraph : ExpressionGraph, label // Natural values are represented as integers. if operandType = null or self.isUnlimitedNaturalType(operandType) then { source := self.addClassificationDecision( - nestedGraph, self.unlimitedNaturalType().toType(), target, source, + nestedGraph, self.typeUnlimitedNatural(), target, source, self.functionUnlimitedNaturalToInteger()); } endif; if operandType = null or self.isBitStringType(operandType) then { source := self.addClassificationDecision( - nestedGraph, self.bitStringType().toType(), target, source, + nestedGraph, self.typeBitString(), target, source, self.functionBitStringToInteger()); } endif; if operandType = null or @@ -1547,14 +1541,14 @@ helper CastExpression::mapNestedGraph(inout nestedGraph : ExpressionGraph, label } endif; if operandType = null or self.isIntegerType(operandType) then { source := self.addClassificationDecision( - nestedGraph, self.integerType().toType(), target, source, + nestedGraph, self.typeInteger(), target, source, self.functionIntegerToUnlimitedNatural()); } endif; } else if self.isBitStringType(type) then { if operandType = null or self.isIntegerType(operandType) then { source := self.addClassificationDecision( - nestedGraph, self.integerType().toType(), target, source, + nestedGraph, self.typeInteger(), target, source, self.functionIntegerToBitString()); } endif; if operandType = null or not self.isIntegerType(operandType) then { @@ -1578,7 +1572,7 @@ helper CastExpression::addClassificationDecision( conversionFunction : Behavior) : ActivityNode { graph.nodes += var isClassifiedAction ::= - new ReadIsClassifiedObjectAction(type.oclAsType(Classifier), false, self.booleanType().toType()); + new ReadIsClassifiedObjectAction(type.oclAsType(Classifier), false, self.typeBoolean()); graph.nodes += var forkNode ::= new ForkNode(isClassifiedAction._'object'.name); graph.edges += new ObjectFlow(forkNode, isClassifiedAction._'object'); @@ -1740,7 +1734,7 @@ mapping ClassificationExpression::toActivityGraph() : ExpressionGraph resultSource := valueAction.result; } else { var classifier := self.referent.toUml().oclAsType(Classifier); - nodes += var action ::= new ReadIsClassifiedObjectAction(classifier, self.isDirect, self.booleanType().toType()); + nodes += var action ::= new ReadIsClassifiedObjectAction(classifier, self.isDirect, self.typeBoolean()); edges += new ObjectFlow(operandGraph.resultSource, action._'object'); resultSource := action.result; } endif; @@ -1772,7 +1766,7 @@ mapping EqualityExpression::toActivityGraph() : ExpressionGraph helper EqualityExpression::mapOperator(inout graph : ExpressionGraph, operator : String, operand1Result : ActivityNode, operand2Result : ActivityNode) { - graph.nodes += var testAction ::= new TestIdentityAction("==", self.booleanType().toType()); + graph.nodes += var testAction ::= new TestIdentityAction("==", self.typeBoolean()); graph.resultSource := testAction.result; var operand1Lower := self.operand1.lower; @@ -1995,7 +1989,7 @@ mapping AssignmentExpression::toActivityGraph() : ExpressionGraph // Apply Bit String conversion to the right-hand side, if necessary. self.mapConversions(rhsGraph, null, false, - self.isIntegerType(rhs.type) and callAction.argument->at(2).type = self.bitStringType().toType()); + self.isIntegerType(rhs.type) and callAction.argument->at(2).type = self.typeBitString()); rhsGraph.edges += new ObjectFlow(rhsGraph.resultSource, callAction.argument->at(2)); rhsGraph.resultSource := callAction.result->at(1); @@ -2043,7 +2037,7 @@ helper SyntaxElement::mapPropertyAssignment(property_ : Property, objectSource : var graph = object ExpressionGraph {}; var featuringClassifier := property_.featuringClassifier![true]; var isReplaceAll := property_.lower = 1 and property_.upper = 1 ; - var unlimitedNaturalType = self.unlimitedNaturalType().toType(); + var unlimitedNaturalType = self.typeUnlimitedNatural(); // Create a write action for the property. graph.nodes += var writeAction ::= new AddStructuralFeatureValueAction(property_, isReplaceAll, unlimitedNaturalType); @@ -2249,7 +2243,7 @@ helper LeftHandSide::mapFeatureLeftHandSide(inout graph : LhsGraph, objectSource indexResultSource := indexConversionAction.result->at(1); } endif; - var unlimitedNaturalType := self.unlimitedNaturalType().toType(); + var unlimitedNaturalType := self.typeUnlimitedNatural(); graph.nodes += var removeAction ::= new RemoveStructuralFeatureValueAction(property_, false, unlimitedNaturalType); graph.edges += new ObjectFlow(objectResultSource, removeAction._'object'); if rhsUpper = 0 then { diff --git a/plugins/uml/alf/org.eclipse.papyrus.uml.alf.to.fuml/transformation/AlfStatement2UML.qvto b/plugins/uml/alf/org.eclipse.papyrus.uml.alf.to.fuml/transformation/AlfStatement2UML.qvto index 9772b59c402..4007b1d89d1 100644 --- a/plugins/uml/alf/org.eclipse.papyrus.uml.alf.to.fuml/transformation/AlfStatement2UML.qvto +++ b/plugins/uml/alf/org.eclipse.papyrus.uml.alf.to.fuml/transformation/AlfStatement2UML.qvto @@ -884,7 +884,7 @@ mapping ForStatement::toActivityGraph() : StatementActivityGraph loopNode.bodyOutput += callAction.result->at(1); // Map the passing through of the upper bound value. - bodyGraph.nodes += var passthruNode ::= createPassthruNode("upper", self.integerType().toType(), 1, 1); + bodyGraph.nodes += var passthruNode ::= createPassthruNode("upper", self.typeInteger(), 1, 1); bodyGraph.edges += new ObjectFlow(upperFork, passthruNode.structuredNodeInput![true]); loopNode.bodyOutput += passthruNode.structuredNodeOutput![true]; @@ -1095,7 +1095,7 @@ mapping AcceptBlock::toActivityGraph(parent : AcceptStatement, previousNode : Ac } endif; signalNames := signalNames + signal.name; - nodes += var testAction ::= new ReadIsClassifiedObjectAction(signal, false, self.booleanType().toType()); + nodes += var testAction ::= new ReadIsClassifiedObjectAction(signal, false, self.typeBoolean()); edges += new ObjectFlow(parent.signalSourceNode, testAction._'object'); var decisionGraph := createControlDecisionGraph( |