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

原文: [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方法
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]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值