pmd规则中文解释

· ShortVariable: Detects when a field, local, or parameter has a very short name.

翻译 短变量:检测出域或参数的名字命名非常短。

· LongVariable: Detects when a field, formal or local variable is declared with a long name.

翻译 长变量:检测出域或参数的名字命名非常长。

· ShortMethodName: Detects when very short method names are used.

翻译 短方法名:检测出方法命名太短。

· VariableNamingConventions: A variable naming conventions rule - customize this to your liking. Currently, it checks for final variables that should be fully capitalized and non-final variables that should not include underscores.

翻译 变量命名约定:变量命名规则-根据你的喜好调整。当前规则检查final类型变量应该全部大写而且非final变量应该不包含下划线。

· MethodNamingConventions: Method names should always begin with a lower case character, and should not contain underscores.

翻译 方法命名约定:方法命名应该总是以小写字符开头,而且不应该包含下划线。

· ClassNamingConventions: Class names should always begin with an upper case character.

扫描二维码关注公众号,回复: 16474149 查看本文章

翻译 类命名约定:类名应该总是以大写字符开头

· AbstractNaming: Abstract classes should be named ‘AbstractXXX’.

翻译 抽象类命名:抽象类应该命名为‘AbstractXXX’

· AvoidDollarSigns: Avoid using dollar signs in variable/method/class/interface names.

翻译 避免美元符号:在变量/方法/类/接口中避免使用美元符号。

· MethodWithSameNameAsEnclosingClass: Non-constructor methods should not have the same name as the enclosing class.

翻译 方法和封装类同名:非构造方法不能和封装类同名

· SuspiciousHashcodeMethodName: The method name and return type are suspiciously close to hashCode(), which may mean you are intending to override the hashCode() method.

翻译 令人疑惑的hashCode方法名:方法名和返回值类似于hashCode(),将令人误解为你试图覆盖hashCode()方法。

· SuspiciousConstantFieldName: A field name is all in uppercase characters, which in Sun’s Java naming conventions indicate a constant. However, the field is not final.

翻译 令人疑惑的常量字段名:一个字段的名称全部用大些字符表示是Sun的JAVA命名规则,表示这个是常量。然而,字段不是final的。

· SuspiciousEqualsMethodName: The method name and parameter number are suspiciously close to equals(Object), which may mean you are intending to override the equals(Object) method.

翻译 令人迷惑的equals方法名:方法名和参数近似于equals(Object),可能让人迷惑为你想覆盖equals(Object)方法

· AvoidFieldNameMatchingTypeName: It is somewhat confusing to have a field name matching the declaring class name. This probably means that type and or field names could be more precise.

翻译 避免属性和类同名:属性和类同名易造成误解,这可能意味着类型或属性名可以命名的更精确

· AvoidFieldNameMatchingMethodName: It is somewhat confusing to have a field name with the same name as a method. While this is totally legal, having information (field) and actions (method) is not clear naming.

翻译 避免属性和方法同名:属性和方法同名易造成误解。即使这是完全合法的,但信息(属性)和动作(方法)都没有清晰地命名。

· NoPackage: Detects when a class or interface does not have a package definition.

翻译 没有包:检测到类或接口没有定义在包里面。

· PackageCase: Detects when a package definition contains upper case characters.

翻译 包的大小写:检测到包的定义中包含大写字符

· MisleadingVariableName: Detects when a non-field has a name starting with ‘m_’. This usually indicates a field and thus is confusing.

翻译 令人迷惑的变量名:检测到非字段类型以m_开头,这通常表示这是一个字段所以这种做法让人迷惑。

· BooleanGetMethodName: Looks for methods named ‘getX()’ with ‘boolean’ as the return type. The convention is to name these methods ‘isX()’.

翻译 返回布尔类型的方法命名:发现返回布尔类型的方法被命名为’getX()’,而惯例是命名为‘isX()’的形式。

· AvoidDuplicateLiterals: Code containing duplicate String literals can usually be improved by declaring the String as a constant field.

翻译 避免重复的字面量:代码包含重复的字符串常常可以重构为将此字符串声明为常量

· StringInstantiation: Avoid instantiating String objects; this is usually unnecessary.

翻译 字符串初始化:避免初始化字符串对象;这是不必要的。

· StringToString: Avoid calling toString() on String objects; this is unnecessary.

翻译 String.toString():避免对字符串对象调用toString()方法,这是不必要的

· InefficientStringBuffering: Avoid concatenating non literals in a StringBuffer constructor or append().

翻译 低效的StringBuffering:避免在StringBuffer的构造器或append()方法中连接非字面量类型

· UnnecessaryCaseChange: Using equalsIgnoreCase() is faster than using toUpperCase/toLowerCase().equals()

翻译 不必要的大小写转换:使用equalsIgnoreCase()比将字符串大小写转换一致后再比较要快。

· UseStringBufferLength: Use StringBuffer.length() to determine StringBuffer length rather than using StringBuffer.toString().equals(“”) or StringBuffer.toString().length() ==.

翻译 使用StringBuffer的length()方法:使用StringBuffer对象的length()方法来计算StringBuffer对象的长度,而不是使用StringBuffer.toString().equals(“”) or StringBuffer.toString().length() ==.等方法

· AppendCharacterWithChar: Avoid concatenating characters as strings in StringBuffer.append.

翻译 用char类型连接字符:在使用StringBuffer的append()方法连接字符时,避免使用string类型。

· ConsecutiveLiteralAppends: Consecutively calling StringBuffer.append with String literals

翻译 连续的字面量连接:连接字符串时连续的调用StringBuffer的append()方法

· UseIndexOfChar: Use String.indexOf(char) when checking for the index of a single character; it executes faster.

翻译 使用indexOf(字符):当你检测单个字符的位置时使用String.indexOf(字符),它执行的很快。不要使用indexOf(字符串)

· InefficientEmptyStringCheck: String.trim().length() is an inefficient way to check if a String is really empty, as it creates a new String object just to check its size. Consider creating a static function that loops through a string, checking Character.isWhitespace() on each character and returning false if a non-whitespace character is found.

翻译 低效的空字符串检查:用String.trim().length()来判断字符串是否空是低效的做法,因为它会创建一个新的字符串对象然后判断大小。考虑创建一个静态的方法循环String,用isWhitespace()检查每个字符如果遇到非空白字符就返回false

· InsufficientStringBufferDeclaration: Failing to pre-size a StringBuffer properly could cause it to re-size many times during runtime. This rule checks the characters that are actually passed into StringBuffer.append(), but represents a best guess “worst case” scenario. An empty StringBuffer constructor initializes the object to 16 characters. This default is assumed if the length of the constructor can not be determined.

翻译 不充分的StringBuffer声明:如果不能在事前声明合适大小的StringBuffer容量可能导致运行期不断地重新分配大小。本规则检查字符事实上传递给StringBuffer.append(),但是表明了在最坏情况下的最好的预测。空参数的StringBuffer构造器默认将对象初始化为16个字符的容量。这个默认情况是在构造长度无法确定的情况下假定的。

· UselessStringValueOf: No need to call String.valueOf to append to a string; just use the valueOf() argument directly.

翻译 无用的valueOf方法:调用append()方法时不需要把参数用valueOf()转换一次,直接将非String类型的值作为参数放在append()里面。

· StringBufferInstantiationWithChar: StringBuffer sb = new StringBuffer(‘c’); The char will be converted into int to intialize StringBuffer size.

翻译 StringBuffer使用字符初始化:StringBuffer sb = new StringBuffer(‘c’);字符c会转换为int值,作为StringBuffer的初始化大小参数。

· UseEqualsToCompareStrings: Using ‘==’ or ‘!=’ to compare strings only works if intern version is used on both sides

翻译 使用equals方法比较字符串:使用‘==’或‘!=’比较字符串大小只是比较两边的常量池的引用。

· AvoidStringBufferField: StringBuffers can grow quite a lot, and so may become a source of memory leak (if the owning class has a long life time).

翻译 避免在类中使用StringBuffer属性:StringBuffer类型变量可以变得非常庞大,所以可能造成内存泄漏。(如果宿主类有很长的生命期)

猜你喜欢

转载自blog.csdn.net/a772304419/article/details/132719318
PMD