| /******************************************************************************* |
| * Copyright (c) 2004, 2006 IBM Corporation and others. |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License v1.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/epl-v10.html |
| * |
| * Contributors: |
| * IBM Corporation - initial API and implementation |
| *******************************************************************************/ |
| package org.eclipse.gymnast.generator.core.ast; |
| |
| import org.eclipse.gymnast.runtime.core.ast.ASTNode; |
| import org.eclipse.gymnast.runtime.core.ast.ASTNodeImpl; |
| import org.eclipse.gymnast.runtime.core.ast.TokenInfo; |
| |
| import antlr.Token; |
| |
| |
| /** |
| * The superclass of all ASTNodes for language Gymnast. |
| * |
| * @generated by Gymnast from gymnast.ast on Aug 15, 2004 2:28:15 PM |
| */ |
| public abstract class GymnastASTNode extends ASTNodeImpl { |
| |
| protected GymnastASTNode _parent; |
| |
| /** |
| * @return the parent of this ASTNode or null if this is the root node of a tree |
| */ |
| public ASTNode getParent() { |
| return _parent; |
| } |
| |
| /** |
| * Construct a new GymnastASTNode. |
| */ |
| public GymnastASTNode() { |
| super(); |
| } |
| |
| /** |
| * Construct a new GymnastASTNode. |
| * |
| * @param token a Token to initialize the offset and text for this node. |
| */ |
| public GymnastASTNode(Token token) { |
| super(new TokenInfo(token.getText(), token.getColumn(), token.getType())); |
| } |
| |
| /** |
| * The external entry point used to initiate the visitor on this node. |
| * |
| * @param visitor the Visitor to visit this node tree |
| */ |
| public final void accept(GymnastASTNodeVisitor visitor) { |
| visitor.preVisit(this); |
| acceptImpl(visitor); |
| visitor.postVisit(this); |
| } |
| |
| /** |
| * This method can be overridden by subclasses which should provide exactly |
| * the same implementation. Here <code>this</code> refers to the generic node |
| * class, but in the subclass implementations <code>this</code> will refer to |
| * the specific subclass type. Thus the correct specific <code>beginVisit</code> |
| * and <code>endVisit</code> methods will be invoked for each subclass and the |
| * generic methods will be invoked for subclasses that don't need specific visitor |
| * behavior. |
| */ |
| public void acceptImpl(GymnastASTNodeVisitor visitor) { |
| boolean visitChildren = visitor.beginVisit(this); |
| if (visitChildren) visitChildren(visitor); |
| visitor.endVisit(this); |
| } |
| |
| /** |
| * Iterate through the children of this node and accept the visitor on each. |
| */ |
| protected void visitChildren(GymnastASTNodeVisitor visitor) { |
| for (int i = 0; i < getChildCount(); i++) { |
| ASTNode child = getChild(i); |
| if (child instanceof GymnastASTNode) { |
| GymnastASTNode c = (GymnastASTNode)child; |
| c.accept(visitor); |
| } |
| } |
| } |
| |
| } |