Accessing language classes from a model
Hi all,
I would like to access the classes defined in the behavior aspect of the language and invoke them when necessary. However, I could not find any method to do that yet? Could anyone show me a direction to solve the problem? Thanks in advance!
Regards,
Salman
Please sign in to leave a comment.
You will need to import the behaviour model into the model, in which you want to use the classes.
Vaclav
Invoking Java classes that you defined in the behaviour aspect is done just by mere instantiation, e.g. a class Foo defined in the behaviour aspect is instantiated as new Foo(). There is no need to use reflection API.
If, on the other hand, you are trying to invoke behaviour methods of a concept, you just call them on nodes or concepts directly, e.g. node.myMethod() and node.concept.myStaticMethod().
The name of the model to import would be something like <language_name>.behavior
Hi Vaclav,
Could you please tell me the exact name of the model? Thanks.
Hi Vaclav,
Thanks a lot, I can see the methods of behavior now, with the following code from an intention:
nlist<ConceptMethodDeclaration> availableConceptMethods = node.conceptNode.getAvailableConceptMethods(node);
node<ConceptMethodDeclaration> conceptMethod = availableConceptMethods.first;
try {
Method method = conceptMethod.getMethod(node.concept.getLanguage().getSourceModule());
} catch (Exception e) {
System.out.println("the exception is " + e);
}
I can see the concept method and the name, but for invoking I need to use GetMethod instance(if I am not wrong). However, I am getting the following exception:
the exception is java.lang.RuntimeException: jetbrains.mps.classloading.ModuleClassNotFoundException: Unable to load class: 'ConstraintsLanguage.behavior.StateChartRoot_Behavior' using ModuleClassLoader of the 'ConstraintsLanguage' module
Hi Vaclav,
Actually my use case is as follows:
1. User selects behavior methods which has to be executed from a list.
2. Those methods are invoked.
3. return results are processed and transformation menu is generated programatically based on those results.
Currently I am trying to invoke the methods and I am getting the exception I mentioned earlier.
Thanks a lot.
I assume you are calling these behaviour methods from an intention or an action defined in a plugin solution, right?
Vaclav