Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Adding simple code formatting to a SourceViewer?
Adding simple code formatting to a SourceViewer? [message #333544] Wed, 17 December 2008 04:13 Go to next message
Bret Schuhmacher is currently offline Bret SchuhmacherFriend
Messages: 26
Registered: July 2009
Junior Member
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] Thu, 18 December 2008 04:58 Go to previous message
Bret Schuhmacher is currently offline Bret SchuhmacherFriend
Messages: 26
Registered: July 2009
Junior Member
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
Previous Topic:How to create an indirect reference to the javadoc for a classpath entry
Next Topic:How to install plugins in a specialized location for Eclipse 3.4
Goto Forum:
  


Current Time: Sat Apr 27 01:03:35 GMT 2024

Powered by FUDForum. Page generated in 0.02834 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top