Clover coverage report - PMD - 3.7
Coverage timestamp: Wed May 31 2006 09:25:59 EDT

file stats: | LOC: | 105 |  | Methods: | 11
| NCLOC: | 57 |  | Classes: | 1

Source file | Conditionals | Statements | Methods | TOTAL

ViewerModel.java

0%

0%

0%

0%

1 |  | package net.sourceforge.pmd.util.viewer.model;
2 |  |
3 |  | import net.sourceforge.pmd.TargetJDKVersion;
4 |  | import net.sourceforge.pmd.ast.ASTCompilationUnit;
5 |  | import net.sourceforge.pmd.ast.ParseException;
6 |  | import net.sourceforge.pmd.ast.SimpleNode;
7 |  | import net.sourceforge.pmd.jaxen.DocumentNavigator;
8 |  | import org.jaxen.BaseXPath;
9 |  | import org.jaxen.JaxenException;
10 |  | import org.jaxen.XPath;
11 |  |
12 |  | import java.io.StringReader;
13 |  | import java.util.List;
14 |  | import java.util.Vector;
15 |  |
16 |  | public class ViewerModel {
17 |  | private Vector listeners;
18 |  | private SimpleNode rootNode;
19 |  | private List evaluationResults;
20 |  |
21 | 0 | public ViewerModel() {
22 | 0 | listeners = new Vector(5);
23 |  | }
24 |  |
25 | 0 | public SimpleNode getRootNode() {
26 | 0 | return rootNode;
27 |  | }
28 |  |
29 |  | /**
30 |  | * commits source code to the model.
31 |  | * all existing source will be replaced
32 |  | */
33 | 0 | public void commitSource(String source, TargetJDKVersion jdk) {
34 | 0 | ASTCompilationUnit compilationUnit = jdk.createParser(new StringReader(source)).CompilationUnit();
35 | 0 | rootNode = compilationUnit;
36 | 0 | fireViewerModelEvent(new ViewerModelEvent(this, ViewerModelEvent.CODE_RECOMPILED));
37 |  | }
38 |  |
39 |  | /**
40 |  | * determines whether the model has a compiled tree at it's disposal
41 |  | *
42 |  | * @return true if there is an AST, false otherwise
43 |  | */
44 | 0 | public boolean hasCompiledTree() {
45 | 0 | return rootNode != null;
46 |  | }
47 |  |
48 |  | /**
49 |  | * evaluates the given XPath expression against the current tree
50 |  | *
51 |  | * @param xPath XPath expression to be evaluated
52 |  | * @param evaluator object which requests the evaluation
53 |  | */
54 | 0 | public void evaluateXPathExpression(String xPath, Object evaluator)
55 |  | throws ParseException, JaxenException {
56 | 0 | XPath xpath = new BaseXPath(xPath, new DocumentNavigator());
57 | 0 | evaluationResults = xpath.selectNodes(rootNode);
58 | 0 | fireViewerModelEvent(new ViewerModelEvent(evaluator, ViewerModelEvent.PATH_EXPRESSION_EVALUATED));
59 |  | }
60 |  |
61 |  | /**
62 |  | * retrieves the results of last evaluation
63 |  | *
64 |  | * @return a list containing the nodes selected by the last XPath expression
65 |  | * <p/>
66 |  | * evaluation
67 |  | */
68 | 0 | public List getLastEvaluationResults() {
69 | 0 | return evaluationResults;
70 |  | }
71 |  |
72 |  | /**
73 |  | * selects the given node in the AST
74 |  | *
75 |  | * @param node node to be selected
76 |  | * @param selector object which requests the selection
77 |  | */
78 | 0 | public void selectNode(SimpleNode node, Object selector) {
79 | 0 | fireViewerModelEvent(new ViewerModelEvent(selector, ViewerModelEvent.NODE_SELECTED, node));
80 |  | }
81 |  |
82 |  | /**
83 |  | * appends the given fragment to the XPath expression
84 |  | *
85 |  | * @param pathFragment fragment to be added
86 |  | * @param appender object that is trying to append the fragment
87 |  | */
88 | 0 | public void appendToXPathExpression(String pathFragment, Object appender) {
89 | 0 | fireViewerModelEvent(new ViewerModelEvent(appender, ViewerModelEvent.PATH_EXPRESSION_APPENDED, pathFragment));
90 |  | }
91 |  |
92 | 0 | public void addViewerModelListener(ViewerModelListener l) {
93 | 0 | listeners.add(l);
94 |  | }
95 |  |
96 | 0 | public void removeViewerModelListener(ViewerModelListener l) {
97 | 0 | listeners.remove(l);
98 |  | }
99 |  |
100 | 0 | protected void fireViewerModelEvent(ViewerModelEvent e) {
101 | 0 | for (int i = 0; i < listeners.size(); i++) {
102 | 0 | ((ViewerModelListener) listeners.elementAt(i)).viewerModelChanged(e);
103 |  | }
104 |  | }
105 |  | }