Top Description Fields Constructors Methods
javassist.tools.reflect

public Class Reflection

extends Object
implements Translator
Class Inheritance
All Implemented Interfaces
javassist.Translator
Imports
javassist.CannotCompileException, .ClassPool, .CodeConverter, .CtClass, .CtField, .CtMethod, .CtMethod.ConstParameter, .CtNewMethod, .Modifier, .NotFoundException, .Translator, javassist.bytecode.BadBytecode, .ClassFile, .MethodInfo

The class implementing the behavioral reflection mechanism.

If a class is reflective, then all the method invocations on every instance of that class are intercepted by the runtime metaobject controlling that instance. The methods inherited from the super classes are also intercepted except final methods. To intercept a final method in a super class, that super class must be also reflective.

To do this, the original class file representing a reflective class:

class Person {
  public int f(int i) { return i + 1; }
  public int value;
}

is modified so that it represents a class:

class Person implements Metalevel {
  public int _original_f(int i) { return i + 1; }
  public int f(int i) { delegate to the metaobject }

  public int value;
  public int _r_value() { read "value" }
  public void _w_value(int v) { write "value" }

  public ClassMetaobject _getClass() { return a class metaobject }
  public Metaobject _getMetaobject() { return a metaobject }
  public void _setMetaobject(Metaobject m) { change a metaobject }
}
See Also
javassist.tools.reflect.ClassMetaobject, javassist.tools.reflect.Metaobject, javassist.tools.reflect.Loader, javassist.tools.reflect.Compiler

Field Summary

Modifier and TypeField and Description
pack-priv static final String
pack-priv static final String
pack-priv static final String
protected ClassPool
protected CodeConverter
pack-priv static final String
pack-priv static final String
pack-priv static final String
pack-priv static final String
protected CtClass[]
pack-priv static final String
protected CtMethod
protected CtMethod
protected CtMethod
protected CtMethod
pack-priv static final String

Constructor Summary

AccessConstructor and Description
public
Reflection()

Constructs a new Reflection object.

Method Summary

Modifier and TypeMethod and Description
private CtMethod
findOriginal(CtMethod m, boolean dontSearch)

private boolean
public boolean

Returns:

false if the class is already reflective.
makeReflective
(String
the name of the reflective class
classname
,
String
the class name of metaobjects.
metaobject
,
String
the class name of the class metaobject.
metaclass
)

Produces a reflective class.

public boolean

Returns:

false if the class is already reflective.
makeReflective
(Class<?>
the reflective class.
clazz
,
Class<?>
the class of metaobjects. It must be a subclass of Metaobject.
metaobject
,
Class<?>
the class of the class metaobject. It must be a subclass of ClassMetaobject.
metaclass
)

Produces a reflective class.

public boolean

Returns:

false if the class is already reflective.
makeReflective
(CtClass
the reflective class.
clazz
,
CtClass
the class of metaobjects. It must be a subclass of Metaobject.
metaobject
,
CtClass
the class of the class metaobject. It must be a subclass of ClassMetaobject.
metaclass
)

Produces a reflective class.

private boolean
modifyClassfile(CtClass clazz, CtClass metaobject, CtClass metaclass)

public void
onLoad(ClassPool
the ClassPool that this translator should use.
pool
,
String
the name of the class being loaded.
classname
)

Implements javassist.Translator.onLoad.

Inserts hooks for intercepting accesses to the fields declared in reflective classes.

private void
private void
processMethods(CtClass clazz, boolean dontSearch)

private void
processMethods0(int mod, CtClass clazz, CtMethod m, int identifier, boolean dontSearch)

public void
private void
registerReflectiveClass(CtClass clazz)

Registers a reflective class.

public void
start(ClassPool
the ClassPool that this translator should use.
pool
)

Implements javassist.Translator.start.

Initializes the object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

classMetaobjectClassNameback to summary
pack-priv static final String classMetaobjectClassName
classobjectAccessorback to summary
pack-priv static final String classobjectAccessor
classobjectFieldback to summary
pack-priv static final String classobjectField
classPoolback to summary
protected ClassPool classPool
converterback to summary
protected CodeConverter converter
metaobjectClassNameback to summary
pack-priv static final String metaobjectClassName
metaobjectFieldback to summary
pack-priv static final String metaobjectField
metaobjectGetterback to summary
pack-priv static final String metaobjectGetter
metaobjectSetterback to summary
pack-priv static final String metaobjectSetter
readParamback to summary
protected CtClass[] readParam
readPrefixback to summary
pack-priv static final String readPrefix
trapMethodback to summary
protected CtMethod trapMethod
trapReadback to summary
protected CtMethod trapRead
trapStaticMethodback to summary
protected CtMethod trapStaticMethod
trapWriteback to summary
protected CtMethod trapWrite
writePrefixback to summary
pack-priv static final String writePrefix

Constructor Detail

Reflectionback to summary
public Reflection()

Constructs a new Reflection object.

Method Detail

findOriginalback to summary
private CtMethod findOriginal(CtMethod m, boolean dontSearch) throws NotFoundException
isExcludedback to summary
private boolean isExcluded(String name)
makeReflectiveback to summary
public boolean makeReflective(String classname, String metaobject, String metaclass) throws CannotCompileException, NotFoundException

Produces a reflective class. If the super class is also made reflective, it must be done before the sub class.

Parameters
classname:String

the name of the reflective class

metaobject:String

the class name of metaobjects.

metaclass:String

the class name of the class metaobject.

Returns:boolean

false if the class is already reflective.

See Also
javassist.tools.reflect.Metaobject, javassist.tools.reflect.ClassMetaobject
makeReflectiveback to summary
public boolean makeReflective(Class<?> clazz, Class<?> metaobject, Class<?> metaclass) throws CannotCompileException, NotFoundException

Produces a reflective class. If the super class is also made reflective, it must be done before the sub class.

Parameters
clazz:Class<?>

the reflective class.

metaobject:Class<?>

the class of metaobjects. It must be a subclass of Metaobject.

metaclass:Class<?>

the class of the class metaobject. It must be a subclass of ClassMetaobject.

Returns:boolean

false if the class is already reflective.

See Also
javassist.tools.reflect.Metaobject, javassist.tools.reflect.ClassMetaobject
makeReflectiveback to summary
public boolean makeReflective(CtClass clazz, CtClass metaobject, CtClass metaclass) throws CannotCompileException, CannotReflectException, NotFoundException

Produces a reflective class. It modifies the given CtClass object and makes it reflective. If the super class is also made reflective, it must be done before the sub class.

Parameters
clazz:CtClass

the reflective class.

metaobject:CtClass

the class of metaobjects. It must be a subclass of Metaobject.

metaclass:CtClass

the class of the class metaobject. It must be a subclass of ClassMetaobject.

Returns:boolean

false if the class is already reflective.

See Also
javassist.tools.reflect.Metaobject, javassist.tools.reflect.ClassMetaobject
modifyClassfileback to summary
private boolean modifyClassfile(CtClass clazz, CtClass metaobject, CtClass metaclass) throws CannotCompileException, NotFoundException
onLoadback to summary
public void onLoad(ClassPool pool, String classname) throws CannotCompileException, NotFoundException

Implements javassist.Translator.onLoad.

Inserts hooks for intercepting accesses to the fields declared in reflective classes.

Parameters
pool:ClassPool

Doc from javassist.Translator.onLoad.

the ClassPool that this translator should use.

classname:String

Doc from javassist.Translator.onLoad.

the name of the class being loaded.

Annotations
@Override
Exceptions
CannotCompileException:

Doc from javassist.Translator.onLoad.

if the code transformation by this method fails.

NotFoundException:

Doc from javassist.Translator.onLoad.

if a CtClass cannot be found.

processFieldsback to summary
private void processFields(CtClass clazz) throws CannotCompileException, NotFoundException
processMethodsback to summary
private void processMethods(CtClass clazz, boolean dontSearch) throws CannotCompileException, NotFoundException
processMethods0back to summary
private void processMethods0(int mod, CtClass clazz, CtMethod m, int identifier, boolean dontSearch) throws CannotCompileException, NotFoundException
rebuildClassFileback to summary
public void rebuildClassFile(ClassFile cf) throws BadBytecode
registerReflectiveClassback to summary
private void registerReflectiveClass(CtClass clazz)

Registers a reflective class. The field accesses to the instances of this class are instrumented.

startback to summary
public void start(ClassPool pool) throws NotFoundException

Implements javassist.Translator.start.

Initializes the object.

Parameters
pool:ClassPool

Doc from javassist.Translator.start.

the ClassPool that this translator should use.

Annotations
@Override
Exceptions
NotFoundException:

Doc from javassist.Translator.start.

if a CtClass cannot be found.