zoukankan      html  css  js  c++  java
  • 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.

  • 相关阅读:
    并查集基本操作及其优化
    POJ-3159.Candies.(差分约束 + Spfa)
    差分约束和最短路径(算法导论)
    POJ-3660.Cow Contest(有向图的传递闭包)
    Floyd-Warshall算法计算有向图的传递闭包
    深入理解链式前向星
    POJ-1860.CurrencyExchange(Spfa判断负环模版题)
    HDU-4725.TheShortestPathinNyaGraph(最短路 + 建图)
    POJ-3268.SilverCowParty.(最短路 + 图的转置)
    POJ-1797.HeavyTransportation(最长路中的最小权值)
  • 原文地址:https://www.cnblogs.com/meetrice/p/4848697.html
Copyright © 2011-2022 走看看