Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Intellij Live Template

Is there any way to use a default token value in Intellij Live templates? For example I have the following live template which declares a private variable that I would like to create nearly for every class:

private static final Logger logger = Logger.getLogger($CLASS$.class)

It seems unnecessary to type $CLASS$ every time when this live template is used, because it can be derived from the class in scope or filename. I was wondering if it is possible to use environment defined tokens in live templates as defaults?

like image 944
Leonid Avatar asked May 23 '11 13:05

Leonid


People also ask

What is live template in IntelliJ?

Use live templates to insert common constructs into your code, such as loops, conditions, various declarations, or print statements. To expand a code snippet, type the corresponding template abbreviation and press Tab . Keep pressing Tab to jump from one variable in the template to the next one.

How do you add a live template?

Press Ctrl+Alt+S to open the IDE settings and select Editor | Live Templates. Select the template group where you want to create a new live template (for example, other). If you do not select a template group, the live template will be added to the user group. and select Live Template.

Where are live templates stored?

Live template group configuration files are stored in the templates directory of the IDE configuration directory.

How do I save a template in IntelliJ?

From the main menu, select File | New Projects Setup | Save Project as Template. In the dialog that opens, name the template and configure the options: Save: if the project contains more than one module, select whether you want to create a template from the whole project or from one of the modules.


1 Answers

Check some other templates that already use the current class name:

enter image description here

like image 135
CrazyCoder Avatar answered Sep 22 '22 13:09

CrazyCoder