generator property macro

The name of the class in my generator is a property macro returning node.name just like in the tutorial.
Now I'd like to create an object of the class in a method of the class.
Problem is: I don't get the option "property macro" when selecting and right-clicking (or alt-enter).
So my question is:
How do I specify a Class based on a property macro?
or
How do I get an instance of a class named from a property macro?

Thanks
0
8 comments
Property macro is just a way to substitute some particular property of node created by generator. If you need to create new node completely you have to use node macro and (most probably) create a reduction rule for it. See generator documentation page for more details.
0
Hi Alex,

I think you probably misunderstood the problem.

What rzw meant, and I don't know how to do that either is:

How to generate a Reference to a Class, to which you only know the name. As i only generate non-java, i always circumvent generating references.
There is a reference macro, but you need to return a node there. And of course you dont have the node, as it is just getting generated...
0
Hi!

From reference macro you can return either a node or a string which will be used to resolve this reference. Another option is to use concepts from baseLanguageInternal or create your own "internal" language for specific low-level language (other then java).
0

I'll try to rephrase my question.

What I want generated:

  public class Foo {

    public static void main(String[] argv) {
      new Foo();
  .
  .
  .

What my template looks like:

  public class $[TestImpl] extends <none> implements <none> {

    public static void main(String[] argv) {
      //How do I create the instance ?
  .
  .
  .


I can specify the name of the class from a property macro ($[TestImpl]). That option doesn't seem to be available for a ClassCreator.
In the calculator tutorial they managed to add a
  new CalcuatorImpl()
directly, but in my own project that option is not available for some reason. The closest I get is
  new TestImpl[]
0
Hi!

The proper way to handle it is to write new TestImpl(). In MPS this construction just refer to an instance of TestImpl class you've created, so once you modify the name of this class by using property macro it will be automatically updated in all references (including constructor name & new expression).

BTW, just checked following steps with MPS 2.0:
  • create new class in generator
  • specify input concept for this template
  • specify class name "TestImpl"
  • create property macro substituting class name with a property from input concept
    - create main method
  • in method body type "new |" and press Ctrl+Space -> type "TestImpl" and choose TestImpl() constructor from the popup menu..
0
And just for the fun of it:

If I would like to create an instance of another class, that is generated somewhere else, I would have to use the reference macro?
0
It works as described in scope of one model, but if you'd like to use this generated class from another model you have to use string to represent this reference.
0
Ok, It works now.
The problem was that a new TestImpl() option is only available if there is a constructor in TestImpl.
It didn't have one anymore.

To access the rest of the created TestImpl I have to fall back to a string array and Class.forName.
Not very elegant but it works.


Thanks for the help!
0

Please sign in to leave a comment.