`

省时利器:代码美化与格式化工具

 
阅读更多
原文: http://blog.jobbole.com/16979/
PrettyPrinter 适用于 PHP, Java, C++, C, Perl, JavaScript, CSS。提供了大量格式化选项,可以按照你喜欢的方式来展示代码。 http://prettyprinter.de/

how to use the eclipse code formatter from your code ,使用eclipse的格式化包
http://ssscripting.wordpress.com/2009/06/10/how-to-use-the-eclipse-code-formatter-from-your-code/
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:
K_EXPRESSION
K_STATEMENTS
K_CLASS_BODY_DECLARATIONS
K_COMPILATION_UNIT

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)
K_UNKNOWN
K_SINGLE_LINE_COMMENT
K_MULTI_LINE_COMMENT
K_JAVA_DOC

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.

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 https://code.google.com/p/maven-java-formatter-plugin/
maven-java-formatter-plugin无法格式化comment http://tianya23.blog.51cto.com/1081650/630044
Maven Eclipse Format Plugin http://sourceforge.net/projects/mvneclipsefmt/
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics