如何定義Checkstyle驗證以確保具有特定注釋的所有方法都出現在 java 類的構造函數之前?驗證應接受以下內容:class User { @Injected // -> [OK]: method with @Injected is before the constructor. public void setName(String name) { this.name = name; } public User(String name) { this.name = name; }}以下應該會導致 Checkstyle 違規:class User { public User(String name) { this.name = name; } @Injected // -> [NOK]: method should be before the constructor public void setName(String name) { this.name = name; }}是否有開箱即用的 Checkstyle Check可以配置為檢查此功能,或者需要自定義 Check 實現來實現此功能?
1 回答

搖曳的薔薇
TA貢獻1793條經驗 獲得超6個贊
不,沒有這樣的現成可用的 Checkstyle Check。
為此,需要實現自定義 Checkstyle Check,并且必須通過將其添加到驗證配置 xml 中來觸發此自定義驗證。
添加回答
舉報
0/150
提交
取消