原文: [url]http://blog.jobbole.com/16979/[/url]
[color=blue][b]PrettyPrinter[/b][/color] 适用于 PHP, Java, C++, C, Perl, JavaScript, CSS。提供了大量格式化选项,可以按照你喜欢的方式来展示代码。 [url]http://prettyprinter.de/[/url]
[color=red][b]how to use the eclipse code formatter from your code[/b][/color] ,使用eclipse的格式化包
[url]http://ssscripting.wordpress.com/2009/06/10/how-to-use-the-eclipse-code-formatter-from-your-code/[/url]
org.eclipse.jdt.core.formatter.CodeFormatter的format方法
Format source, and returns a text edit that correspond to the difference between the given string and the formatted string.
It returns null if the given string cannot be formatted.
If the offset position is matching a whitespace, the result can include whitespaces. It would be up to the caller to get rid of preceding whitespaces.
Parameters:
kind - Use to specify the kind of the code snippet to format. It can be any of these:
[color=darkblue]K_EXPRESSION
K_STATEMENTS
K_CLASS_BODY_DECLARATIONS
K_COMPILATION_UNIT[/color]
Since 3.4, the comments can be formatted on the fly while using this kind of code snippet
(see F_INCLUDE_COMMENTS for more detailed explanation on this flag)
[color=darkblue]K_UNKNOWN
K_SINGLE_LINE_COMMENT
K_MULTI_LINE_COMMENT
K_JAVA_DOC[/color]
[i]source - the source to format
offset - the given offset to start recording the edits (inclusive).
length - the given length to stop recording the edits (exclusive).
indentationLevel - the initial indentation level, used to shift left/right the entire source fragment. An initial indentation level of zero or below has no effect.
lineSeparator - the line separator to use in formatted source, if set to null, then the platform default one will be used.[/i]
Returns:
the text edit
Throws:
IllegalArgumentException - if offset is lower than 0, length is lower than 0 or length is greater than source length.
maven-java-formatter-plugin [url]https://code.google.com/p/maven-java-formatter-plugin/[/url]
maven-java-formatter-plugin无法格式化comment [url]http://tianya23.blog.51cto.com/1081650/630044[/url]
Maven Eclipse Format Plugin [url]http://sourceforge.net/projects/mvneclipsefmt/[/url]
[color=blue][b]PrettyPrinter[/b][/color] 适用于 PHP, Java, C++, C, Perl, JavaScript, CSS。提供了大量格式化选项,可以按照你喜欢的方式来展示代码。 [url]http://prettyprinter.de/[/url]
[color=red][b]how to use the eclipse code formatter from your code[/b][/color] ,使用eclipse的格式化包
[url]http://ssscripting.wordpress.com/2009/06/10/how-to-use-the-eclipse-code-formatter-from-your-code/[/url]
org.eclipse.jdt.core.formatter.CodeFormatter的format方法
public abstract TextEdit format(int kind,
String source,
int offset,
int length,
int indentationLevel,
String lineSeparator)
Format source, and returns a text edit that correspond to the difference between the given string and the formatted string.
It returns null if the given string cannot be formatted.
If the offset position is matching a whitespace, the result can include whitespaces. It would be up to the caller to get rid of preceding whitespaces.
Parameters:
kind - Use to specify the kind of the code snippet to format. It can be any of these:
[color=darkblue]K_EXPRESSION
K_STATEMENTS
K_CLASS_BODY_DECLARATIONS
K_COMPILATION_UNIT[/color]
Since 3.4, the comments can be formatted on the fly while using this kind of code snippet
(see F_INCLUDE_COMMENTS for more detailed explanation on this flag)
[color=darkblue]K_UNKNOWN
K_SINGLE_LINE_COMMENT
K_MULTI_LINE_COMMENT
K_JAVA_DOC[/color]
[i]source - the source to format
offset - the given offset to start recording the edits (inclusive).
length - the given length to stop recording the edits (exclusive).
indentationLevel - the initial indentation level, used to shift left/right the entire source fragment. An initial indentation level of zero or below has no effect.
lineSeparator - the line separator to use in formatted source, if set to null, then the platform default one will be used.[/i]
Returns:
the text edit
Throws:
IllegalArgumentException - if offset is lower than 0, length is lower than 0 or length is greater than source length.
maven-java-formatter-plugin [url]https://code.google.com/p/maven-java-formatter-plugin/[/url]
maven-java-formatter-plugin无法格式化comment [url]http://tianya23.blog.51cto.com/1081650/630044[/url]
Maven Eclipse Format Plugin [url]http://sourceforge.net/projects/mvneclipsefmt/[/url]