Skip to content

Commit

Permalink
Update documentation
Browse files Browse the repository at this point in the history
TRAVIS_JOB_NUMBER=3997.1
TRAVIS_COMMIT_RANGE=26e74b880e96...ca71d2f
  • Loading branch information
pmd-bot committed Jul 23, 2019
1 parent ca71d2f commit f269b3d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 14 deletions.
2 changes: 1 addition & 1 deletion docs/pages/pmd/rules/java.md
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ folder: pmd/rules
* [MisplacedNullCheck](pmd_rules_java_errorprone.html#misplacednullcheck): The null check here is misplaced. If the variable is null a NullPointerException will be thrown.E...
* [MissingBreakInSwitch](pmd_rules_java_errorprone.html#missingbreakinswitch): Switch statements without break or return statements for each case optionmay indicate problematic...
* [MissingSerialVersionUID](pmd_rules_java_errorprone.html#missingserialversionuid): Serializable classes should provide a serialVersionUID field.The serialVersionUID field is also n...
* [MissingStaticMethodInNonInstantiatableClass](pmd_rules_java_errorprone.html#missingstaticmethodinnoninstantiatableclass): A class that has private constructors and does not have any static methods or fields cannot be used.
* [MissingStaticMethodInNonInstantiatableClass](pmd_rules_java_errorprone.html#missingstaticmethodinnoninstantiatableclass): A class that has private constructors and does not have any static methods or fields cannot be us...
* [MoreThanOneLogger](pmd_rules_java_errorprone.html#morethanonelogger): Normally only one logger is used in each class.
* [NonCaseLabelInSwitchStatement](pmd_rules_java_errorprone.html#noncaselabelinswitchstatement): A non-case label (e.g. a named break/continue label) was present in a switch statement.This legal...
* [NonStaticInitializer](pmd_rules_java_errorprone.html#nonstaticinitializer): A non-static initializer block will be called any time a constructor is invoked (just prior toinv...
Expand Down
49 changes: 36 additions & 13 deletions docs/pages/pmd/rules/java/errorprone.md
Original file line number Diff line number Diff line change
Expand Up @@ -2620,31 +2620,39 @@ chain needs an own serialVersionUID field. See also [Should an abstract class ha

A class that has private constructors and does not have any static methods or fields cannot be used.

When one of the private constructors is annotated with one of the annotations, then the class is not considered
non-instantiatable anymore and no violation will be reported.
See the property `annotations`.

**This rule is defined by the following XPath expression:**
``` xpath
//ClassOrInterfaceDeclaration[@Nested='false']
//ClassOrInterfaceDeclaration[@Nested=false()]
[
(
(: at least one constructor :)
./ClassOrInterfaceBody/ClassOrInterfaceBodyDeclaration/ConstructorDeclaration
and
count(./ClassOrInterfaceBody/ClassOrInterfaceBodyDeclaration/ConstructorDeclaration) = count(./ClassOrInterfaceBody/ClassOrInterfaceBodyDeclaration/ConstructorDeclaration[@Private='true'])
(: only private constructors :)
count(./ClassOrInterfaceBody/ClassOrInterfaceBodyDeclaration/ConstructorDeclaration) = count(./ClassOrInterfaceBody/ClassOrInterfaceBodyDeclaration/ConstructorDeclaration[@Private=true()])
and
not(./ClassOrInterfaceBody/ClassOrInterfaceBodyDeclaration/ConstructorDeclaration/
../Annotation/MarkerAnnotation/Name[pmd-java:typeIs('org.springframework.beans.factory.annotation.Autowired') or pmd-java:typeIs('javax.inject.Inject')])
(: all constructors must not be annotated :)
(every $x in $annotations satisfies
not(./ClassOrInterfaceBody/ClassOrInterfaceBodyDeclaration/ConstructorDeclaration/
../Annotation/MarkerAnnotation/Name[pmd-java:typeIs($x)]))
)
and
not(.//MethodDeclaration[@Static='true'])
not(.//MethodDeclaration[@Static=true()])
and
not(.//FieldDeclaration[@Private='false'][@Static='true'])
not(.//FieldDeclaration[@Private=false()][@Static=true()])
and
not(.//ClassOrInterfaceDeclaration[@Nested='true']
[@Public='true']
[@Static='true']
[not(./ClassOrInterfaceBody/ClassOrInterfaceBodyDeclaration/ConstructorDeclaration) or ./ClassOrInterfaceBody/ClassOrInterfaceBodyDeclaration/ConstructorDeclaration[@Public='true']]
not(.//ClassOrInterfaceDeclaration[@Nested=true()]
[@Public=true()]
[@Static=true()]
[not(./ClassOrInterfaceBody/ClassOrInterfaceBodyDeclaration/ConstructorDeclaration) or ./ClassOrInterfaceBody/ClassOrInterfaceBodyDeclaration/ConstructorDeclaration[@Public=true()]]
[./ClassOrInterfaceBody/ClassOrInterfaceBodyDeclaration/MethodDeclaration
[@Public='true']
[@Public=true()]
[./ResultType/Type/ReferenceType/ClassOrInterfaceType
[@Image = //ClassOrInterfaceDeclaration[@Nested='false']/@Image]
[@Image = //ClassOrInterfaceDeclaration[@Nested=false()]/@Image]
]
]
)
Expand All @@ -2664,11 +2672,26 @@ public class Foo {
}{%endraw%}
```

**Use this rule by referencing it:**
**This rule has the following properties:**

|Name|Default Value|Description|Multivalued|
|----|-------------|-----------|-----------|
|annotations|org.springframework.beans.factory.annotation.Autowired , javax.inject.Inject|If a constructor is annotated with one of these annotations, then the class is ignored.|yes. Delimiter is ','.|

**Use this rule with the default properties by just referencing it:**
``` xml
<rule ref="category/java/errorprone.xml/MissingStaticMethodInNonInstantiatableClass" />
```

**Use this rule and customize it:**
``` xml
<rule ref="category/java/errorprone.xml/MissingStaticMethodInNonInstantiatableClass">
<properties>
<property name="annotations" value="org.springframework.beans.factory.annotation.Autowired, javax.inject.Inject" />
</properties>
</rule>
```

## MoreThanOneLogger

**Since:** PMD 2.0
Expand Down

0 comments on commit f269b3d

Please sign in to comment.