Skip to content

Commit

Permalink
Adding test cases and fixing review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Rohit Kumar authored and Rohit Kumar committed Nov 12, 2018
1 parent 6fb8b6b commit 874b528
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pmd-java/etc/grammar/Java.jjt
Expand Up @@ -1854,7 +1854,7 @@ void ConstructorDeclaration(int modifiers) :
Token t;}
{
[ TypeParameters() ]
t=<IDENTIFIER> {jjtThis.setImage(t.image);} FormalParameters() [ "throws" NameList() ]
<IDENTIFIER> {jjtThis.setImage(getToken(0).getImage());} FormalParameters() [ "throws" NameList() ]
"{"
[ LOOKAHEAD(ExplicitConstructorInvocation()) ExplicitConstructorInvocation() ]
( BlockStatement() )*
Expand Down
Expand Up @@ -254,4 +254,25 @@ public class CommentDefaultAccessModifier {
}
]]></code>
</test-code>

<code-fragment id="constructor-with-default-access-modifier-rule"><![CDATA[
public class Foo {
Foo() {} // should be reported
Foo(final String str) {} // should be reported
/* default */ Foo(final String str1, final String str2) {} // should not be reported
}
]]>
</code-fragment>
<test-code>
<description>Add a comment to the constructors with default access modifiers to avoid mistakes</description>
<expected-problems>2</expected-problems>
<expected-linenumbers>2,4</expected-linenumbers>
<expected-messages>
<message>To avoid mistakes add a comment at the beginning of the Foo constructor if you want a default access modifier</message>
<message>To avoid mistakes add a comment at the beginning of the Foo constructor if you want a default access modifier</message>
</expected-messages>
<code-ref id="constructor-with-default-access-modifier-rule"/>
</test-code>
</test-data>

0 comments on commit 874b528

Please sign in to comment.