Live Templates

Custom Live Templates #

Live templates can be used to insert common constructs such as declarations easily. For example, writing sout will be replaced with System.out.println() in Java files.

Creating Live Templates #

Go into the Settings (Ctrl + Alt + S) and then Editor > Live Templates, then select Java and click on the + button. The assigned name is the abbreviation which will be auto completed, e.g. sout or wpool.

liveTemplateSetup

Add the code which will be inserted into the Template text field:

de.uni_trier.wi2.procake.data.objectpool.WriteableObjectPool<de.uni_trier.wi2.procake.data.object.base.AggregateObject> $POOL$ = new de.uni_trier.wi2.procake.data.objectpool.impl.WriteableObjectPoolImpl<>();
    $POOL$.store($TO_STORE$);
    de.uni_trier.wi2.procake.utils.io.IOUtil.writeFile($POOL$,
        $PATH$,
        de.uni_trier.wi2.procake.data.io.xml.xerces_writerImpl.ObjectPoolWriter.WRITERNAME);
$END$

To add variables which are editable, wrap them with $, e.g. $POOL. If the template gets inserted, all instances of this variable will be replaced simultaneously. The $END$ variable denotes the position of the variable after the insertion of the template is finished and all variables are inserted. Check Reformat according to style so that the style rules are applied after insertion. Check Shorten FQ names so that fully qualified names are imported automatically.

Important: Always use fully qualified names (e.g. de.uni_trier.wi2.procake.data.objectpool.WriteableObjectPool instead of WriteableObjectPool) and check Shorten FQ names.

Usage: #

Write the abbreviation (wpool) in a .java file and write the variable names in the fields. Press Enter to confirm a variable and Tab to cycle to the next variable.

More Information #

More information on Live Templates can be found here and https://www.jetbrains.com/help/idea/using-live-templates.html in the official IntelliJ documentation.

Sharing Live Templates #

To share Live Templates with team members, the settings need to be ex- and imported manually using a zip archive. The documentation can be found here.