1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.jexl3.parser;
18
19 import java.util.Map;
20
21 import org.apache.commons.jexl3.JexlFeatures;
22 import org.apache.commons.jexl3.internal.Frame;
23 import org.apache.commons.jexl3.internal.Scope;
24
25
26
27
28 public class ASTJexlScript extends JexlLexicalNode {
29
30 private static final long serialVersionUID = 202112111533L;
31
32 private Map<String, Object> pragmas;
33
34 private transient JexlFeatures features = null;
35
36 private transient Scope scope = null;
37
38 public ASTJexlScript(final int id) {
39 super(id);
40 }
41
42 public ASTJexlScript(final Parser p, final int id) {
43 super(id);
44 }
45
46
47
48
49
50
51
52 public Frame createFrame(final Frame caller, final Object... values) {
53 return scope != null ? scope.createFrame(caller, values) : null;
54 }
55
56
57
58
59
60
61 public Frame createFrame(final Object... values) {
62 return createFrame(null, values);
63 }
64
65
66
67
68
69 public int getArgCount() {
70 return scope != null ? scope.getArgCount() : 0;
71 }
72
73
74
75
76
77 public String[] getCapturedVariables() {
78 return scope != null ? scope.getCapturedVariables() : null;
79 }
80
81
82
83
84 public JexlFeatures getFeatures() {
85 return features;
86 }
87
88
89
90
91
92 public String[] getLocalVariables() {
93 return scope != null ? scope.getLocalVariables() : null;
94 }
95
96
97
98
99
100 public String[] getParameters() {
101 return scope != null ? scope.getParameters() : null;
102 }
103
104
105
106
107 public Map<String, Object> getPragmas() {
108 return pragmas;
109 }
110
111
112
113
114 public Scope getScope() {
115 return scope;
116 }
117
118
119
120
121
122 public String[] getSymbols() {
123 return scope != null ? scope.getSymbols() : null;
124 }
125
126
127
128
129
130
131 public boolean isCapturedSymbol(final int symbol) {
132 return scope != null && scope.isCapturedSymbol(symbol);
133 }
134
135 @Override
136 public Object jjtAccept(final ParserVisitor visitor, final Object data) {
137 return visitor.visit(this, data);
138 }
139
140
141
142
143
144 public ASTJexlScript script() {
145 if (scope == null && jjtGetNumChildren() == 1 && jjtGetChild(0) instanceof ASTJexlLambda) {
146 final ASTJexlLambda lambda = (ASTJexlLambda) jjtGetChild(0);
147 lambda.jjtSetParent(null);
148 return lambda;
149 }
150 return this;
151 }
152
153
154
155
156
157 public void setFeatures(final JexlFeatures theFeatures) {
158 this.features = theFeatures;
159 }
160
161
162
163
164
165 public void setPragmas(final Map<String, Object> thePragmas) {
166 this.pragmas = thePragmas;
167 }
168
169
170
171
172
173 public void setScope(final Scope theScope) {
174 this.scope = theScope;
175 if (theScope != null) {
176 for(int a = 0; a < theScope.getArgCount(); ++a) {
177 declareSymbol(a);
178 }
179 }
180 }
181 }