How to convert a LocalMethodCall to a LocalVariableDeclaration and a LocalMethodCall using Template Fragments ?

Hi, I'm extending the BaseLanguage with Agent Oriented concept. In my generator I want to replace all LocalMethodCall which matches a given condition to something else. This something else is a LocalVariableDeclaration and a LocalMethodCall.

For instance I want to convert this (in my own DSL):

  • info("Hello")

To this (in the BaseLanguage):

  • Logging LOGGING_CAPACITY = getSkill(Logging.class);
  • LOGGING_CAPACITY.info("Hello")

How can I do it ?

When I'm using a reduction rule template with two template fragments I end up with an error saying that the two template fragments must be of the same type.

Thanks.

 

1 comment
Comment actions Permalink

A LocalMethodCall is an expression and replacing it with two expressions won't be syntactically valid in most places.

You probably want to convert an ExpressionStatement containing a LocalMethodCall to two statements: a LocalVariableDeclarationStatement and an ExpressionStatement. That's going to be syntactically valid since they will usually be located in a StatementList.

0

Please sign in to leave a comment.