Code faster with Intellij IDEA live templates

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.

时间: 2024-08-11 07:49:54

Code faster with Intellij IDEA live templates的相关文章

Django Templates

二分春色到穷阎,儿女祈翁出滞淹.幽蛰夜惊雷奋地,小窗朝爽日筛帘. 惠风全解墨池冻,清昼胜翻云笈签.亲友莫嗔情话少,向来屏息似龟蟾. 料峭寒犹薄,阴云带晚烟. 雨催惊蛰候,风作勒花开. 日永消香篆,愁浓逼酒船. 为君借余景,收拾赋新篇. 作者:小亲姐姐来源链接:http://www.qbaobei.com/jiaoyu/407464.html来源:亲亲宝贝著作权归作者所有. 料峭寒犹薄,阴云带晚烟. 雨催惊蛰候,风作勒花开. 日永消香篆,愁浓逼酒船. 为君借余景,收拾赋新篇. 作者:小亲姐姐来源链

PatentTips - Method and Apparatus to Support Virtualization with Code Patches

BACKGROUND As recognized in Revision 2.0 of the Intel? Virtualization Technology Specification for the Intel? Itanium? Architecture (VT-I), dated April 2005 (hereinafter "the VT-I Specification"), conventional operating system (OS) designs typic

资源盘点|IntelliJ IDEA示例/使用教程/视频教程等你来体验

IntelliJ IDEA是Java语言开发的集成环境,在业界被公认为优秀的Java开发平台之一,在智能代码助手.代码自动提示.重构.J2EE支持.Ant.JUnit.CVS整合.代码审查. 创新的GUI设计等方面表现突出,并支持基于Android平台的程序开发. 为解决大家找资源难的问题,小编整理了IntelliJ IDEA使用资讯.Demo示例.视频资源,以及各种教程推荐等.后续的资源也在持续更新中,欢迎大家持续关注~ 查看资源详情 文章教程 更多教程资源仍在持续更新,敬请期待 Intell

Python著名的lib和开发框架(均为转载)

第一,https://github.com/vinta/awesome-python Awesome Python A curated list of awesome Python frameworks, libraries, software and resources. Inspired by awesome-php. Awesome Python Admin Panels Algorithms and Design Patterns Anti-spam Asset Management A

Awesome Python

Awesome Python  A curated list of awesome Python frameworks, libraries, software and resources. Inspired by awesome-php. Awesome Python Environment Management Package Management Package Repositories Distribution Build Tools Interactive Interpreter Fi

PatentTips - Safe general purpose virtual machine computing system

BACKGROUND OF THE INVENTION The present invention relates to virtual machine implementations, and in particular to a safe general purpose virtual machine that generates optimized virtual machine computer programs that are executable in a general purp

The Best Tools for Developers, 2014

http://theneodesign.com/the-best-tools-for-developers-2014/ Tools, apps, software are the resources that claim to help people complete their assigned tasks without any hassle, in comparatively much lesser time and provide the ease of workflow. We at

Python开源框架、库、软件和资源大集合

A curated list of awesome Python frameworks, libraries, software and resources. Inspired by awesome-php. Admin Panels Libraries for administrative interfaces. Ajenti - The admin panel your servers deserve. django-suit - Alternative Django Admin-Inter

NetCore开源项目集合

具体见:https://github.com/thangchung/awesome-dotnet-core 半年前看到的,今天又看到了,记录下. General ASP.NET Core Documentation - The official ASP.NET Core documentation site. .NET Core Documentation - Home of the technical documentation for .NET Core, C#, F# and Visual