Here is the Eclipse template that I want to port:
${:import(org.apache.log4j.Logger)}
private static final Logger LOG = Logger.getLogger(${enclosing_type}.class);
My current version in IDEA is as follows:
private static final Logger LOG = Logger.getLogger($CLASS_NAME$.class);$END$
where $CLASS_NAME$
is configured to use className()
as its expression.
Unfortunately, I don't find any documentation on adding the import statement. Is there somehing equivalent to Eclipse ${:import(...)}
?
Just to save a little time for new visitors here: the accepted answer now needs some changes.
Go to
Settings -> Editor -> Live Templates
, selectothers
, add a template:Then, press
Edit Variables
on the left and set expression forCLASS_NAME
toclassName()
.After all, set context on the bottom to
Java -> Declaration
(andGroovy -> Declaration
if desired). Imports will be magically generated on insert.According to this post, it seems to be intended to use only full-qualified expressions. I tried it out and this worked for me:
IDEA automatically shortens it and adds the necessary import statements:
For apache commons logging use: