Clover coverage report - PMD - 3.3
Coverage timestamp: Thu Sep 15 2005 17:59:57 EDT
file stats: LOC: 95   Methods: 6
NCLOC: 67   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
MethodNameDeclaration.java 68.8% 81.1% 83.3% 78%
coverage coverage
 1    /**
 2    * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
 3    */
 4    package net.sourceforge.pmd.symboltable;
 5   
 6    import net.sourceforge.pmd.ast.ASTFormalParameter;
 7    import net.sourceforge.pmd.ast.ASTFormalParameters;
 8    import net.sourceforge.pmd.ast.ASTMethodDeclarator;
 9    import net.sourceforge.pmd.ast.ASTPrimitiveType;
 10    import net.sourceforge.pmd.ast.ASTType;
 11    import net.sourceforge.pmd.ast.SimpleNode;
 12   
 13    public class MethodNameDeclaration extends AbstractNameDeclaration {
 14   
 15  687 public MethodNameDeclaration(ASTMethodDeclarator node) {
 16  687 super(node);
 17    }
 18   
 19  214 public int getParameterCount() {
 20  214 return ((ASTMethodDeclarator) node).getParameterCount();
 21    }
 22   
 23  7 public String getParameterDisplaySignature() {
 24  7 StringBuffer sb = new StringBuffer("(");
 25  7 ASTFormalParameters params = (ASTFormalParameters) node.jjtGetChild(0);
 26  7 for (int i = 0; i < ((ASTMethodDeclarator) node).getParameterCount(); i++) {
 27  4 ASTFormalParameter p = (ASTFormalParameter) params.jjtGetChild(i);
 28  4 sb.append(((ASTType)p.getFirstChildOfType(ASTType.class)).getTypeImage());
 29  4 sb.append(",");
 30    }
 31  7 if (sb.charAt(sb.length()-1) == ',') {
 32  3 sb.deleteCharAt(sb.length()-1);
 33    }
 34  7 return sb.toString() + ")";
 35    }
 36   
 37  3 public boolean equals(Object o) {
 38  3 MethodNameDeclaration other = (MethodNameDeclaration) o;
 39   
 40    // compare name
 41  3 if (!other.node.getImage().equals(node.getImage())) {
 42  0 return false;
 43    }
 44   
 45    // compare parameter count - this catches the case where there are no params, too
 46  3 if (((ASTMethodDeclarator) (other.node)).getParameterCount() != ((ASTMethodDeclarator) node).getParameterCount()) {
 47  0 return false;
 48    }
 49   
 50    // compare parameter types
 51  3 ASTFormalParameters myParams = (ASTFormalParameters) node.jjtGetChild(0);
 52  3 ASTFormalParameters otherParams = (ASTFormalParameters) other.node.jjtGetChild(0);
 53  3 for (int i = 0; i < ((ASTMethodDeclarator) node).getParameterCount(); i++) {
 54  1 ASTFormalParameter myParam = (ASTFormalParameter) myParams.jjtGetChild(i);
 55  1 ASTFormalParameter otherParam = (ASTFormalParameter) otherParams.jjtGetChild(i);
 56   
 57  1 SimpleNode myTypeNode = (SimpleNode) myParam.jjtGetChild(0).jjtGetChild(0);
 58  1 SimpleNode otherTypeNode = (SimpleNode) otherParam.jjtGetChild(0).jjtGetChild(0);
 59   
 60    // compare primitive vs reference type
 61  1 if (myTypeNode.getClass() != otherTypeNode.getClass()) {
 62  0 return false;
 63    }
 64   
 65    // simple comparison of type images
 66    // this can be fooled by one method using "String"
 67    // and the other method using "java.lang.String"
 68    // once we get real types in here that should get fixed
 69  1 String myTypeImg;
 70  1 String otherTypeImg;
 71  1 if (myTypeNode instanceof ASTPrimitiveType) {
 72  0 myTypeImg = myTypeNode.getImage();
 73  0 otherTypeImg = otherTypeNode.getImage();
 74    } else {
 75  1 myTypeImg = ((SimpleNode)(myTypeNode.jjtGetChild(0))).getImage();
 76  1 otherTypeImg = ((SimpleNode)(otherTypeNode.jjtGetChild(0))).getImage();
 77    }
 78   
 79  1 if (!myTypeImg.equals(otherTypeImg)) {
 80  0 return false;
 81    }
 82   
 83    // if type is ASTPrimitiveType and is an array, make sure the other one is also
 84    }
 85  3 return true;
 86    }
 87   
 88  782 public int hashCode() {
 89  782 return node.getImage().hashCode() + ((ASTMethodDeclarator) node).getParameterCount();
 90    }
 91   
 92  0 public String toString() {
 93  0 return "Method " + node.getImage() + ", line " + node.getBeginLine() + ", params = " + ((ASTMethodDeclarator) node).getParameterCount();
 94    }
 95    }