EmptyPublicCtorInClass: enable rule

This commit is contained in:
Paul Campbell 2017-07-04 12:19:36 +01:00
parent f6112ca823
commit 55ff66d98b
6 changed files with 93 additions and 6 deletions

View file

@ -116,7 +116,7 @@ Rule|Level|Source|Enabled|Suppressible
[EmptyForInitializerPad](#emptyforinitializerpad)|layout|checkstyle|Yes|
[EmptyForIteratorPad](#emptyforiteratorpad)|layout|checkstyle|Yes|
[EmptyLineSeparator](#emptylineseparator)|layout|checkstyle|Yes|
[EmptyPublicCtorInClass](#emptypublicctorinclass)|tweaks|sevntu||
[EmptyPublicCtorInClass](#emptypublicctorinclass)|tweaks|sevntu|Yes|
[EmptyStatement](#emptystatement)|layout|checkstyle|Yes|
[EnumValueName](#enumvaluename)|naming|sevntu|Yes|
[EqualsAvoidNull](#equalsavoidnull)|tweaks|checkstyle|Yes|
@ -2258,6 +2258,32 @@ Map<Long, String> idTable = new HashMap<Long, String>();
Checks that when an exception is caught, that if it is logged then it is not also re-thrown. Log or throw; one or the other or neither, but not both.
Accepts `java.util.logging.Logger` and `org.slf4j.Logger`.
#### [EmptyPublicCtorInClass](http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/coding/EmptyPublicCtorInClassCheck.html)
This Check looks for useless empty public constructors. Class constructor is considered useless by this Check if and only if class has exactly one ctor, which is public, empty(one that has no statements) and default.
Valid:
````java
class ValidPrivateCtor {
private ValidPrivateCtor() {
}
}
class ValidOverloadedCtor {
public ValidOverloadedCtor() {
}
public ValidOverloadedCtor(int i) {
}
}
````
Invalid:
````java
class Invalid {
public Invalid() {
}
}
````
#### [EnumValueName](http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/naming/EnumValueNameCheck.html)
Checks that Enum Values match the pattern: `^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$`
@ -2686,9 +2712,6 @@ Appears to be broken as of `1.21.0`.
#### [CustomDeclarationOrder](http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/coding/CustomDeclarationOrderCheck.html)
The [DeclarationOrder](#declarationorder) check already imposes an order for class elements.
#### [EmptyPublicCtorInClass](http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/coding/EmptyPublicCtorInClassCheck.html)
TODO: enable
#### [FinalizeImplementation](http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/coding/FinalizeImplementationCheck.html)
TODO: enable

View file

@ -1433,10 +1433,9 @@ rules:
name: EmptyPublicCtorInClass
parent: TREEWALKER
level: TWEAKS
enabled: false
enabled: true
source: SEVNTU
uri: http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/coding/EmptyPublicCtorInClassCheck.html
reason: "TODO: enable"
-
name: FinalizeImplementation
parent: TREEWALKER

View file

@ -0,0 +1,25 @@
This Check looks for useless empty public constructors. Class constructor is considered useless by this Check if and only if class has exactly one ctor, which is public, empty(one that has no statements) and default.
Valid:
````java
class ValidPrivateCtor {
private ValidPrivateCtor() {
}
}
class ValidOverloadedCtor {
public ValidOverloadedCtor() {
}
public ValidOverloadedCtor(int i) {
}
}
````
Invalid:
````java
class Invalid {
public Invalid() {
}
}
````

View file

@ -0,0 +1,38 @@
/**
* The MIT License (MIT)
*
* Copyright (c) 2017 Paul Campbell
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
* and associated documentation files (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies
* or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
* AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package net.kemitix.checkstyle.regressions;
/**
* Regression demo for {@code EmptyPublicCtorInClassCheck}.
*
* @author Paul Campbell (pcampbell@kemitix.net)
*/
public class EmptyPublicCtorInClass {
/**
* Useless empty public constructors.
*/
@SuppressWarnings("emptypublicctorinclass")
EmptyPublicCtorInClass() {
}
}

View file

@ -177,6 +177,7 @@
<module name="com.github.sevntu.checkstyle.checks.naming.UniformEnumConstantNameCheck"/>
<module name="com.github.sevntu.checkstyle.checks.coding.UselessSingleCatchCheck"/>
<module name="com.github.sevntu.checkstyle.checks.coding.UselessSuperCtorCallCheck"/>
<module name="com.github.sevntu.checkstyle.checks.coding.EmptyPublicCtorInClassCheck"/>
<module name="com.github.sevntu.checkstyle.checks.coding.MoveVariableInsideIfCheck"/>
</module><!-- /TreeWalker -->

View file

@ -230,6 +230,7 @@
<module name="com.github.sevntu.checkstyle.checks.naming.UniformEnumConstantNameCheck"/>
<module name="com.github.sevntu.checkstyle.checks.coding.UselessSingleCatchCheck"/>
<module name="com.github.sevntu.checkstyle.checks.coding.UselessSuperCtorCallCheck"/>
<module name="com.github.sevntu.checkstyle.checks.coding.EmptyPublicCtorInClassCheck"/>
<module name="com.github.sevntu.checkstyle.checks.coding.MoveVariableInsideIfCheck"/>
</module><!-- /TreeWalker -->