Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Useful Intellij Live Templates

In the same manner as the Useful Eclipse Java Code Templates, and having converted to Intellij I'm wondering whether there are similar useful code templates that people use.

I've setup the slf4j import as follows:

  • Abbreviation: slog
  • Section: output
  • Edit Variables: CLASS_NAME -> className()
  • Applicable in Java: declaration

and the template text is:

private static final org.slf4j.Logger LOG = org.slf4j.LoggerFactory.getLogger($CLASS_NAME$.class);

Are there other useful Live Templates that people use?

like image 935
Jon Avatar asked Feb 28 '14 11:02

Jon


People also ask

What are live templates 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 did you make 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.

How do I import a live template?

Choose File | Manage IDE Settings | Import Settings from the menu. Specify the path to the archive with the exported live template configuration. In the Import Settings dialog, select the Live templates checkbox and click OK.


2 Answers

With Java 7 you can use the lookup method in the MethodHandlesclass to simplify the logging template.

https://docs.oracle.com/javase/7/docs/api/java/lang/invoke/MethodHandles.Lookup.html

private static final org.slf4j.Logger LOG = org.slf4j.LoggerFactory.getLogger(java.lang.invoke.MethodHandles.lookup().lookupClass());
like image 130
Will Humphreys Avatar answered Oct 05 '22 03:10

Will Humphreys


There are many examples. Just try with searching for example in GitHub: https://github.com/search?q=intellij+live+templates

like image 29
hsz Avatar answered Oct 05 '22 02:10

hsz