Adding simple code formatting to a SourceViewer? [message #333544] |
Tue, 16 December 2008 23:13  |
Eclipse User |
|
|
|
What's the quickest/simplest way to add rudimentary JavaScript formatting
to a subclass of a SourceViewer? I'm confused about whether I need a
ContentFormatter, a ContentFormaterStrategy, whether I should use a
multi-pass formatter, etc.
Is there a simple, straightforward set of things I can add to a
SourceViewer that will do minimal formatting, like indenting, for
JavaScript? I'd like to use the JSDT editor, but I don't have that luxury
(I'm retrofitting some old code and don't have all the original source).
Thanks!
Bret
|
|
|
Re: Adding simple code formatting to a SourceViewer? [message #333588 is a reply to message #333544] |
Wed, 17 December 2008 23:58  |
Eclipse User |
|
|
|
Turned out to be pretty simple... For anyone else who comes along wanting
this:
final CodeFormatter codeFormatter =
ToolFactory.createCodeFormatter(DefaultCodeFormatterOptions. getEclipseDefaultSettings().getMap());
TextEdit fmtText =
codeFormatter.format(CodeFormatter.K_JAVASCRIPT_UNIT,
fSourceViewer.getDocument().get(), 0,
fSourceViewer.getDocument().getLength(), 0, null);
try {
fmtText.apply(fSourceViewer.getDocument());
} catch (Exception e) {
System.out.println("Caught text format exception: " +
e.getMessage());
}
Bret
|
|
|
Powered by
FUDForum. Page generated in 0.02728 seconds