Create property in template fragment

Hi,

I want to create a simple class with some Properties.

Therefore I tried the following:

 

<T public string $[name] {get; public set;} T>

What I get is:

private String myFoo;
public String getFoo() {
return this.myFoo;
}
public void setFoo(String value) {
this.myFoo = value;
}

Thats close to what I want to archieve, but I dont want the 'my' before the field.

What do I wrong? Is there a way to get it the way I want?

 

Thx.

3 comments
Comment actions Permalink

The field for a property always gets generated with a name prepended with "my". You will have to generate the private field and the getter + setter methods yourself, if you want to customize the name of the field.

0
Comment actions Permalink

Thanks for your answer. I am totally new to MPS and a little bit lost. Can you tell me what is the best way to do it?

0
Comment actions Permalink

I'm not sure what exactly is the structure of your language and the generator, but maybe this gives you an idea. The reduction rule that used to generate your property should contain the field together with the getter and the setter.


public class Foo {
<TF private int $foo = 0; TF>

<TF public int $getFoo() {
            foo;
        } TF>
<TF public void $setFoo(int foo1) {
            foo = foo1;
        } TF>
}

}

 

The property macros on the getter and setter can leverage the NameUtil class to properly capitalize the method names: "NameUtil.getGetterName("foo");"

As to a beginner, I would recommend you to consider going through the Fast Track tutorial - https://confluence.jetbrains.com/display/MPSD20173/Fast+Track+to+MPS

0

Please sign in to leave a comment.