Jason
Jason

Reputation: 4130

Auto Import With Eclipse Snippets

I started using snippets recently. The most common one I use inserts this at the cursor:

private Logger log = LoggerFactory.getLogger(getClass());

However, I still have to do a CTRL-SHIFT-O to import Logger and LoggerFactory.

Out of pure laziness I ask this: Is there a way to do an automatic import when I insert this snippet?

Upvotes: 2

Views: 176

Answers (1)

E-Riz
E-Riz

Reputation: 32895

I don't think a Snippet can automatically insert an import statement (or do anything other than insert text at the current cursor location). But you can set up an automatic Save Action to do the organize imports whenever you save. Open the project properties and navigate to Java Editor > Save Actions.

I usually set up a few different things in the Additional Actions including Organize Imports, removed trailing whitespace, insert missing annotations, etc.

Upvotes: 1

Related Questions