Saturday, April 28, 2012

Sublime snippet for creating getter and setter methods in Java class.

  1. Go to 'Tools' -> 'New Snippet'
  2. Replace the default content with the below
    <snippet>
     <content><![CDATA[ public ${1:returnType} get${2:Property}(){
      return ${3:property};
     }
    
     public void set${2:Property}(${1:returnType} ${3:property}){
      this.${3:property} = ${3:property};
     }
    ]]></content>
     <tabTrigger>gs</tabTrigger> 
    </snippet>
    
  3. Save the file in sublime-text-2/Packages/User/urfilename.sublime-snippet
  4. Open the java file that needs getter and setter methods
  5. Type "gs" and hit 'tab'
  6. Snippet should be created at this point and returnType should be highlighted. Type in the returnType of the property for which these getter and setters are being created
  7. Hit 'tab'. Property will be highlighted. Type in the property name with first letter in uppercase.
  8. Hit 'tab'. type in the property name as it is

4 comments:

  1. Thanks for you idea, and I just improve it ;)

    add auto Upper case to property name
    ------------------------------------------------



    property

    source.java


    -------------------------------------------------

    ReplyDelete
    Replies
    1. http://pastebin.com/fbXceD7d

      Delete
    2. when I'm editing the java class, the trigger property doesn't work

      Delete

Followers