Skip to main content



      Home
Home » Language IDEs » Java Development Tools (JDT) » Programmatic reformat of java source
Programmatic reformat of java source [message #249619] Thu, 15 November 2007 12:09 Go to next message
Eclipse UserFriend
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
Re: Programmatic reformat of java source [message #249624 is a reply to message #249619] Thu, 15 November 2007 15:31 Go to previous messageGo to next message
Eclipse UserFriend
Christian Rivasseau a écrit :
> 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)
What version of Eclipse are you using?
--
Olivier
Re: Programmatic reformat of java source [message #249637 is a reply to message #249624] Thu, 15 November 2007 18:58 Go to previous message
Eclipse UserFriend
Originally posted by: christian.rivasseau.gmail.com

this is 3.3 stable
Previous Topic:Missing code implementation in the compiler
Next Topic:Formatting source code
Goto Forum:
  


Current Time: Wed Jul 16 14:26:02 EDT 2025

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

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

Back to the top