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

7 comments
Comment actions Permalink

You will need to import the behaviour model into the model, in which you want to use the classes.

Vaclav

 

2
Comment actions Permalink

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().

 

2
Comment actions Permalink

The name of the model to import would be something like <language_name>.behavior

1
Comment actions Permalink

Hi Vaclav, 

Could you please tell me the exact name of the model? Thanks.

 

0
Comment actions Permalink

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

0
Comment actions Permalink

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.

0
Comment actions Permalink

I assume you are calling these behaviour methods from an intention or an action defined in a plugin solution, right?

Vaclav

 

0

Please sign in to leave a comment.