How to add "import" statements from templates in IntelliJ?

Viewed 1135

I have defined the following live template in IntelliJ:

private static final Logger log = LoggerFactory.getLogger($CLASS_NAME$.class);

I use it to insert logger variable to a class.

Is it possible to define so that template also adds

import org.slf4j.Logger;
import org.slf4j.LoggerFactory; 

to the file if these definitions are still absent?

2 Answers

Now its possible to add live templates with static imports:

You have to check static import in Options

@org.junit.Test
public void should$EXPR$when$CONDITION$() {
    org.junit.Assert.assertThat(null, org.hamcrest.CoreMatchers.is(org.hamcrest.CoreMatchers.nullValue())); 
}

enter image description here

Related