001    /*
002     * Copyright 2008 Google Inc.
003     *
004     * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
005     * in compliance with the License. You may obtain a copy of the License at
006     *
007     * http://www.apache.org/licenses/LICENSE-2.0
008     *
009     * Unless required by applicable law or agreed to in writing, software distributed under the License
010     * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
011     * or implied. See the License for the specific language governing permissions and limitations under
012     * the License.
013     */
014    
015    package org.jetbrains.kotlin.js.backend.ast;
016    
017    /**
018     * Taken from GWT project with modifications.
019     * Original:
020     *  repository: https://gwt.googlesource.com/gwt
021     *  revision: e32bf0a95029165d9e6ab457c7ee7ca8b07b908c
022     *  file: dev/core/src/com/google/gwt/dev/js/ast/JsVisitor.java
023     */
024    
025    import org.jetbrains.annotations.NotNull;
026    
027    import java.util.List;
028    
029    /**
030     * Implemented by nodes that will visit child nodes.
031     */
032    @SuppressWarnings("UnusedParameters")
033    public abstract class JsVisitorWithContext {
034    
035        public final <T extends JsNode> T accept(T node) {
036            if (node == null) return null;
037    
038            return doAccept(node);
039        }
040    
041        public JsExpression acceptLvalue(JsExpression expr) {
042            if (expr == null) return null;
043    
044            return doAcceptLvalue(expr);
045        }
046    
047        public final <T extends JsNode> void acceptList(List<T> collection) {
048            doAcceptList(collection);
049        }
050    
051        public final <T extends JsStatement> T acceptStatement(T statement) {
052            if (statement == null) return null;
053    
054            //noinspection unchecked
055            return (T) doAcceptStatement(statement);
056        }
057    
058        public final void acceptStatementList(List<JsStatement> statements) {
059            doAcceptStatementList(statements);
060        }
061    
062        public void endVisit(@NotNull JsArrayAccess x, @NotNull JsContext ctx) {
063        }
064    
065        public void endVisit(@NotNull JsArrayLiteral x, @NotNull JsContext ctx) {
066        }
067    
068        public void endVisit(@NotNull JsBinaryOperation x, @NotNull JsContext ctx) {
069        }
070    
071        public void endVisit(@NotNull JsBlock x, @NotNull JsContext ctx) {
072        }
073    
074        public void endVisit(@NotNull JsLiteral.JsBooleanLiteral x, @NotNull JsContext ctx) {
075        }
076    
077        public void endVisit(@NotNull JsBreak x, @NotNull JsContext ctx) {
078        }
079    
080        public void endVisit(@NotNull JsCase x, @NotNull JsContext ctx) {
081        }
082    
083        public void endVisit(@NotNull JsCatch x, @NotNull JsContext ctx) {
084        }
085    
086        public void endVisit(@NotNull JsConditional x, @NotNull JsContext ctx) {
087        }
088    
089        public void endVisit(@NotNull JsContinue x, @NotNull JsContext ctx) {
090        }
091    
092        public void endVisit(@NotNull JsDebugger x, @NotNull JsContext ctx) {
093        }
094    
095        public void endVisit(@NotNull JsDefault x, @NotNull JsContext ctx) {
096        }
097    
098        public void endVisit(@NotNull JsDoWhile x, @NotNull JsContext ctx) {
099        }
100    
101        public void endVisit(@NotNull JsEmpty x, @NotNull JsContext ctx) {
102        }
103    
104        public void endVisit(@NotNull JsExpressionStatement x, @NotNull JsContext ctx) {
105        }
106    
107        public void endVisit(@NotNull JsFor x, @NotNull JsContext ctx) {
108        }
109    
110        public void endVisit(@NotNull JsForIn x, @NotNull JsContext ctx) {
111        }
112    
113        public void endVisit(@NotNull JsFunction x, @NotNull JsContext ctx) {
114        }
115    
116        public void endVisit(@NotNull JsIf x, @NotNull JsContext ctx) {
117        }
118    
119        public void endVisit(@NotNull JsInvocation x, @NotNull JsContext ctx) {
120        }
121    
122        public void endVisit(@NotNull JsLabel x, @NotNull JsContext ctx) {
123        }
124    
125        public void endVisit(@NotNull JsName x, @NotNull JsContext ctx) {
126        }
127    
128        public void endVisit(@NotNull JsNameRef x, @NotNull JsContext ctx) {
129        }
130    
131        public void endVisit(@NotNull JsNew x, @NotNull JsContext ctx) {
132        }
133    
134        public void endVisit(@NotNull JsNullLiteral x, @NotNull JsContext ctx) {
135        }
136    
137        public void endVisit(@NotNull JsNumberLiteral x, @NotNull JsContext ctx) {
138        }
139    
140        public void endVisit(@NotNull JsObjectLiteral x, @NotNull JsContext ctx) {
141        }
142    
143        public void endVisit(@NotNull JsParameter x, @NotNull JsContext ctx) {
144        }
145    
146        public void endVisit(@NotNull JsPostfixOperation x, @NotNull JsContext ctx) {
147        }
148    
149        public void endVisit(@NotNull JsPrefixOperation x, @NotNull JsContext ctx) {
150        }
151    
152        public void endVisit(@NotNull JsProgram x, @NotNull JsContext ctx) {
153        }
154    
155        public void endVisit(@NotNull JsProgramFragment x, @NotNull JsContext ctx) {
156        }
157    
158        public void endVisit(@NotNull JsPropertyInitializer x, @NotNull JsContext ctx) {
159        }
160    
161        public void endVisit(@NotNull JsRegExp x, @NotNull JsContext ctx) {
162        }
163    
164        public void endVisit(@NotNull JsReturn x, @NotNull JsContext ctx) {
165        }
166    
167        public void endVisit(@NotNull JsStringLiteral x, @NotNull JsContext ctx) {
168        }
169    
170        public void endVisit(@NotNull JsSwitch x, @NotNull JsContext ctx) {
171        }
172    
173        public void endVisit(@NotNull JsLiteral.JsThisRef x, @NotNull JsContext ctx) {
174        }
175    
176        public void endVisit(@NotNull JsThrow x, @NotNull JsContext ctx) {
177        }
178    
179        public void endVisit(@NotNull JsTry x, @NotNull JsContext ctx) {
180        }
181    
182        public void endVisit(@NotNull JsVars.JsVar x, @NotNull JsContext ctx) {
183        }
184    
185        public void endVisit(@NotNull JsVars x, @NotNull JsContext ctx) {
186        }
187    
188        public void endVisit(@NotNull JsWhile x, @NotNull JsContext ctx) {
189        }
190    
191        public boolean visit(@NotNull JsArrayAccess x, @NotNull JsContext ctx) {
192            return true;
193        }
194    
195        public boolean visit(@NotNull JsArrayLiteral x, @NotNull JsContext ctx) {
196            return true;
197        }
198    
199        public boolean visit(@NotNull JsBinaryOperation x, @NotNull JsContext ctx) {
200            return true;
201        }
202    
203        public boolean visit(@NotNull JsBlock x, @NotNull JsContext ctx) {
204            return true;
205        }
206    
207        public boolean visit(@NotNull JsLiteral.JsBooleanLiteral x, @NotNull JsContext ctx) {
208            return true;
209        }
210    
211        public boolean visit(@NotNull JsBreak x, @NotNull JsContext ctx) {
212            return true;
213        }
214    
215        public boolean visit(@NotNull JsCase x, @NotNull JsContext ctx) {
216            return true;
217        }
218    
219        public boolean visit(@NotNull JsCatch x, @NotNull JsContext ctx) {
220            return true;
221        }
222    
223        public boolean visit(@NotNull JsConditional x, @NotNull JsContext ctx) {
224            return true;
225        }
226    
227        public boolean visit(@NotNull JsContinue x, @NotNull JsContext ctx) {
228            return true;
229        }
230    
231        public boolean visit(@NotNull JsDebugger x, @NotNull JsContext ctx) {
232            return true;
233        }
234    
235        public boolean visit(@NotNull JsDefault x, @NotNull JsContext ctx) {
236            return true;
237        }
238    
239        public boolean visit(@NotNull JsDoWhile x, @NotNull JsContext ctx) {
240            return true;
241        }
242    
243        public boolean visit(@NotNull JsEmpty x, @NotNull JsContext ctx) {
244            return true;
245        }
246    
247        public boolean visit(@NotNull JsExpressionStatement x, @NotNull JsContext ctx) {
248            return true;
249        }
250    
251        public boolean visit(@NotNull JsFor x, @NotNull JsContext ctx) {
252            return true;
253        }
254    
255        public boolean visit(@NotNull JsForIn x, @NotNull JsContext ctx) {
256            return true;
257        }
258    
259        public boolean visit(@NotNull JsFunction x, @NotNull JsContext ctx) {
260            return true;
261        }
262    
263        public boolean visit(@NotNull JsIf x, @NotNull JsContext ctx) {
264            return true;
265        }
266    
267        public boolean visit(@NotNull JsInvocation x, @NotNull JsContext ctx) {
268            return true;
269        }
270    
271        public boolean visit(@NotNull JsLabel x, @NotNull JsContext ctx) {
272            return true;
273        }
274    
275        public boolean visit(@NotNull JsName x, @NotNull JsContext ctx) {
276            return true;
277        }
278    
279        public boolean visit(@NotNull JsNameRef x, @NotNull JsContext ctx) {
280            return true;
281        }
282    
283        public boolean visit(@NotNull JsNew x, @NotNull JsContext ctx) {
284            return true;
285        }
286    
287        public boolean visit(@NotNull JsNullLiteral x, @NotNull JsContext ctx) {
288            return true;
289        }
290    
291        public boolean visit(@NotNull JsNumberLiteral x, @NotNull JsContext ctx) {
292            return true;
293        }
294    
295        public boolean visit(@NotNull JsObjectLiteral x, @NotNull JsContext ctx) {
296            return true;
297        }
298    
299        public boolean visit(@NotNull JsParameter x, @NotNull JsContext ctx) {
300            return true;
301        }
302    
303        public boolean visit(@NotNull JsPostfixOperation x, @NotNull JsContext ctx) {
304            return true;
305        }
306    
307        public boolean visit(@NotNull JsPrefixOperation x, @NotNull JsContext ctx) {
308            return true;
309        }
310    
311        public boolean visit(@NotNull JsProgram x, @NotNull JsContext ctx) {
312            return true;
313        }
314    
315        public boolean visit(@NotNull JsProgramFragment x, @NotNull JsContext ctx) {
316            return true;
317        }
318    
319        public boolean visit(@NotNull JsPropertyInitializer x, @NotNull JsContext ctx) {
320            return true;
321        }
322    
323        public boolean visit(@NotNull JsRegExp x, @NotNull JsContext ctx) {
324            return true;
325        }
326    
327        public boolean visit(@NotNull JsReturn x, @NotNull JsContext ctx) {
328            return true;
329        }
330    
331        public boolean visit(@NotNull JsStringLiteral x, @NotNull JsContext ctx) {
332            return true;
333        }
334    
335        public boolean visit(@NotNull JsSwitch x, @NotNull JsContext ctx) {
336            return true;
337        }
338    
339        public boolean visit(@NotNull JsLiteral.JsThisRef x, @NotNull JsContext ctx) {
340            return true;
341        }
342    
343        public boolean visit(@NotNull JsThrow x, @NotNull JsContext ctx) {
344            return true;
345        }
346    
347        public boolean visit(@NotNull JsTry x, @NotNull JsContext ctx) {
348            return true;
349        }
350    
351        public boolean visit(@NotNull JsVars.JsVar x, @NotNull JsContext ctx) {
352            return true;
353        }
354    
355        public boolean visit(@NotNull JsVars x, @NotNull JsContext ctx) {
356            return true;
357        }
358    
359        public boolean visit(@NotNull JsWhile x, @NotNull JsContext ctx) {
360            return true;
361        }
362    
363        protected abstract  <T extends JsNode> T doAccept(T node);
364    
365        protected abstract JsExpression doAcceptLvalue(JsExpression expr);
366    
367        protected abstract <T extends JsNode> void doAcceptList(List<T> collection);
368    
369        protected abstract <T extends JsStatement> JsStatement doAcceptStatement(T statement);
370    
371        protected abstract void doAcceptStatementList(List<JsStatement> statements);
372    
373        protected abstract <T extends JsNode> void doTraverse(T node, JsContext ctx) ;
374    }