How do i change the Getter/Setter format ?

Answered

I guess i will earn a lot of hate for this request...

Im doing java programming the whole day and i dont like the typical c# getter and setter style... this is why im searching for a way to automatic generate java getter and setter...

Does anyone know if this is possible or what i could try to achieve this goal ? 

 

from this...

 public Transform List
    {
        get { return list; }
        set { list = value; }       
    }


to this....
public Transform getList(){ return this.list; }
public void setList(Transform list){ this.list = list;  }
6 comments
Comment actions Permalink

Hello, Lars! 

Do you use Live Template to create a property? If so, you can change it

Also, you create your own Live Template to create getter and setter as in your example. 

Please, let me know if you need help with it. 

1
Comment actions Permalink

Thanks for the tipp !

Currently i generate them via "rightclick -> generate properties" because theres no "rightclick -> generate getter and setter" in rider...
Is it possible to add such a button by myself ? Or any options i could enable/disable to change the way Rider generates the property code construct ?

1
Comment actions Permalink

So heres a little update...

The live template is pretty good... i created following one : 

public void set$SET_NAME$($TYPE$ obj){ $NAME$ = obj; }
public $TYPE$ get$SET_NAME$(){ return $NAME$; }
$END$

It creates a getter/setter template, but its quite annoying that you actually need to write down the Type name, variable name, and method name by yourself. Furthermore it doesnt automaticly updates the input name to lowercase, which is quite annoying...

Any idea how i could change the property generation code format ? 

0
Comment actions Permalink

Sure, 

you can use macros for your variables. 

So, in Live Template Editor choose your template and click Edit Variables. 

 

Then, choose the parameters for variables. E.g. for TYPE you can choose  "Containing type name" and make it non-editable. So, type always will be set automatically. 

For Name and Set_Name you need two variables. Just choose for the second one macro "Value of another variable with the first character in lower/upper case", also make it non-editable and choose a dependent variable. 

It should work :) 

1
Comment actions Permalink

Thanks for your fast reply !

Somehow it doesnt work as intended :( I can set the name of the method... i also need to set the return type, because it always chooses the wrong type... and the "Value of another variable with the first character in lower/upper case" for name gets created instantly, without waiting for the setting of the method name, and well... this is how it looks : 

public TYPE getSET_NAME() { return sET_NAME; }

As next i am able to set the Type and the method name... Setting type works fine... but once i set the method name, the return
variable name doesnt change to lowercase...


public Transform getList() { return sET_NAME; }

This is how it looks after setting the return type and method name

 

Is it also possible to link the "rightclick -> generate property" Button to this live template for changing permantly the look of the getter and setter ? This would be very helpfull :)

1
Comment actions Permalink

Unfortunately, you're right. There is an issue in this place :( 

There is the YouTrack ticket for this: RIDER-22161. Please, upvote, I hope we'll fix this soon. 

Also, it is not possible now (RIDER-2512) to choose live templates from a popup-menu vie shortcuts, but anytime you can start to type template's shortcut and then Tab to auto-complete. 

I apologize for the inconvenience.  

0

Please sign in to leave a comment.