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