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 |
| |
22 |
| implements TreeNode { |
23 |
| |
24 |
| private SimpleNode node; |
25 |
| |
26 |
| private List children; |
27 |
| |
28 |
| private SimpleNodeTreeNodeAdapter parent; |
29 |
| |
30 |
| |
31 |
| |
32 |
| |
33 |
| |
34 |
| |
35 |
| |
36 |
| |
37 |
0
| public SimpleNodeTreeNodeAdapter(SimpleNodeTreeNodeAdapter parent, SimpleNode node) {
|
38 |
| |
39 |
0
| this.parent = parent;
|
40 |
| |
41 |
0
| this.node = node;
|
42 |
| |
43 |
| } |
44 |
| |
45 |
| |
46 |
| |
47 |
| |
48 |
| |
49 |
| |
50 |
| |
51 |
| |
52 |
0
| public SimpleNode getSimpleNode() {
|
53 |
| |
54 |
0
| return node;
|
55 |
| |
56 |
| } |
57 |
| |
58 |
| |
59 |
| |
60 |
| |
61 |
| |
62 |
| |
63 |
0
| public TreeNode getChildAt(int childIndex) {
|
64 |
| |
65 |
0
| checkChildren();
|
66 |
| |
67 |
| |
68 |
0
| return (TreeNode) children.get(childIndex);
|
69 |
| |
70 |
| } |
71 |
| |
72 |
| |
73 |
| |
74 |
| |
75 |
| |
76 |
| |
77 |
0
| public int getChildCount() {
|
78 |
| |
79 |
0
| checkChildren();
|
80 |
| |
81 |
| |
82 |
0
| return children.size();
|
83 |
| |
84 |
| } |
85 |
| |
86 |
| |
87 |
| |
88 |
| |
89 |
| |
90 |
| |
91 |
0
| public TreeNode getParent() {
|
92 |
| |
93 |
0
| return parent;
|
94 |
| |
95 |
| } |
96 |
| |
97 |
| |
98 |
| |
99 |
| |
100 |
| |
101 |
| |
102 |
0
| public int getIndex(TreeNode node) {
|
103 |
| |
104 |
0
| checkChildren();
|
105 |
| |
106 |
| |
107 |
0
| return children.indexOf(node);
|
108 |
| |
109 |
| } |
110 |
| |
111 |
| |
112 |
| |
113 |
| |
114 |
| |
115 |
| |
116 |
0
| public boolean getAllowsChildren() {
|
117 |
| |
118 |
0
| return true;
|
119 |
| |
120 |
| } |
121 |
| |
122 |
| |
123 |
| |
124 |
| |
125 |
| |
126 |
| |
127 |
0
| public boolean isLeaf() {
|
128 |
| |
129 |
0
| checkChildren();
|
130 |
| |
131 |
| |
132 |
0
| return children.size() == 0;
|
133 |
| |
134 |
| } |
135 |
| |
136 |
| |
137 |
| |
138 |
| |
139 |
| |
140 |
| |
141 |
0
| public Enumeration children() {
|
142 |
| |
143 |
0
| return Collections.enumeration(children);
|
144 |
| |
145 |
| } |
146 |
| |
147 |
| |
148 |
| |
149 |
| |
150 |
| |
151 |
| |
152 |
0
| private void checkChildren() {
|
153 |
| |
154 |
0
| if (children == null) {
|
155 |
| |
156 |
0
| children = new ArrayList(node.jjtGetNumChildren());
|
157 |
| |
158 |
| |
159 |
0
| for (int i = 0; i < node.jjtGetNumChildren(); i++) {
|
160 |
| |
161 |
0
| children.add(new SimpleNodeTreeNodeAdapter(this, (SimpleNode) node.jjtGetChild(i)));
|
162 |
| |
163 |
| } |
164 |
| |
165 |
| } |
166 |
| |
167 |
| } |
168 |
| |
169 |
| |
170 |
| |
171 |
| |
172 |
| |
173 |
| |
174 |
0
| public String toString() {
|
175 |
| |
176 |
0
| return node.toString();
|
177 |
| |
178 |
| } |
179 |
| |
180 |
| } |
181 |
| |