Class Reflection

  • All Implemented Interfaces:
    Translator

    public class Reflection
    extends java.lang.Object
    implements Translator
    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:
    ClassMetaobject, Metaobject, Loader, Compiler
    • Constructor Summary

      Constructors 
      Constructor Description
      Reflection()
      Constructs a new Reflection object.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean makeReflective​(java.lang.Class<?> clazz, java.lang.Class<?> metaobject, java.lang.Class<?> metaclass)
      Produces a reflective class.
      boolean makeReflective​(java.lang.String classname, java.lang.String metaobject, java.lang.String metaclass)
      Produces a reflective class.
      boolean makeReflective​(CtClass clazz, CtClass metaobject, CtClass metaclass)
      Produces a reflective class.
      void onLoad​(ClassPool pool, java.lang.String classname)
      Inserts hooks for intercepting accesses to the fields declared in reflective classes.
      void rebuildClassFile​(ClassFile cf)  
      void start​(ClassPool pool)
      Initializes the object.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Reflection

        public Reflection()
        Constructs a new Reflection object.