Merge branch 'bug-1467'

This commit is contained in:
Andreas Dangel
2016-04-01 21:43:54 +02:00
3 changed files with 35 additions and 4 deletions

View File

@ -32,10 +32,7 @@ public class UseUtilityClassRule extends AbstractJavaRule {
if (p.jjtGetNumChildren() == 0) {
continue;
}
Node n = p.jjtGetChild(0);
if (n instanceof ASTAnnotation) {
n = p.jjtGetChild(1);
}
Node n = skipAnnotations(p);
if (n instanceof ASTFieldDeclaration) {
if (!((ASTFieldDeclaration) n).isStatic()) {
isOK = true;
@ -75,6 +72,15 @@ public class UseUtilityClassRule extends AbstractJavaRule {
return super.visit(decl, data);
}
private Node skipAnnotations(Node p) {
int index = 0;
Node n = p.jjtGetChild(index++);
while (n instanceof ASTAnnotation && index < p.jjtGetNumChildren()) {
n = p.jjtGetChild(index++);
}
return n;
}
private boolean isExceptionType(ASTClassOrInterfaceDeclaration parent) {
ASTExtendsList extendsList = parent.getFirstChildOfType(ASTExtendsList.class);
if (extendsList != null) {

View File

@ -209,6 +209,29 @@ public class MyException extends RuntimeException {
protected static String foo() {
return "foo";
}
}
]]></code>
</test-code>
<test-code>
<description>#1467 UseUtilityClass can't correctly check functions with multiple annotations</description>
<expected-problems>0</expected-problems>
<code><![CDATA[
public class AccountFragment extends Fragment {
public static AccountFragment newInstance() {
AccountFragment instance = new AccountFragment();
//OTHER STUFF
return instance;
}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return inflater.inflate(R.layout.mylayout, container, false);
}
}
]]></code>
</test-code>

View File

@ -62,6 +62,8 @@
* [#1452](https://sourceforge.net/p/pmd/bugs/1452/): ArrayIndexOutOfBoundsException with Annotations for AccessorClassGenerationRule
* java-design/UseNotifyAllInsteadOfNotify
* [#1438](https://sourceforge.net/p/pmd/bugs/1438/): UseNotifyAllInsteadOfNotify gives false positive
* java-design/UseUtilityClass:
* [#1467](https://sourceforge.net/p/pmd/bugs/1467/): UseUtilityClass can't correctly check functions with multiple annotations
* java-finalizers/AvoidCallingFinalize
* [#1440](https://sourceforge.net/p/pmd/bugs/1440/): NPE in AvoidCallingFinalize
* java-imports/UnnecessaryFullyQualifiedName