org.eigenbase.oj.util
Class OJUtil

java.lang.Object
  extended by org.eigenbase.oj.util.OJUtil

public abstract class OJUtil
extends Object

Static utilities for manipulating OpenJava expressions.


Nested Class Summary
static class OJUtil.StopIterationException
          A StopIterationException is a way to tell a ParseTreeVisitor to halt traversal of the tree, but is not regarded as an error.
 
Field Summary
static OJClass clazzArrays
           
static OJClass clazzClass
           
static OJClass clazzCollection
           
static OJClass clazzComparable
           
static OJClass clazzComparator
           
static OJClass clazzEntry
           
static OJClass clazzEnumeration
           
static OJClass clazzHashtable
           
static OJClass clazzInteger
           
static OJClass clazzIterable
           
static OJClass clazzIterator
           
static OJClass clazzList
           
static OJClass clazzMap
           
static OJClass clazzMapEntry
           
static OJClass clazzObject
           
static OJClass clazzObjectArray
           
static OJClass clazzRestartableIterator
           
static OJClass clazzResultSet
           
static OJClass clazzSet
           
static OJClass clazzSQLException
           
static OJClass clazzString
           
static OJClass clazzTupleIter
           
static OJClass clazzVector
           
static OJClass clazzVoid
           
static OJClass[] emptyArrayOfOJClass
           
static ModifierList modFinal
           
static ThreadLocal<OJClass> threadDeclarers
          Each thread's enclosing OJClass.
private static ThreadLocal<OJTypeFactory> threadTypeFactories
           
static TypeName tnArrays
           
static TypeName tnInt
           
static TypeName tnList
           
static TypeName tnObject
           
static TypeName tnRestartableIterator
           
 
Constructor Summary
OJUtil()
           
 
Method Summary
static Expression box(OJClass clazz, Expression exp)
          Ensures that an expression is an object.
static int countParseTreeNodes(ParseTree parseTree)
          Counts the number of nodes in a parse tree.
static GlobalEnvironment getGlobalEnvironment(Environment env)
          Gets the root environment, which is always a GlobalEnvironment.
static OJClass getType(Environment env, Expression exp)
           
static Expression go(ParseTreeVisitor visitor, Expression p)
          Sets a ParseTreeVisitor going on a given non-relational expression, and returns the result.
static ParseTree go(ParseTreeVisitor visitor, ParseTree p)
          Sets a ParseTreeVisitor going on a parse tree, and returns the result.
static OJClass guessRowType(OJClass clazz)
          Guesses the row-type of an expression which has type clazz.
static Object literalValue(Literal literal)
           
static RelDataType ojToType(RelDataTypeFactory typeFactory, OJClass ojClass)
           
static void recordMemberClass(Environment env, String declarerName, String innerName)
          If env is a ClassEnvironment for declarerName, records new inner class innerName; otherwise, delegates up the environment hierarchy.
static String replaceDotWithDollar(String base, int i)
           
static void setThreadTypeFactory(OJTypeFactory typeFactory)
           
static OJTypeFactory threadTypeFactory()
           
static TypeName toTypeName(RelDataType rowType, RelDataTypeFactory typeFactory)
          Converts a RelDataType to a TypeName.
static TypeName typeNameForClass(Class clazz)
           
static OJClass typeToOJClass(OJClass declarer, RelDataType rowType, RelDataTypeFactory typeFactory)
           
static OJClass typeToOJClass(RelDataType rowType, RelDataTypeFactory typeFactory)
          Converts a RelDataType to a OJClass.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

clazzVoid

public static final OJClass clazzVoid

clazzObject

public static final OJClass clazzObject

clazzObjectArray

public static final OJClass clazzObjectArray

clazzCollection

public static final OJClass clazzCollection

clazzMap

public static final OJClass clazzMap

clazzMapEntry

public static final OJClass clazzMapEntry

clazzHashtable

public static final OJClass clazzHashtable

clazzEnumeration

public static final OJClass clazzEnumeration

clazzIterator

public static final OJClass clazzIterator

clazzIterable

public static final OJClass clazzIterable

clazzTupleIter

public static final OJClass clazzTupleIter

clazzVector

public static final OJClass clazzVector

clazzComparable

public static final OJClass clazzComparable

clazzComparator

public static final OJClass clazzComparator

clazzResultSet

public static final OJClass clazzResultSet

clazzClass

public static final OJClass clazzClass

clazzString

public static final OJClass clazzString

clazzSet

public static final OJClass clazzSet

clazzSQLException

public static final OJClass clazzSQLException

clazzEntry

public static final OJClass clazzEntry

emptyArrayOfOJClass

public static final OJClass[] emptyArrayOfOJClass

modFinal

public static final ModifierList modFinal

clazzInteger

public static final OJClass clazzInteger

tnInt

public static final TypeName tnInt

clazzList

public static final OJClass clazzList

tnList

public static final TypeName tnList

clazzArrays

public static final OJClass clazzArrays

tnArrays

public static final TypeName tnArrays

tnObject

public static final TypeName tnObject

clazzRestartableIterator

public static final OJClass clazzRestartableIterator

tnRestartableIterator

public static TypeName tnRestartableIterator

threadDeclarers

public static final ThreadLocal<OJClass> threadDeclarers
Each thread's enclosing OJClass. Synthetic classes are declared as inner classes of this.


threadTypeFactories

private static final ThreadLocal<OJTypeFactory> threadTypeFactories
Constructor Detail

OJUtil

public OJUtil()
Method Detail

setThreadTypeFactory

public static void setThreadTypeFactory(OJTypeFactory typeFactory)

threadTypeFactory

public static OJTypeFactory threadTypeFactory()

ojToType

public static RelDataType ojToType(RelDataTypeFactory typeFactory,
                                   OJClass ojClass)

toTypeName

public static TypeName toTypeName(RelDataType rowType,
                                  RelDataTypeFactory typeFactory)
Converts a RelDataType to a TypeName.

"Precondition:"
threadDeclarers.get() != null

typeToOJClass

public static OJClass typeToOJClass(OJClass declarer,
                                    RelDataType rowType,
                                    RelDataTypeFactory typeFactory)

typeToOJClass

public static OJClass typeToOJClass(RelDataType rowType,
                                    RelDataTypeFactory typeFactory)
Converts a RelDataType to a OJClass.

"Precondition:"
threadDeclarers.get() != null

literalValue

public static Object literalValue(Literal literal)

typeNameForClass

public static TypeName typeNameForClass(Class clazz)

replaceDotWithDollar

public static String replaceDotWithDollar(String base,
                                          int i)

guessRowType

public static final OJClass guessRowType(OJClass clazz)
Guesses the row-type of an expression which has type clazz. For example, String[] --> String; Iterator --> Object.


go

public static ParseTree go(ParseTreeVisitor visitor,
                           ParseTree p)
Sets a ParseTreeVisitor going on a parse tree, and returns the result.


go

public static Expression go(ParseTreeVisitor visitor,
                            Expression p)
Sets a ParseTreeVisitor going on a given non-relational expression, and returns the result.


box

public static Expression box(OJClass clazz,
                             Expression exp)
Ensures that an expression is an object. Primitive expressions are wrapped in a constructor (for example, the int expression 2 + 3 becomes new Integer(2 + 3)); non-primitive expressions are unchanged.

Parameters:
exp - an expression
clazz - exp's type
Returns:
a call to the constructor of a wrapper class if exp is primitive, exp otherwise

getGlobalEnvironment

public static GlobalEnvironment getGlobalEnvironment(Environment env)
Gets the root environment, which is always a GlobalEnvironment.

Parameters:
env - environment to start search from

recordMemberClass

public static void recordMemberClass(Environment env,
                                     String declarerName,
                                     String innerName)
If env is a ClassEnvironment for declarerName, records new inner class innerName; otherwise, delegates up the environment hierarchy.

Parameters:
env - environment to start search from
declarerName - fully-qualified name of enclosing class
innerName - simple name of inner class

getType

public static OJClass getType(Environment env,
                              Expression exp)

countParseTreeNodes

public static int countParseTreeNodes(ParseTree parseTree)
Counts the number of nodes in a parse tree.

Parameters:
parseTree - tree to walk
Returns:
count of nodes