001 /* 002 // $Id: ParseTreeNode.java 229 2009-05-08 19:11:29Z jhyde $ 003 // This software is subject to the terms of the Eclipse Public License v1.0 004 // Agreement, available at the following URL: 005 // http://www.eclipse.org/legal/epl-v10.html. 006 // Copyright (C) 2007-2009 Julian Hyde 007 // All Rights Reserved. 008 // You must accept the terms of that agreement to use this software. 009 */ 010 package org.olap4j.mdx; 011 012 import org.olap4j.type.Type; 013 014 /** 015 * Node in a parse tree representing a parsed MDX statement. 016 * 017 * <p>To convert a parse tree to an MDX string, use a {@link ParseTreeWriter} 018 * and the {@link #unparse(ParseTreeWriter)} method. 019 * 020 * @author jhyde 021 * @version $Id: ParseTreeNode.java 229 2009-05-08 19:11:29Z jhyde $ 022 * @since Jun 4, 2007 023 */ 024 public interface ParseTreeNode { 025 /** 026 * Accepts a visitor to this MDX parse tree node. 027 * 028 * <p>The implementation should generally dispatches to the 029 * {@link ParseTreeVisitor#visit} method appropriate to the type of expression. 030 * 031 * @param visitor Visitor 032 * @return T, the specific return type of the visitor 033 */ 034 <T> T accept(ParseTreeVisitor<T> visitor); 035 036 /** 037 * Returns the type of this expression. 038 * 039 * <p>Returns null if this node is not an expression, for instance a 040 * <code>SELECT</code> node. 041 * 042 * @return type of this expression 043 */ 044 Type getType(); 045 046 /** 047 * Converts this node into MDX text. 048 * 049 * @param writer Parse tree writer 050 */ 051 void unparse(ParseTreeWriter writer); 052 053 /** 054 * Returns the region of the source code which this node was created from, 055 * if it was created by parsing. 056 * 057 * <p>A non-leaf node's region will encompass the regions of all of its 058 * children. For example, a the region of a function call node 059 * <code>Crossjoin([Gender], {[Store].[USA]})</code> stretches from 060 * the first character of the function name to the closing parenthesis. 061 * 062 * <p>Region may be null, if the node was created programmatically, not 063 * from a piece of source code. 064 * 065 * @return Region of the source code this node was created from, if it was 066 * created by parsing 067 */ 068 ParseRegion getRegion(); 069 070 /** 071 * Creates a deep copy of this ParseTreeNode object. 072 * 073 * <p>Note: implementing classes can return the concrete type instead 074 * of ParseTreeNode (using Java 1.5 covariant return types) 075 * 076 * @return The deep copy of this ParseTreeNode 077 */ 078 ParseTreeNode deepCopy(); 079 080 } 081 082 // End ParseTreeNode.java