Merge branch 'pr-1085'

This commit is contained in:
Juan Martín Sotuyo Dodero
2018-05-09 19:14:06 -03:00
3 changed files with 36 additions and 1 deletions

View File

@ -26,6 +26,7 @@ This is a bug fixing release.
* java-bestpractices
* [#1063](https://github.com/pmd/pmd/issues/1063): \[java] MissingOverride is triggered in illegal places
* java-codestyle
* [#1064](https://github.com/pmd/pmd/issues/1064): \[java] ClassNamingConventions suggests to add Util suffix for simple exception wrappers
* [#1065](https://github.com/pmd/pmd/issues/1065): \[java] ClassNamingConventions shouldn't prohibit numbers in class names
* [#1067](https://github.com/pmd/pmd/issues/1067): \[java] [6.3.0] PrematureDeclaration false-positive

View File

@ -66,10 +66,18 @@ public class ClassNamingConventionsRule extends AbstractJavaRule {
return false;
}
ASTClassOrInterfaceDeclaration classNode = (ASTClassOrInterfaceDeclaration) node;
// A class with a superclass or interfaces should not be considered
if (classNode.getSuperClassTypeNode() != null
|| !classNode.getSuperInterfacesTypeNodes().isEmpty()) {
return false;
}
// A class without declarations shouldn't be reported
boolean hasAny = false;
for (ASTAnyTypeBodyDeclaration decl : node.getDeclarations()) {
for (ASTAnyTypeBodyDeclaration decl : classNode.getDeclarations()) {
switch (decl.getKind()) {
case FIELD:
case METHOD:

View File

@ -3,6 +3,7 @@
xmlns="http://pmd.sourceforge.net/rule-tests"
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>Default config reports on every type decl</description>
<expected-problems>5</expected-problems>
@ -189,4 +190,29 @@
]]></code>
</test-code>
<test-code>
<description>Class extending another class should not be utility class</description>
<expected-problems>0</expected-problems>
<code><![CDATA[
public class StringList extends ArrayList<String> {
static StringList emptyList() {
return new StringList();
}
}
]]></code>
</test-code>
<test-code>
<description>Class extending another class should not be utility class 2</description>
<expected-problems>0</expected-problems>
<code><![CDATA[
// I couldn't reproduce the original failure, but we can use another regression test.
public class MyException extends RuntimeException {
public MyException(Exception exception) {
super(exception);
}
}
]]></code>
</test-code>
</test-data>