001/* 002// $Id: ParseTreeNode.java 482 2012-01-05 23:27:27Z jhyde $ 003// 004// Licensed to Julian Hyde under one or more contributor license 005// agreements. See the NOTICE file distributed with this work for 006// additional information regarding copyright ownership. 007// 008// Julian Hyde licenses this file to you under the Apache License, 009// Version 2.0 (the "License"); you may not use this file except in 010// compliance with the License. You may obtain a copy of the License at: 011// 012// http://www.apache.org/licenses/LICENSE-2.0 013// 014// Unless required by applicable law or agreed to in writing, software 015// distributed under the License is distributed on an "AS IS" BASIS, 016// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 017// See the License for the specific language governing permissions and 018// limitations under the License. 019*/ 020package org.olap4j.mdx; 021 022import org.olap4j.type.Type; 023 024/** 025 * Node in a parse tree representing a parsed MDX statement. 026 * 027 * <p>To convert a parse tree to an MDX string, use a {@link ParseTreeWriter} 028 * and the {@link #unparse(ParseTreeWriter)} method. 029 * 030 * @author jhyde 031 * @version $Id: ParseTreeNode.java 482 2012-01-05 23:27:27Z jhyde $ 032 * @since Jun 4, 2007 033 */ 034public interface ParseTreeNode { 035 /** 036 * Accepts a visitor to this MDX parse tree node. 037 * 038 * <p>The implementation should generally dispatches to the 039 * {@link ParseTreeVisitor#visit} method appropriate to the type of expression. 040 * 041 * @param visitor Visitor 042 * @return T, the specific return type of the visitor 043 */ 044 <T> T accept(ParseTreeVisitor<T> visitor); 045 046 /** 047 * Returns the type of this expression. 048 * 049 * <p>Returns null if this node is not an expression, for instance a 050 * <code>SELECT</code> node. 051 * 052 * @return type of this expression 053 */ 054 Type getType(); 055 056 /** 057 * Converts this node into MDX text. 058 * 059 * @param writer Parse tree writer 060 */ 061 void unparse(ParseTreeWriter writer); 062 063 /** 064 * Returns the region of the source code which this node was created from, 065 * if it was created by parsing. 066 * 067 * <p>A non-leaf node's region will encompass the regions of all of its 068 * children. For example, a the region of a function call node 069 * <code>Crossjoin([Gender], {[Store].[USA]})</code> stretches from 070 * the first character of the function name to the closing parenthesis. 071 * 072 * <p>Region may be null, if the node was created programmatically, not 073 * from a piece of source code. 074 * 075 * @return Region of the source code this node was created from, if it was 076 * created by parsing 077 */ 078 ParseRegion getRegion(); 079 080 /** 081 * Creates a deep copy of this ParseTreeNode object. 082 * 083 * <p>Note: implementing classes can return the concrete type instead 084 * of ParseTreeNode (using Java 1.5 covariant return types) 085 * 086 * @return The deep copy of this ParseTreeNode 087 */ 088 ParseTreeNode deepCopy(); 089 090} 091 092// End ParseTreeNode.java