1 /*
2 * Themis: Java Project Framework
3 * Copyright 2012-2026. Tony Washer
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
6 * use this file except in compliance with the License. You may obtain a copy
7 * of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14 * License for the specific language governing permissions and limitations under
15 * the License.
16 */
17 package io.github.tonywasher.joceanus.themis.xanalysis.parser.base;
18
19 import com.github.javaparser.ast.Node;
20
21 import java.util.ArrayList;
22 import java.util.Collections;
23 import java.util.List;
24 import java.util.function.Predicate;
25
26 /**
27 * Instance definitions.
28 */
29 public interface ThemisXAnalysisInstance {
30 /**
31 * Obtain the node.
32 *
33 * @return the node
34 */
35 Node getNode();
36
37 /**
38 * Obtain the id of the node.
39 *
40 * @return the id
41 */
42 ThemisXAnalysisId getId();
43
44 /**
45 * Register child node.
46 *
47 * @param pChild the child node
48 */
49 void registerChild(ThemisXAnalysisInstance pChild);
50
51 /**
52 * Obtain the parent.
53 *
54 * @return the parent
55 */
56 ThemisXAnalysisInstance getParent();
57
58 /**
59 * Obtain the list of children.
60 *
61 * @return the list of children
62 */
63 List<ThemisXAnalysisInstance> getChildren();
64
65 /**
66 * Select children from tree.
67 *
68 * @param pId the type of node
69 * @return the list of selected children
70 */
71 default List<ThemisXAnalysisInstance> discoverChildren(final ThemisXAnalysisId pId) {
72 return discoverChildren(n -> n.getId().equals(pId));
73 }
74
75 /**
76 * Select children.
77 *
78 * @param pTest the predicate to select children
79 * @return the list of selected children
80 */
81 List<ThemisXAnalysisInstance> discoverChildren(Predicate<ThemisXAnalysisInstance> pTest);
82
83 /**
84 * Select nodes from tree.
85 *
86 * @param pList the list to populate
87 * @param pTest the predicate to select nodes
88 */
89 void discoverNodes(List<ThemisXAnalysisInstance> pList,
90 Predicate<ThemisXAnalysisInstance> pTest);
91
92 /**
93 * Select nodes from tree.
94 *
95 * @param pId the type of node
96 * @return the list of selected nodes
97 */
98 default List<ThemisXAnalysisInstance> discoverNodes(final ThemisXAnalysisId pId) {
99 return discoverNodes(n -> n.getId().equals(pId));
100 }
101
102 /**
103 * Select nodes from tree.
104 *
105 * @param pTest the predicate to select nodes
106 * @return the list of selected nodes
107 */
108 default List<ThemisXAnalysisInstance> discoverNodes(final Predicate<ThemisXAnalysisInstance> pTest) {
109 final List<ThemisXAnalysisInstance> myList = new ArrayList<>();
110 discoverNodes(myList, pTest);
111 return myList;
112 }
113
114 /**
115 * The id.
116 */
117 interface ThemisXAnalysisId {
118 }
119
120 /**
121 * The base declaration interface.
122 */
123 interface ThemisXAnalysisDeclarationInstance
124 extends ThemisXAnalysisInstance {
125 }
126
127 /**
128 * The base type interface.
129 */
130 interface ThemisXAnalysisTypeInstance
131 extends ThemisXAnalysisInstance {
132 }
133
134 /**
135 * The base node interface.
136 */
137 interface ThemisXAnalysisNodeInstance
138 extends ThemisXAnalysisInstance {
139 }
140
141 /**
142 * The base statement interface.
143 */
144 interface ThemisXAnalysisStatementInstance
145 extends ThemisXAnalysisInstance {
146 }
147
148 /**
149 * The base expression interface.
150 */
151 interface ThemisXAnalysisExpressionInstance
152 extends ThemisXAnalysisInstance {
153 }
154
155 /**
156 * The base module interface.
157 */
158 interface ThemisXAnalysisModuleInstance
159 extends ThemisXAnalysisInstance {
160 }
161
162 /**
163 * The base class interface.
164 */
165 interface ThemisXAnalysisClassInstance {
166 /**
167 * Obtain the name.
168 *
169 * @return the name
170 */
171 String getName();
172
173 /**
174 * Obtain the fullName.
175 *
176 * @return the fullName
177 */
178 String getFullName();
179
180 /**
181 * Obtain the modifiers.
182 *
183 * @return the modifiers
184 */
185 ThemisXAnalysisModifierList getModifiers();
186
187 /**
188 * Obtain the body.
189 *
190 * @return the body
191 */
192 default List<ThemisXAnalysisDeclarationInstance> getBody() {
193 return Collections.emptyList();
194 }
195
196 /**
197 * Obtain the extends types.
198 *
199 * @return the extends
200 */
201 default List<ThemisXAnalysisTypeInstance> getExtends() {
202 return Collections.emptyList();
203 }
204
205 /**
206 * Obtain the implements types.
207 *
208 * @return the implements
209 */
210 default List<ThemisXAnalysisTypeInstance> getImplements() {
211 return Collections.emptyList();
212 }
213
214 /**
215 * Obtain the type parameters.
216 *
217 * @return the parameters
218 */
219 default List<ThemisXAnalysisTypeInstance> getTypeParameters() {
220 return Collections.emptyList();
221 }
222
223 /**
224 * Obtain the annotations.
225 *
226 * @return the annotations
227 */
228 default List<ThemisXAnalysisExpressionInstance> getAnnotations() {
229 return Collections.emptyList();
230 }
231
232 /**
233 * is the class a top-level class?
234 *
235 * @return true/false
236 */
237 default boolean isTopLevel() {
238 return false;
239 }
240
241 /**
242 * is the class an interface?
243 *
244 * @return true/false
245 */
246 default boolean isInterface() {
247 return false;
248 }
249
250 /**
251 * is the class an inner class?
252 *
253 * @return true/false
254 */
255 default boolean isInner() {
256 return false;
257 }
258
259 /**
260 * is the class a local declaration?
261 *
262 * @return true/false
263 */
264 default boolean isLocalDeclaration() {
265 return false;
266 }
267
268 /**
269 * is the class an anonymous class?
270 *
271 * @return true/false
272 */
273 default boolean isAnonClass() {
274 return false;
275 }
276 }
277
278 /**
279 * The base method interface.
280 */
281 interface ThemisXAnalysisMethodInstance {
282 /**
283 * Obtain the name.
284 *
285 * @return the name
286 */
287 String getName();
288
289 /**
290 * Obtain the modifiers.
291 *
292 * @return the modifiers
293 */
294 ThemisXAnalysisModifierList getModifiers();
295
296 /**
297 * Obtain the parameters.
298 *
299 * @return the parameters
300 */
301 default List<ThemisXAnalysisNodeInstance> getParameters() {
302 return Collections.emptyList();
303 }
304
305 /**
306 * Obtain the thrown exceptions.
307 *
308 * @return the thrown exceptions
309 */
310 default List<ThemisXAnalysisTypeInstance> getThrown() {
311 return Collections.emptyList();
312 }
313
314 /**
315 * Obtain the type parameters.
316 *
317 * @return the parameters
318 */
319 default List<ThemisXAnalysisTypeInstance> getTypeParameters() {
320 return Collections.emptyList();
321 }
322
323 /**
324 * Obtain the body.
325 *
326 * @return the body
327 */
328 ThemisXAnalysisStatementInstance getBody();
329
330 /**
331 * Obtain the annotations.
332 *
333 * @return the annotations
334 */
335 default List<ThemisXAnalysisExpressionInstance> getAnnotations() {
336 return Collections.emptyList();
337 }
338 }
339 }