Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to deal with Camel Case for Eclipse Templates?

I'm trying to write an Eclipse template which will create getters and setters when I create an attribute. My current template works, except for the camel casing for the getters and setters.

private ${type} ${field};

private ${type} get${field}() {return ${field};}

private void set${field}(${type} ${field}) {this.${field} = ${field};}

Any tricks to do so? I am aware that Eclipse can generate the getters and setters for me, but #1: it's menu driven (slow), #2: it's not in the format I want.

Thanks!

like image 350
Mark Avatar asked Sep 29 '10 20:09

Mark


People also ask

How do you capitalize words in eclipse?

Ctrl+Shift+Y for Lowercase, Ctrl+Shift+X for Uppercase.

What is a CamelCase in Java?

CamelCase is a way to separate the words in a phrase by making the first letter of each word capitalized and not using spaces. It is commonly used in web URLs, programming and computer naming conventions. It is named after camels because the capital letters resemble the humps on a camel's back.


2 Answers

Nope, it's not possible to do it straight up using Eclipse. It's actually logged as a bug:

https://bugs.eclipse.org/bugs/show_bug.cgi?id=220953

but you should be able to add a custom extension to allow this, but you'll need to learn about the Eclipse framework and plugins in order to do that.

like image 175
Jon Avatar answered Sep 18 '22 00:09

Jon


Best you can do right now is

private ${Type} ${field};

private ${Type} get${Field}() {return ${field};}

private void set${Field}(${Type} ${field}) {this.${field} = ${field};}

This defines separate linked variables for the upper and lower case names.

You may be able to define a VariableResolver in a custom plugin to do this

like image 34
Scott Stanchfield Avatar answered Sep 18 '22 00:09

Scott Stanchfield