Merge branch 'issue-536' of https://github.com/Monits/pmd into pr-539
This commit is contained in:
@ -12,6 +12,7 @@ import net.sourceforge.pmd.lang.java.ast.ASTAnnotation;
|
|||||||
import net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceBodyDeclaration;
|
import net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceBodyDeclaration;
|
||||||
import net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceDeclaration;
|
import net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceDeclaration;
|
||||||
import net.sourceforge.pmd.lang.java.ast.ASTCompilationUnit;
|
import net.sourceforge.pmd.lang.java.ast.ASTCompilationUnit;
|
||||||
|
import net.sourceforge.pmd.lang.java.ast.ASTConstructorDeclaration;
|
||||||
import net.sourceforge.pmd.lang.java.ast.ASTFieldDeclaration;
|
import net.sourceforge.pmd.lang.java.ast.ASTFieldDeclaration;
|
||||||
import net.sourceforge.pmd.lang.java.ast.ASTMethodDeclaration;
|
import net.sourceforge.pmd.lang.java.ast.ASTMethodDeclaration;
|
||||||
import net.sourceforge.pmd.lang.java.ast.ASTMethodDeclarator;
|
import net.sourceforge.pmd.lang.java.ast.ASTMethodDeclarator;
|
||||||
@ -86,6 +87,14 @@ public class CommentDefaultAccessModifierRule extends AbstractCommentRule {
|
|||||||
return super.visit(decl, data);
|
return super.visit(decl, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object visit(final ASTConstructorDeclaration decl, Object data) {
|
||||||
|
if (shouldReport(decl)) {
|
||||||
|
addViolationWithMessage(data, decl, String.format(MESSAGE, decl.getImage(), "constructor"));
|
||||||
|
}
|
||||||
|
return super.visit(decl, data);
|
||||||
|
}
|
||||||
|
|
||||||
private boolean shouldReport(final AbstractJavaAccessNode decl) {
|
private boolean shouldReport(final AbstractJavaAccessNode decl) {
|
||||||
List<ASTClassOrInterfaceDeclaration> parentClassOrInterface = decl
|
List<ASTClassOrInterfaceDeclaration> parentClassOrInterface = decl
|
||||||
.getParentsOfType(ASTClassOrInterfaceDeclaration.class);
|
.getParentsOfType(ASTClassOrInterfaceDeclaration.class);
|
||||||
|
@ -82,9 +82,9 @@ A rule for the politically correct... we don't want to offend anyone.
|
|||||||
message="Missing commented default access modifier"
|
message="Missing commented default access modifier"
|
||||||
externalInfoUrl="${pmd.website.baseurl}/rules/java/comments.html#CommentDefaultAccessModifier">
|
externalInfoUrl="${pmd.website.baseurl}/rules/java/comments.html#CommentDefaultAccessModifier">
|
||||||
<description>
|
<description>
|
||||||
To avoid mistakes if we want that a Method, Field or Nested class have a default access modifier
|
To avoid mistakes if we want that a Method, Constructor, Field or Nested class have a default access modifier
|
||||||
we must add a comment at the beginning of the Method, Field or Nested class.
|
we must add a comment at the beginning of it's declaration.
|
||||||
By default the comment must be /* default */, if you want another, you have to provide a regex.
|
By default the comment must be /* default */, if you want another, you have to provide a regexp.
|
||||||
</description>
|
</description>
|
||||||
<priority>3</priority>
|
<priority>3</priority>
|
||||||
<properties>
|
<properties>
|
||||||
|
@ -155,6 +155,28 @@ public enum TestEnum {
|
|||||||
<code><![CDATA[
|
<code><![CDATA[
|
||||||
public class CommentDefaultAccessModifier {
|
public class CommentDefaultAccessModifier {
|
||||||
@VisibleForTesting void method() {}
|
@VisibleForTesting void method() {}
|
||||||
|
}
|
||||||
|
]]></code>
|
||||||
|
</test-code>
|
||||||
|
|
||||||
|
<test-code>
|
||||||
|
<description>#536 Constructor with default access modifier should trigger</description>
|
||||||
|
<expected-problems>1</expected-problems>
|
||||||
|
<code><![CDATA[
|
||||||
|
public class Foo {
|
||||||
|
Foo() {}
|
||||||
|
}
|
||||||
|
]]></code>
|
||||||
|
</test-code>
|
||||||
|
|
||||||
|
<test-code>
|
||||||
|
<description>#536 Enum constructor with implicit private modifier should not trigger</description>
|
||||||
|
<expected-problems>0</expected-problems>
|
||||||
|
<code><![CDATA[
|
||||||
|
public enum Bar {
|
||||||
|
ONE, TWO;
|
||||||
|
|
||||||
|
Bar() {}
|
||||||
}
|
}
|
||||||
]]></code>
|
]]></code>
|
||||||
</test-code>
|
</test-code>
|
||||||
|
@ -99,6 +99,8 @@ and include them to such reports.
|
|||||||
* [#487](https://github.com/pmd/pmd/pull/487): \[java] Fix typeresolution for anonymous extending object
|
* [#487](https://github.com/pmd/pmd/pull/487): \[java] Fix typeresolution for anonymous extending object
|
||||||
* [#496](https://github.com/pmd/pmd/issues/496): \[java] processing error on generics inherited from enclosing class
|
* [#496](https://github.com/pmd/pmd/issues/496): \[java] processing error on generics inherited from enclosing class
|
||||||
* [#527](https://github.com/pmd/pmd/issues/527): \[java] Lombok getter annotation on enum is not recognized correctly
|
* [#527](https://github.com/pmd/pmd/issues/527): \[java] Lombok getter annotation on enum is not recognized correctly
|
||||||
|
* java-comments
|
||||||
|
* [#536](https://github.com/pmd/pmd/issues/536): \[java] CommentDefaultAccessModifierRule ignores constructors
|
||||||
* java-controversial
|
* java-controversial
|
||||||
* [#408](https://github.com/pmd/pmd/issues/408): \[java] DFA not analyzing asserts
|
* [#408](https://github.com/pmd/pmd/issues/408): \[java] DFA not analyzing asserts
|
||||||
* java-sunsecure
|
* java-sunsecure
|
||||||
|
Reference in New Issue
Block a user