0001: /*BEGIN_COPYRIGHT_BLOCK
0002: *
0003: * Copyright (c) 2001-2007, JavaPLT group at Rice University (javaplt@rice.edu)
0004: * All rights reserved.
0005: *
0006: * Redistribution and use in source and binary forms, with or without
0007: * modification, are permitted provided that the following conditions are met:
0008: * * Redistributions of source code must retain the above copyright
0009: * notice, this list of conditions and the following disclaimer.
0010: * * Redistributions in binary form must reproduce the above copyright
0011: * notice, this list of conditions and the following disclaimer in the
0012: * documentation and/or other materials provided with the distribution.
0013: * * Neither the names of DrJava, the JavaPLT group, Rice University, nor the
0014: * names of its contributors may be used to endorse or promote products
0015: * derived from this software without specific prior written permission.
0016: *
0017: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
0018: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
0019: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
0020: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
0021: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
0022: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
0023: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
0024: * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
0025: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
0026: * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
0027: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
0028: *
0029: * This software is Open Source Initiative approved Open Source Software.
0030: * Open Source Initative Approved is a trademark of the Open Source Initiative.
0031: *
0032: * This file is part of DrJava. Download the current version of this project
0033: * from http://www.drjava.org/ or http://sourceforge.net/projects/drjava/
0034: *
0035: * END_COPYRIGHT_BLOCK*/
0036:
0037: package edu.rice.cs.drjava.model.repl;
0038:
0039: import java.util.*;
0040:
0041: import koala.dynamicjava.tree.*;
0042: import koala.dynamicjava.tree.visitor.*;
0043:
0044: /**
0045: * This class visits each node and each node's members, recursively
0046: * walking the syntax tree, returning the identical node back for
0047: * each case. Note that Try, Catch, and ArrayAllocation statements
0048: * return a new Node with the same fields because they did not appear
0049: * to have all of the necessary setters.
0050: *
0051: * @version $Id: IdentityVisitor.java 4255 2007-08-28 19:17:37Z mgricken $
0052: */
0053:
0054: public class IdentityVisitor implements Visitor<Node> {
0055: /**
0056: * Visits a PackageDeclaration
0057: * @param node the node to visit
0058: * @return node
0059: */
0060:
0061: public Node visit(PackageDeclaration node) {
0062: return node;
0063: }
0064:
0065: /**
0066: * Visits an ImportDeclaration
0067: * @param node the node to visit
0068: * @return node
0069: */
0070:
0071: public Node visit(ImportDeclaration node) {
0072: return node;
0073: }
0074:
0075: /**
0076: * Visits an EmptyStatement
0077: * @param node the node to visit
0078: */
0079:
0080: public Node visit(EmptyStatement node) {
0081: return node;
0082: }
0083:
0084: /**
0085: * Visits a WhileStatement
0086: * @param node the node to visit
0087: */
0088: public Node visit(WhileStatement node) {
0089: node.setCondition((Expression) node.getCondition()
0090: .acceptVisitor(this ));
0091: node.setBody(node.getBody().acceptVisitor(this ));
0092: return node;
0093: }
0094:
0095: /**
0096: * Visits a ForStatement
0097: * @param node the node to visit
0098: */
0099: public Node visit(ForStatement node) {
0100: LinkedList<Node> init = null; // Add parameterization <Node>.
0101: if (node.getInitialization() != null) {
0102: init = new LinkedList<Node>(); // Add parameterization <Node>.
0103: Iterator<Node> it = node.getInitialization().iterator();
0104: while (it.hasNext()) {
0105: init.add(it.next().acceptVisitor(this ));
0106: }
0107: }
0108: node.setInitialization(init);
0109: Expression cond = null;
0110: if (node.getCondition() != null) {
0111: cond = (Expression) node.getCondition().acceptVisitor(this );
0112: }
0113: node.setCondition(cond);
0114: LinkedList<Node> updt = null; // Add parameterization <Node>.
0115: if (node.getUpdate() != null) {
0116: updt = new LinkedList<Node>(); // Add parameterization <Node>.
0117: Iterator<Node> it = node.getUpdate().iterator();
0118: while (it.hasNext()) {
0119: updt.add(it.next().acceptVisitor(this ));
0120: }
0121: }
0122: node.setUpdate(updt);
0123: node.setBody(node.getBody().acceptVisitor(this ));
0124: return node;
0125: }
0126:
0127: /**
0128: * Visits a ForEachStatement
0129: * @param node the node to visit
0130: */
0131: public Node visit(ForEachStatement node) {
0132: FormalParameter param = node.getParameter();
0133: Expression collection = node.getCollection();
0134: Node stmt = node.getBody();
0135:
0136: node.setParameter((FormalParameter) param.acceptVisitor(this ));
0137: node.setCollection((Expression) collection.acceptVisitor(this ));
0138: node.setBody(stmt.acceptVisitor(this ));
0139:
0140: return node;
0141: }
0142:
0143: /**
0144: * Visits a DoStatement
0145: * @param node the node to visit
0146: */
0147: public Node visit(DoStatement node) {
0148: Expression cond = (Expression) node.getCondition()
0149: .acceptVisitor(this );
0150: node.setCondition(cond);
0151: Node body = node.getBody().acceptVisitor(this );
0152: node.setBody(body);
0153: return node;
0154: }
0155:
0156: /**
0157: * Visits a SwitchStatement
0158: * @param node the node to visit
0159: */
0160: public Node visit(SwitchStatement node) {
0161: Expression sel = (Expression) node.getSelector().acceptVisitor(
0162: this );
0163: node.setSelector(sel);
0164: LinkedList<SwitchBlock> cases = new LinkedList<SwitchBlock>(); // Add parameterization <Node>.
0165: Iterator<SwitchBlock> it = node.getBindings().iterator();
0166: while (it.hasNext()) {
0167: cases.add((SwitchBlock) it.next().acceptVisitor(this ));
0168: }
0169: node.setBindings(cases);
0170: return node;
0171: }
0172:
0173: /**
0174: * Visits a SwitchBlock
0175: * @param node the node to visit
0176: */
0177: public Node visit(SwitchBlock node) {
0178: Expression e = null;
0179: if (node.getExpression() != null) {
0180: e = (Expression) node.getExpression().acceptVisitor(this );
0181: }
0182: node.setExpression(e);
0183: LinkedList<Node> statements = null; // Add parameterization <Node>.
0184: if (node.getStatements() != null) {
0185: statements = new LinkedList<Node>(); // Add parameterization <Node>.
0186: Iterator<Node> it = node.getStatements().iterator();
0187: while (it.hasNext()) {
0188: statements.add(it.next().acceptVisitor(this ));
0189: }
0190: }
0191: node.setStatements(statements);
0192: return node;
0193: }
0194:
0195: /**
0196: * Visits a LabeledStatement
0197: * @param node the node to visit
0198: */
0199: public Node visit(LabeledStatement node) {
0200: node.setStatement(node.getStatement().acceptVisitor(this ));
0201: return node;
0202: }
0203:
0204: /**
0205: * Visits a BreakStatement
0206: * @param node the node to visit
0207: */
0208: public Node visit(BreakStatement node) {
0209: return node;
0210: }
0211:
0212: /**
0213: * Visits a TryStatement
0214: * @param node the node to visit
0215: */
0216: public Node visit(TryStatement node) {
0217: Node tryBlock = node.getTryBlock().acceptVisitor(this );
0218: LinkedList<CatchStatement> catchStatements = new LinkedList<CatchStatement>();
0219: Iterator<CatchStatement> it = node.getCatchStatements()
0220: .iterator();
0221: while (it.hasNext()) {
0222: catchStatements.add((CatchStatement) it.next()
0223: .acceptVisitor(this ));
0224: }
0225: Node finallyBlock = null;
0226: if (node.getFinallyBlock() != null) {
0227: finallyBlock = node.getFinallyBlock().acceptVisitor(this );
0228: }
0229: node = new TryStatement(tryBlock, catchStatements,
0230: finallyBlock, null, 0, 0, 0, 0);
0231: return node;
0232: }
0233:
0234: /**
0235: * Visits a CatchStatement
0236: * @param node the node to visit
0237: */
0238: public Node visit(CatchStatement node) {
0239: Node exp = node.getException().acceptVisitor(this );
0240: Node block = node.getBlock().acceptVisitor(this );
0241: node = new CatchStatement((FormalParameter) exp, block, null,
0242: 0, 0, 0, 0);
0243: return node;
0244: }
0245:
0246: /**
0247: * Visits a ThrowStatement
0248: * @param node the node to visit
0249: */
0250: public Node visit(ThrowStatement node) {
0251: node.setExpression((Expression) node.getExpression()
0252: .acceptVisitor(this ));
0253: return node;
0254: }
0255:
0256: /**
0257: * Visits a ReturnStatement
0258: * @param node the node to visit
0259: */
0260: public Node visit(ReturnStatement node) {
0261: node.setExpression((Expression) node.getExpression()
0262: .acceptVisitor(this ));
0263: return node;
0264: }
0265:
0266: /**
0267: * Visits a SynchronizedStatement
0268: * @param node the node to visit
0269: */
0270: public Node visit(SynchronizedStatement node) {
0271: node.setLock((Expression) node.getLock().acceptVisitor(this ));
0272: node.setBody(node.getBody().acceptVisitor(this ));
0273: return node;
0274: }
0275:
0276: /**
0277: * Visits a ContinueStatement
0278: * @param node the node to visit
0279: */
0280: public Node visit(ContinueStatement node) {
0281: return node;
0282: }
0283:
0284: /**
0285: * Visits a IfThenStatement
0286: * @param node the node to visit
0287: */
0288: public Node visit(IfThenStatement node) {
0289: node.setCondition((Expression) node.getCondition()
0290: .acceptVisitor(this ));
0291: node.setThenStatement(node.getThenStatement().acceptVisitor(
0292: this ));
0293: return node;
0294: }
0295:
0296: /**
0297: * Visits a IfThenElseStatement
0298: * @param node the node to visit
0299: */
0300: public Node visit(IfThenElseStatement node) {
0301: node.setCondition((Expression) node.getCondition()
0302: .acceptVisitor(this ));
0303: node.setThenStatement(node.getThenStatement().acceptVisitor(
0304: this ));
0305: node.setElseStatement(node.getElseStatement().acceptVisitor(
0306: this ));
0307: return node;
0308: }
0309:
0310: /**
0311: * Visits an AssertStatement
0312: * @param node the node to visit
0313: */
0314: public Node visit(AssertStatement node) {
0315: node.setCondition((Expression) node.getCondition()
0316: .acceptVisitor(this ));
0317: if (node.getFailString() != null)
0318: node.setFailString((Expression) node.getFailString()
0319: .acceptVisitor(this ));
0320: return node;
0321: }
0322:
0323: /**
0324: * Visits a Literal
0325: * @param node the node to visit
0326: */
0327: public Node visit(Literal node) {
0328: return node;
0329: }
0330:
0331: /**
0332: * Visits a ThisExpression
0333: * @param node the node to visit
0334: */
0335: public Node visit(ThisExpression node) {
0336: return node;
0337: }
0338:
0339: /**
0340: * Visits a QualifiedName
0341: * @param node the node to visit
0342: */
0343: public Node visit(QualifiedName node) {
0344: return node;
0345: }
0346:
0347: /**
0348: * Visits a ObjectFieldAccess
0349: * @param node the node to visit
0350: */
0351: public Node visit(ObjectFieldAccess node) {
0352: node.setExpression((Expression) node.getExpression()
0353: .acceptVisitor(this ));
0354: return node;
0355: }
0356:
0357: /**
0358: * Visits a StaticFieldAccess
0359: * @param node the node to visit
0360: */
0361: public Node visit(StaticFieldAccess node) {
0362: node.setFieldType((ReferenceType) node.getFieldType()
0363: .acceptVisitor(this ));
0364: return node;
0365: }
0366:
0367: /**
0368: * Visits a ArrayAccess
0369: * @param node the node to visit
0370: */
0371: public Node visit(ArrayAccess node) {
0372: node.setExpression((Expression) node.getExpression()
0373: .acceptVisitor(this ));
0374: node.setCellNumber((Expression) node.getCellNumber()
0375: .acceptVisitor(this ));
0376: return node;
0377: }
0378:
0379: /**
0380: * Visits a SuperFieldAccess
0381: * @param node the node to visit
0382: */
0383: public Node visit(SuperFieldAccess node) {
0384: return node;
0385: }
0386:
0387: /**
0388: * Visits a ObjectMethodCall
0389: * @param node the node to visit
0390: */
0391: public Node visit(ObjectMethodCall node) {
0392: if (node.getExpression() != null) {
0393: node.setExpression((Expression) node.getExpression()
0394: .acceptVisitor(this ));
0395: }
0396: LinkedList<Expression> arguments = null; // Add parameterization <Node>.
0397: if (node.getArguments() != null) {
0398: arguments = new LinkedList<Expression>(); // Add parameterization <Node>.
0399: Iterator<Expression> it = node.getArguments().iterator();
0400: while (it.hasNext()) {
0401: arguments.add((Expression) it.next()
0402: .acceptVisitor(this ));
0403: }
0404: }
0405: node.setArguments(arguments);
0406: return node;
0407: }
0408:
0409: /**
0410: * Visits a FunctionCall
0411: * @param node the node to visit
0412: */
0413: public Node visit(FunctionCall node) {
0414: LinkedList<Expression> arguments = null; // Add parameterization <Node>.
0415: if (node.getArguments() != null) {
0416: arguments = new LinkedList<Expression>(); // Add parameterization <Node>.
0417: Iterator<Expression> it = node.getArguments().iterator();
0418: while (it.hasNext()) {
0419: arguments.add((Expression) it.next()
0420: .acceptVisitor(this ));
0421: }
0422: }
0423: node.setArguments(arguments);
0424: return node;
0425: }
0426:
0427: /**
0428: * Visits a StaticMethodCall
0429: * @param node the node to visit
0430: */
0431: public Node visit(StaticMethodCall node) {
0432: node.setMethodType((ReferenceType) node.getMethodType()
0433: .acceptVisitor(this ));
0434: LinkedList<Expression> arguments = null; // Add parameterization <Node>.
0435: if (node.getArguments() != null) {
0436: arguments = new LinkedList<Expression>(); // Add parameterization <Node>.
0437: Iterator<Expression> it = node.getArguments().iterator();
0438: while (it.hasNext()) {
0439: arguments.add((Expression) it.next()
0440: .acceptVisitor(this ));
0441: }
0442: }
0443: node.setArguments(arguments);
0444: return node;
0445: }
0446:
0447: /**
0448: * Visits a ConstructorInvocation
0449: * @param node the node to visit
0450: */
0451: public Node visit(ConstructorInvocation node) {
0452: if (node.getExpression() != null) {
0453: node.setExpression((Expression) node.getExpression()
0454: .acceptVisitor(this ));
0455: }
0456: LinkedList<Expression> arguments = null; // Add parameterization <Node>.
0457: if (node.getArguments() != null) {
0458: arguments = new LinkedList<Expression>(); // Add parameterization <Node>.
0459: Iterator<Expression> it = node.getArguments().iterator();
0460: while (it.hasNext()) {
0461: arguments.add((Expression) it.next()
0462: .acceptVisitor(this ));
0463: }
0464: }
0465: node.setArguments(arguments);
0466: return node;
0467: }
0468:
0469: /**
0470: * Visits a SuperMethodCall
0471: * @param node the node to visit
0472: */
0473: public Node visit(SuperMethodCall node) {
0474: LinkedList<Expression> arguments = null; // Add parameterization <Node>.
0475: if (node.getArguments() != null) {
0476: arguments = new LinkedList<Expression>(); // Add parameterization <Node>.
0477: Iterator<Expression> it = node.getArguments().iterator();
0478: while (it.hasNext()) {
0479: arguments.add((Expression) it.next()
0480: .acceptVisitor(this ));
0481: }
0482: }
0483: node.setArguments(arguments);
0484: return node;
0485: }
0486:
0487: /**
0488: * Visits a PrimitiveType
0489: * @param node the node to visit
0490: */
0491: public Node visit(PrimitiveType node) {
0492: return node;
0493: }
0494:
0495: /**
0496: * Visits a ReferenceType
0497: * @param node the node to visit
0498: */
0499: public Node visit(ReferenceType node) {
0500: return node;
0501: }
0502:
0503: /**
0504: * Visits a ArrayType
0505: * @param node the node to visit
0506: */
0507: public Node visit(ArrayType node) {
0508: if (node.getElementType() != null) {
0509: node.setElementType((Type) node.getElementType()
0510: .acceptVisitor(this ));
0511: }
0512: return node;
0513: }
0514:
0515: /**
0516: * Visits a TypeExpression
0517: * @param node the node to visit
0518: */
0519: public Node visit(TypeExpression node) {
0520: // For some reason, the setType expression in node only takes in
0521: // ReferenceTypes so we have to create a new TypeExpression in
0522: // case the visitor returns a PrimitiveType (e.g. int.class used
0523: // to cause a ClassCastException).
0524: node = new TypeExpression((Type) node.getType().acceptVisitor(
0525: this ));
0526: return node;
0527: }
0528:
0529: /**
0530: * Visits a PostIncrement
0531: * @param node the node to visit
0532: */
0533: public Node visit(PostIncrement node) {
0534: return _visitUnary(node);
0535: }
0536:
0537: /**
0538: * Visits a PostDecrement
0539: * @param node the node to visit
0540: */
0541: public Node visit(PostDecrement node) {
0542: return _visitUnary(node);
0543: }
0544:
0545: /**
0546: * Visits a PreIncrement
0547: * @param node the node to visit
0548: */
0549: public Node visit(PreIncrement node) {
0550: return _visitUnary(node);
0551: }
0552:
0553: /**
0554: * Visits a PreDecrement
0555: * @param node the node to visit
0556: */
0557: public Node visit(PreDecrement node) {
0558: return _visitUnary(node);
0559: }
0560:
0561: /**
0562: * Visits a ArrayInitializer
0563: * @param node the node to visit
0564: */
0565: public Node visit(ArrayInitializer node) {
0566: LinkedList<Expression> cells = new LinkedList<Expression>(); // Add parameterization <Node>.
0567: Iterator<Expression> it = node.getCells().iterator();
0568: while (it.hasNext()) {
0569: cells.add((Expression) it.next().acceptVisitor(this ));
0570: }
0571: node.setCells(cells);
0572: node.setElementType((Type) node.getElementType().acceptVisitor(
0573: this ));
0574: return node;
0575: }
0576:
0577: /**
0578: * Visits an ArrayAllocation, check me on this one.
0579: * @param node the node to visit
0580: */
0581: public Node visit(ArrayAllocation node) {
0582: int dim = node.getDimension();
0583: Type creationType = (Type) node.getCreationType()
0584: .acceptVisitor(this );
0585: LinkedList<Expression> sizes = new LinkedList<Expression>(); // Add parameterization <Expression>.
0586: Iterator<Expression> it = node.getSizes().iterator();
0587: while (it.hasNext()) {
0588: sizes.add((Expression) it.next().acceptVisitor(this ));
0589: }
0590: ArrayInitializer ai = null;
0591: if (node.getInitialization() != null) {
0592: ai = (ArrayInitializer) node.getInitialization()
0593: .acceptVisitor(this );
0594: }
0595: node = new ArrayAllocation(
0596: creationType,
0597: new ArrayAllocation.TypeDescriptor(sizes, dim, ai, 0, 0));
0598: return node;
0599: }
0600:
0601: /**
0602: * Visits an SimpleAllocation
0603: * @param node the node to visit
0604: */
0605: public Node visit(SimpleAllocation node) {
0606: node.setCreationType((Type) node.getCreationType()
0607: .acceptVisitor(this ));
0608: LinkedList<Expression> arguments = null; // Add parameterization <Expresion>.
0609: if (node.getArguments() != null) {
0610: arguments = new LinkedList<Expression>(); // Add parameterization <Expression>.
0611: Iterator<Expression> it = node.getArguments().iterator();
0612: while (it.hasNext()) {
0613: arguments.add((Expression) it.next()
0614: .acceptVisitor(this ));
0615: }
0616: }
0617: node.setArguments(arguments);
0618: return node;
0619: }
0620:
0621: /**
0622: * Visits an ClassAllocation
0623: * @param node the node to visit
0624: */
0625: public Node visit(ClassAllocation node) {
0626: node.setCreationType((Type) node.getCreationType()
0627: .acceptVisitor(this ));
0628: LinkedList<Expression> arguments = null; // Add parameterization <Expression>.
0629: if (node.getArguments() != null) {
0630: arguments = new LinkedList<Expression>(); // Add parameterization <Expression>.
0631: Iterator<Expression> it = node.getArguments().iterator();
0632: while (it.hasNext()) {
0633: arguments.add((Expression) it.next()
0634: .acceptVisitor(this ));
0635: }
0636: }
0637: node.setArguments(arguments);
0638: LinkedList<Node> members = new LinkedList<Node>(); // Add parameterization <Node>.
0639: Iterator<Node> it = node.getMembers().iterator();
0640: while (it.hasNext()) {
0641: members.add(it.next().acceptVisitor(this ));
0642: }
0643: node.setMembers(members);
0644: return node;
0645: }
0646:
0647: /**
0648: * Visits an InnerAllocation
0649: * @param node the node to visit
0650: */
0651: public Node visit(InnerAllocation node) {
0652: node.setExpression((Expression) node.getExpression()
0653: .acceptVisitor(this ));
0654: node.setCreationType((Type) node.getCreationType()
0655: .acceptVisitor(this ));
0656: LinkedList<Expression> arguments = null; // Add parameterization <Expression>.
0657: if (node.getArguments() != null) {
0658: arguments = new LinkedList<Expression>(); // Add parameterization <Expression>.
0659: Iterator<Expression> it = node.getArguments().iterator();
0660: while (it.hasNext()) {
0661: arguments.add((Expression) it.next()
0662: .acceptVisitor(this ));
0663: }
0664: }
0665: node.setArguments(arguments);
0666: return node;
0667: }
0668:
0669: /**
0670: * Visits an InnerClassAllocation
0671: * @param node the node to visit
0672: */
0673: public Node visit(InnerClassAllocation node) {
0674: node.setExpression((Expression) node.getExpression()
0675: .acceptVisitor(this ));
0676: node.setCreationType((Type) node.getCreationType()
0677: .acceptVisitor(this ));
0678: LinkedList<Expression> arguments = null; // Add parameterization <Expression>.
0679: if (node.getArguments() != null) {
0680: arguments = new LinkedList<Expression>(); // Add parameterization <Expression>.
0681: Iterator<Expression> it = node.getArguments().iterator();
0682: while (it.hasNext()) {
0683: arguments.add((Expression) it.next()
0684: .acceptVisitor(this ));
0685: }
0686: }
0687: node.setArguments(arguments);
0688: LinkedList<Node> members = new LinkedList<Node>(); // Add parameterization <Node>.
0689: Iterator<Node> it = node.getMembers().iterator();
0690: while (it.hasNext()) {
0691: members.add(it.next().acceptVisitor(this ));
0692: }
0693: node.setMembers(members);
0694: return node;
0695: }
0696:
0697: /**
0698: * Visits a CastExpression
0699: * @param node the node to visit
0700: */
0701: public Node visit(CastExpression node) {
0702: node.setTargetType((Type) node.getTargetType().acceptVisitor(
0703: this ));
0704: node.setExpression((Expression) node.getExpression()
0705: .acceptVisitor(this ));
0706: return node;
0707: }
0708:
0709: /**
0710: * Visits a NotExpression
0711: * @param node the node to visit
0712: */
0713: public Node visit(NotExpression node) {
0714: return _visitUnary(node);
0715: }
0716:
0717: /**
0718: * Visits a ComplementExpression
0719: * @param node the node to visit
0720: */
0721: public Node visit(ComplementExpression node) {
0722: return _visitUnary(node);
0723: }
0724:
0725: /**
0726: * Visits a PlusExpression
0727: * @param node the node to visit
0728: */
0729: public Node visit(PlusExpression node) {
0730: return _visitUnary(node);
0731: }
0732:
0733: /**
0734: * Visits a MinusExpression
0735: * @param node the node to visit
0736: */
0737: public Node visit(MinusExpression node) {
0738: return _visitUnary(node);
0739: }
0740:
0741: /**
0742: * Visits a MultiplyExpression
0743: * @param node the node to visit
0744: */
0745: public Node visit(MultiplyExpression node) {
0746: return _visitBinary(node);
0747: }
0748:
0749: /**
0750: * Visits a DivideExpression
0751: * @param node the node to visit
0752: */
0753: public Node visit(DivideExpression node) {
0754: return _visitBinary(node);
0755: }
0756:
0757: /**
0758: * Visits a RemainderExpression
0759: * @param node the node to visit
0760: */
0761: public Node visit(RemainderExpression node) {
0762: return _visitBinary(node);
0763: }
0764:
0765: /**
0766: * Visits a AddExpression
0767: * @param node the node to visit
0768: */
0769: public Node visit(AddExpression node) {
0770: return _visitBinary(node);
0771: }
0772:
0773: /**
0774: * Visits a SubtractExpression
0775: * @param node the node to visit
0776: */
0777: public Node visit(SubtractExpression node) {
0778: return _visitBinary(node);
0779: }
0780:
0781: /**
0782: * Visits a ShiftLeftExpression
0783: * @param node the node to visit
0784: */
0785: public Node visit(ShiftLeftExpression node) {
0786: return _visitBinary(node);
0787: }
0788:
0789: /**
0790: * Visits a ShiftRightExpression
0791: * @param node the node to visit
0792: */
0793: public Node visit(ShiftRightExpression node) {
0794: return _visitBinary(node);
0795: }
0796:
0797: /**
0798: * Visits a UnsignedShiftRightExpression
0799: * @param node the node to visit
0800: */
0801: public Node visit(UnsignedShiftRightExpression node) {
0802: return _visitBinary(node);
0803: }
0804:
0805: /**
0806: * Visits a LessExpression
0807: * @param node the node to visit
0808: */
0809: public Node visit(LessExpression node) {
0810: return _visitBinary(node);
0811: }
0812:
0813: /**
0814: * Visits a GreaterExpression
0815: * @param node the node to visit
0816: */
0817: public Node visit(GreaterExpression node) {
0818: return _visitBinary(node);
0819: }
0820:
0821: /**
0822: * Visits a LessOrEqualExpression
0823: * @param node the node to visit
0824: */
0825: public Node visit(LessOrEqualExpression node) {
0826: return _visitBinary(node);
0827: }
0828:
0829: /**
0830: * Visits a GreaterOrEqualExpression
0831: * @param node the node to visit
0832: */
0833: public Node visit(GreaterOrEqualExpression node) {
0834: return _visitBinary(node);
0835: }
0836:
0837: /**
0838: * Visits a InstanceOfExpression
0839: * @param node the node to visit
0840: */
0841: public Node visit(InstanceOfExpression node) {
0842: node.setExpression((Expression) node.getExpression()
0843: .acceptVisitor(this ));
0844: node.setReferenceType((Type) node.getReferenceType()
0845: .acceptVisitor(this ));
0846: return node;
0847: }
0848:
0849: /**
0850: * Visits a EqualExpression
0851: * @param node the node to visit
0852: */
0853: public Node visit(EqualExpression node) {
0854: return _visitBinary(node);
0855: }
0856:
0857: /**
0858: * Visits a NotEqualExpression
0859: * @param node the node to visit
0860: */
0861: public Node visit(NotEqualExpression node) {
0862: return _visitBinary(node);
0863: }
0864:
0865: /**
0866: * Visits a BitAndExpression
0867: * @param node the node to visit
0868: */
0869: public Node visit(BitAndExpression node) {
0870: return _visitBinary(node);
0871: }
0872:
0873: /**
0874: * Visits a ExclusiveOrExpression
0875: * @param node the node to visit
0876: */
0877: public Node visit(ExclusiveOrExpression node) {
0878: return _visitBinary(node);
0879: }
0880:
0881: /**
0882: * Visits a BitOrExpression
0883: * @param node the node to visit
0884: */
0885: public Node visit(BitOrExpression node) {
0886: return _visitBinary(node);
0887: }
0888:
0889: /**
0890: * Visits an AndExpression
0891: * @param node the node to visit
0892: */
0893: public Node visit(AndExpression node) {
0894: return _visitBinary(node);
0895: }
0896:
0897: /**
0898: * Visits an OrExpression
0899: * @param node the node to visit
0900: */
0901: public Node visit(OrExpression node) {
0902: return _visitBinary(node);
0903: }
0904:
0905: /**
0906: * Visits a ConditionalExpression
0907: * @param node the node to visit
0908: */
0909: public Node visit(ConditionalExpression node) {
0910: node.setConditionExpression((Expression) node
0911: .getConditionExpression().acceptVisitor(this ));
0912: node.setIfTrueExpression((Expression) node
0913: .getIfTrueExpression().acceptVisitor(this ));
0914: node.setIfFalseExpression((Expression) node
0915: .getIfFalseExpression().acceptVisitor(this ));
0916: return node;
0917: }
0918:
0919: /**
0920: * Visits an SimpleAssignExpression
0921: * @param node the node to visit
0922: */
0923: public Node visit(SimpleAssignExpression node) {
0924: return _visitBinary(node);
0925: }
0926:
0927: /**
0928: * Visits an MultiplyAssignExpression
0929: * @param node the node to visit
0930: */
0931: public Node visit(MultiplyAssignExpression node) {
0932: return _visitBinary(node);
0933: }
0934:
0935: /**
0936: * Visits an DivideAssignExpression
0937: * @param node the node to visit
0938: */
0939: public Node visit(DivideAssignExpression node) {
0940: return _visitBinary(node);
0941: }
0942:
0943: /**
0944: * Visits an RemainderAssignExpression
0945: * @param node the node to visit
0946: */
0947: public Node visit(RemainderAssignExpression node) {
0948: return _visitBinary(node);
0949: }
0950:
0951: /**
0952: * Visits an AddAssignExpression
0953: * @param node the node to visit
0954: */
0955: public Node visit(AddAssignExpression node) {
0956: return _visitBinary(node);
0957: }
0958:
0959: /**
0960: * Visits an SubtractAssignExpression
0961: * @param node the node to visit
0962: */
0963: public Node visit(SubtractAssignExpression node) {
0964: return _visitBinary(node);
0965: }
0966:
0967: /**
0968: * Visits an ShiftLeftAssignExpression
0969: * @param node the node to visit
0970: */
0971: public Node visit(ShiftLeftAssignExpression node) {
0972: return _visitBinary(node);
0973: }
0974:
0975: /**
0976: * Visits an ShiftRightAssignExpression
0977: * @param node the node to visit
0978: */
0979: public Node visit(ShiftRightAssignExpression node) {
0980: return _visitBinary(node);
0981: }
0982:
0983: /**
0984: * Visits an UnsignedShiftRightAssignExpression
0985: * @param node the node to visit
0986: */
0987: public Node visit(UnsignedShiftRightAssignExpression node) {
0988: return _visitBinary(node);
0989: }
0990:
0991: /**
0992: * Visits a BitAndAssignExpression
0993: * @param node the node to visit
0994: */
0995: public Node visit(BitAndAssignExpression node) {
0996: return _visitBinary(node);
0997: }
0998:
0999: /**
1000: * Visits a ExclusiveOrAssignExpression
1001: * @param node the node to visit
1002: */
1003: public Node visit(ExclusiveOrAssignExpression node) {
1004: return _visitBinary(node);
1005: }
1006:
1007: /**
1008: * Visits a BitOrAssignExpression
1009: * @param node the node to visit
1010: */
1011: public Node visit(BitOrAssignExpression node) {
1012: return _visitBinary(node);
1013: }
1014:
1015: /**
1016: * Visits a BlockStatement
1017: * @param node the node to visit
1018: */
1019: public Node visit(BlockStatement node) {
1020: LinkedList<Node> statements = new LinkedList<Node>(); // Add parameterization <Node>.
1021: Iterator<Node> it = node.getStatements().iterator();
1022: while (it.hasNext()) {
1023: statements.add(it.next().acceptVisitor(this ));
1024: }
1025: node.setStatements(statements);
1026: return node;
1027: }
1028:
1029: /**
1030: * Visits a ClassDeclaration
1031: * @param node the node to visit
1032: */
1033: public Node visit(ClassDeclaration node) {
1034: LinkedList<Node> members = new LinkedList<Node>(); // Add parameterization <Node>.
1035: Iterator<Node> it = node.getMembers().iterator();
1036: while (it.hasNext()) {
1037: members.add(it.next().acceptVisitor(this ));
1038: }
1039: node.setMembers(members);
1040: return node;
1041: }
1042:
1043: /**
1044: * Visits an InterfaceDeclaration
1045: * @param node the node to visit
1046: */
1047: public Node visit(InterfaceDeclaration node) {
1048: LinkedList<Node> members = new LinkedList<Node>(); // Add parameterization <Node>.
1049: Iterator<Node> it = node.getMembers().iterator();
1050: while (it.hasNext()) {
1051: members.add(it.next().acceptVisitor(this ));
1052: }
1053: node.setMembers(members);
1054: return node;
1055: }
1056:
1057: /**
1058: * Visits a ConstructorDeclaration
1059: * @param node the node to visit
1060: */
1061: public Node visit(ConstructorDeclaration node) {
1062: LinkedList<FormalParameter> parameters = new LinkedList<FormalParameter>(); // Add parameterization <Node>.
1063: Iterator<FormalParameter> it1 = node.getParameters().iterator();
1064: while (it1.hasNext()) {
1065: parameters.add((FormalParameter) it1.next().acceptVisitor(
1066: this ));
1067: }
1068: node.setParameters(parameters);
1069: if (node.getConstructorInvocation() != null) {
1070: node.setConstructorInvocation((ConstructorInvocation) node
1071: .getConstructorInvocation().acceptVisitor(this ));
1072: }
1073: LinkedList<Node> statements = new LinkedList<Node>(); // Add parameterization <Node>.
1074: Iterator<Node> it2 = node.getStatements().iterator();
1075: while (it2.hasNext()) {
1076: statements.add(it2.next().acceptVisitor(this ));
1077: }
1078: node.setStatements(statements);
1079: return node;
1080: }
1081:
1082: /**
1083: * Visits a MethodDeclaration
1084: * @param node the node to visit
1085: */
1086: public Node visit(MethodDeclaration node) {
1087: node.setReturnType((Type) node.getReturnType().acceptVisitor(
1088: this ));
1089: LinkedList<FormalParameter> parameters = new LinkedList<FormalParameter>(); // Add parameterization <Node>.
1090: Iterator<FormalParameter> it = node.getParameters().iterator();
1091: while (it.hasNext()) {
1092: parameters.add((FormalParameter) it.next().acceptVisitor(
1093: this ));
1094: }
1095: node.setParameters(parameters);
1096: if (node.getBody() != null) {
1097: node.setBody((BlockStatement) node.getBody().acceptVisitor(
1098: this ));
1099: }
1100: return node;
1101: }
1102:
1103: /**
1104: * Visits a FormalParameter
1105: * @param node the node to visit
1106: */
1107: public Node visit(FormalParameter node) {
1108: node.setType((Type) node.getType().acceptVisitor(this ));
1109: return node;
1110: }
1111:
1112: /**
1113: * Visits a FieldDeclaration
1114: * @param node the node to visit
1115: */
1116: public Node visit(FieldDeclaration node) {
1117: node.setType((Type) node.getType().acceptVisitor(this ));
1118: if (node.getInitializer() != null) {
1119: node.setInitializer((Expression) node.getInitializer()
1120: .acceptVisitor(this ));
1121: }
1122: return node;
1123: }
1124:
1125: /**
1126: * Visits a VariableDeclaration
1127: * @param node the node to visit
1128: */
1129: public Node visit(VariableDeclaration node) {
1130: node.setType((Type) node.getType().acceptVisitor(this ));
1131: if (node.getInitializer() != null) {
1132: node.setInitializer((Expression) node.getInitializer()
1133: .acceptVisitor(this ));
1134: }
1135: return node;
1136: }
1137:
1138: /**
1139: * Visits a ClassInitializer
1140: * @param node the node to visit
1141: */
1142: public Node visit(ClassInitializer node) {
1143: node.setBlock((BlockStatement) node.getBlock().acceptVisitor(
1144: this ));
1145: return node;
1146: }
1147:
1148: /**
1149: * Visits a InstanceInitializer
1150: * @param node the node to visit
1151: */
1152: public Node visit(InstanceInitializer node) {
1153: node.setBlock((BlockStatement) node.getBlock().acceptVisitor(
1154: this ));
1155: return node;
1156: }
1157:
1158: private Node _visitUnary(UnaryExpression node) {
1159: node.setExpression((Expression) node.getExpression()
1160: .acceptVisitor(this ));
1161: return node;
1162: }
1163:
1164: private Node _visitBinary(BinaryExpression node) {
1165: node.setLeftExpression((Expression) node.getLeftExpression()
1166: .acceptVisitor(this ));
1167: node.setRightExpression((Expression) node.getRightExpression()
1168: .acceptVisitor(this));
1169: return node;
1170: }
1171: }
|