protected Object firstInstance(Class type) { return ReflectUtils.newInstance(type, new Class[]{ Class.class }, new Object[]{ this.type }); }
public static MethodInfo getMethodInfo(final Member member, final int modifiers) { final Signature sig = getSignature(member); return new MethodInfo() { private ClassInfo ci; public ClassInfo getClassInfo() { if (ci == null) ci = ReflectUtils.getClassInfo(member.getDeclaringClass()); return ci; } public int getModifiers() { return modifiers; } public Signature getSignature() { return sig; } public Type[] getExceptionTypes() { return ReflectUtils.getExceptionTypes(member); } public Attribute getAttribute() { return null; } }; }
protected Class[] getInterfaces(Class[] classes) { List list = new ArrayList(); for (int i = 0; i < classes.length; i++) { ReflectUtils.addAllInterfaces(classes[i], list); } return (Class[])list.toArray(new Class[list.size()]); }
public static Object newInstance(Class type, Class[] parameterTypes, Object[] args) { return newInstance(getConstructor(type, parameterTypes), args); }
/** * Add a method signature to the interface. The method modifiers are ignored, * since interface methods are by definition abstract and public. * @param method the method to add to the interface */ public void add(Method method) { add(ReflectUtils.getSignature(method), ReflectUtils.getExceptionTypes(method)); }
public void generateClass(ClassVisitor cv) { final MethodInfo method = ReflectUtils.getMethodInfo(ReflectUtils.findInterfaceMethod(iface)); ClassEmitter ce = new ClassEmitter(cv); ce.begin_class(Constants.V1_2, Constants.ACC_PUBLIC, getClassName(), MULTICAST_DELEGATE, new Type[]{ Type.getType(iface) }, Constants.SOURCE_FILE); EmitUtils.null_constructor(ce); // generate proxied method emitProxy(ce, method); // newInstance CodeEmitter e = ce.begin_method(Constants.ACC_PUBLIC, NEW_INSTANCE, null); e.new_instance_this(); e.dup(); e.invoke_constructor_this(); e.return_value(); e.end_method(); // add e = ce.begin_method(Constants.ACC_PUBLIC, ADD_DELEGATE, null); e.load_this(); e.load_arg(0); e.checkcast(Type.getType(iface)); e.invoke_virtual_this(ADD_HELPER); e.return_value(); e.end_method(); ce.end_class(); }
public BeanMapEmitter(ClassVisitor v, String className, Class type, int require) { super(v); begin_class(Constants.V1_2, Constants.ACC_PUBLIC, className, BEAN_MAP, null, Constants.SOURCE_FILE); EmitUtils.null_constructor(this); EmitUtils.factory_method(this, NEW_INSTANCE); generateConstructor(); Map getters = makePropertyMap(ReflectUtils.getBeanGetters(type)); Map setters = makePropertyMap(ReflectUtils.getBeanSetters(type)); Map allProps = new HashMap(); allProps.putAll(getters); allProps.putAll(setters); if (require != 0) { for (Iterator it = allProps.keySet().iterator(); it.hasNext();) { String name = (String)it.next(); if ((((require & BeanMap.REQUIRE_GETTER) != 0) && !getters.containsKey(name)) || (((require & BeanMap.REQUIRE_SETTER) != 0) && !setters.containsKey(name))) { it.remove(); getters.remove(name); setters.remove(name); } } } generateGet(type, getters); generatePut(type, setters); String[] allNames = getNames(allProps); generateKeySet(allNames); generateGetPropertyType(allProps, allNames); end_class(); }
PropertyDescriptor[] getters = ReflectUtils.getBeanGetters(source); PropertyDescriptor[] setters = ReflectUtils.getBeanSetters(target); PropertyDescriptor getter = (PropertyDescriptor)names.get(setter.getName()); if (getter != null) { MethodInfo read = ReflectUtils.getMethodInfo(getter.getReadMethod()); MethodInfo write = ReflectUtils.getMethodInfo(setter.getWriteMethod()); if (useConverter) { Type setterType = write.getSignature().getArgumentTypes()[0];
public void generateClass(ClassVisitor v) { setNamePrefix(targetClass.getName()); final Method newInstance = ReflectUtils.findNewInstance(iface); if (!newInstance.getReturnType().isAssignableFrom(targetClass)) { throw new IllegalArgumentException("incompatible return type"); EmitUtils.null_constructor(ce); CodeEmitter e = ce.begin_method(Constants.ACC_PUBLIC, ReflectUtils.getSignature(newInstance), ReflectUtils.getExceptionTypes(newInstance)); e.new_instance(declaring); e.dup(); e.load_args(); e.invoke_constructor(declaring, ReflectUtils.getSignature(constructor)); e.return_value(); e.end_method();
PropertyDescriptor[] getters = ReflectUtils.getBeanGetters(source); PropertyDescriptor[] setters = ReflectUtils.getBeanGetters(target); PropertyDescriptor getter = (PropertyDescriptor)names.get(setter.getName()); if (getter != null) { MethodInfo read = ReflectUtils.getMethodInfo(getter.getReadMethod()); MethodInfo write = ReflectUtils.getMethodInfo(setter.getWriteMethod()); if (useConverter) { Type setterType = write.getSignature().getArgumentTypes()[0];
public static List addAllMethods(final Class type, final List list) { if (type == Object.class) { list.addAll(OBJECT_METHODS); } else list.addAll(java.util.Arrays.asList(type.getDeclaredMethods())); Class superclass = type.getSuperclass(); if (superclass != null) { addAllMethods(superclass, list); } Class[] interfaces = type.getInterfaces(); for (int i = 0; i < interfaces.length; i++) { addAllMethods(interfaces[i], list); } return list; }
public static Class defineClass(String className, byte[] b, ClassLoader loader) throws Exception { return defineClass(className, b, loader, PROTECTION_DOMAIN); }
public static Method findNewInstance(Class iface) { Method m = findInterfaceMethod(iface); if (!m.getName().equals("newInstance")) { throw new IllegalArgumentException(iface + " missing newInstance method"); } return m; }
public static Constructor findConstructor(String desc) { return findConstructor(desc, defaultLoader); }
for (i = 0; i < types.length; i++) { if (getters[i] != null) { Method method = ReflectUtils.findDeclaredMethod(target, getters[i], null); if (method.getReturnType() != types[i]) { throw new BulkBeanException("Specified type " + types[i] + Method method = ReflectUtils.findDeclaredMethod(target, setters[i], new Class[]{ types[i] }); if (Modifier.isPrivate(method.getModifiers()) ){ throw new BulkBeanException("Property is private", i);
static List<PropertyDescriptor> findSettableProperties(Class<? extends BeanTag> clazz) { List<PropertyDescriptor> list = new ArrayList<PropertyDescriptor>(0); for (PropertyDescriptor pd : net.sf.cglib.core.ReflectUtils.getBeanSetters(clazz)) { Method setter = pd.getWriteMethod(); Class<?> ownerClass = setter.getDeclaringClass(); if (BeanTag.class.equals(ownerClass) || ReflectUtils.isSubClass(ownerClass, BeanTag.class, true)) { list.add(pd); } } return list; }
private ChildrenResultList visitBean(Context context, Object bean, boolean readValue) { if (bean == null) { return null; } ChildrenResultList list = null; int i = 0; for (PropertyDescriptor d : ReflectUtils.getBeanGetters(bean.getClass())) { Method method = d.getReadMethod(); Object value = null; if (readValue) { try { value = method.invoke(bean); } catch (Exception e) { throw new PaxmlRuntimeException("Cannot read property '" + d.getName() + "' from class: " + bean.getClass().getName(), e); } } list = addAll(list, visit(context, bean, d.getName(), i++, value)); } return list; }
public void generateClass(ClassVisitor v) throws NoSuchMethodException { Method proxy = ReflectUtils.findInterfaceMethod(iface); final Method method = targetClass.getMethod(methodName, proxy.getParameterTypes()); if (!proxy.getReturnType().isAssignableFrom(method.getReturnType())) { MethodInfo methodInfo = ReflectUtils.getMethodInfo(method); MethodInfo proxied = ReflectUtils.getMethodInfo(iface.getDeclaredMethods()[0]); int modifiers = Constants.ACC_PUBLIC; if ((proxied.getModifiers() & Constants.ACC_VARARGS) == Constants.ACC_VARARGS) {
public BeanMapEmitter(ClassVisitor v, String className, Class type, int require) { super(v); begin_class(Constants.V1_2, Constants.ACC_PUBLIC, className, BEAN_MAP, null, Constants.SOURCE_FILE); EmitUtils.null_constructor(this); EmitUtils.factory_method(this, NEW_INSTANCE); generateConstructor(); Map getters = makePropertyMap(ReflectUtils.getBeanGetters(type)); Map setters = makePropertyMap(ReflectUtils.getBeanSetters(type)); Map allProps = new HashMap(); allProps.putAll(getters); allProps.putAll(setters); if (require != 0) { for (Iterator it = allProps.keySet().iterator(); it.hasNext();) { String name = (String)it.next(); if ((((require & BeanMap.REQUIRE_GETTER) != 0) && !getters.containsKey(name)) || (((require & BeanMap.REQUIRE_SETTER) != 0) && !setters.containsKey(name))) { it.remove(); getters.remove(name); setters.remove(name); } } } generateGet(type, getters); generatePut(type, setters); String[] allNames = getNames(allProps); generateKeySet(allNames); generateGetPropertyType(allProps, allNames); end_class(); }
PropertyDescriptor[] getters = ReflectUtils.getBeanGetters(source); PropertyDescriptor[] setters = ReflectUtils.getBeanSetters(target); PropertyDescriptor getter = (PropertyDescriptor)names.get(setter.getName()); if (getter != null) { MethodInfo read = ReflectUtils.getMethodInfo(getter.getReadMethod()); MethodInfo write = ReflectUtils.getMethodInfo(setter.getWriteMethod()); if (useConverter) { Type setterType = write.getSignature().getArgumentTypes()[0];