Hi Johannes,
Am 06.06.2017 um 20:37 schrieb Johannes
Groß:
Hi Daniel,
thanks for the explanation, escaping the name value
gets me the desired result.
I do need to create the rules via api since i want to
generate them from the UML level model, so i cannot
use the henshin UI.
Ah, I see - you're creating Henshin rules from UML models, which
is sort of an advanced use-case. We did something similar in a
research work [1] where we "turned UML into a transformation
language" by extending it with transformation stereotypes, and
translating the stereotyped UML models to Henshin rules [1]. I
think I could obtain the source code for you, if you're
interested.
[1] Vlad Acretoaie, Harald Störrle, Daniel Strüber: Transparent
Model Transformation: Turning Your Favourite Model Editor into a
Transformation Tool. ICMT 2015: 121-130
https://www.uni-marburg.de/fb12/arbeitsgruppen/swt/forschung/publikationen/2015/ASS15.pdf
I seem to have another issue now, i am trying to set
the name of a newly created Class and the it ends up
with the name qualified name of the java object.
Here is how the code proceeds:
// Manually create two nodes on the RHS.
Node rhsClassNode = factory.createNode(rhsGraph, rhsClass.eClass(), null);
Node rhsPackageNode = factory.createNode(rhsGraph, rhsPackage.eClass(), null);
Edge rhsPackEdge = factory.createEdge(rhsPackageNode, rhsClassNode, UMLFactory.eINSTANCE.getUMLPackage().getPackage_PackagedElement());
String rhsname = (String) rhsPackage.eGet(UMLFactory.eINSTANCE.getUMLPackage().getNamedElement_Name());
rhsPackageNode.setName(rhsname);
rhsClassNode.setName("name");
Attribute nameatt = HenshinFactoryImpl.eINSTANCE.createAttribute();
nameatt.setType(UMLFactory.eINSTANCE.getUMLPackage().getNamedElement_Name());
nameatt.setValue("name");
rhsClassNode.getAttributes().add(nameatt);
Parameter nameParam = HenshinFactoryImpl.eINSTANCE.createParameter();
nameParam.setKind(ParameterKind.IN);
nameParam.setType(EcoreFactoryImpl.eINSTANCE.getEcorePackage().getEString());
nameParam.setName("name");
nameParam.setUnit(rule);
rule.getParameters().add(nameParam);
Mapping m1 = factory.createMapping(lhsPackageNode, rhsPackageNode);
rule.getMappings().add(m1);
Engine engine = new EngineImpl();
UnitApplication createAccountApp = new UnitApplicationImpl(engine);
createAccountApp.setEGraph(graph);
createAccountApp.setUnit(rule);
createAccountApp.setParameterValue("name", "myGreatName");
if (!createAccountApp.execute(null)) {
throw new RuntimeException("Error creating class.");
}
Do i need to set the name of the nodes?
In general no. The intended use of node names it is that it allows you to parametrize a node: You can set the node name to a parameter. For LHS nodes, you can then use RuleApplication.setParameterValue() to bind the parameter to a particular object before the rule execution. This is an alternative to searching an object by its name. For RHS nodes, the parameter value is set automatically during the rule application, and can be used to retrieve an object from the changed model after the rule was executed.
Am i specifying the parameter and attribute correctly?
Any leads on why the name is set to something weird?
In your case, the unintended behavior seems to arise because you use the
same parameter twice, first for the node (via its name), and then also
for its "name" attribute. Apparently, during the rule execution, the following things happen: First, the "name" parameter is re-assigned by setting it to the newly created class (thus overwriting your specified value), and then this new value is used to set the "name" attribute (turning it into a String by using its FQN).
Therefore, I was able to reproduce your problem, and I also could avoid
it by removing the line " rhsClassNode.setName("name"); "
Best regards,
Daniel
_______________________________________________
henshin-dev mailing list
henshin-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/henshin-dev
--
Dr. rer. nat. Daniel Strüber, Dipl.-Inf.
Software Engineering Research Group
Philipps-Universität Marburg, Germany
|