org.jboss.byteman.rule.type
Class Type

java.lang.Object
  extended by org.jboss.byteman.rule.type.Type

public class Type
extends java.lang.Object

models the type of a rule binding or expression


Nested Class Summary
private static class Type.Undefined
           
 
Field Summary
private  Type aliasFor
           
private  Type arrayType
           
static Type B
           
private  Type baseType
           
static Type BOOLEAN
           
private static java.util.HashMap<Type,Type> boxedTypes
           
private static java.util.HashMap<java.lang.String,Type> builtinTypes
           
static Type BYTE
           
static Type C
           
static Type CHARACTER
           
private  java.lang.Class clazz
           
static Type D
           
static Type DOUBLE
           
static Type F
           
static int F_ARRAY
           
static int F_BOOLEAN
           
static int F_FLOATING
           
static int F_INTEGRAL
           
static int F_NUMERIC
           
static int F_OBJECT
           
static int F_PRIMITIVE
           
static int F_STRING
           
static int F_UNKNOWN
           
static int F_VALUE
           
static int F_VOID
           
private  int flags
           
static Type FLOAT
           
static Type I
           
static Type INTEGER
           
private static java.util.HashMap<java.lang.String,java.lang.String> internalNames
           
static Type J
           
static Type LONG
           
static Type N
           
private  int nBytes
           
static Type NUMBER
           
static Type OBJECT
           
private  java.lang.String packageName
           
private static java.util.HashMap<java.lang.String,Type> primitiveTypes
           
static Type S
           
static Type SHORT
           
static Type STRING
           
private  java.lang.String typeName
           
static Type UNDEFINED
           
static Type VOID
           
static Type Z
           
 
Constructor Summary
  Type(java.lang.String typeName)
          create a type with a given name and no associated class
  Type(java.lang.String typeName, java.lang.Class clazz)
          create a type with a given name and optionally an associated class
protected Type(java.lang.String typeName, java.lang.Class clazz, int flags, int nBytes)
           
protected Type(java.lang.String typeName, java.lang.Class clazz, int flags, int nBytes, Type baseType)
           
 
Method Summary
 boolean aliasTo(Type target)
          attempt to establish an alias from an package unqualified named object type to a package qualified named object type whose unqualified name equals this type's name
 Type arrayType()
          create an array type from this base type
 Type arrayType(java.lang.Class clazz)
          create an array type from this base type
static Type boxType(java.lang.Class clazz)
          return the primitive type whose boxed equivalent is associated with a given class
static Type boxType(Type type)
          return the primitive type for a boxed type or vice versa
static Type builtinType(java.lang.Class clazz)
          return the builtin type associated with a given class
static Type dereference(Type target)
          dereference an object type to the fully qualified named type to which it is aliased where such an alias has been found to exist or return the supplied type if no alias exists or the type is a non-objecttype or was originally specified using a fully qualified type name.
static java.lang.String fixArrayType(java.lang.String baseType, int dimension)
           
 Type getBaseType()
          retrieve the base type for an array type or null if this is not an array type
 java.lang.String getInternalName()
          get the internal name for this type used by the class loader.
 java.lang.String getInternalName(boolean forDescriptor, boolean slashSeparate)
          get the internal name for this type used by the class loader.
 java.lang.String getName()
          get the possibly unqualified name with which this type was created
 int getNBytes()
          return the number of stack words occupied by instances of this type
 java.lang.String getPackageName()
          get the package component of the name associated with this type or the empty String if it has no package or is was defiend with an unqualified name or is a builtin type
 java.lang.Class getTargetClass()
          get the class associated with this type if it has one or a special undefined class if the type is not defined or null if there is no associated class
static java.lang.String internalName(java.lang.Class<?> clazz)
           
static java.lang.String internalName(java.lang.Class<?> clazz, boolean forField)
           
 boolean isArray()
          return true if this is an array type
 boolean isAssignableFrom(Type type)
          check whether this type can be assigned with values of the supplied type including the case where numeric conversion from known or unknown numeric types but excluding any other cases where this type is undefined n.b.
 boolean isBoolean()
          return true if this is a boolean type
 boolean isDefined()
          check if this type is a known type.
 boolean isFloating()
          return true if this is a floating type of whatever size, including the unknown primitive numeric type
 boolean isIntegral()
          return true if this is an integral type of whatever size, including the unknown primitive numeric type
 boolean isNumeric()
          return true if this is a numeric type, including the unknown primitive numeric type
 boolean isObject()
          return true if this is an object type, including unbound types mentioned in rules
 boolean isPrimitive()
          return true if this is a primitive value type
 boolean isString()
          return true if this is the string type
 boolean isUnbound()
          return true if this is a type mentioned in a rule but not yet bound to a specific class
 boolean isUndefined()
          test if this type is an unknown type.
 boolean isValue()
          return true if this is a value type, which includes the boxed versions of primitive types
 boolean isVoid()
          return true if this is the void type
private static java.lang.String packagePart(java.lang.String className)
           
static int paramSlotIdx(int access, java.lang.String desc, int paramIdx)
          identify the local var slot used to store a method parameter identified by parameter index
static java.lang.String parseFieldDescriptor(java.lang.String descriptor)
           
static java.util.List<java.lang.String> parseMethodDescriptor(java.lang.String descriptor, boolean includeReturnType)
           
static java.lang.String parseMethodReturnType(java.lang.String descriptor)
           
static Type promote(Type type1, Type type2)
          compute the type to which a binary arithmetic operator should promote its operands before combination based on the two operand types which is also the type to be used for the result of the operation
 void resolve(java.lang.ClassLoader loader)
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

typeName

private java.lang.String typeName

clazz

private java.lang.Class clazz

packageName

private java.lang.String packageName

flags

private int flags

nBytes

private int nBytes

aliasFor

private Type aliasFor

baseType

private Type baseType

arrayType

private Type arrayType

F_BOOLEAN

public static final int F_BOOLEAN
See Also:
Constant Field Values

F_INTEGRAL

public static final int F_INTEGRAL
See Also:
Constant Field Values

F_FLOATING

public static final int F_FLOATING
See Also:
Constant Field Values

F_OBJECT

public static final int F_OBJECT
See Also:
Constant Field Values

F_VOID

public static final int F_VOID
See Also:
Constant Field Values

F_ARRAY

public static final int F_ARRAY
See Also:
Constant Field Values

F_NUMERIC

public static final int F_NUMERIC
See Also:
Constant Field Values

F_VALUE

public static final int F_VALUE
See Also:
Constant Field Values

F_UNKNOWN

public static final int F_UNKNOWN
See Also:
Constant Field Values

F_PRIMITIVE

public static final int F_PRIMITIVE
See Also:
Constant Field Values

F_STRING

public static final int F_STRING
See Also:
Constant Field Values

Z

public static final Type Z

B

public static final Type B

S

public static final Type S

C

public static final Type C

I

public static final Type I

J

public static final Type J

F

public static final Type F

D

public static final Type D

N

public static final Type N

BOOLEAN

public static final Type BOOLEAN

BYTE

public static final Type BYTE

SHORT

public static final Type SHORT

CHARACTER

public static final Type CHARACTER

INTEGER

public static final Type INTEGER

LONG

public static final Type LONG

FLOAT

public static final Type FLOAT

DOUBLE

public static final Type DOUBLE

STRING

public static final Type STRING

VOID

public static final Type VOID

NUMBER

public static final Type NUMBER

OBJECT

public static final Type OBJECT

UNDEFINED

public static final Type UNDEFINED

builtinTypes

private static final java.util.HashMap<java.lang.String,Type> builtinTypes

primitiveTypes

private static final java.util.HashMap<java.lang.String,Type> primitiveTypes

boxedTypes

private static final java.util.HashMap<Type,Type> boxedTypes

internalNames

private static final java.util.HashMap<java.lang.String,java.lang.String> internalNames
Constructor Detail

Type

public Type(java.lang.String typeName,
            java.lang.Class clazz)
create a type with a given name and optionally an associated class

Parameters:
typeName - the name of the type which may or may not be fully qualified
clazz - the class associated with this name if it is know otherwise null

Type

public Type(java.lang.String typeName)
create a type with a given name and no associated class

Parameters:
typeName - the name of the type which may or may not be fully qualified

Type

protected Type(java.lang.String typeName,
               java.lang.Class clazz,
               int flags,
               int nBytes)

Type

protected Type(java.lang.String typeName,
               java.lang.Class clazz,
               int flags,
               int nBytes,
               Type baseType)
Method Detail

arrayType

public Type arrayType()
create an array type from this base type

Returns:
an array type

arrayType

public Type arrayType(java.lang.Class clazz)
create an array type from this base type

Parameters:
clazz - the class for the array type derived from the class of base type or null if the base type is undefined
Returns:
an array type

getBaseType

public Type getBaseType()
retrieve the base type for an array type or null if this is not an array type

Returns:
an array type

getName

public java.lang.String getName()
get the possibly unqualified name with which this type was created

Returns:
the type name

getInternalName

public java.lang.String getInternalName()
get the internal name for this type used by the class loader. this is only valid for defined types, defined array types or primitive types

Returns:
the type name

getInternalName

public java.lang.String getInternalName(boolean forDescriptor,
                                        boolean slashSeparate)
get the internal name for this type used by the class loader. this is only valid for defined types, defined array types or primitive types

Returns:
the type name

getTargetClass

public java.lang.Class getTargetClass()
get the class associated with this type if it has one or a special undefined class if the type is not defined or null if there is no associated class

Returns:
the associated class

getPackageName

public java.lang.String getPackageName()
get the package component of the name associated with this type or the empty String if it has no package or is was defiend with an unqualified name or is a builtin type

Returns:
the package component or an empty string

dereference

public static Type dereference(Type target)
dereference an object type to the fully qualified named type to which it is aliased where such an alias has been found to exist or return the supplied type if no alias exists or the type is a non-objecttype or was originally specified using a fully qualified type name.

Parameters:
target - the type to be dereferenced
Returns:
the alias where it exists or the supplied type where there is no alias or null if a null value is supplied

resolve

public void resolve(java.lang.ClassLoader loader)

aliasTo

public boolean aliasTo(Type target)
attempt to establish an alias from an package unqualified named object type to a package qualified named object type whose unqualified name equals this type's name

Parameters:
target - the package qualified named type for which this type should become an alias
Returns:
true if the alias link can be established or already exsits or false if an alias to a different target already exists or this type or the target are not object types

isAssignableFrom

public boolean isAssignableFrom(Type type)
check whether this type can be assigned with values of the supplied type including the case where numeric conversion from known or unknown numeric types but excluding any other cases where this type is undefined n.b. the caller must dereference the recipient and argument types before calling this method

Parameters:
type - the type poviding RHS values
Returns:
true if it is known that the assignment is valid, false if it is not known to be valid or is known not to be valid

isUndefined

public boolean isUndefined()
test if this type is an unknown type. a type may be unknown either because it is one of the pseudo types used as type variables or because it represents an object type mentioned in a rule but not yet bound to a specific class

Returns:
true if the type is unknown otherwise false

isDefined

public boolean isDefined()
check if this type is a known type. this is just teh oppositeof isUndefined

Returns:
false if the type is unknown otherwise true

isUnbound

public boolean isUnbound()
return true if this is a type mentioned in a rule but not yet bound to a specific class

Returns:
true if the type is not yet bound to a specific class

isPrimitive

public boolean isPrimitive()
return true if this is a primitive value type

Returns:
true if this is a primitive value type

isValue

public boolean isValue()
return true if this is a value type, which includes the boxed versions of primitive types

Returns:
true if this is a value type

isVoid

public boolean isVoid()
return true if this is the void type

Returns:
true if this is void type

isString

public boolean isString()
return true if this is the string type

Returns:
true if this is string type

isNumeric

public boolean isNumeric()
return true if this is a numeric type, including the unknown primitive numeric type

Returns:
true if this is a numeric type

isIntegral

public boolean isIntegral()
return true if this is an integral type of whatever size, including the unknown primitive numeric type

Returns:
true if this is an integral type

isFloating

public boolean isFloating()
return true if this is a floating type of whatever size, including the unknown primitive numeric type

Returns:
true if this is a floating type

isBoolean

public boolean isBoolean()
return true if this is a boolean type

Returns:
true if this is a boolean type

isObject

public boolean isObject()
return true if this is an object type, including unbound types mentioned in rules

Returns:
true if this is an object type

isArray

public boolean isArray()
return true if this is an array type

Returns:
true if this is an array type

getNBytes

public int getNBytes()
return the number of stack words occupied by instances of this type

Returns:
true if this is an array type

builtinType

public static Type builtinType(java.lang.Class clazz)
return the builtin type associated with a given class

Returns:
the corresponding builtin type

boxType

public static Type boxType(java.lang.Class clazz)
return the primitive type whose boxed equivalent is associated with a given class

Returns:
the corresponding primitive type

boxType

public static Type boxType(Type type)
return the primitive type for a boxed type or vice versa

Returns:
the corresponding primitive type

promote

public static Type promote(Type type1,
                           Type type2)
                    throws TypeException
compute the type to which a binary arithmetic operator should promote its operands before combination based on the two operand types which is also the type to be used for the result of the operation

Parameters:
type1 - the type of the left operand which must be numeric but may be undefined
type2 - the type of the right operand which must be numeric but may be undefined
Returns:
the corresponding promotion/result type which may be undefined numeric
Throws:
TypeException

packagePart

private static java.lang.String packagePart(java.lang.String className)

parseMethodDescriptor

public static java.util.List<java.lang.String> parseMethodDescriptor(java.lang.String descriptor,
                                                                     boolean includeReturnType)

parseFieldDescriptor

public static java.lang.String parseFieldDescriptor(java.lang.String descriptor)

parseMethodReturnType

public static java.lang.String parseMethodReturnType(java.lang.String descriptor)

paramSlotIdx

public static int paramSlotIdx(int access,
                               java.lang.String desc,
                               int paramIdx)
identify the local var slot used to store a method parameter identified by parameter index

Parameters:
access - the access flags for the method including whether or not it is static
desc - the intrenal form descriptor for the maethod
paramIdx - the index of the parameter in the parameter lost starting with 0 for this or 1 for actual parameters
Returns:
the corresponding local var slot or -1 if there is no such parameter

fixArrayType

public static java.lang.String fixArrayType(java.lang.String baseType,
                                            int dimension)

internalName

public static java.lang.String internalName(java.lang.Class<?> clazz)

internalName

public static java.lang.String internalName(java.lang.Class<?> clazz,
                                            boolean forField)

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object