edu.mit.ai.psg.jevaES
Class TypeMethods

java.lang.Object
  |
  +--edu.mit.ai.psg.jevaES.TypeMethods

public class TypeMethods
extends Object

Predicates and Methods for testing and comparing types.

Author:
CarlManning, caroma@ai.mit.edu
Copyright (c) 1997 Massachusetts Institute of Technology

Method Summary
static Class binaryCombineBitwiseTypes(Token operator, Class cX, Class cY)
           
static Class binaryCombineNumericTypes(Token operator, Class cX, Class cY)
           
static Class binaryCombineShiftTypes(Token operator, Class leftType, Class rightType)
           
static Class binaryPromoteType(Class cX, Class cY)
          [JavaLangSpec1.0 sec 5.6.2 Binary Numeric Promotion]
static boolean canNarrowPrimitive(Class to, Class from)
          [JavaLangSpec1.0 sec 5.1.3 Narrowing Primitive Conversions]
static boolean canNarrowPrimitiveConstant(Class receivingType, Class exprType, IExpressionNode expr, IEnv env)
          [JavaLangSpec1.0 sec 5.2, 15.24]
check if expr is integer constant that fits in char, short, or byte.
static boolean canNarrowReference(Class to, Class from)
          [JavaLangSpec1.0 sec 5.1.5 Narrowing Reference Conversions]
(does not check for methods that differ only in return type)
static boolean canWidenPrimitive(Class to, Class from)
          [JavaLangSpec1.0 sec 5.1.2 Widening Primitive Conversions]
static boolean canWidenReference(Class to, Class from)
          [JavaLangSpec1.0 sec 5.1.4 Widening Reference Conversions]
static void checkCastTypes(Class castType, Class exprType)
          check for impermissible casts [JavaLangSpec1.0 sec 5.5 Casting Conversion]
static boolean isAbstractClass(Class aClass)
           
static boolean isApplicable(Class[] parameterTypes, Class[] argExprTypes)
           
static boolean isApplicable(Constructor constructor, Class[] argExprTypes)
           
static boolean isApplicable(Method method, Class[] argExprTypes)
          [JavaLangSpec 15.11.2.1 Find Methods that are applicable (& accessible)]
Accessibility is not a concern, since only public methods are accessiblethrough reflection.
static boolean isAssignable(Class receivingType, IExpressionNode expr, IEnv env)
          [JavaLangSpec1.0 sec 5.2 Assignment Conversion] This checks for primitive as well as reference widenings.
static boolean isBindableType(Class receivingType, Class exprType)
          [JavaLangSpec1.0 sec 5.3 Method Invocation Conversion]
static boolean isCaughtOrDeclaredException(Class exceptionClass, Class[] caughtOrDeclareds)
           
static boolean isClassType(Class type)
          Class is not primitive, array, nor interface
static boolean isFinalClass(Class aClass)
           
static boolean isImplementation(Class sub, Class anInterface)
           
static boolean isIntegralType(Class type)
          primitive integer types of various sizes (byte, short, int, long)
static boolean isIntExpression(IExpressionNode expr, IEnv env)
          Check that array dims/indexes are int [JavaLangSpec1.0 sec15.9, 15.12]
static boolean isMoreSpecific(Constructor c1, Constructor c2)
           
static boolean isMoreSpecific(Method m1, Method m2)
          [JavaLangSpec 15.11.2.2 Choose Most Specific Method]
Assumes method name matches
static boolean isNumericType(Class type)
          primitive numeric types
static boolean isReferenceType(Class type)
           
static boolean isSubclass(Class sub, Class aSuper)
           
static boolean isSubinterface(Class sub, Class aSuper)
           
static boolean isThrowableClass(Throwable thrown, Class[] throwClasses)
          [JavaLangSpec 14.16 Throw statement]
static boolean isUncheckedException(Class exceptionClass)
           
static Class makeArrayType(Class baseType, int nDims)
           
static Class nameToPrimitiveType(String name)
          Get primitive type from its name, e.g., for "long" return long.class
static Class toPrimitiveType(Class wrapperType)
          Get primitive type associated with wrapper, e.g., for a new Long(0) return long.class
static String toSourceString(Class type)
          Return source code declaration string for class even if it is an array, e.g., "int[][]" instead of "[[I", which is what type.getName() returns
static Class unaryPromoteType(Class type)
          [JavaLangSpec1.0 sec 5.6.1 Unary Numeric Promotion]
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

isReferenceType

public static final boolean isReferenceType(Class type)

isClassType

public static final boolean isClassType(Class type)
Class is not primitive, array, nor interface

isNumericType

public static final boolean isNumericType(Class type)
primitive numeric types

isIntegralType

public static final boolean isIntegralType(Class type)
primitive integer types of various sizes (byte, short, int, long)

unaryPromoteType

public static final Class unaryPromoteType(Class type)
[JavaLangSpec1.0 sec 5.6.1 Unary Numeric Promotion]

binaryPromoteType

public static final Class binaryPromoteType(Class cX,
                                            Class cY)
[JavaLangSpec1.0 sec 5.6.2 Binary Numeric Promotion]

binaryCombineNumericTypes

public static final Class binaryCombineNumericTypes(Token operator,
                                                    Class cX,
                                                    Class cY)
Throws:
IllegalArgumentException - if given non-numeric type

binaryCombineBitwiseTypes

public static final Class binaryCombineBitwiseTypes(Token operator,
                                                    Class cX,
                                                    Class cY)
Throws:
IllegalArgumentException - if given non-numeric non-boolean type

binaryCombineShiftTypes

public static final Class binaryCombineShiftTypes(Token operator,
                                                  Class leftType,
                                                  Class rightType)
Throws:
IllegalArgumentException - if given non-integral types

isAssignable

public static final boolean isAssignable(Class receivingType,
                                         IExpressionNode expr,
                                         IEnv env)
                                  throws VerifyingException
[JavaLangSpec1.0 sec 5.2 Assignment Conversion] This checks for primitive as well as reference widenings.
Throws:
VerifyingException - if expr has type err

isBindableType

public static final boolean isBindableType(Class receivingType,
                                           Class exprType)
[JavaLangSpec1.0 sec 5.3 Method Invocation Conversion]

canWidenPrimitive

public static final boolean canWidenPrimitive(Class to,
                                              Class from)
[JavaLangSpec1.0 sec 5.1.2 Widening Primitive Conversions]

canNarrowPrimitiveConstant

public static final boolean canNarrowPrimitiveConstant(Class receivingType,
                                                       Class exprType,
                                                       IExpressionNode expr,
                                                       IEnv env)
                                                throws VerifyingException
[JavaLangSpec1.0 sec 5.2, 15.24]
check if expr is integer constant that fits in char, short, or byte.
Throws:
VerifyingException - if expr is illegal

canNarrowPrimitive

public static final boolean canNarrowPrimitive(Class to,
                                               Class from)
[JavaLangSpec1.0 sec 5.1.3 Narrowing Primitive Conversions]

canWidenReference

public static final boolean canWidenReference(Class to,
                                              Class from)
[JavaLangSpec1.0 sec 5.1.4 Widening Reference Conversions]

isFinalClass

public static final boolean isFinalClass(Class aClass)

isAbstractClass

public static final boolean isAbstractClass(Class aClass)

isSubinterface

public static final boolean isSubinterface(Class sub,
                                           Class aSuper)

isSubclass

public static final boolean isSubclass(Class sub,
                                       Class aSuper)

isImplementation

public static final boolean isImplementation(Class sub,
                                             Class anInterface)

canNarrowReference

public static final boolean canNarrowReference(Class to,
                                               Class from)
[JavaLangSpec1.0 sec 5.1.5 Narrowing Reference Conversions]
(does not check for methods that differ only in return type)

toPrimitiveType

public static final Class toPrimitiveType(Class wrapperType)
Get primitive type associated with wrapper, e.g., for a new Long(0) return long.class

nameToPrimitiveType

public static final Class nameToPrimitiveType(String name)
                                       throws ClassNotFoundException
Get primitive type from its name, e.g., for "long" return long.class
Throws:
ClassNotFoundException - if not primitive type

toSourceString

public static final String toSourceString(Class type)
Return source code declaration string for class even if it is an array, e.g., "int[][]" instead of "[[I", which is what type.getName() returns

makeArrayType

public static final Class makeArrayType(Class baseType,
                                        int nDims)

checkCastTypes

public static final void checkCastTypes(Class castType,
                                        Class exprType)
check for impermissible casts [JavaLangSpec1.0 sec 5.5 Casting Conversion]

isThrowableClass

public static boolean isThrowableClass(Throwable thrown,
                                       Class[] throwClasses)
[JavaLangSpec 14.16 Throw statement]

isApplicable

public static final boolean isApplicable(Method method,
                                         Class[] argExprTypes)
[JavaLangSpec 15.11.2.1 Find Methods that are applicable (& accessible)]
Accessibility is not a concern, since only public methods are accessiblethrough reflection.

isApplicable

public static final boolean isApplicable(Constructor constructor,
                                         Class[] argExprTypes)

isApplicable

public static final boolean isApplicable(Class[] parameterTypes,
                                         Class[] argExprTypes)

isMoreSpecific

public static final boolean isMoreSpecific(Method m1,
                                           Method m2)
[JavaLangSpec 15.11.2.2 Choose Most Specific Method]
Assumes method name matches

isMoreSpecific

public static final boolean isMoreSpecific(Constructor c1,
                                           Constructor c2)

isIntExpression

public static final boolean isIntExpression(IExpressionNode expr,
                                            IEnv env)
                                     throws VerifyingException
Check that array dims/indexes are int [JavaLangSpec1.0 sec15.9, 15.12]
Throws:
VerifyingException - if expr has type err

isUncheckedException

public static boolean isUncheckedException(Class exceptionClass)

isCaughtOrDeclaredException

public static boolean isCaughtOrDeclaredException(Class exceptionClass,
                                                  Class[] caughtOrDeclareds)

Copyright (c) 1996-1999
Massachusetts Institute of Technology

Feedback: jeva-bugs@ai.mit.edu