1. Tools -> Developer -> New Snippet。
2. 复制以下内容并保存:
<snippet> <content><![CDATA[private ${1:type} ${2:name};public void set${3:property}(${1:type} ${2:name}) { this.${2:name} = ${2:name};}public ${1:type} get${3:property}() { return ${2:name};}]]></content> <!-- Optional: Set a tabTrigger to define how to trigger the snippet --> <tabTrigger>gs</tabTrigger> <!-- Optional: Set a scope to limit where the snippet will trigger --> <scope>source.java</scope> <!-- Optional: Description to show in the menu --> <description>Create getter and setter methods</description></snippet>
以上为Java的Getter和Setter例子。
对于其他OO语言,可参考原有格式修改“source.java”以及<content></content>中的内容。
3. 使用方法:
1. 在需要插入变量+Getter+Setter的地方输入gs,按Tab
2. 输入变量类型,按Tab
3. 输入变量名字,按Tab
4. 输入首字母为大写的变量名字,完成!