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 }
}
javassist.tools.reflect.ClassMetaobject , javassist.tools.reflect.Metaobject , javassist.tools.reflect.Loader , javassist.tools.reflect.Compiler
| Modifier and Type | Field 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 |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| private CtMethod | |
| private boolean | |
| public boolean | Returns: false if the class is already reflective.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.the reflective class. clazz, Class<?> the class of metaobjects.
It must be a subclass of
metaobject, Class<?> Metaobject.the class of the class metaobject.
It must be a subclass of
metaclass)ClassMetaobject.Produces a reflective class. |
| public boolean | Returns: false if the class is already reflective.the reflective class. clazz, CtClass the class of metaobjects.
It must be a subclass of
metaobject, CtClass Metaobject.the class of the class metaobject.
It must be a subclass of
metaclass)ClassMetaobject.Produces a reflective class. |
| private boolean | |
| public void | onLoad(ClassPool
the pool, String ClassPool that this translator
should use.the name of the class being loaded. classname)Implements javassist. Inserts hooks for intercepting accesses to the fields declared in reflective classes. |
| private void | |
| private void | |
| private void | |
| public void | |
| private void | |
| public void | start(ClassPool
the pool)ClassPool that this translator
should use.Implements javassist. Initializes the object. |
| classMetaobjectClassName | back to summary |
|---|---|
| pack-priv static final String classMetaobjectClassName | |
| classobjectAccessor | back to summary |
|---|---|
| pack-priv static final String classobjectAccessor | |
| classobjectField | back to summary |
|---|---|
| pack-priv static final String classobjectField | |
| classPool | back to summary |
|---|---|
| protected ClassPool classPool | |
| converter | back to summary |
|---|---|
| protected CodeConverter converter | |
| metaobjectClassName | back to summary |
|---|---|
| pack-priv static final String metaobjectClassName | |
| metaobjectField | back to summary |
|---|---|
| pack-priv static final String metaobjectField | |
| metaobjectGetter | back to summary |
|---|---|
| pack-priv static final String metaobjectGetter | |
| metaobjectSetter | back to summary |
|---|---|
| pack-priv static final String metaobjectSetter | |
| readParam | back to summary |
|---|---|
| protected CtClass[] readParam | |
| readPrefix | back to summary |
|---|---|
| pack-priv static final String readPrefix | |
| trapMethod | back to summary |
|---|---|
| protected CtMethod trapMethod | |
| trapRead | back to summary |
|---|---|
| protected CtMethod trapRead | |
| trapStaticMethod | back to summary |
|---|---|
| protected CtMethod trapStaticMethod | |
| trapWrite | back to summary |
|---|---|
| protected CtMethod trapWrite | |
| writePrefix | back to summary |
|---|---|
| pack-priv static final String writePrefix | |
| Reflection | back to summary |
|---|---|
| public Reflection() Constructs a new | |
| findOriginal | back to summary |
|---|---|
| private CtMethod findOriginal(CtMethod m, boolean dontSearch) throws NotFoundException | |
| isExcluded | back to summary |
|---|---|
| private boolean isExcluded(String name) | |
| makeReflective | back 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.
| |
| makeReflective | back 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.
| |
| makeReflective | back to summary |
|---|---|
| public boolean makeReflective(CtClass clazz, CtClass metaobject, CtClass metaclass) throws CannotCompileException, CannotReflectException, NotFoundException Produces a reflective class. It modifies the given
| |
| modifyClassfile | back to summary |
|---|---|
| private boolean modifyClassfile(CtClass clazz, CtClass metaobject, CtClass metaclass) throws CannotCompileException, NotFoundException | |
| onLoad | back to summary |
|---|---|
| public void onLoad(ClassPool pool, String classname) throws CannotCompileException, NotFoundException Implements javassist. Inserts hooks for intercepting accesses to the fields declared in reflective classes.
| |
| processFields | back to summary |
|---|---|
| private void processFields(CtClass clazz) throws CannotCompileException, NotFoundException | |
| processMethods | back to summary |
|---|---|
| private void processMethods(CtClass clazz, boolean dontSearch) throws CannotCompileException, NotFoundException | |
| processMethods0 | back to summary |
|---|---|
| private void processMethods0(int mod, CtClass clazz, CtMethod m, int identifier, boolean dontSearch) throws CannotCompileException, NotFoundException | |
| rebuildClassFile | back to summary |
|---|---|
| public void rebuildClassFile(ClassFile cf) throws BadBytecode | |
| registerReflectiveClass | back to summary |
|---|---|
| private void registerReflectiveClass(CtClass clazz) Registers a reflective class. The field accesses to the instances of this class are instrumented. | |
| start | back to summary |
|---|---|
| public void start(ClassPool pool) throws NotFoundException Implements javassist. Initializes the object.
| |