Clover coverage report - PMD - 3.7
Coverage timestamp: Wed May 31 2006 09:25:59 EDT
file stats: LOC: 71   Methods: 5
NCLOC: 54   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
UseSingleton.java 92.9% 100% 100% 97.7%
coverage coverage
 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.ASTClassOrInterfaceType;
 9    import net.sourceforge.pmd.ast.ASTCompilationUnit;
 10    import net.sourceforge.pmd.ast.ASTConstructorDeclaration;
 11    import net.sourceforge.pmd.ast.ASTFieldDeclaration;
 12    import net.sourceforge.pmd.ast.ASTMethodDeclaration;
 13    import net.sourceforge.pmd.ast.ASTResultType;
 14   
 15    public class UseSingleton extends AbstractRule {
 16   
 17    private boolean isOK;
 18    private int methodCount;
 19   
 20  11 public Object visit(ASTCompilationUnit cu, Object data) {
 21  11 methodCount = 0;
 22  11 isOK = false;
 23  11 Object result = cu.childrenAccept(this, data);
 24  11 if (!isOK && methodCount > 0) {
 25  4 addViolation(data, cu);
 26    }
 27   
 28  11 return result;
 29    }
 30   
 31  2 public Object visit(ASTFieldDeclaration decl, Object data) {
 32  2 if (!decl.isStatic()) {
 33  1 isOK = true;
 34    }
 35  2 return data;
 36    }
 37   
 38  6 public Object visit(ASTConstructorDeclaration decl, Object data) {
 39  6 if (decl.isPrivate()) {
 40  1 isOK = true;
 41    }
 42  6 return data;
 43    }
 44   
 45  11 public Object visit(ASTClassOrInterfaceDeclaration decl, Object data) {
 46  11 if (decl.isAbstract()) {
 47  1 isOK = true;
 48    }
 49  11 return super.visit(decl, data);
 50    }
 51   
 52  15 public Object visit(ASTMethodDeclaration decl, Object data) {
 53  15 methodCount++;
 54   
 55  15 if (!isOK && !decl.isStatic()) {
 56  1 isOK = true;
 57    }
 58   
 59    // TODO use symbol table
 60  15 if (decl.getMethodName().equals("suite")) {
 61  1 ASTResultType res = (ASTResultType) decl.getFirstChildOfType(ASTResultType.class);
 62  1 ASTClassOrInterfaceType c = (ASTClassOrInterfaceType) res.getFirstChildOfType(ASTClassOrInterfaceType.class);
 63  1 if (c != null && c.getImage().equals("Test")) {
 64  1 isOK = true;
 65    }
 66    }
 67   
 68  15 return data;
 69    }
 70   
 71    }