Code faster with Intellij IDEA live templates
2015-09-30 11:23
435 查看
Intellij IDEA – in my opinion the most productive IDE for Java – comes with bunch of features helping getting rid of writing repetitive code – which is a everyday business no matter what language you use. One of them is live templates.
Live templates contain predefined code fragments. You can use them to insert frequently-used or custom code constructs into your source code file quickly, efficiently, and accurately.
IDEA comes with a set of live templates for Java, Maven, HTML, CSS and more and also enables to create custom templates.
Type live template abbreviation (for example dep) and next press TAB key
Use shortcut Command + J (Mac) / Ctrl + J (PC) to popup list of available live templates in current context
At the beginning it’s quite difficult to remember all you wish to use and going back and forth from code to settings or browsing list is not very efficient – especially when you don’t know what you are looking for. That’s why I created gallery of (in my opinion) most useful built-in live templates for Java and Maven that can be used as a cheat sheet:
pl – Inserts <plugin/>
repo – Inserts <repo/>
itar – iterates elements of array
itco – iterates elements of java.util.Collection
iter – iterates Iterable
itit – iterates java.util.Iterator
itli – iterates elements of java.util.List
inn – Inserts “if not null” statement
inst – Checks object type with instanceof and down-casts it
lazy – Performs lazy initialization
psfi – public static final int
psfs – public static final String
thr – throw new
If you created interesting common use live templates for Java or related frameworks feel invited to post them in comments.
Live templates contain predefined code fragments. You can use them to insert frequently-used or custom code constructs into your source code file quickly, efficiently, and accurately.
IDEA comes with a set of live templates for Java, Maven, HTML, CSS and more and also enables to create custom templates.
Inserting live template
There are 2 ways to insert live template:Type live template abbreviation (for example dep) and next press TAB key
Use shortcut Command + J (Mac) / Ctrl + J (PC) to popup list of available live templates in current context
At the beginning it’s quite difficult to remember all you wish to use and going back and forth from code to settings or browsing list is not very efficient – especially when you don’t know what you are looking for. That’s why I created gallery of (in my opinion) most useful built-in live templates for Java and Maven that can be used as a cheat sheet:
Maven
dep – Inserts <dependency/>pl – Inserts <plugin/>
repo – Inserts <repo/>
Iterations
fori – creates iteration loopitar – iterates elements of array
itco – iterates elements of java.util.Collection
iter – iterates Iterable
itit – iterates java.util.Iterator
itli – iterates elements of java.util.List
Other
ifn – Inserts “if null” statementinn – Inserts “if not null” statement
inst – Checks object type with instanceof and down-casts it
lazy – Performs lazy initialization
Plain
psf – public static finalpsfi – public static final int
psfs – public static final String
thr – throw new
Summary
Using predefined Java templates is just a beginning. You can find ready to use templates for particular frameworks on Github and I really encourage you to create your custom, project specific ones.If you created interesting common use live templates for Java or related frameworks feel invited to post them in comments.
相关文章推荐
- 第三次作业 黄学才
- 当代西方经济思潮
- 创建eclipse新的workspace并设置workspace共享配置
- 基于 CoreText 的排版引擎:进阶
- 拷贝构造函数
- 苹果开发者各地区联系电话
- ios - 解决XCode6在IOS7系统上出现部分黑屏与不适配问题
- 通过前端获取客户端ip和所在城市,并在后端获得这些值
- IOS——AFN
- 第四次作业
- 关于中文域名转码
- 入世对我国税收的影响及应对措施
- Lightmaping
- 解决oralce 11g dg搭建报错:ORA-16664、ORA-16714、ORA-16810问题--转
- Python函数:装饰器
- 支持城市及查询条件 车行易车辆违章查询sdk代码示例
- STL学习之vector
- JSP学习笔记之基础语法
- 对称加密和分组加密中的四种模式(ECB、CBC、CFB、OFB)
- Keil MDK与h-jtag联调