1 |
| package net.sourceforge.pmd.rules; |
2 |
| |
3 |
| import net.sourceforge.pmd.AbstractRule; |
4 |
| import net.sourceforge.pmd.ast.ASTBlock; |
5 |
| import net.sourceforge.pmd.ast.ASTEmptyStatement; |
6 |
| import net.sourceforge.pmd.ast.ASTIfStatement; |
7 |
| import net.sourceforge.pmd.ast.ASTStatement; |
8 |
| import net.sourceforge.pmd.ast.Node; |
9 |
| |
10 |
| public class EmptyIf extends AbstractRule { |
11 |
| |
12 |
0
| public Object visit(ASTIfStatement node, Object data) {
|
13 |
0
| ASTStatement stmt = (ASTStatement)node.jjtGetChild(1);
|
14 |
0
| Node stmtChild = stmt.jjtGetChild(0);
|
15 |
0
| if (stmtChild instanceof ASTEmptyStatement) {
|
16 |
0
| addViolation(data, node);
|
17 |
0
| } else if (stmtChild instanceof ASTBlock && stmtChild.jjtGetNumChildren() == 0) {
|
18 |
0
| addViolation(data, node);
|
19 |
| } |
20 |
0
| return super.visit(node, data);
|
21 |
| } |
22 |
| } |