openjava.mop
Class Toolbox

java.lang.Object
  |
  +--openjava.mop.Toolbox
Direct Known Subclasses:
Util

public abstract class Toolbox
extends Object

The class Toolbox is a utility class.

 

Since:
%SOFTWARE% 1.0
Version:
1.0
Author:
Michiaki Tatsubori
See Also:
Object

Nested Class Summary
static class Toolbox.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 clazzAggAndAcc
           
static OJClass clazzAggregationExtender
           
static OJClass clazzClass
           
static OJClass clazzCollection
           
static OJClass clazzComparable
           
static OJClass clazzComparator
           
static OJClass clazzConnection
           
static OJClass clazzEntry
           
static OJClass clazzEnumeration
           
static OJClass clazzHashtable
           
static OJClass clazzIterable
           
static OJClass clazzIterator
           
static OJClass clazzMap
           
static OJClass clazzMapEntry
           
static OJClass clazzObject
           
static OJClass clazzObjectArray
           
static OJClass clazzResultSet
           
static OJClass clazzSaffronUtil
           
static OJClass clazzSet
           
static OJClass clazzSQLException
           
static OJClass clazzString
           
static OJClass clazzSyntheticObject
           
static OJClass clazzVector
           
static OJClass clazzVoid
           
static OJClass[] emptyArrayOfOJClass
           
private static String PARAMETER_NAME
           
 
Constructor Summary
Toolbox()
           
 
Method Summary
static OJClass[] append(OJClass[] a, OJClass[] b)
           
static OJConstructor[] append(OJConstructor[] a, OJConstructor[] b)
           
static OJField[] append(OJField[] a, OJField[] b)
           
static OJMethod[] append(OJMethod[] a, OJMethod[] b)
           
static OJClass[] arrayForNames(Environment env, String[] names)
           
static Expression box(OJClass clazz, Expression exp)
          Ensures that an expression is an object.
static Expression castObject(Expression exp, OJClass fromClazz, OJClass toClazz)
          Converts an expression of type Object into an appropriate type.
static OJClass forNameAnyway(Environment env, String name)
           
static ParameterList generateParameters(OJClass[] parameterTypes)
           
static ParameterList generateParameters(OJClass[] parameterTypes, String[] parameterNames)
           
static String getAlias(Expression expression)
          Gets or derives the alias of an expression.
static OJClass getRowType(Environment env, Expression exp)
           
private static SaffronSchema getSaffronSchema(ParseTree expr, Environment env)
           
static SaffronTable getTable(Environment env, ParseTree expr, String qualifier, String name)
          Converts a field access into a table.
static OJClass getType(Environment env, Expression exp)
           
static OJClass getType(Environment env, ParseTree ref)
          Finds the type of a parse tree node (which may be an Expression or a TypeName).
static OJClass[] getTypes(Environment env, Expression[] exps)
           
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 Class guessRowType(Class clazz)
          Guesses the row-type of an expression which has type clazz.
static OJClass guessRowType(OJClass clazz)
          Guesses the row-type of an expression which has type clazz.
static boolean isAcceptable(OJClass[] accepter, OJClass[] acceptee)
           
static boolean isAdaptableTo(OJClass[] adapter, OJClass[] adaptee)
           
static Expression[] isEquals(Expression expression)
          If the expression is an equals condition, returns the two arguments, otherwise returns null.
static boolean isSame(OJClass[] accepter, OJClass[] acceptee)
           
static OJClass lookupAnonymousClass(ClassEnvironment env, AllocationExpression allocExp)
          Creates or (subsequently) retrieves a class object corresponding to the declaration of an anonymous class.
static Expression makeEquals(Expression left, Expression right, OJClass type, boolean nullable)
          Generates an equality condition appropriate for the types of the operands.
static String nameForJavaClassName(String jcname)
           
static String nameToJavaClassName(String ojcname)
           
static RuntimeException needToImplement(Object o)
          Returns a RuntimeException indicating that a particular feature has not been implemented, but should be.
static Error newInternal()
           
static Error newInternal(String s)
           
static Error newInternal(Throwable e)
           
static Error newInternal(Throwable e, String s)
           
static OJClass[] overridesOn(OJClass[] declareds, OJClass[] bases)
          Generates an array of classes containing the declared classes and the based classes except the declared one.
static OJField[] overridesOn(OJField[] declareds, OJField[] bases)
          Generates an array of fields containing the declared fields and the based fields except the declared one.
static OJMethod[] overridesOn(OJMethod[] declareds, OJMethod[] bases)
          Generates an array of methods containing the declared methods and the based methods except the declared one.
static OJConstructor pickupAcceptableConstructor(OJConstructor[] src_constrs, OJClass[] param_types)
          Pick up a constructor with the signature acceptable the specified signature in the source array of constructors.
static OJConstructor[] pickupAcceptableConstructors(OJConstructor[] src_constrs, OJClass[] param_types)
          Generates an array of constructors containing the constructors with the specified parameter types in the source array of constructors.
static OJMethod pickupAcceptableMethod(OJMethod[] src_methods, String name, OJClass[] param_types)
          Pick up a method with the signature acceptable the specified signature in the source array of methods.
static OJMethod[] pickupAcceptableMethods(OJMethod[] src_methods, String name, OJClass[] param_types)
          Generates an array of methods containing the methods with the signature acceptable the specified signature in the source array of methods.
static OJMethod[] pickupAcceptableMethodsByParameterTypes(OJMethod[] src_methods, OJClass[] param_types)
          Generates an array of methods containing the methods with the parameter types acceptable specified parameter types in the source array of methods.
static OJConstructor pickupConstructor(OJConstructor[] src_constrs, OJClass[] param_types)
          Pick up a constructor with the specified signature in the source array of constructors.
static OJField pickupField(OJField[] src_fields, String name)
          Pick up a field with the specified name in the source array of fields.
static OJMethod pickupMethod(OJMethod[] src_methods, String name, OJClass[] param_types)
          Pick up a method with the specified signature in the source array of methods.
static OJMethod pickupMethodByParameterTypes(OJMethod[] src_methods, OJClass[] param_types)
          Picks up a method with the specified parameter types in the source array of methods.
static OJMethod[] pickupMethodsByName(OJMethod[] src_methods, String name)
          Generates an array of methods containing the methods with the specified name in the source array of methods.
static OJConstructor pickupMostSpecified(OJConstructor[] constrs)
           
static OJMethod pickupMostSpecified(OJMethod[] methods)
           
static void pre(boolean b, String description)
           
static OJClass[] removeTheDefaults(OJClass[] src_classes)
          Generates an array of classes containing the source classes except ones with private access modifier.
static OJConstructor[] removeTheDefaults(OJConstructor[] src_constrs)
          Generates an array of constructors containing the source constructors except ones with private access modifier.
static OJField[] removeTheDefaults(OJField[] src_fields)
          Generates an array of fields containing the source fields except ones with private access modifier.
static OJMethod[] removeTheDefaults(OJMethod[] src_methods)
          Generates an array of methods containing the source methods except ones with private access modifier.
static OJClass[] removeTheNonPublics(OJClass[] src_classes)
          Generates an array of classes containing the source classes except ones with non-public access modifier; one of private, protected or package level access modifiers.
static OJConstructor[] removeTheNonPublics(OJConstructor[] src_constrs)
          Generates an array of constructors containing the source constructors except ones with non-public access modifier; one of private, protected or package level access modifiers.
static OJField[] removeTheNonPublics(OJField[] src_fields)
          Generates an array of fields containing the source fields except ones with non-public access modifier; one of private, protected or package level access modifiers.
static OJMethod[] removeTheNonPublics(OJMethod[] src_methods)
          Generates an array of methods containing the source methods except ones with non-public access modifier; one of private, protected or package level access modifiers.
static OJClass[] removeThePrivates(OJClass[] src_classes)
          Generates an array of classes containing the source classes except ones with private access modifier.
static OJConstructor[] removeThePrivates(OJConstructor[] src_constrs)
          Generates an array of constructors containing the source constructors except ones with private access modifier.
static OJField[] removeThePrivates(OJField[] src_fields)
          Generates an array of fields containing the source fields except ones with private access modifier.
static OJMethod[] removeThePrivates(OJMethod[] src_methods)
          Generates an array of methods containing the source methods except ones with private access modifier.
private static String stripBrackets(String ojcname)
           
private static String stripHeadBracket(String jcname)
           
static TypeName[] TNsForOJClasses(OJClass[] classes)
           
static Expression[] toArray(ExpressionList expressionList)
           
static ExpressionList toList(Expression[] exps)
           
private static Expression unbox(OJClass clazz, Expression exp)
          Converts an expression representing a wrapped primitive into a primitive.
 
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

clazzConnection

public static final OJClass clazzConnection

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

clazzVector

public static final OJClass clazzVector

clazzComparable

public static final OJClass clazzComparable

clazzComparator

public static final OJClass clazzComparator

clazzResultSet

public static final OJClass clazzResultSet

clazzAggregationExtender

public static final OJClass clazzAggregationExtender

clazzAggAndAcc

public static final OJClass clazzAggAndAcc

clazzSyntheticObject

public static final OJClass clazzSyntheticObject

clazzClass

public static final OJClass clazzClass

clazzString

public static final OJClass clazzString

clazzSaffronUtil

public static final OJClass clazzSaffronUtil

clazzSet

public static final OJClass clazzSet

clazzSQLException

public static final OJClass clazzSQLException

clazzEntry

public static final OJClass clazzEntry

emptyArrayOfOJClass

public static final OJClass[] emptyArrayOfOJClass

PARAMETER_NAME

private static final String PARAMETER_NAME
See Also:
Constant Field Values
Constructor Detail

Toolbox

public Toolbox()
Method Detail

overridesOn

public static final OJClass[] overridesOn(OJClass[] declareds,
                                          OJClass[] bases)
Generates an array of classes containing the declared classes and the based classes except the declared one.

Parameters:
declareds - declared classes to override
bases - based classes.
Returns:
classes which contains the declared classes and the based classes except the declared one.
See Also:
OJClass

overridesOn

public static final OJField[] overridesOn(OJField[] declareds,
                                          OJField[] bases)
Generates an array of fields containing the declared fields and the based fields except the declared one.

Parameters:
declareds - declared fields to override
bases - based fields.
Returns:
fields which contains the declared fields and the based fields except the declared one.
See Also:
OJField

overridesOn

public static final OJMethod[] overridesOn(OJMethod[] declareds,
                                           OJMethod[] bases)
Generates an array of methods containing the declared methods and the based methods except the declared one.

Parameters:
declareds - declared methods to override
bases - based methods.
Returns:
methods which contains the declared methods and the based methods except the declared one.
See Also:
OJMethod

removeThePrivates

public static final OJClass[] removeThePrivates(OJClass[] src_classes)
Generates an array of classes containing the source classes except ones with private access modifier.

Parameters:
src_classes - source classes.
Returns:
classes except ones with private access modifier.
See Also:
OJModifier

removeThePrivates

public static final OJField[] removeThePrivates(OJField[] src_fields)
Generates an array of fields containing the source fields except ones with private access modifier.

Parameters:
src_fields - source fields.
Returns:
fields except ones with private access modifier.
See Also:
OJModifier

removeThePrivates

public static final OJMethod[] removeThePrivates(OJMethod[] src_methods)
Generates an array of methods containing the source methods except ones with private access modifier.

Parameters:
src_methods - source methods.
Returns:
methods except ones with private access modifier.
See Also:
OJModifier

removeThePrivates

public static final OJConstructor[] removeThePrivates(OJConstructor[] src_constrs)
Generates an array of constructors containing the source constructors except ones with private access modifier.

Parameters:
src_constrs - source constructors.
Returns:
constructors except ones with private access modifier.
See Also:
OJModifier

removeTheDefaults

public static final OJClass[] removeTheDefaults(OJClass[] src_classes)
Generates an array of classes containing the source classes except ones with private access modifier.

Parameters:
src_classes - source classes.
Returns:
classes except ones with private access modifier.
See Also:
OJModifier

removeTheDefaults

public static final OJField[] removeTheDefaults(OJField[] src_fields)
Generates an array of fields containing the source fields except ones with private access modifier.

Parameters:
src_fields - source fields.
Returns:
fields except ones with private access modifier.
See Also:
OJModifier

removeTheDefaults

public static final OJMethod[] removeTheDefaults(OJMethod[] src_methods)
Generates an array of methods containing the source methods except ones with private access modifier.

Parameters:
src_methods - source methods.
Returns:
methods except ones with private access modifier.
See Also:
OJModifier

removeTheDefaults

public static final OJConstructor[] removeTheDefaults(OJConstructor[] src_constrs)
Generates an array of constructors containing the source constructors except ones with private access modifier.

Parameters:
src_constrs - source constructors.
Returns:
constructors except ones with private access modifier.
See Also:
OJModifier

removeTheNonPublics

public static final OJClass[] removeTheNonPublics(OJClass[] src_classes)
Generates an array of classes containing the source classes except ones with non-public access modifier; one of private, protected or package level access modifiers.

Parameters:
src_classes - source classes.
Returns:
classes except ones with non-public access modifier.
See Also:
OJModifier

removeTheNonPublics

public static final OJField[] removeTheNonPublics(OJField[] src_fields)
Generates an array of fields containing the source fields except ones with non-public access modifier; one of private, protected or package level access modifiers.

Parameters:
src_fields - source fields.
Returns:
fields except ones with non-public access modifier.
See Also:
OJModifier

removeTheNonPublics

public static final OJMethod[] removeTheNonPublics(OJMethod[] src_methods)
Generates an array of methods containing the source methods except ones with non-public access modifier; one of private, protected or package level access modifiers.

Parameters:
src_methods - source methods.
Returns:
methods except ones with non-public access modifier.
See Also:
OJModifier

removeTheNonPublics

public static final OJConstructor[] removeTheNonPublics(OJConstructor[] src_constrs)
Generates an array of constructors containing the source constructors except ones with non-public access modifier; one of private, protected or package level access modifiers.

Parameters:
src_constrs - source constructors.
Returns:
constructors except ones with non-public access modifier.
See Also:
OJModifier

pickupField

public static final OJField pickupField(OJField[] src_fields,
                                        String name)
Pick up a field with the specified name in the source array of fields.

Parameters:
src_fields - source fields.
name - a name to specify.
Returns:
a field with the specified name.
See Also:
OJClass

pickupMethod

public static final OJMethod pickupMethod(OJMethod[] src_methods,
                                          String name,
                                          OJClass[] param_types)
Pick up a method with the specified signature in the source array of methods.

Parameters:
src_methods - source methods.
name - a name to specify.
param_types - parameter types to specify.
Returns:
a method with the specified signature. This returns null if it doesn't exist.
See Also:
OJClass

pickupAcceptableMethod

public static final OJMethod pickupAcceptableMethod(OJMethod[] src_methods,
                                                    String name,
                                                    OJClass[] param_types)
Pick up a method with the signature acceptable the specified signature in the source array of methods.

Parameters:
src_methods - source methods.
name - a name to specify.
param_types - parameter types to specify.
Returns:
a method with the specified signature. This returns null if it doesn't exist.
See Also:
OJClass

pickupAcceptableMethods

public static final OJMethod[] pickupAcceptableMethods(OJMethod[] src_methods,
                                                       String name,
                                                       OJClass[] param_types)
Generates an array of methods containing the methods with the signature acceptable the specified signature in the source array of methods.

Parameters:
src_methods - source methods.
name - a name to specify.
param_types - parameter types to specify.
Returns:
methods with the specified signature.
See Also:
OJClass

pickupConstructor

public static final OJConstructor pickupConstructor(OJConstructor[] src_constrs,
                                                    OJClass[] param_types)
Pick up a constructor with the specified signature in the source array of constructors.

Parameters:
src_constrs - source constructors.
param_types - parameter types to specify.
Returns:
a Constructor with the specified signature. This returns null if it doesn't exist.
See Also:
OJClass

pickupAcceptableConstructor

public static final OJConstructor pickupAcceptableConstructor(OJConstructor[] src_constrs,
                                                              OJClass[] param_types)
Pick up a constructor with the signature acceptable the specified signature in the source array of constructors.

Parameters:
src_constrs - source constructors.
param_types - parameter types to specify.
Returns:
a constructor with the specified signature. This returns null if it doesn't exist.
See Also:
OJClass

pickupAcceptableConstructors

public static final OJConstructor[] pickupAcceptableConstructors(OJConstructor[] src_constrs,
                                                                 OJClass[] param_types)
Generates an array of constructors containing the constructors with the specified parameter types in the source array of constructors.

Parameters:
src_constrs - source constructors.
param_types - parameter types to specify.
Returns:
constructors acceptable the specified parameter types.
See Also:
OJClass

pickupMethodsByName

public static final OJMethod[] pickupMethodsByName(OJMethod[] src_methods,
                                                   String name)
Generates an array of methods containing the methods with the specified name in the source array of methods.

Parameters:
src_methods - source methods.
name - a name to specify.
Returns:
methods with the specified name.
See Also:
OJClass

pickupMethodByParameterTypes

public static final OJMethod pickupMethodByParameterTypes(OJMethod[] src_methods,
                                                          OJClass[] param_types)
Picks up a method with the specified parameter types in the source array of methods.

Parameters:
src_methods - source methods.
param_types - parameter types to specify.
Returns:
a method with the specified parameter types.
See Also:
OJClass

pickupAcceptableMethodsByParameterTypes

public static final OJMethod[] pickupAcceptableMethodsByParameterTypes(OJMethod[] src_methods,
                                                                       OJClass[] param_types)
Generates an array of methods containing the methods with the parameter types acceptable specified parameter types in the source array of methods.

Parameters:
src_methods - source methods.
param_types - parameter types to specify.
Returns:
methods acceptable the specified parameter types.
See Also:
OJClass

isSame

public static final boolean isSame(OJClass[] accepter,
                                   OJClass[] acceptee)

isAcceptable

public static final boolean isAcceptable(OJClass[] accepter,
                                         OJClass[] acceptee)

isAdaptableTo

public static final boolean isAdaptableTo(OJClass[] adapter,
                                          OJClass[] adaptee)

pickupMostSpecified

public static final OJConstructor pickupMostSpecified(OJConstructor[] constrs)

pickupMostSpecified

public static final OJMethod pickupMostSpecified(OJMethod[] methods)

append

public static final OJClass[] append(OJClass[] a,
                                     OJClass[] b)

append

public static final OJField[] append(OJField[] a,
                                     OJField[] b)

append

public static final OJMethod[] append(OJMethod[] a,
                                      OJMethod[] b)

append

public static final OJConstructor[] append(OJConstructor[] a,
                                           OJConstructor[] b)

nameForJavaClassName

public static final String nameForJavaClassName(String jcname)

nameToJavaClassName

public static final String nameToJavaClassName(String ojcname)

stripHeadBracket

private static final String stripHeadBracket(String jcname)

stripBrackets

private static final String stripBrackets(String ojcname)

forNameAnyway

public static final OJClass forNameAnyway(Environment env,
                                          String name)

arrayForNames

public static final OJClass[] arrayForNames(Environment env,
                                            String[] names)

TNsForOJClasses

public static final TypeName[] TNsForOJClasses(OJClass[] classes)

generateParameters

public static final ParameterList generateParameters(OJClass[] parameterTypes)

generateParameters

public static final ParameterList generateParameters(OJClass[] parameterTypes,
                                                     String[] parameterNames)

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.


guessRowType

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


getAlias

public static String getAlias(Expression expression)
Gets or derives the alias of an expression. Saffron expressions are allowed to have explicit AS alias clauses; variables and field accesses are their own alias.


getType

public static OJClass getType(Environment env,
                              Expression exp)

getTypes

public static OJClass[] getTypes(Environment env,
                                 Expression[] exps)

getRowType

public static OJClass getRowType(Environment env,
                                 Expression exp)

getType

public static OJClass getType(Environment env,
                              ParseTree ref)
Finds the type of a parse tree node (which may be an Expression or a TypeName).

Pre-condition:
ref instanceof Expression || ref instanceof TypeName
Post-condition:
return != null

toArray

public static Expression[] toArray(ExpressionList expressionList)

toList

public static ExpressionList toList(Expression[] exps)

newInternal

public static Error newInternal()

newInternal

public static Error newInternal(String s)

newInternal

public static Error newInternal(Throwable e)

newInternal

public static Error newInternal(Throwable e,
                                String s)

pre

public static void pre(boolean b,
                       String description)

needToImplement

public static RuntimeException needToImplement(Object o)
Returns a RuntimeException indicating that a particular feature has not been implemented, but should be.

If every 'hole' in our functionality uses this method, it will be easier for us to identity the holes. Throwing a UnsupportedOperationException isn't as good, because sometimes we actually want to partially implement an API.


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.


lookupAnonymousClass

public static OJClass lookupAnonymousClass(ClassEnvironment env,
                                           AllocationExpression allocExp)
Creates or (subsequently) retrieves a class object corresponding to the declaration of an anonymous class.


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

unbox

private static Expression unbox(OJClass clazz,
                                Expression exp)
Converts an expression representing a wrapped primitive into a primitive. For example, new Integer(1 + 2) becomes new Integer(1 + 2).intValue(). It is an error if the expression is not a primitive type.

Parameters:
clazz - is the class of the expression. If the class is not a primitive wrapper (e.g. Integer), the expression is returned unchanged
exp - expression to unwrap

castObject

public static Expression castObject(Expression exp,
                                    OJClass fromClazz,
                                    OJClass toClazz)
Converts an expression of type Object into an appropriate type. If the target type is an object, generates a cast; primitive types are unboxed. For example:
// to convert an Object to a String, need a cast
 while (stringIter.hasMoreElements()) {
   String s  = (String) stringIter.next();
 }
 // to convert an Object to an int, need to unbox
 while (intIter.hasMoreElements()) {
   int i  = ((Integer) intIter.next()).intValue();
 }
 // Objects are unchanged
 while (objectIter.hasMoreElements()) {
   Object i  = objectIter.next();
 }

Parameters:
exp - expression to unwrap
fromClazz - class that expression is now
toClazz - class to convert expression to

makeEquals

public static Expression makeEquals(Expression left,
                                    Expression right,
                                    OJClass type,
                                    boolean nullable)
Generates an equality condition appropriate for the types of the operands.

It generates:


getTable

public static SaffronTable getTable(Environment env,
                                    ParseTree expr,
                                    String qualifier,
                                    String name)
Converts a field access into a table.


getSaffronSchema

private static SaffronSchema getSaffronSchema(ParseTree expr,
                                              Environment env)

isEquals

public static Expression[] isEquals(Expression expression)
If the expression is an equals condition, returns the two arguments, otherwise returns null.


SourceForge.net_Logo