Programmatic reformat of java source [message #249619] |
Thu, 15 November 2007 12:09  |
Eclipse User |
|
|
|
Originally posted by: christian.rivasseau.gmail.com
Hi,
I want to learn how to to reformat java source programmatically, and have
been following a previous thread on this forum. Sorry to bother but I have
been trying for some time and don't understand what I do wrong.
Here is my code :
public class JavaFormatterImpl implements JavaFormatter {
private CodeFormatter codeFormatter ;
public JavaFormatterImpl() {
this.codeFormatter=ToolFactory.createCodeFormatter(JavaCore. getOptions());
}
public String formatJavaSource() throws BadLocationException {
String source="public class Dummy { }";
TextEdit textEdit=
this.codeFormatter.format(CodeFormatter.K_COMPILATION_UNIT,s ource,0,source.length(),0,null);
SimpleDocument simpleDocument=new SimpleDocument(source);
textEdit.apply(simpleDocument);
return simpleDocument.get();
}
}
Gets this exception :
java.lang.NoSuchMethodError:
org.eclipse.jdt.internal.compiler.CompilationResult.getLineS eparatorPositions()[I
org.eclipse.jdt.internal.core.util.CodeSnippetParsingUtil.ge tRecordedParsingInformation(CodeSnippetParsingUtil.java:47)
org.eclipse.jdt.internal.core.util.CodeSnippetParsingUtil.pa rseCompilationUnit(CodeSnippetParsingUtil.java:106)
org.eclipse.jdt.internal.formatter.DefaultCodeFormatter.form atCompilationUnit(DefaultCodeFormatter.java:226)
org.eclipse.jdt.internal.formatter.DefaultCodeFormatter.form at(DefaultCodeFormatter.java:155)
org.naiade.core.ide.utils.JavaFormatterImpl.formatJavaSource (JavaFormatterImpl.java:25)
thanx for any help,
Christian
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04153 seconds