maven-java-formatter-plugin

1、source download:

http://maven-java-formatter-plugin.googlecode.com/svn/trunk

2、对换行的comment无法处理

 
  
  1. /** 
  2.      * @uid 2 
  3.      * @场景描述 使用中连接不受影响 
  4.      * @前置条件 1.一个应11111用端 
  5. 2.一台cobar 
  6. 4.两台MySQL 一主一备 
  7.      * @测试步骤 11111启动两台MySQL、cobar 应用连接cobar并执行完一条sql 触发切换 
  8.      * @期望结果 应用无任何异常 sql在主库执行成功 切换后主库连接被释放 
  9.      * @负责人 
  10.      */ 

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_UNITF_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:

 

Note also that it has an effect only when one or several format comments options for javadoc , block orline are set to true while calling format(int, String, int, int, int, String) or format(int, String, IRegion[], int, String) methods

For 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 F_INCLUDE_COMMENT flag is set.
  * @param str The input string
  */
  void foo(String str){}}
 
will produce the following output:
 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){
        }
  }
 
Adding this flavor to the kind given while formatting the same source (e.g.  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