0

I'm currently writing a Eclipse plugin for model driven code generation.

This Plugin features a Wizard for converting UML to Java Code and deploying (in this case copying) the Code Base to different Projects. One Project now has the necessity for one auto-import cleanup (the pipeline messes around with the imports). I usually do this by selecting the source folder and then pressing ctrl+shift+o (organize imports).

Is there the possibility to start this operation out of my Plugin?

in short: How to start the "organize-import" function from my plugin?

1 Answers1

0

The command id for organize imports is org.eclipse.jdt.ui.edit.text.java.organize.imports so you can execute it with:

IHandlerService handlerService = PlatformUI.getWorkbench().getService(IHandlerService.class);

handlerService.executeCommand("org.eclipse.jdt.ui.edit.text.java.organize.imports", null);

The command probably expects the current selection to be a Java file.

greg-449
  • 109,219
  • 232
  • 102
  • 145