public void generateClass(ClassVisitor v) throws Exception { int size = props.size(); String[] names = (String[])props.keySet().toArray(new String[size]); Type[] types = new Type[size]; for (int i = 0; i < size; i++) { types[i] = (Type)props.get(names[i]); } ClassEmitter ce = new ClassEmitter(v); ce.begin_class(Constants.V1_2, Constants.ACC_PUBLIC, getClassName(), superclass != null ? Type.getType(superclass) : Constants.TYPE_OBJECT, null, null); EmitUtils.null_constructor(ce); EmitUtils.add_properties(ce, names, types); ce.end_class(); }
public static void add_properties(ClassEmitter ce, String[] names, Type[] types) { for (int i = 0; i < names.length; i++) { String fieldName = "$cglib_prop_" + names[i]; ce.declare_field(Constants.ACC_PRIVATE, fieldName, types[i], null); EmitUtils.add_property(ce, names[i], types[i], fieldName); } }
public static void append_string(final CodeEmitter e, Type type, final ArrayDelimiters delims, final Customizer customizer) { final ArrayDelimiters d = (delims != null) ? delims : DEFAULT_DELIMITERS; ProcessArrayCallback callback = new ProcessArrayCallback() { public void processElement(Type type) { append_string_helper(e, type, d, customizer, this); e.push(d.inside); e.invoke_virtual(Constants.TYPE_STRING_BUFFER, APPEND_STRING); } }; append_string_helper(e, type, d, customizer, callback); }
public ParallelSorterEmitter(ClassVisitor v, String className, Object[] arrays) { super(v); begin_class(Constants.V1_2, Constants.ACC_PUBLIC, className, PARALLEL_SORTER, null, Constants.SOURCE_FILE); EmitUtils.null_constructor(this); EmitUtils.factory_method(this, NEW_INSTANCE); generateConstructor(arrays); generateSwap(arrays); end_class(); }
public static void hash_code(CodeEmitter e, Type type, int multiplier, Customizer customizer) { if (TypeUtils.isArray(type)) { hash_array(e, type, multiplier, customizer); } else { e.swap(Type.INT_TYPE, type); e.push(multiplier); e.math(e.MUL, Type.INT_TYPE); e.swap(type, Type.INT_TYPE); if (TypeUtils.isPrimitive(type)) { hash_primitive(e, type); } else { hash_object(e, type, customizer); } e.math(e.ADD, Type.INT_TYPE); } }
new Type[]{ Type.getType(keyInterface) }, Constants.SOURCE_FILE); EmitUtils.null_constructor(ce); EmitUtils.factory_method(ce, ReflectUtils.getSignature(newInstance)); e.load_this(); e.getfield(getFieldName(i)); EmitUtils.hash_code(e, parameterTypes[i], hm, customizer); e.checkcast_this(); e.getfield(getFieldName(i)); EmitUtils.not_equals(e, parameterTypes[i], fail, customizer); EmitUtils.append_string(e, parameterTypes[i], EmitUtils.DEFAULT_DELIMITERS, customizer);
TypeUtils.getTypes(getInterfaces(classes)), Constants.SOURCE_FILE); EmitUtils.null_constructor(this); EmitUtils.factory_method(this, NEW_INSTANCE); if (unique.add(MethodWrapper.create(methods[j]))) { MethodInfo method = ReflectUtils.getMethodInfo(methods[j]); e = EmitUtils.begin_method(this, method, Constants.ACC_PUBLIC); e.load_this(); e.getfield(FIELD_NAME);
public static CodeEmitter begin_method(ClassEmitter e, MethodInfo method) { return begin_method(e, method, method.getModifiers()); }
private static void stringSwitchHelper(final CodeEmitter e, List strings, final ObjectSwitchCallback callback, final Label def, final Label end, final int index) throws Exception { final int len = ((String)strings.get(0)).length(); final Map buckets = CollectionUtils.bucket(strings, new Transformer() { public Object transform(Object value) { return new Integer(((String)value).charAt(index)); } }); e.dup(); e.push(index); e.invoke_virtual(Constants.TYPE_STRING, STRING_CHAR_AT); e.process_switch(getSwitchKeys(buckets), new ProcessSwitchCallback() { public void processCase(int key, Label ignore_end) throws Exception { List bucket = (List)buckets.get(new Integer(key)); if (index + 1 == len) { e.pop(); callback.processCase(bucket.get(0), end); } else { stringSwitchHelper(e, bucket, callback, def, end, index + 1); } } public void processDefault() { e.goTo(def); } }); }
private void emitProxy(ClassEmitter ce, final MethodInfo method) { final CodeEmitter e = EmitUtils.begin_method(ce, method, Constants.ACC_PUBLIC); Type returnType = method.getSignature().getReturnType(); final boolean returns = returnType != Type.VOID_TYPE; Local result = null; if (returns) { result = e.make_local(returnType); e.zero_or_null(returnType); e.store_local(result); } e.load_this(); e.super_getfield("targets", Constants.TYPE_OBJECT_ARRAY); final Local result2 = result; EmitUtils.process_array(e, Constants.TYPE_OBJECT_ARRAY, new ProcessArrayCallback() { public void processElement(Type type) { e.checkcast(Type.getType(iface)); e.load_args(); e.invoke(method); if (returns) { e.store_local(result2); } } }); if (returns) { e.load_local(result); } e.return_value(); e.end_method(); }
Constants.SOURCE_FILE); ce.declare_field(Constants.PRIVATE_FINAL_STATIC, "eqMethod", Constants.TYPE_STRING, null); EmitUtils.null_constructor(ce); e = EmitUtils.begin_method(ce, proxied, Constants.ACC_PUBLIC); e.load_this(); e.super_getfield("target", Constants.TYPE_OBJECT);
private void emitNewInstanceMultiarg(ClassEmitter ce, List constructors) { final CodeEmitter e = ce.begin_method(Constants.ACC_PUBLIC, MULTIARG_NEW_INSTANCE, null); e.load_arg(2); e.invoke_static_this(SET_THREAD_CALLBACKS); e.new_instance_this(); e.dup(); e.load_arg(0); EmitUtils.constructor_switch(e, constructors, new ObjectSwitchCallback() { public void processCase(Object key, Label end) { MethodInfo constructor = (MethodInfo)key; Type types[] = constructor.getSignature().getArgumentTypes(); for (int i = 0; i < types.length; i++) { e.load_arg(1); e.push(i); e.aaload(); e.unbox(types[i]); } e.invoke_constructor_this(constructor.getSignature()); e.goTo(end); } public void processDefault() { e.throw_exception(ILLEGAL_ARGUMENT_EXCEPTION, "Constructor not found"); } }); e.aconst_null(); e.invoke_static_this(SET_THREAD_CALLBACKS); e.return_value(); e.end_method(); }
public void end_class() { if (!TypeUtils.isAbstract(getAccess())) { EmitUtils.add_properties(this, names, types); } super.end_class(); } }
public void processElement(Type type) { hash_code(e, type, multiplier, customizer); } });
new Type[]{ Type.getType(keyInterface) }, Constants.SOURCE_FILE); EmitUtils.null_constructor(ce); EmitUtils.factory_method(ce, ReflectUtils.getSignature(newInstance)); e.load_this(); e.getfield(getFieldName(i)); EmitUtils.hash_code(e, parameterTypes[i], hm, customizer); e.checkcast_this(); e.getfield(getFieldName(i)); EmitUtils.not_equals(e, parameterTypes[i], fail, customizer); EmitUtils.append_string(e, parameterTypes[i], EmitUtils.DEFAULT_DELIMITERS, customizer);
public static void hash_code(CodeEmitter e, Type type, int multiplier, Customizer customizer) { if (TypeUtils.isArray(type)) { hash_array(e, type, multiplier, customizer); } else { e.swap(Type.INT_TYPE, type); e.push(multiplier); e.math(e.MUL, Type.INT_TYPE); e.swap(type, Type.INT_TYPE); if (TypeUtils.isPrimitive(type)) { hash_primitive(e, type); } else { hash_object(e, type, customizer); } e.math(e.ADD, Type.INT_TYPE); } }
TypeUtils.getTypes(getInterfaces(classes)), Constants.SOURCE_FILE); EmitUtils.null_constructor(this); EmitUtils.factory_method(this, NEW_INSTANCE); if (unique.add(MethodWrapper.create(methods[j]))) { MethodInfo method = ReflectUtils.getMethodInfo(methods[j]); e = EmitUtils.begin_method(this, method, Constants.ACC_PUBLIC); e.load_this(); e.getfield(FIELD_NAME);
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(); }
public void generate(ClassEmitter ce, Context context, List methods) { for (Iterator it = methods.iterator(); it.hasNext();) { MethodInfo method = (MethodInfo)it.next(); if (TypeUtils.isProtected(context.getOriginalModifiers(method)) && TypeUtils.isPublic(method.getModifiers())) { CodeEmitter e = EmitUtils.begin_method(ce, method); e.load_this(); e.load_args(); e.super_invoke(); e.return_value(); e.end_method(); } } }
private static void member_helper_size(final CodeEmitter e, List members, final ObjectSwitchCallback callback, final ParameterTyper typer, final Label def, final Label end) throws Exception { final Map buckets = CollectionUtils.bucket(members, new Transformer() { public Object transform(Object value) { return new Integer(typer.getParameterTypes((MethodInfo)value).length); } }); e.dup(); e.arraylength(); e.process_switch(EmitUtils.getSwitchKeys(buckets), new ProcessSwitchCallback() { public void processCase(int key, Label dontUseEnd) throws Exception { List bucket = (List)buckets.get(new Integer(key)); member_helper_type(e, bucket, callback, typer, def, end, new BitSet()); } public void processDefault() throws Exception { e.goTo(def); } }); }