tags:

views:

28

answers:

1

I've been trying to create a new TextMate snippet that allows me to create the Getters / Setters for Java.

Currently this is all I can come up with:

public void set${1:Var}(String $1){
    this.$1 = $1;
}

public String get$1(){
    return $1;
}

However, my desired snippet should take the currently selected text, eg. name and produce the following output:

public String getName(){
     return this.name;
}

public void setName(String name){
     this.name = name;
}

To summarize, I need to be able to:

  • Get the user's selected text
  • Capitalize the first character of the selected text

Can this be done?

A: 

You can use regex replace within placeholders.

public void set${1/./\u$0/}(String $1){
    this.$1 = $1;
}

The \u will cause the next character to be converted to uppercase.

(See: http://manual.macromates.com/en/snippets#transformations)

takteek
Thanks, it works.
Victor Neo