001: /*
002: * Janino - An embedded Java[TM] compiler
003: *
004: * Copyright (c) 2006, 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
042: TypeDeclarationVisitor, TypeBodyDeclarationVisitor,
043: BlockStatementVisitor, AtomVisitor {
044:
045: // ImportDeclaration-derived.
046: void visitSingleTypeImportDeclaration(
047: Java.CompilationUnit.SingleTypeImportDeclaration stid);
048:
049: void visitTypeImportOnDemandDeclaration(
050: Java.CompilationUnit.TypeImportOnDemandDeclaration tiodd);
051: }
052:
053: public interface TypeDeclarationVisitor {
054: void visitAnonymousClassDeclaration(
055: Java.AnonymousClassDeclaration acd);
056:
057: void visitLocalClassDeclaration(Java.LocalClassDeclaration lcd);
058:
059: void visitPackageMemberClassDeclaration(
060: Java.PackageMemberClassDeclaration pmcd);
061:
062: void visitMemberInterfaceDeclaration(
063: Java.MemberInterfaceDeclaration mid);
064:
065: void visitPackageMemberInterfaceDeclaration(
066: Java.PackageMemberInterfaceDeclaration pmid);
067:
068: void visitMemberClassDeclaration(Java.MemberClassDeclaration mcd);
069: }
070:
071: public interface TypeBodyDeclarationVisitor {
072: void visitMemberInterfaceDeclaration(
073: Java.MemberInterfaceDeclaration mid);
074:
075: void visitMemberClassDeclaration(Java.MemberClassDeclaration mcd);
076:
077: void visitConstructorDeclarator(Java.ConstructorDeclarator cd);
078:
079: void visitInitializer(Java.Initializer i);
080:
081: void visitMethodDeclarator(Java.MethodDeclarator md);
082:
083: void visitFieldDeclaration(Java.FieldDeclaration fd);
084: }
085:
086: public interface BlockStatementVisitor {
087: void visitInitializer(Java.Initializer i);
088:
089: void visitFieldDeclaration(Java.FieldDeclaration fd);
090:
091: void visitLabeledStatement(Java.LabeledStatement ls);
092:
093: void visitBlock(Java.Block b);
094:
095: void visitExpressionStatement(Java.ExpressionStatement es);
096:
097: void visitIfStatement(Java.IfStatement is);
098:
099: void visitForStatement(Java.ForStatement fs);
100:
101: void visitWhileStatement(Java.WhileStatement ws);
102:
103: void visitTryStatement(Java.TryStatement ts);
104:
105: void visitSwitchStatement(Java.SwitchStatement ss);
106:
107: void visitSynchronizedStatement(Java.SynchronizedStatement ss);
108:
109: void visitDoStatement(Java.DoStatement ds);
110:
111: void visitLocalVariableDeclarationStatement(
112: Java.LocalVariableDeclarationStatement lvds);
113:
114: void visitReturnStatement(Java.ReturnStatement rs);
115:
116: void visitThrowStatement(Java.ThrowStatement ts);
117:
118: void visitBreakStatement(Java.BreakStatement bs);
119:
120: void visitContinueStatement(Java.ContinueStatement cs);
121:
122: void visitEmptyStatement(Java.EmptyStatement es);
123:
124: void visitLocalClassDeclarationStatement(
125: Java.LocalClassDeclarationStatement lcds);
126:
127: void visitAlternateConstructorInvocation(
128: Java.AlternateConstructorInvocation aci);
129:
130: void visitSuperConstructorInvocation(
131: Java.SuperConstructorInvocation sci);
132: }
133:
134: public interface AtomVisitor extends RvalueVisitor, TypeVisitor {
135: void visitPackage(Java.Package p);
136: }
137:
138: public interface TypeVisitor {
139: void visitArrayType(Java.ArrayType at);
140:
141: void visitBasicType(Java.BasicType bt);
142:
143: void visitReferenceType(Java.ReferenceType rt);
144:
145: void visitRvalueMemberType(Java.RvalueMemberType rmt);
146:
147: void visitSimpleType(Java.SimpleType st);
148: }
149:
150: public interface RvalueVisitor extends LvalueVisitor {
151: void visitArrayLength(Java.ArrayLength al);
152:
153: void visitAssignment(Java.Assignment a);
154:
155: void visitUnaryOperation(Java.UnaryOperation uo);
156:
157: void visitBinaryOperation(Java.BinaryOperation bo);
158:
159: void visitCast(Java.Cast c);
160:
161: void visitClassLiteral(Java.ClassLiteral cl);
162:
163: void visitConditionalExpression(Java.ConditionalExpression ce);
164:
165: void visitConstantValue(Java.ConstantValue cv);
166:
167: void visitCrement(Java.Crement c);
168:
169: void visitInstanceof(Java.Instanceof io);
170:
171: void visitMethodInvocation(Java.MethodInvocation mi);
172:
173: void visitSuperclassMethodInvocation(
174: Java.SuperclassMethodInvocation smi);
175:
176: void visitLiteral(Java.Literal l);
177:
178: void visitNewAnonymousClassInstance(
179: Java.NewAnonymousClassInstance naci);
180:
181: void visitNewArray(Java.NewArray na);
182:
183: void visitNewInitializedArray(Java.NewInitializedArray nia);
184:
185: void visitNewClassInstance(Java.NewClassInstance nci);
186:
187: void visitParameterAccess(Java.ParameterAccess pa);
188:
189: void visitQualifiedThisReference(Java.QualifiedThisReference qtr);
190:
191: void visitThisReference(Java.ThisReference tr);
192: }
193:
194: public interface LvalueVisitor {
195: void visitAmbiguousName(Java.AmbiguousName an);
196:
197: void visitArrayAccessExpression(Java.ArrayAccessExpression aae);
198:
199: void visitFieldAccess(Java.FieldAccess fa);
200:
201: void visitFieldAccessExpression(Java.FieldAccessExpression fae);
202:
203: void visitLocalVariableAccess(Java.LocalVariableAccess lva);
204:
205: void visitParenthesizedExpression(
206: Java.ParenthesizedExpression pe);
207: }
208: }
|