maven-java-formatter-plugin
1、source download:
http://maven-java-formatter-plugin.googlecode.com/svn/trunk
2、对换行的comment无法处理
- /**
- * @uid 2
- * @场景描述 使用中连接不受影响
- * @前置条件 1.一个应11111用端
- 2.一台cobar
- 4.两台MySQL 一主一备
- * @测试步骤 11111启动两台MySQL、cobar 应用连接cobar并执行完一条sql 触发切换
- * @期望结果 应用无任何异常 sql在主库执行成功 切换后主库连接被释放
- * @负责人
- */
3、调试formatter的源代码
其format功能使用的是jdt的org.eclipse.jdt.core.formatter.CodeFormatter的format方法, 该方法的第一个参数为:CodeFormatter.K_COMPILATION_UNIT。
查阅eclipse jdt的官方文档,其关于format方法的描述参考:http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.jdt.doc.isv%2Freference%2Fapi%2Forg%2Feclipse%2Fjdt%2Fcore%2Fformatter%2FCodeFormatter.html
阅读关于K_COMPILATION_UNIT和
F_INCLUDE_COMMENTS的描述信息,具体如下:
F_INCLUDE_COMMENTS
public static final int F_INCLUDE_COMMENTS
-
Flag used to include the comments during the formatting of the code snippet.
This flag can be combined with the following kinds:
K_COMPILATION_UNIT
K_UNKNOWN
K_CLASS_BODY_DECLARATIONS
(since 3.6)K_EXPRESSION
(since 3.6)K_STATEMENTS
(since 3.6)
Note also that it has an effect only when one or several format comments options for
javadoc
,block
orline
are set totrue
while callingformat(int, String, int, int, int, String)
orformat(int, String, IRegion[], int, String)
methodsFor example, with the Eclipse default formatter options, the formatting of the following code snippet using
K_COMPILATION_UNIT
:public class X { /** * This is just a simple example to show that comments will be formatted while processing a compilation unit only if the constant flag
will produce the following output:F_INCLUDE_COMMENT
flag is set. * @param str The input string */ void foo(String str){}}public class X { /** * This is just a simple example to show that comments will be formatted while processing a compilation unit only if the constant flag
Adding this flavor to the kind given while formatting the same source (e.g.F_INCLUDE_COMMENT
flag is set. * * @param str The input string */ void foo(String str){ } }K_COMPILATION_UNIT
|F_INCLUDE_COMMENTS
) will produce the following output instead:public class X { /** * This is just a simple example to show that comments will be formatted * while processing a compilation unit only if the constant flag *
F_INCLUDE_COMMENT
flag is set. * * @param str * The input string */ void foo(String str){ } }Note: Although we're convinced that the formatter should always include the comments while processing a
kind of compilation unit
, we have decided to add a specific flag to fix this formatter incorrect behavior. This will prevent all existing clients (e.g. 3.3 and previous versions) using theK_COMPILATION_UNIT
kind to be broken while formatting.-
Since:
- 3.4 See Also:
- Constant Field Values
4、解决方案:
K_COMPILATION_UNIT
|F_INCLUDE_COMMENTS
转载于:https://blog.51cto.com/tianya23/630044