Clover coverage report - PMD - 3.9 Coverage timestamp: Tue Dec 19 2006 09:38:44 EST FRAMES NO FRAMES |
file stats: | LOC: | 56 |  | Methods: | 5
| NCLOC: | 40 |  | Classes: | 1
Source file | Conditionals | Statements | Methods | TOTAL
Attribute.java | 100% | 80% | 80% | 83.3% |

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 | 9804 | public Attribute(Node parent, String name, Method m) {
22 | 9804 | this.parent = parent;
23 | 9804 | this.name = name;
24 | 9804 | this.method = m;
25 |  | }
26 |  |
27 | 903 | public String getValue() {
28 |  | // this lazy loading reduces calls to Method.invoke() by about 90%
29 | 903 | try {
30 | 903 | Object res = method.invoke(parent, EMPTY_OBJ_ARRAY);
31 | 903 | if (res != null) {
32 | 880 | if (res instanceof String) {
33 | 589 | return (String) res;
34 |  | }
35 | 291 | return String.valueOf(res);
36 |  | }
37 |  | } catch (IllegalAccessException iae) {
38 | 0 | iae.printStackTrace();
39 |  | } catch (InvocationTargetException ite) {
40 | 0 | ite.printStackTrace();
41 |  | }
42 | 23 | return "";
43 |  | }
44 |  |
45 | 9800 | public String getName() {
46 | 9800 | return name;
47 |  | }
48 |  |
49 | 5 | public Node getParent() {
50 | 5 | return parent;
51 |  | }
52 |  |
53 | 0 | public String toString() {
54 | 0 | return name + ":" + getValue() + ":" + parent;
55 |  | }
56 |  | }