码迷,mamicode.com
首页 > 其他好文 > 详细

Code faster with Intellij IDEA live templates

时间:2015-09-30 12:49:10      阅读:186      评论:0      收藏:0      [点我收藏+]

标签:

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.

Inserting live template

There are 2 ways to insert live template:

  1. Type live template abbreviation (for example dep) and next press TAB key
  2. 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 loop

技术分享

  • 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

技术分享

Other

  • ifn – Inserts “if null” statement

技术分享

  • inn – Inserts “if not null” statement

技术分享

  • inst – Checks object type with instanceof and down-casts it

技术分享

  • lazy – Performs lazy initialization

技术分享

Plain

  • psf – public static final

技术分享

  • psfi – 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.

Code faster with Intellij IDEA live templates

标签:

原文地址:http://www.cnblogs.com/meetrice/p/4848697.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!