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