Revert "added acceptable length property"

This reverts commit 2ccfe15a148346b54d9980386c38927499ba26b5.
This commit is contained in:
rajeshggwp
2018-11-08 21:43:48 +05:30
parent 2ccfe15a14
commit c330cfba13
4 changed files with 109 additions and 124 deletions

View File

@ -98,6 +98,7 @@ folder: pmd/rules
* [MethodNamingConventions](pmd_rules_java_codestyle.html#methodnamingconventions): Configurable naming conventions for method declarations. This rule reports method decl...
* [MIsLeadingVariableName](pmd_rules_java_codestyle.html#misleadingvariablename): <span style="border-radius: 0.25em; color: #fff; padding: 0.2em 0.6em 0.3em; display: inline; background-color: #d9534f; font-size: 75%;">Deprecated</span> Detects when a non-field has a name starting with 'm_'. This usually denotes a field and could b...
* [NoPackage](pmd_rules_java_codestyle.html#nopackage): Detects when a class or interface does not have a package definition.
* [NumericLiteralConvention](pmd_rules_java_codestyle.html#numericliteralconvention): Numeric literals with more than 3 digits must use '_' as a separator.
* [OnlyOneReturn](pmd_rules_java_codestyle.html#onlyonereturn): A method should have only one exit point, and that should be the last statement in the method.
* [PackageCase](pmd_rules_java_codestyle.html#packagecase): Detects when a package definition contains uppercase characters.
* [PrematureDeclaration](pmd_rules_java_codestyle.html#prematuredeclaration): Checks for variables that are defined before they might be used. A reference is deemed to be prem...
@ -116,7 +117,6 @@ folder: pmd/rules
* [UnnecessaryReturn](pmd_rules_java_codestyle.html#unnecessaryreturn): Avoid the use of unnecessary return statements.
* [UselessParentheses](pmd_rules_java_codestyle.html#uselessparentheses): Useless parentheses should be removed.
* [UselessQualifiedThis](pmd_rules_java_codestyle.html#uselessqualifiedthis): Reports qualified this usages in the same class.
* [UseUnderscoresInNumericLiterals](pmd_rules_java_codestyle.html#useunderscoresinnumericliterals): Numeric literals with more than 3 digits must use '_' as a separator.
* [VariableNamingConventions](pmd_rules_java_codestyle.html#variablenamingconventions): <span style="border-radius: 0.25em; color: #fff; padding: 0.2em 0.6em 0.3em; display: inline; background-color: #d9534f; font-size: 75%;">Deprecated</span> A variable naming conventions rule - customize this to your liking. Currently, itchecks for fina...
* [WhileLoopsMustUseBraces](pmd_rules_java_codestyle.html#whileloopsmustusebraces): <span style="border-radius: 0.25em; color: #fff; padding: 0.2em 0.6em 0.3em; display: inline; background-color: #d9534f; font-size: 75%;">Deprecated</span> Avoid using 'while' statements without using braces to surround the code block. If the code forma...

View File

@ -5,7 +5,7 @@ permalink: pmd_rules_java_codestyle.html
folder: pmd/rules/java
sidebaractiveurl: /pmd_rules_java.html
editmepath: ../pmd-java/src/main/resources/category/java/codestyle.xml
keywords: Code Style, AbstractNaming, AtLeastOneConstructor, AvoidDollarSigns, AvoidFinalLocalVariable, AvoidPrefixingMethodParameters, AvoidProtectedFieldInFinalClass, AvoidProtectedMethodInFinalClassNotExtending, AvoidUsingNativeCode, BooleanGetMethodName, CallSuperInConstructor, ClassNamingConventions, CommentDefaultAccessModifier, ConfusingTernary, ControlStatementBraces, DefaultPackage, DontImportJavaLang, DuplicateImports, EmptyMethodInAbstractClassShouldBeAbstract, ExtendsObject, FieldDeclarationsShouldBeAtStartOfClass, FieldNamingConventions, ForLoopShouldBeWhileLoop, ForLoopsMustUseBraces, FormalParameterNamingConventions, GenericsNaming, IdenticalCatchBranches, IfElseStmtsMustUseBraces, IfStmtsMustUseBraces, LinguisticNaming, LocalHomeNamingConvention, LocalInterfaceSessionNamingConvention, LocalVariableCouldBeFinal, LocalVariableNamingConventions, LongVariable, MDBAndSessionBeanNamingConvention, MethodArgumentCouldBeFinal, MethodNamingConventions, MIsLeadingVariableName, NoPackage, UseUnderscoresInNumericLiterals, OnlyOneReturn, PackageCase, PrematureDeclaration, RemoteInterfaceNamingConvention, RemoteSessionInterfaceNamingConvention, ShortClassName, ShortMethodName, ShortVariable, SuspiciousConstantFieldName, TooManyStaticImports, UnnecessaryAnnotationValueElement, UnnecessaryConstructor, UnnecessaryFullyQualifiedName, UnnecessaryLocalBeforeReturn, UnnecessaryModifier, UnnecessaryReturn, UselessParentheses, UselessQualifiedThis, VariableNamingConventions, WhileLoopsMustUseBraces
keywords: Code Style, AbstractNaming, AtLeastOneConstructor, AvoidDollarSigns, AvoidFinalLocalVariable, AvoidPrefixingMethodParameters, AvoidProtectedFieldInFinalClass, AvoidProtectedMethodInFinalClassNotExtending, AvoidUsingNativeCode, BooleanGetMethodName, CallSuperInConstructor, ClassNamingConventions, CommentDefaultAccessModifier, ConfusingTernary, ControlStatementBraces, DefaultPackage, DontImportJavaLang, DuplicateImports, EmptyMethodInAbstractClassShouldBeAbstract, ExtendsObject, FieldDeclarationsShouldBeAtStartOfClass, FieldNamingConventions, ForLoopShouldBeWhileLoop, ForLoopsMustUseBraces, FormalParameterNamingConventions, GenericsNaming, IdenticalCatchBranches, IfElseStmtsMustUseBraces, IfStmtsMustUseBraces, LinguisticNaming, LocalHomeNamingConvention, LocalInterfaceSessionNamingConvention, LocalVariableCouldBeFinal, LocalVariableNamingConventions, LongVariable, MDBAndSessionBeanNamingConvention, MethodArgumentCouldBeFinal, MethodNamingConventions, MIsLeadingVariableName, NoPackage, NumericLiteralConvention, OnlyOneReturn, PackageCase, PrematureDeclaration, RemoteInterfaceNamingConvention, RemoteSessionInterfaceNamingConvention, ShortClassName, ShortMethodName, ShortVariable, SuspiciousConstantFieldName, TooManyStaticImports, UnnecessaryAnnotationValueElement, UnnecessaryConstructor, UnnecessaryFullyQualifiedName, UnnecessaryLocalBeforeReturn, UnnecessaryModifier, UnnecessaryReturn, UselessParentheses, UselessQualifiedThis, VariableNamingConventions, WhileLoopsMustUseBraces
language: Java
---
## AbstractNaming
@ -1508,6 +1508,38 @@ public class ClassInDefaultPackage {
<rule ref="category/java/codestyle.xml/NoPackage" />
```
## NumericLiteralConvention
**Since:** PMD 6.9.0
**Priority:** Medium (3)
**Minimum Language Version:** Java 1.7
Numeric literals with more than 3 digits must use '_' as a separator.
**This rule is defined by the following XPath expression:**
``` xpath
//Literal[@IntLiteral = true() or
@LongLiteral = true() or
@DoubleLiteral = true() or
@FloatLiteral = true()]
[not(matches(@Image, "^[0-9]{1,3}(_[0-9]{3})*(l|L|\.[0-9]+)?(d|D|f|F)?$"))]
```
**Example(s):**
``` java
public class Foo {
private int num = 1000000; // should be 1_000_000
}
```
**Use this rule by referencing it:**
``` xml
<rule ref="category/java/codestyle.xml/NumericLiteralConvention" />
```
## OnlyOneReturn
**Since:** PMD 1.0
@ -2203,40 +2235,6 @@ public class Foo {
<rule ref="category/java/codestyle.xml/UselessQualifiedThis" />
```
## UseUnderscoresInNumericLiterals
**Since:** PMD 6.10.0
**Priority:** Medium (3)
**Minimum Language Version:** Java 1.7
Numeric literals with more than 3 digits must use '_' as a separator.
**This rule is defined by the following XPath expression:**
``` xpath
//Literal[@IntLiteral = true() or
@LongLiteral = true() or
@DoubleLiteral = true() or
@FloatLiteral = true()]
[not (matches(@Image, "^(0([xb]?[0-9a-fA-F]+)?|[1-9][0-9]{0,2}(_[0-9]{3})*)(l|L|\.[0-9_]+)?([eE][\+-]?[0-9]+)?[dDfF]?$"))]
[ancestor::VariableDeclarator[not (@Name = 'serialVersionUID')] or
not (ancestor::VariableDeclarator)]
```
**Example(s):**
``` java
public class Foo {
private int num = 1000000; // should be 1_000_000
}
```
**Use this rule by referencing it:**
``` xml
<rule ref="category/java/codestyle.xml/UseUnderscoresInNumericLiterals" />
```
## VariableNamingConventions
<span style="border-radius: 0.25em; color: #fff; padding: 0.2em 0.6em 0.3em; display: inline; background-color: #d9534f;">Deprecated</span>

View File

@ -1366,8 +1366,6 @@ public class ClassInDefaultPackage {
<priority>3</priority>
<properties>
<property name="version" value="2.0"/>
<property name="acceptableLength" type="Integer" value="4"
description="Maximum acceptable length within which the rule is not applicable"/>
<property name="xpath">
<value>
<![CDATA[
@ -1375,18 +1373,7 @@ public class ClassInDefaultPackage {
@LongLiteral = true() or
@DoubleLiteral = true() or
@FloatLiteral = true()]
[not (matches(@Image, "^0([xb]?[0-9a-fA-F]+)?$"))]
[
some $num in tokenize(@Image, "[.dDfFlL]|[eE][\+-]?")
satisfies not(
string-length($num) <= $acceptableLength
and (
not(contains($num,"_"))
or matches($num, "^[0-9]{1,3}(_[0-9]{3})*$")
)
or matches($num, "^[0-9]{1,3}(_[0-9]{3})*$")
)
]
[not (matches(@Image, "^(0([xb]?[0-9a-fA-F]+)?|[1-9][0-9]{0,2}(_[0-9]{3})*)(l|L|\.[0-9_]+)?([eE][\+-]?[0-9]+)?[dDfF]?$"))]
[ancestor::VariableDeclarator[not (@Name = 'serialVersionUID')] or
not (ancestor::VariableDeclarator)]
]]>

View File

@ -4,9 +4,9 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://pmd.sourceforge.net/rule-tests http://pmd.sourceforge.net/rule-tests_1_0_0.xsd">
<test-code>
<description>
ok, numeric literal with correct '_' usage
</description>
<description><![CDATA[
ok, numeric literal with correct '_' usage
]]></description>
<expected-problems>0</expected-problems>
<code><![CDATA[
public class Foo {
@ -15,9 +15,9 @@ public class Foo {
]]></code>
</test-code>
<test-code>
<description>
bad, numeric literal without '_'
</description>
<description><![CDATA[
bad, numeric literal without '_'
]]></description>
<expected-problems>1</expected-problems>
<code><![CDATA[
public class Foo {
@ -26,9 +26,9 @@ public class Foo {
]]></code>
</test-code>
<test-code>
<description>
bad, numeric literal used as a method parameter without '_'
</description>
<description><![CDATA[
bad, numeric literal used as a method parameter without '_'
]]></description>
<expected-problems>1</expected-problems>
<code><![CDATA[
public class Foo {
@ -39,9 +39,9 @@ public class Foo {
]]></code>
</test-code>
<test-code>
<description>
ok, float value with less than 3 numbers.
</description>
<description><![CDATA[
ok, float value with less than 3 numbers.
]]></description>
<expected-problems>0</expected-problems>
<code><![CDATA[
public class Foo {
@ -50,9 +50,9 @@ public class Foo {
]]></code>
</test-code>
<test-code>
<description>
bad, double value without '_'
</description>
<description><![CDATA[
bad, double value without '_'
]]></description>
<expected-problems>1</expected-problems>
<code><![CDATA[
public class Foo {
@ -61,9 +61,9 @@ public class Foo {
]]></code>
</test-code>
<test-code>
<description>
ok, numeric literal used as a method parameter with '_'
</description>
<description><![CDATA[
ok, numeric literal used as a method parameter with '_'
]]></description>
<expected-problems>0</expected-problems>
<code><![CDATA[
public class Foo {
@ -74,9 +74,9 @@ public class Foo {
]]></code>
</test-code>
<test-code>
<description>
ok, Long value with 'l' used as a method parameter with '_'
</description>
<description><![CDATA[
ok, Long value with 'l' used as a method parameter with '_'
]]></description>
<expected-problems>0</expected-problems>
<code><![CDATA[
public class Foo {
@ -87,9 +87,9 @@ public class Foo {
]]></code>
</test-code>
<test-code>
<description>
bad, numeric literal with incorrect '_' usage
</description>
<description><![CDATA[
bad, numeric literal with incorrect '_' usage
]]></description>
<expected-problems>1</expected-problems>
<code><![CDATA[
public class Foo {
@ -98,9 +98,9 @@ public class Foo {
]]></code>
</test-code>
<test-code>
<description>
ok, Double value with 'D' used as a method parameter with '_'
</description>
<description><![CDATA[
ok, Double value with 'D' used as a method parameter with '_'
]]></description>
<expected-problems>0</expected-problems>
<code><![CDATA[
public class Foo {
@ -111,9 +111,9 @@ public class Foo {
]]></code>
</test-code>
<test-code>
<description>
ok, Float value with 'F' with less than 3 numbers
</description>
<description><![CDATA[
ok, Float value with 'F' with less than 3 numbers
]]></description>
<expected-problems>0</expected-problems>
<code><![CDATA[
public class Foo {
@ -122,9 +122,9 @@ public class Foo {
]]></code>
</test-code>
<test-code>
<description>
ok, Double value with 'd' with correct '_' usage
</description>
<description><![CDATA[
ok, Double value with 'd' with correct '_' usage
]]></description>
<expected-problems>0</expected-problems>
<code><![CDATA[
public class Foo {
@ -133,9 +133,9 @@ public class Foo {
]]></code>
</test-code>
<test-code>
<description>
ok, Long value with 'L' used as a method parameter with '_'
</description>
<description><![CDATA[
ok, Long value with 'L' used as a method parameter with '_'
]]></description>
<expected-problems>0</expected-problems>
<code><![CDATA[
public class Foo {
@ -146,9 +146,9 @@ public class Foo {
]]></code>
</test-code>
<test-code>
<description>
ok, String value with '_'
</description>
<description><![CDATA[
ok, String value with '_'
]]></description>
<expected-problems>0</expected-problems>
<code><![CDATA[
public class Foo {
@ -157,9 +157,9 @@ public class Foo {
]]></code>
</test-code>
<test-code>
<description>
ok, String value without '_'
</description>
<description><![CDATA[
ok, String value without '_'
]]></description>
<expected-problems>0</expected-problems>
<code><![CDATA[
public class Foo {
@ -168,9 +168,9 @@ public class Foo {
]]></code>
</test-code>
<test-code>
<description>
ok, Numeric Literal in binary
</description>
<description><![CDATA[
ok, Numeric Literal in binary
]]></description>
<expected-problems>0</expected-problems>
<code><![CDATA[
public class Foo {
@ -179,9 +179,9 @@ public class Foo {
]]></code>
</test-code>
<test-code>
<description>
ok, Numeric Literal in octal
</description>
<description><![CDATA[
ok, Numeric Literal in octal
]]></description>
<expected-problems>0</expected-problems>
<code><![CDATA[
public class Foo {
@ -190,9 +190,9 @@ public class Foo {
]]></code>
</test-code>
<test-code>
<description>
ok, Numeric Literal in hexadecimal
</description>
<description><![CDATA[
ok, Numeric Literal in hexadecimal
]]></description>
<expected-problems>0</expected-problems>
<code><![CDATA[
public class Foo {
@ -201,9 +201,9 @@ public class Foo {
]]></code>
</test-code>
<test-code>
<description>
ok, Numeric Literal in negative binary
</description>
<description><![CDATA[
ok, Numeric Literal in negative binary
]]></description>
<expected-problems>0</expected-problems>
<code><![CDATA[
public class Foo {
@ -212,9 +212,9 @@ public class Foo {
]]></code>
</test-code>
<test-code>
<description>
ok, Numeric Literal in negative octal
</description>
<description><![CDATA[
ok, Numeric Literal in negative octal
]]></description>
<expected-problems>0</expected-problems>
<code><![CDATA[
public class Foo {
@ -223,9 +223,9 @@ public class Foo {
]]></code>
</test-code>
<test-code>
<description>
ok, Numeric Literal in negative hexadecimal
</description>
<description><![CDATA[
ok, Numeric Literal in negative hexadecimal
]]></description>
<expected-problems>0</expected-problems>
<code><![CDATA[
public class Foo {
@ -234,21 +234,21 @@ public class Foo {
]]></code>
</test-code>
<test-code>
<description>
ok, Numeric Literal with exponent
</description>
<description><![CDATA[
ok, Numeric Literal with exponent
]]></description>
<expected-problems>0</expected-problems>
<code><![CDATA[
public class Foo {
int binary = 39e123;
int binary = 39e1234;
}
]]></code>
</test-code>
<test-code>
<description>
bad, Negative exponent without '_'
</description>
<expected-problems>1</expected-problems>
<description><![CDATA[
ok, Numeric Literal with negative exponent
]]></description>
<expected-problems>0</expected-problems>
<code><![CDATA[
public class Foo {
int binary = 36e-11234;
@ -256,9 +256,9 @@ public class Foo {
]]></code>
</test-code>
<test-code>
<description>
ok, Numeric Literal with positive exponent
</description>
<description><![CDATA[
ok, Numeric Literal with positive exponent
]]></description>
<expected-problems>0</expected-problems>
<code><![CDATA[
public class Foo {
@ -267,9 +267,9 @@ public class Foo {
]]></code>
</test-code>
<test-code>
<description>
ok, Lengthy numeric literal with variable name as serialVersionUID
</description>
<description><![CDATA[
ok, Lengthy numeric literal with variable name as serialVersionUID
]]></description>
<expected-problems>0</expected-problems>
<code><![CDATA[
public class Foo {