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