View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      https://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,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.commons.jexl3.internal;
18  
19  import org.apache.commons.jexl3.JexlExpression;
20  import org.apache.commons.jexl3.JexlScript;
21  import org.apache.commons.jexl3.parser.ASTAddNode;
22  import org.apache.commons.jexl3.parser.ASTAndNode;
23  import org.apache.commons.jexl3.parser.ASTAnnotatedStatement;
24  import org.apache.commons.jexl3.parser.ASTAnnotation;
25  import org.apache.commons.jexl3.parser.ASTArguments;
26  import org.apache.commons.jexl3.parser.ASTArrayAccess;
27  import org.apache.commons.jexl3.parser.ASTArrayLiteral;
28  import org.apache.commons.jexl3.parser.ASTAssignment;
29  import org.apache.commons.jexl3.parser.ASTBitwiseAndNode;
30  import org.apache.commons.jexl3.parser.ASTBitwiseComplNode;
31  import org.apache.commons.jexl3.parser.ASTBitwiseOrNode;
32  import org.apache.commons.jexl3.parser.ASTBitwiseXorNode;
33  import org.apache.commons.jexl3.parser.ASTBlock;
34  import org.apache.commons.jexl3.parser.ASTBreak;
35  import org.apache.commons.jexl3.parser.ASTCaseExpression;
36  import org.apache.commons.jexl3.parser.ASTCaseStatement;
37  import org.apache.commons.jexl3.parser.ASTConstructorNode;
38  import org.apache.commons.jexl3.parser.ASTContinue;
39  import org.apache.commons.jexl3.parser.ASTDecrementGetNode;
40  import org.apache.commons.jexl3.parser.ASTDefineVars;
41  import org.apache.commons.jexl3.parser.ASTDivNode;
42  import org.apache.commons.jexl3.parser.ASTDoWhileStatement;
43  import org.apache.commons.jexl3.parser.ASTEQNode;
44  import org.apache.commons.jexl3.parser.ASTEQSNode;
45  import org.apache.commons.jexl3.parser.ASTERNode;
46  import org.apache.commons.jexl3.parser.ASTEWNode;
47  import org.apache.commons.jexl3.parser.ASTEmptyFunction;
48  import org.apache.commons.jexl3.parser.ASTExtendedLiteral;
49  import org.apache.commons.jexl3.parser.ASTFalseNode;
50  import org.apache.commons.jexl3.parser.ASTForeachStatement;
51  import org.apache.commons.jexl3.parser.ASTFunctionNode;
52  import org.apache.commons.jexl3.parser.ASTGENode;
53  import org.apache.commons.jexl3.parser.ASTGTNode;
54  import org.apache.commons.jexl3.parser.ASTGetDecrementNode;
55  import org.apache.commons.jexl3.parser.ASTGetIncrementNode;
56  import org.apache.commons.jexl3.parser.ASTIdentifier;
57  import org.apache.commons.jexl3.parser.ASTIdentifierAccess;
58  import org.apache.commons.jexl3.parser.ASTIfStatement;
59  import org.apache.commons.jexl3.parser.ASTIncrementGetNode;
60  import org.apache.commons.jexl3.parser.ASTInstanceOf;
61  import org.apache.commons.jexl3.parser.ASTJexlScript;
62  import org.apache.commons.jexl3.parser.ASTJxltLiteral;
63  import org.apache.commons.jexl3.parser.ASTLENode;
64  import org.apache.commons.jexl3.parser.ASTLTNode;
65  import org.apache.commons.jexl3.parser.ASTMapEntry;
66  import org.apache.commons.jexl3.parser.ASTMapLiteral;
67  import org.apache.commons.jexl3.parser.ASTMethodNode;
68  import org.apache.commons.jexl3.parser.ASTModNode;
69  import org.apache.commons.jexl3.parser.ASTMulNode;
70  import org.apache.commons.jexl3.parser.ASTNENode;
71  import org.apache.commons.jexl3.parser.ASTNESNode;
72  import org.apache.commons.jexl3.parser.ASTNEWNode;
73  import org.apache.commons.jexl3.parser.ASTNRNode;
74  import org.apache.commons.jexl3.parser.ASTNSWNode;
75  import org.apache.commons.jexl3.parser.ASTNotInstanceOf;
76  import org.apache.commons.jexl3.parser.ASTNotNode;
77  import org.apache.commons.jexl3.parser.ASTNullLiteral;
78  import org.apache.commons.jexl3.parser.ASTNullpNode;
79  import org.apache.commons.jexl3.parser.ASTNumberLiteral;
80  import org.apache.commons.jexl3.parser.ASTOrNode;
81  import org.apache.commons.jexl3.parser.ASTQualifiedIdentifier;
82  import org.apache.commons.jexl3.parser.ASTRangeNode;
83  import org.apache.commons.jexl3.parser.ASTReference;
84  import org.apache.commons.jexl3.parser.ASTReferenceExpression;
85  import org.apache.commons.jexl3.parser.ASTRegexLiteral;
86  import org.apache.commons.jexl3.parser.ASTReturnStatement;
87  import org.apache.commons.jexl3.parser.ASTSWNode;
88  import org.apache.commons.jexl3.parser.ASTSetAddNode;
89  import org.apache.commons.jexl3.parser.ASTSetAndNode;
90  import org.apache.commons.jexl3.parser.ASTSetDivNode;
91  import org.apache.commons.jexl3.parser.ASTSetLiteral;
92  import org.apache.commons.jexl3.parser.ASTSetModNode;
93  import org.apache.commons.jexl3.parser.ASTSetMultNode;
94  import org.apache.commons.jexl3.parser.ASTSetOrNode;
95  import org.apache.commons.jexl3.parser.ASTSetShiftLeftNode;
96  import org.apache.commons.jexl3.parser.ASTSetShiftRightNode;
97  import org.apache.commons.jexl3.parser.ASTSetShiftRightUnsignedNode;
98  import org.apache.commons.jexl3.parser.ASTSetSubNode;
99  import org.apache.commons.jexl3.parser.ASTSetXorNode;
100 import org.apache.commons.jexl3.parser.ASTShiftLeftNode;
101 import org.apache.commons.jexl3.parser.ASTShiftRightNode;
102 import org.apache.commons.jexl3.parser.ASTShiftRightUnsignedNode;
103 import org.apache.commons.jexl3.parser.ASTSizeFunction;
104 import org.apache.commons.jexl3.parser.ASTStringLiteral;
105 import org.apache.commons.jexl3.parser.ASTSubNode;
106 import org.apache.commons.jexl3.parser.ASTSwitchExpression;
107 import org.apache.commons.jexl3.parser.ASTSwitchStatement;
108 import org.apache.commons.jexl3.parser.ASTTernaryNode;
109 import org.apache.commons.jexl3.parser.ASTThrowStatement;
110 import org.apache.commons.jexl3.parser.ASTTrueNode;
111 import org.apache.commons.jexl3.parser.ASTTryResources;
112 import org.apache.commons.jexl3.parser.ASTTryStatement;
113 import org.apache.commons.jexl3.parser.ASTUnaryMinusNode;
114 import org.apache.commons.jexl3.parser.ASTUnaryPlusNode;
115 import org.apache.commons.jexl3.parser.ASTVar;
116 import org.apache.commons.jexl3.parser.ASTWhileStatement;
117 import org.apache.commons.jexl3.parser.JexlNode;
118 import org.apache.commons.jexl3.parser.ParserVisitor;
119 
120 /**
121  * Concrete visitor base, used for feature and operator controllers.
122  */
123 public class ScriptVisitor extends ParserVisitor {
124     @Override
125     protected Object visit(final ASTAddNode node, final Object data) {
126         return visitNode(node, data);
127     }
128 
129     @Override
130     protected Object visit(final ASTAndNode node, final Object data) {
131         return visitNode(node, data);
132     }
133 
134     @Override
135     protected Object visit(final ASTAnnotatedStatement node, final Object data) {
136         return visitNode(node, data);
137     }
138 
139     @Override
140     protected Object visit(final ASTAnnotation node, final Object data) {
141         return visitNode(node, data);
142     }
143 
144     @Override
145     protected Object visit(final ASTArguments node, final Object data) {
146         return visitNode(node, data);
147     }
148 
149     @Override
150     protected Object visit(final ASTArrayAccess node, final Object data) {
151         return visitNode(node, data);
152     }
153 
154     @Override
155     protected Object visit(final ASTArrayLiteral node, final Object data) {
156         return visitNode(node, data);
157     }
158 
159     @Override
160     protected Object visit(final ASTAssignment node, final Object data) {
161         return visitNode(node, data);
162     }
163 
164     @Override
165     protected Object visit(final ASTBitwiseAndNode node, final Object data) {
166         return visitNode(node, data);
167     }
168 
169     @Override
170     protected Object visit(final ASTBitwiseComplNode node, final Object data) {
171         return visitNode(node, data);
172     }
173 
174     @Override
175     protected Object visit(final ASTBitwiseOrNode node, final Object data) {
176         return visitNode(node, data);
177     }
178 
179     @Override
180     protected Object visit(final ASTBitwiseXorNode node, final Object data) {
181         return visitNode(node, data);
182     }
183 
184     @Override
185     protected Object visit(final ASTBlock node, final Object data) {
186         return visitNode(node, data);
187     }
188 
189     @Override
190     protected Object visit(final ASTBreak node, final Object data) {
191         return visitNode(node, data);
192     }
193 
194     @Override
195     protected Object visit(final ASTConstructorNode node, final Object data) {
196         return visitNode(node, data);
197     }
198 
199     @Override
200     protected Object visit(final ASTSwitchStatement node, final Object data) {
201         return visitNode(node, data);
202     }
203 
204     @Override
205     protected Object visit(final ASTCaseStatement node, final Object data) {
206         return visitNode(node, data);
207     }
208 
209     @Override
210     protected Object visit(final ASTSwitchExpression node, final Object data) {
211         return visitNode(node, data);
212     }
213 
214     @Override
215     protected Object visit(final ASTCaseExpression node, final Object data) {
216         return visitNode(node, data);
217     }
218 
219     @Override
220     protected Object visit(final ASTContinue node, final Object data) {
221         return visitNode(node, data);
222     }
223 
224     @Override
225     protected Object visit(final ASTDecrementGetNode node, final Object data) { return visitNode(node, data); }
226 
227     @Override
228     protected Object visit(final ASTDefineVars node, final Object data) {
229         return visitNode(node, data);
230     }
231 
232     @Override
233     protected Object visit(final ASTDivNode node, final Object data) {
234         return visitNode(node, data);
235     }
236 
237     @Override
238     protected Object visit(final ASTDoWhileStatement node, final Object data) {
239         return visitNode(node, data);
240     }
241 
242     @Override
243     protected Object visit(final ASTEmptyFunction node, final Object data) {
244         return visitNode(node, data);
245     }
246 
247     @Override
248     protected Object visit(final ASTEQNode node, final Object data) {
249         return visitNode(node, data);
250     }
251 
252     @Override
253     protected Object visit(final ASTEQSNode node, final Object data) {
254         return visitNode(node, data);
255     }
256 
257     @Override
258     protected Object visit(final ASTERNode node, final Object data) {
259         return visitNode(node, data);
260     }
261 
262     @Override
263     protected Object visit(final ASTEWNode node, final Object data) {
264         return visitNode(node, data);
265     }
266 
267     @Override
268     protected Object visit(final ASTExtendedLiteral node, final Object data) {
269         return visitNode(node, data);
270     }
271 
272     @Override
273     protected Object visit(final ASTFalseNode node, final Object data) {
274         return visitNode(node, data);
275     }
276 
277     @Override
278     protected Object visit(final ASTForeachStatement node, final Object data) {
279         return visitNode(node, data);
280     }
281 
282     @Override
283     protected Object visit(final ASTFunctionNode node, final Object data) {
284         return visitNode(node, data);
285     }
286 
287     @Override
288     protected Object visit(final ASTGENode node, final Object data) {
289         return visitNode(node, data);
290     }
291 
292     @Override
293     protected Object visit(final ASTGetDecrementNode node, final Object data) { return visitNode(node, data); }
294 
295     @Override
296     protected Object visit(final ASTGetIncrementNode node, final Object data) { return visitNode(node, data); }
297     @Override
298     protected Object visit(final ASTGTNode node, final Object data) {
299         return visitNode(node, data);
300     }
301     @Override
302     protected Object visit(final ASTIdentifier node, final Object data) {
303         return visitNode(node, data);
304     }
305 
306     @Override
307     protected Object visit(final ASTIdentifierAccess node, final Object data) {
308         return visitNode(node, data);
309     }
310 
311     @Override
312     protected Object visit(final ASTIfStatement node, final Object data) {
313         return visitNode(node, data);
314     }
315 
316     @Override
317     protected Object visit(final ASTIncrementGetNode node, final Object data) { return visitNode(node, data); }
318 
319     @Override
320     protected Object visit(final ASTInstanceOf node, final Object data) { return visitNode(node, data); }
321 
322     @Override
323     protected Object visit(final ASTJexlScript node, final Object data) {
324         return visitNode(node, data);
325     }
326 
327     @Override
328     protected Object visit(final ASTJxltLiteral node, final Object data) {
329         return visitNode(node, data);
330     }
331 
332     @Override
333     protected Object visit(final ASTLENode node, final Object data) {
334         return visitNode(node, data);
335     }
336 
337     @Override
338     protected Object visit(final ASTLTNode node, final Object data) {
339         return visitNode(node, data);
340     }
341 
342     @Override
343     protected Object visit(final ASTMapEntry node, final Object data) {
344         return visitNode(node, data);
345     }
346 
347     @Override
348     protected Object visit(final ASTMapLiteral node, final Object data) {
349         return visitNode(node, data);
350     }
351 
352     @Override
353     protected Object visit(final ASTMethodNode node, final Object data) {
354         return visitNode(node, data);
355     }
356 
357     @Override
358     protected Object visit(final ASTModNode node, final Object data) {
359         return visitNode(node, data);
360     }
361 
362     @Override
363     protected Object visit(final ASTMulNode node, final Object data) {
364         return visitNode(node, data);
365     }
366 
367     @Override
368     protected Object visit(final ASTNENode node, final Object data) {
369         return visitNode(node, data);
370     }
371 
372     @Override
373     protected Object visit(final ASTNESNode node, final Object data) {
374         return visitNode(node, data);
375     }
376 
377     @Override
378     protected Object visit(final ASTNEWNode node, final Object data) {
379         return visitNode(node, data);
380     }
381 
382     @Override
383     protected Object visit(final ASTNotInstanceOf node, final Object data) { return visitNode(node, data); }
384 
385     @Override
386     protected Object visit(final ASTNotNode node, final Object data) {
387         return visitNode(node, data);
388     }
389 
390     @Override
391     protected Object visit(final ASTNRNode node, final Object data) {
392         return visitNode(node, data);
393     }
394 
395     @Override
396     protected Object visit(final ASTNSWNode node, final Object data) {
397         return visitNode(node, data);
398     }
399 
400     @Override
401     protected Object visit(final ASTNullLiteral node, final Object data) {
402         return visitNode(node, data);
403     }
404 
405     @Override
406     protected Object visit(final ASTNullpNode node, final Object data) {
407         return visitNode(node, data);
408     }
409 
410     @Override
411     protected Object visit(final ASTNumberLiteral node, final Object data) {
412         return visitNode(node, data);
413     }
414 
415     @Override
416     protected Object visit(final ASTOrNode node, final Object data) {
417         return visitNode(node, data);
418     }
419 
420     @Override
421     protected Object visit(final ASTQualifiedIdentifier node, final Object data) {
422         return visitNode(node, data);
423     }
424 
425     @Override
426     protected Object visit(final ASTRangeNode node, final Object data) {
427         return visitNode(node, data);
428     }
429 
430     @Override
431     protected Object visit(final ASTReference node, final Object data) {
432         return visitNode(node, data);
433     }
434 
435     @Override
436     protected Object visit(final ASTReferenceExpression node, final Object data) {
437         return visitNode(node, data);
438     }
439 
440     @Override
441     protected Object visit(final ASTRegexLiteral node, final Object data) {
442         return visitNode(node, data);
443     }
444 
445     @Override
446     protected Object visit(final ASTReturnStatement node, final Object data) {
447         return visitNode(node, data);
448     }
449 
450     @Override
451     protected Object visit(final ASTSetAddNode node, final Object data) {
452         return visitNode(node, data);
453     }
454 
455     @Override
456     protected Object visit(final ASTSetAndNode node, final Object data) {
457         return visitNode(node, data);
458     }
459 
460     @Override
461     protected Object visit(final ASTSetDivNode node, final Object data) {
462         return visitNode(node, data);
463     }
464 
465     @Override
466     protected Object visit(final ASTSetLiteral node, final Object data) {
467         return visitNode(node, data);
468     }
469 
470     @Override
471     protected Object visit(final ASTSetModNode node, final Object data) {
472         return visitNode(node, data);
473     }
474 
475     @Override
476     protected Object visit(final ASTSetMultNode node, final Object data) {
477         return visitNode(node, data);
478     }
479 
480     @Override
481     protected Object visit(final ASTSetOrNode node, final Object data) {
482         return visitNode(node, data);
483     }
484 
485     @Override
486     protected Object visit(final ASTSetShiftLeftNode node, final Object data) {
487         return visitNode(node, data);
488     }
489 
490     @Override
491     protected Object visit(final ASTSetShiftRightNode node, final Object data) {
492         return visitNode(node, data);
493     }
494 
495     @Override
496     protected Object visit(final ASTSetShiftRightUnsignedNode node, final Object data) {
497         return visitNode(node, data);
498     }
499 
500     @Override
501     protected Object visit(final ASTSetSubNode node, final Object data) {
502         return visitNode(node, data);
503     }
504 
505     @Override
506     protected Object visit(final ASTSetXorNode node, final Object data) {
507         return visitNode(node, data);
508     }
509 
510     @Override
511     protected Object visit(final ASTShiftLeftNode node, final Object data) {
512         return visitNode(node, data);
513     }
514 
515     @Override
516     protected Object visit(final ASTShiftRightNode node, final Object data) {
517         return visitNode(node, data);
518     }
519 
520     @Override
521     protected Object visit(final ASTShiftRightUnsignedNode node, final Object data) {
522         return visitNode(node, data);
523     }
524 
525     @Override
526     protected Object visit(final ASTSizeFunction node, final Object data) {
527         return visitNode(node, data);
528     }
529 
530     @Override
531     protected Object visit(final ASTStringLiteral node, final Object data) {
532         return visitNode(node, data);
533     }
534 
535     @Override
536     protected Object visit(final ASTSubNode node, final Object data) {
537         return visitNode(node, data);
538     }
539 
540     @Override
541     protected Object visit(final ASTSWNode node, final Object data) {
542         return visitNode(node, data);
543     }
544 
545     @Override
546     protected Object visit(final ASTTernaryNode node, final Object data) {
547         return visitNode(node, data);
548     }
549 
550     @Override
551     protected Object visit(final ASTThrowStatement node, final Object data) {
552         return visitNode(node, data);
553     }
554 
555     @Override
556     protected Object visit(final ASTTrueNode node, final Object data) {
557         return visitNode(node, data);
558     }
559 
560     @Override
561     protected Object visit(final ASTTryResources node, final Object data) {
562         return visitNode(node, data);
563     }
564 
565     @Override
566     protected Object visit(final ASTTryStatement node, final Object data) {
567         return visitNode(node, data);
568     }
569 
570     @Override
571     protected Object visit(final ASTUnaryMinusNode node, final Object data) {
572         return visitNode(node, data);
573     }
574 
575     @Override
576     protected Object visit(final ASTUnaryPlusNode node, final Object data) {
577         return visitNode(node, data);
578     }
579 
580     @Override
581     protected Object visit(final ASTVar node, final Object data) {
582         return visitNode(node, data);
583     }
584 
585     @Override
586     protected Object visit(final ASTWhileStatement node, final Object data) {
587         return visitNode(node, data);
588     }
589 
590     /**
591      * Visits all AST constituents of a JEXL expression.
592      * @param jscript the expression
593      * @param data some data context
594      * @return the visit result or null if jscript was not a Script implementation
595      */
596     public Object visitExpression (final JexlExpression jscript, final Object data) {
597         if (jscript instanceof Script) {
598             return ((Script) jscript).getScript().jjtAccept(this, data);
599         }
600         return null;
601     }
602 
603     /**
604      * Visits a node.
605      * Default implementation visits all its children.
606      * @param node the node to visit
607      * @param data visitor pattern argument
608      * @return visitor pattern value
609      */
610     protected Object visitNode(final JexlNode node, final Object data) {
611         return node.childrenAccept(this, data);
612     }
613 
614     /**
615      * Visits all AST constituents of a JEXL script.
616      * @param jscript the expression
617      * @param data some data context
618      * @return the visit result or null if jscript was not a Script implementation
619      */
620     public Object visitScript(final JexlScript jscript, final Object data) {
621         if (jscript instanceof Script) {
622             return ((Script) jscript).getScript().jjtAccept(this, data);
623         }
624         return null;
625     }
626 }