Clover coverage report - PMD - 3.7
Coverage timestamp: Wed May 31 2006 09:25:59 EDT
file stats: LOC: 56   Methods: 5
NCLOC: 40   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
Attribute.java 100% 80% 80% 83.3%
coverage coverage
 1    /**
 2    * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
 3    */
 4    package net.sourceforge.pmd.jaxen;
 5   
 6    import net.sourceforge.pmd.ast.Node;
 7   
 8    import java.lang.reflect.InvocationTargetException;
 9    import java.lang.reflect.Method;
 10   
 11    /**
 12    * @author daniels
 13    */
 14    public class Attribute {
 15   
 16    private static final Object[] EMPTY_OBJ_ARRAY = new Object[0];
 17    private Node parent;
 18    private String name;
 19    private Method method;
 20   
 21  8747 public Attribute(Node parent, String name, Method m) {
 22  8747 this.parent = parent;
 23  8747 this.name = name;
 24  8747 this.method = m;
 25    }
 26   
 27  962 public String getValue() {
 28    // this lazy loading reduces calls to Method.invoke() by about 90%
 29  962 try {
 30  962 Object res = method.invoke(parent, EMPTY_OBJ_ARRAY);
 31  962 if (res != null) {
 32  937 if (res instanceof String) {
 33  676 return (String) res;
 34    }
 35  261 return String.valueOf(res);
 36    }
 37    } catch (IllegalAccessException iae) {
 38  0 iae.printStackTrace();
 39    } catch (InvocationTargetException ite) {
 40  0 ite.printStackTrace();
 41    }
 42  25 return "";
 43    }
 44   
 45  8743 public String getName() {
 46  8743 return name;
 47    }
 48   
 49  1 public Node getParent() {
 50  1 return parent;
 51    }
 52   
 53  0 public String toString() {
 54  0 return name + ":" + getValue() + ":" + parent;
 55    }
 56    }