1 |
| package net.sourceforge.pmd.util.viewer.model; |
2 |
| |
3 |
| |
4 |
| import net.sourceforge.pmd.ast.SimpleNode; |
5 |
| |
6 |
| import javax.swing.tree.TreeNode; |
7 |
| import java.util.ArrayList; |
8 |
| import java.util.Collections; |
9 |
| import java.util.Enumeration; |
10 |
| import java.util.List; |
11 |
| |
12 |
| |
13 |
| |
14 |
| |
15 |
| |
16 |
| |
17 |
| |
18 |
| |
19 |
| |
20 |
| public class SimpleNodeTreeNodeAdapter |
21 |
| implements TreeNode { |
22 |
| private SimpleNode node; |
23 |
| private List children; |
24 |
| private SimpleNodeTreeNodeAdapter parent; |
25 |
| |
26 |
| |
27 |
| |
28 |
| |
29 |
| |
30 |
| |
31 |
0
| public SimpleNodeTreeNodeAdapter(SimpleNodeTreeNodeAdapter parent, SimpleNode node) {
|
32 |
0
| this.parent = parent;
|
33 |
0
| this.node = node;
|
34 |
| } |
35 |
| |
36 |
| |
37 |
| |
38 |
| |
39 |
| |
40 |
| |
41 |
0
| public SimpleNode getSimpleNode() {
|
42 |
0
| return node;
|
43 |
| } |
44 |
| |
45 |
| |
46 |
| |
47 |
| |
48 |
| |
49 |
0
| public TreeNode getChildAt(int childIndex) {
|
50 |
0
| checkChildren();
|
51 |
0
| return (TreeNode) children.get(childIndex);
|
52 |
| } |
53 |
| |
54 |
| |
55 |
| |
56 |
| |
57 |
| |
58 |
0
| public int getChildCount() {
|
59 |
0
| checkChildren();
|
60 |
0
| return children.size();
|
61 |
| } |
62 |
| |
63 |
| |
64 |
| |
65 |
| |
66 |
| |
67 |
0
| public TreeNode getParent() {
|
68 |
0
| return parent;
|
69 |
| } |
70 |
| |
71 |
| |
72 |
| |
73 |
| |
74 |
0
| public int getIndex(TreeNode node) {
|
75 |
0
| checkChildren();
|
76 |
0
| return children.indexOf(node);
|
77 |
| } |
78 |
| |
79 |
| |
80 |
| |
81 |
| |
82 |
| |
83 |
0
| public boolean getAllowsChildren() {
|
84 |
0
| return true;
|
85 |
| } |
86 |
| |
87 |
| |
88 |
| |
89 |
| |
90 |
| |
91 |
| |
92 |
0
| public boolean isLeaf() {
|
93 |
0
| checkChildren();
|
94 |
0
| return children.size() == 0;
|
95 |
| } |
96 |
| |
97 |
| |
98 |
| |
99 |
| |
100 |
| |
101 |
| |
102 |
0
| public Enumeration children() {
|
103 |
0
| return Collections.enumeration(children);
|
104 |
| } |
105 |
| |
106 |
| |
107 |
| |
108 |
| |
109 |
| |
110 |
0
| private void checkChildren() {
|
111 |
0
| if (children == null) {
|
112 |
0
| children = new ArrayList(node.jjtGetNumChildren());
|
113 |
0
| for (int i = 0; i < node.jjtGetNumChildren(); i++) {
|
114 |
0
| children.add(new SimpleNodeTreeNodeAdapter(this, (SimpleNode) node.jjtGetChild(i)));
|
115 |
| } |
116 |
| } |
117 |
| } |
118 |
| |
119 |
| |
120 |
| |
121 |
| |
122 |
0
| public String toString() {
|
123 |
0
| return node.toString();
|
124 |
| } |
125 |
| } |
126 |
| |