Package com.firefly.utils.ReflectUtils

Examples of com.firefly.utils.ReflectUtils.FieldProxy


   
  }
 
  @Override
  public FieldProxy getFieldProxy(Field field) throws Throwable {
    FieldProxy ret = fieldCache.get(field);
    if(ret != null)
      return ret;
   
    synchronized(fieldCache) {
      ret = fieldCache.get(field);
View Full Code Here


   
    Class<?> fieldProxyClass = CompilerUtils.compileSource(completeClassName, source);
    if(fieldProxyClass == null)
      return null;
   
    FieldProxy fieldProxy = (FieldProxy)fieldProxyClass.getConstructor(Field.class).newInstance(field);
    return fieldProxy;
  }
View Full Code Here

  public void testProxyField() throws Throwable {
    Foo foo = new Foo();
    Field num2 = Foo.class.getField("num2");
    Field info = Foo.class.getField("info");
   
    FieldProxy proxyNum2 = ReflectUtils.getFieldProxy(num2);
    proxyNum2.set(foo, 30);
    Assert.assertThat((Integer)proxyNum2.get(foo), is(30));
   
    FieldProxy proxyInfo = ReflectUtils.getFieldProxy(info);
    proxyInfo.set(foo, "test info 0");
    Assert.assertThat((String)proxyInfo.get(foo), is("test info 0"));
   
    ReflectUtils.setProperty(foo, "name", "hello");
    Assert.assertThat((String)ReflectUtils.getProperty(foo, "name"), is("hello"));
   
   
    Foo foo2 = new Foo();
   
    proxyNum2 = FieldProxyFactoryUsingJavaCompiler.INSTANCE.getFieldProxy(num2);
    proxyNum2.set(foo2, 303);
    Assert.assertThat((Integer)proxyNum2.get(foo2), is(303));
   
    proxyInfo = FieldProxyFactoryUsingJavaCompiler.INSTANCE.getFieldProxy(info);
    proxyInfo.set(foo2, "test info 03");
    Assert.assertThat((String)proxyInfo.get(foo2), is("test info 03"));
  }
View Full Code Here

  public static void main(String[] args) throws Throwable {
    Foo foo = new Foo();
    Field num2 = Foo.class.getField("num2");
    Field info = Foo.class.getField("info");
   
    FieldProxy proxyNum2 = FieldProxyFactoryUsingJavaCompiler.INSTANCE.getFieldProxy(num2);
    proxyNum2.set(foo, 30);
    System.out.println(proxyNum2.get(foo));
   
    FieldProxy proxyInfo = FieldProxyFactoryUsingJavaCompiler.INSTANCE.getFieldProxy(info);
    proxyInfo.set(foo, "test info 0");
    System.out.println(proxyInfo.get(foo));
  }
View Full Code Here

   
    Field field = Foo.class.getField("num2");
    System.out.println(field.getType());
    System.out.println(field.getName());
    Field info = Foo.class.getField("info");
    FieldProxy proxyInfo = ReflectUtils.getFieldProxy(info);
    proxyInfo.set(foo, "test info 0");
    System.out.println(proxyInfo.get(foo));
//    System.out.println(ReflectUtils.createFieldGetterMethodCode(field));
//    System.out.println(ReflectUtils.createFieldGetterMethodCode(Foo.class.getField("info")));
//    System.out.println(ReflectUtils.createFieldSetterMethodCode(field));
//    System.out.println(ReflectUtils.createFieldSetterMethodCode(Foo.class.getField("info")));
  }
View Full Code Here

   
  }
 
  @Override
  public FieldProxy getFieldProxy(Field field) throws Throwable {
    FieldProxy ret = fieldCache.get(field);
    if(ret != null)
      return ret;
   
    synchronized(fieldCache) {
      ret = fieldCache.get(field);
View Full Code Here

   
    cc.addMethod(CtMethod.make("public Field field(){return field;}", cc));
    cc.addMethod(CtMethod.make(createFieldGetterMethodCode(field), cc));
    cc.addMethod(CtMethod.make(createFieldSetterMethodCode(field), cc));
   
    FieldProxy ret = (FieldProxy) cc.toClass().getConstructor(Field.class).newInstance(field);
//    long end = System.currentTimeMillis();
//    System.out.println("Javassist generates class proxy time -> " + (end - start));
    return ret;
  }
View Full Code Here

TOP

Related Classes of com.firefly.utils.ReflectUtils.FieldProxy

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.