首页 > 其他 > 详细

Code faster with Intellij IDEA live templates

时间:2015-09-30 12:47:34      阅读:357      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!