Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[henshin-dev] Rule and Attribute creation via API

Hi,

i am trying to integrate Henshin in a EMF-based UML tool. To test this, I am creating a rule and all of its components programatically. I am trying to have a UML Package on the LHS that is searched by its name. So i am trying to create an attribute to filter by the name. I also tried naming the node but that does not seem to have any effect. Here is my code:
lhsPackage is my Package named "myPackage".
Module module = factory.createModule();
module.getImports().add(UMLFactory.eINSTANCE.getUMLPackage());

Rule rule = factory.createRule();
module.getUnits().add(rule);

rule.setActivated(true);
rule.setName("createClassInPackage_Generated");
Graph lhsGraph = rule.getLhs(); // left-hand side of the rule
Node lhsPackageNode = factory.createNode(lhsGraph, lhsPackage.eClass(), null);
String name = (String) lhsPackage.eGet(UMLFactory.eINSTANCE.getUMLPackage().getNamedElement_Name());
lhsPackageNode.setName(name);
Attribute att = HenshinFactoryImpl.eINSTANCE.createAttribute();
att.setType(UMLFactory.eINSTANCE.getUMLPackage().getNamedElement_Name());
att.setValue(name);
lhsPackageNode.getAttributes().add(att);
 However when executing the rule, I get an exception:

java.lang.RuntimeException: ReferenceError: "myPackage" is not defined in <eval> at line number 1
    at org.eclipse.emf.henshin.interpreter.impl.EngineImpl.evalAttributeExpression(EngineImpl.java:963)
    at org.eclipse.emf.henshin.interpreter.info.VariableInfo.createConstraints(VariableInfo.java:189)
    at org.eclipse.emf.henshin.interpreter.info.VariableInfo.createVariables(VariableInfo.java:111)
    at org.eclipse.emf.henshin.interpreter.info.VariableInfo.<init>(VariableInfo.java:77)
    at org.eclipse.emf.henshin.interpreter.info.RuleInfo.<init>(RuleInfo.java:26)
    at org.eclipse.emf.henshin.interpreter.impl.EngineImpl.getRuleInfo(EngineImpl.java:748)
    at org.eclipse.emf.henshin.interpreter.impl.EngineImpl$MatchFinder.<init>(EngineImpl.java:323)
    at org.eclipse.emf.henshin.interpreter.impl.EngineImpl$MatchGenerator.iterator(EngineImpl.java:268)
    at org.eclipse.emf.henshin.interpreter.impl.RuleApplicationImpl.execute(RuleApplicationImpl.java:92)
    at org.eclipse.emf.henshin.interpreter.impl.UnitApplicationImpl.executeRule(UnitApplicationImpl.java:176)
    at org.eclipse.emf.henshin.interpreter.impl.UnitApplicationImpl.doExecute(UnitApplicationImpl.java:100)
    at org.eclipse.emf.henshin.interpreter.impl.UnitApplicationImpl.execute(UnitApplicationImpl.java:90)

Any leads what i am missing?

Thanks,
Johannes

Back to the top