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
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
Please sign in to leave a comment.
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...
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).
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[]
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:
If I would like to create an instance of another class, that is generated somewhere else, I would have to use the reference macro?
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!