001: /*
002: * Janino - An embedded Java[TM] compiler
003: *
004: * Copyright (c) 2001-2007, Arno Unkrig
005: * All rights reserved.
006: *
007: * Redistribution and use in source and binary forms, with or without
008: * modification, are permitted provided that the following conditions
009: * are met:
010: *
011: * 1. Redistributions of source code must retain the above copyright
012: * notice, this list of conditions and the following disclaimer.
013: * 2. Redistributions in binary form must reproduce the above
014: * copyright notice, this list of conditions and the following
015: * disclaimer in the documentation and/or other materials
016: * provided with the distribution.
017: * 3. The name of the author may not be used to endorse or promote
018: * products derived from this software without specific prior
019: * written permission.
020: *
021: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
022: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
023: * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
024: * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
025: * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
026: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
027: * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
028: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
029: * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
030: * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
031: * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
032: */
033:
034: package org.codehaus.janino;
035:
036: /**
037: * Basis for the "visitor" pattern as described in "Gamma, Helm, Johnson,
038: * Vlissides: Design Patterns".
039: */
040: public class Visitor {
041: public interface ComprehensiveVisitor extends ImportVisitor,
042: TypeDeclarationVisitor, TypeBodyDeclarationVisitor,
043: BlockStatementVisitor, AtomVisitor {
044: }
045:
046: public interface ImportVisitor {
047: void visitSingleTypeImportDeclaration(
048: Java.CompilationUnit.SingleTypeImportDeclaration stid);
049:
050: void visitTypeImportOnDemandDeclaration(
051: Java.CompilationUnit.TypeImportOnDemandDeclaration tiodd);
052:
053: void visitSingleStaticImportDeclaration(
054: Java.CompilationUnit.SingleStaticImportDeclaration ssid);
055:
056: void visitStaticImportOnDemandDeclaration(
057: Java.CompilationUnit.StaticImportOnDemandDeclaration siodd);
058: }
059:
060: public interface TypeDeclarationVisitor {
061: void visitAnonymousClassDeclaration(
062: Java.AnonymousClassDeclaration acd);
063:
064: void visitLocalClassDeclaration(Java.LocalClassDeclaration lcd);
065:
066: void visitPackageMemberClassDeclaration(
067: Java.PackageMemberClassDeclaration pmcd);
068:
069: void visitMemberInterfaceDeclaration(
070: Java.MemberInterfaceDeclaration mid);
071:
072: void visitPackageMemberInterfaceDeclaration(
073: Java.PackageMemberInterfaceDeclaration pmid);
074:
075: void visitMemberClassDeclaration(Java.MemberClassDeclaration mcd);
076: }
077:
078: public interface TypeBodyDeclarationVisitor {
079: void visitMemberInterfaceDeclaration(
080: Java.MemberInterfaceDeclaration mid);
081:
082: void visitMemberClassDeclaration(Java.MemberClassDeclaration mcd);
083:
084: void visitConstructorDeclarator(Java.ConstructorDeclarator cd);
085:
086: void visitInitializer(Java.Initializer i);
087:
088: void visitMethodDeclarator(Java.MethodDeclarator md);
089:
090: void visitFieldDeclaration(Java.FieldDeclaration fd);
091: }
092:
093: public interface BlockStatementVisitor {
094: void visitInitializer(Java.Initializer i);
095:
096: void visitFieldDeclaration(Java.FieldDeclaration fd);
097:
098: void visitLabeledStatement(Java.LabeledStatement ls);
099:
100: void visitBlock(Java.Block b);
101:
102: void visitExpressionStatement(Java.ExpressionStatement es);
103:
104: void visitIfStatement(Java.IfStatement is);
105:
106: void visitForStatement(Java.ForStatement fs);
107:
108: void visitWhileStatement(Java.WhileStatement ws);
109:
110: void visitTryStatement(Java.TryStatement ts);
111:
112: void visitSwitchStatement(Java.SwitchStatement ss);
113:
114: void visitSynchronizedStatement(Java.SynchronizedStatement ss);
115:
116: void visitDoStatement(Java.DoStatement ds);
117:
118: void visitLocalVariableDeclarationStatement(
119: Java.LocalVariableDeclarationStatement lvds);
120:
121: void visitReturnStatement(Java.ReturnStatement rs);
122:
123: void visitThrowStatement(Java.ThrowStatement ts);
124:
125: void visitBreakStatement(Java.BreakStatement bs);
126:
127: void visitContinueStatement(Java.ContinueStatement cs);
128:
129: void visitEmptyStatement(Java.EmptyStatement es);
130:
131: void visitLocalClassDeclarationStatement(
132: Java.LocalClassDeclarationStatement lcds);
133:
134: void visitAlternateConstructorInvocation(
135: Java.AlternateConstructorInvocation aci);
136:
137: void visitSuperConstructorInvocation(
138: Java.SuperConstructorInvocation sci);
139: }
140:
141: public interface AtomVisitor extends RvalueVisitor, TypeVisitor {
142: void visitPackage(Java.Package p);
143: }
144:
145: public interface TypeVisitor {
146: void visitArrayType(Java.ArrayType at);
147:
148: void visitBasicType(Java.BasicType bt);
149:
150: void visitReferenceType(Java.ReferenceType rt);
151:
152: void visitRvalueMemberType(Java.RvalueMemberType rmt);
153:
154: void visitSimpleType(Java.SimpleType st);
155: }
156:
157: public interface RvalueVisitor extends LvalueVisitor {
158: void visitArrayLength(Java.ArrayLength al);
159:
160: void visitAssignment(Java.Assignment a);
161:
162: void visitUnaryOperation(Java.UnaryOperation uo);
163:
164: void visitBinaryOperation(Java.BinaryOperation bo);
165:
166: void visitCast(Java.Cast c);
167:
168: void visitClassLiteral(Java.ClassLiteral cl);
169:
170: void visitConditionalExpression(Java.ConditionalExpression ce);
171:
172: void visitConstantValue(Java.ConstantValue cv);
173:
174: void visitCrement(Java.Crement c);
175:
176: void visitInstanceof(Java.Instanceof io);
177:
178: void visitMethodInvocation(Java.MethodInvocation mi);
179:
180: void visitSuperclassMethodInvocation(
181: Java.SuperclassMethodInvocation smi);
182:
183: void visitLiteral(Java.Literal l);
184:
185: void visitNewAnonymousClassInstance(
186: Java.NewAnonymousClassInstance naci);
187:
188: void visitNewArray(Java.NewArray na);
189:
190: void visitNewInitializedArray(Java.NewInitializedArray nia);
191:
192: void visitNewClassInstance(Java.NewClassInstance nci);
193:
194: void visitParameterAccess(Java.ParameterAccess pa);
195:
196: void visitQualifiedThisReference(Java.QualifiedThisReference qtr);
197:
198: void visitThisReference(Java.ThisReference tr);
199: }
200:
201: public interface LvalueVisitor {
202: void visitAmbiguousName(Java.AmbiguousName an);
203:
204: void visitArrayAccessExpression(Java.ArrayAccessExpression aae);
205:
206: void visitFieldAccess(Java.FieldAccess fa);
207:
208: void visitFieldAccessExpression(Java.FieldAccessExpression fae);
209:
210: void visitSuperclassFieldAccessExpression(
211: Java.SuperclassFieldAccessExpression scfae);
212:
213: void visitLocalVariableAccess(Java.LocalVariableAccess lva);
214:
215: void visitParenthesizedExpression(
216: Java.ParenthesizedExpression pe);
217: }
218: }
|