Clover coverage report - PMD - 3.7 Coverage timestamp: Wed May 31 2006 09:25:59 EDT FRAMES NO FRAMES |
file stats: | LOC: | 45 |  | Methods: | 2
| NCLOC: | 34 |  | Classes: | 1
Source file | Conditionals | Statements | Methods | TOTAL
OnlyOneReturnRule.java | 80% | 85.7% | 100% | 84.6% |

1 |  | /**
2 |  | * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
3 |  | */
4 |  | package net.sourceforge.pmd.rules.design;
5 |  |
6 |  | import net.sourceforge.pmd.AbstractRule;
7 |  | import net.sourceforge.pmd.ast.ASTClassOrInterfaceDeclaration;
8 |  | import net.sourceforge.pmd.ast.ASTMethodDeclaration;
9 |  | import net.sourceforge.pmd.ast.ASTReturnStatement;
10 |  | import net.sourceforge.pmd.ast.SimpleNode;
11 |  |
12 |  | import java.util.ArrayList;
13 |  | import java.util.Iterator;
14 |  | import java.util.List;
15 |  |
16 |  | public class OnlyOneReturnRule extends AbstractRule {
17 |  |
18 | 6 | public Object visit(ASTClassOrInterfaceDeclaration node, Object data) {
19 | 6 | if (node.isInterface()) {
20 | 0 | return data;
21 |  | }
22 | 6 | return super.visit(node, data);
23 |  | }
24 |  |
25 | 6 | public Object visit(ASTMethodDeclaration node, Object data) {
26 | 6 | if (node.isAbstract()) {
27 | 0 | return data;
28 |  | }
29 |  |
30 | 6 | List returnNodes = new ArrayList();
31 | 6 | node.findChildrenOfType(ASTReturnStatement.class, returnNodes, false);
32 | 6 | if (returnNodes.size() > 1) {
33 | 1 | for (Iterator i = returnNodes.iterator(); i.hasNext();) {
34 | 2 | SimpleNode problem = (SimpleNode) i.next();
35 |  | // skip the last one, it's OK
36 | 2 | if (!i.hasNext()) {
37 | 1 | continue;
38 |  | }
39 | 1 | addViolation(data, problem);
40 |  | }
41 |  | }
42 | 6 | return data;
43 |  | }
44 |  |
45 |  | }