PojoUtils { public static <T> SetterInt<T> createSetterInt(Class<? extends T> pojoClass, String setterExpr) { return createSetterInt(pojoClass, setterExpr, DEFAULT_EXP_OBJECT_PLACEHOLDER, DEFAULT_EXP_VAL_PLACEHOLDER); } private  PojoUtils(); static GetterBoolean<T> createGetterBoolean(Class<? extends T> pojoClass, String getterExpr); @SuppressWarnings("unchecked") static GetterBoolean<T> createGetterBoolean(Class<? extends T> pojoClass, String getterExpr, String exprObjectPlaceholder); static GetterByte<T> createGetterByte(Class<? extends T> pojoClass, String getterExpr); @SuppressWarnings("unchecked") static GetterByte<T> createGetterByte(Class<? extends T> pojoClass, String getterExpr, String exprObjectPlaceholder); static GetterChar<T> createGetterChar(Class<? extends T> pojoClass, String getterExpr); @SuppressWarnings({ "unchecked"}) static GetterChar<T> createGetterChar(Class<? extends T> pojoClass, String getterExpr, String exprObjectPlaceholder); static GetterShort<T> createGetterShort(Class<? extends T> pojoClass, String getterExpr); @SuppressWarnings("unchecked") static GetterShort<T> createGetterShort(Class<? extends T> pojoClass, String getterExpr, String exprObjectPlaceholder); static GetterInt<T> createGetterInt(Class<? extends T> pojoClass, String getterExpr); @SuppressWarnings("unchecked") static GetterInt<T> createGetterInt(Class<? extends T> pojoClass, String getterExpr, String exprObjectPlaceholder); static GetterLong<T> createGetterLong(Class<? extends T> pojoClass, String getterExpr); @SuppressWarnings("unchecked") static GetterLong<T> createGetterLong(Class<? extends T> pojoClass, String getterExpr, String exprObjectPlaceholder); static GetterFloat<T> createGetterFloat(Class<? extends T> pojoClass, String getterExpr); @SuppressWarnings("unchecked") static GetterFloat<T> createGetterFloat(Class<? extends T> pojoClass, String getterExpr, String exprObjectPlaceholder); static GetterDouble<T> createGetterDouble(Class<? extends T> pojoClass, String getterExpr); @SuppressWarnings("unchecked") static GetterDouble<T> createGetterDouble(Class<? extends T> pojoClass, String getterExpr, String exprObjectPlaceholder); static Getter<T, V> createGetter(Class<? extends T> pojoClass, String getterExpr, Class<? extends V> exprClass); @SuppressWarnings("unchecked") static Getter<T, V> createGetter(Class<? extends T> pojoClass, String getterExpr, String exprObjectPlaceholder, Class<? extends V> exprClass); static Object constructGetter(Class<?> pojoClass, String getterExpr, Class<?> exprClass); static Object constructGetter(Class<?> pojoClass, String getterExpr, String exprObjectPlaceholder, Class<?> exprClass); static SetterBoolean<T> createSetterBoolean(Class<? extends T> pojoClass, String setterExpr); @SuppressWarnings("unchecked") static SetterBoolean<T> createSetterBoolean(Class<? extends T> pojoClass, String setterExpr, String exprObjectPlaceholder, String exprValuePlaceholder); static SetterByte<T> createSetterByte(Class<? extends T> pojoClass, String setterExpr); @SuppressWarnings("unchecked") static SetterByte<T> createSetterByte(Class<? extends T> pojoClass, String setterExpr, String exprObjectPlaceholder, String exprValuePlaceholder); static SetterChar<T> createSetterChar(Class<? extends T> pojoClass, String setterExpr); @SuppressWarnings("unchecked") static SetterChar<T> createSetterChar(Class<? extends T> pojoClass, String setterExpr, String exprObjectPlaceholder, String exprValuePlaceholder); static SetterShort<T> createSetterShort(Class<? extends T> pojoClass, String setterExpr); @SuppressWarnings("unchecked") static SetterShort<T> createSetterShort(Class<? extends T> pojoClass, String setterExpr, String exprObjectPlaceholder, String exprValuePlaceholder); static SetterInt<T> createSetterInt(Class<? extends T> pojoClass, String setterExpr); @SuppressWarnings("unchecked") static SetterInt<T> createSetterInt(Class<? extends T> pojoClass, String setterExpr, String exprObjectPlaceholder, String exprValuePlaceholder); static SetterLong<T> createSetterLong(Class<? extends T> pojoClass, String setterExpr); @SuppressWarnings("unchecked") static SetterLong<T> createSetterLong(Class<? extends T> pojoClass, String setterExpr, String exprObjectPlaceholder, String exprValuePlaceholder); static SetterFloat<T> createSetterFloat(Class<? extends T> pojoClass, String setterExpr); @SuppressWarnings("unchecked") static SetterFloat<T> createSetterFloat(Class<? extends T> pojoClass, String setterExpr, String exprObjectPlaceholder, String exprValuePlaceholder); static SetterDouble<T> createSetterDouble(Class<? extends T> pojoClass, String setterExpr); @SuppressWarnings("unchecked") static SetterDouble<T> createSetterDouble(Class<? extends T> pojoClass, String setterExpr, String exprObjectPlaceholder, String exprValuePlaceholder); static Setter<T, V> createSetter(Class<? extends T> pojoClass, String setterExpr, Class<? extends V> exprClass); @SuppressWarnings("unchecked") static Setter<T, V> createSetter(Class<? extends T> pojoClass, String setterExpr, String exprObjectPlaceholder, String exprValuePlaceholder, Class<? extends V> exprClass); static Object constructSetter(Class<?> pojoClass, String setterExpr, Class<?> exprClass); static Object constructSetter(Class<?> pojoClass, String setterExpr, String exprObjectPlaceholder, String exprValPlaceholder, Class<?> exprClass); static Expression createExpression(Class<?> inputType, String expr, Class<?> returnType); static Expression createExpression(Class<?> inputType, String expr, Class<?> returnType,
      String[] defaultImports); static Expression createExpression(Class<?> inputType, String expr, Class<?> returnType,
      String[] defaultImports, Expression.ExpressionParser parser); static final String DEFAULT_EXP_OBJECT_PLACEHOLDER; static final String DEFAULT_EXP_VAL_PLACEHOLDER; static final String DEFAULT_EXPRESSION_OBJ_PLACEHOLDER; }
@Test public void testSetterInt() throws Exception { int intVal = innerObj.intVal; PojoUtils.createSetterInt(fqcn, "innerObj.intVal").set(testObj, ++intVal); assertEquals(intVal, innerObj.intVal); createSetterInt(innerObjClass, "intVal").set(innerObj, ++intVal); assertEquals(intVal, innerObj.intVal); createSetterInt(innerObjClass, "protectedIntVal").set(innerObj, ++intVal); assertEquals(intVal, innerObj.protectedIntVal); createSetterInt(innerObjClass, "privateIntVal").set(innerObj, ++intVal); assertEquals(intVal, innerObj.getPrivateIntVal()); }
@Test (expected = RuntimeException.class) public void testWrongSetterMethod() { final Class<?> testPojoClass = TestPojo.class; @SuppressWarnings("unused") SetterInt<Object> setterInt = createSetterInt(testPojoClass, "privateInt"); }
@Test (expected = RuntimeException.class) public void testPrivateField() { final Class<?> testPojoClass = TestPojo.class; @SuppressWarnings("unused") SetterInt<Object> setterInt = createSetterInt(testPojoClass, "privateIntField"); }