As
Mateusz asked for
how to add Newlines to generated code in Eclipse, i looked at how Eclipse JDT is doing it. And of course, the Eclipse guys
eat their own dog food and use the
abstract syntax tree (AST) feature.
For a showcase, let's assume we've got an open Java Editor with an empty class and we want to add a new method. For the sake of simplicity for the demo, i'm going to implement it in an action and use the current editor as target. That's not nice, but pretty simple for now:
IWorkbench workbench = PlatformUI.getWorkbench();
IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
IWorkbenchPage page = window.getActivePage();
IEditorPart editor = page.getActiveEditor();
IEditorInput input = editor.getEditorInput();
IJavaElement element = JavaUI.getEditorInputJavaElement(input);