2013-02-26 56 views
2

我们正在使用PMD和Checkstyle(来自开发人员IDE和中央CI服务器)来检查代码以符合我们的编码约定。如何检查Java类成员订单

我期待这些工具提供一个检查类成员顺序的规则,但他们似乎没有。

通过类成员为了我的意思是这样的:

public static properties 
public properties 
protected properties 
private properties 

public constructors 
protected constructors 
private constructors 

static methods 

non-static methods 

我肯定会写我自己的PMD规则,但我不会用它,宁愿不要重新发明轮子。

你知道有什么工具可以为我们做这种检查吗?

+0

我建议你与现代IDE这表明各成员的顺序反正有更好的东西缠住有关。 – EJP 2013-02-26 23:04:04

回答

2

可以使用的Checkstyle的声明顺序检查

检查某个类或接口声明的部分出现在 的顺序由代码约定为Java建议编程 语言。

1.Class (static) variables. First the public class variables, 

然后保护,然后包级别(没有访问修饰符),然后私人。

2.Instance variables. First the public class variables, then the protected, 

然后包级别(没有访问修饰符),然后私人。

3.Constructors 

4.Methods 

Reference

+0

谢谢,你是对的,我没有看到它! – 2013-02-26 09:53:08