Code faster with Intellij idea live templates

Source: Internet
Author: User

Intellij Idea–in My opinion the most productive IDE for java–comes with bunch of features helping getting rid of Writi Ng 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 the 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 is 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 the 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 BR Owsing list is not very efficient–especially if you don ' t know what's looking for. That's why I created Gallery of (in my opinion) most useful built-in live templates for Java and Maven so 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 the 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.