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:
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?
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.
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.
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.
With Java 7 you can use the lookup
method in the MethodHandles
class 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());
There are many examples. Just try with searching for example in GitHub: https://github.com/search?q=intellij+live+templates
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With