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 CustomizerRegistry registry) { final ArrayDelimiters d = (delims != null) ? delims : DEFAULT_DELIMITERS; ProcessArrayCallback callback = new ProcessArrayCallback() { public void processElement(Type type) { append_string_helper(e, type, d, registry, this); e.push(d.inside); e.invoke_virtual(Constants.TYPE_STRING_BUFFER, APPEND_STRING); } }; append_string_helper(e, type, d, registry, 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(); }
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, customizers); e.checkcast_this(); e.getfield(getFieldName(i)); EmitUtils.not_equals(e, parameterTypes[i], fail, customizers); EmitUtils.append_string(e, parameterTypes[i], EmitUtils.DEFAULT_DELIMITERS, customizers);
public static void hash_code(CodeEmitter e, Type type, int multiplier, final CustomizerRegistry registry) { if (TypeUtils.isArray(type)) { hash_array(e, type, multiplier, registry); } 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, registry); } e.math(e.ADD, Type.INT_TYPE); } }
TypeUtils.getTypes(getInterfaces(classes)), Constants.SOURCE_FILE); EmitUtils.null_constructor(this); EmitUtils.factory_method(this, NEW_INSTANCE); modifiers |= Constants.ACC_VARARGS; e = EmitUtils.begin_method(this, method, modifiers); e.load_this(); e.getfield(FIELD_NAME);
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); } }); }
public static CodeEmitter begin_method(ClassEmitter e, MethodInfo method) { return begin_method(e, method, method.getModifiers()); }
private void emitNewInstanceMultiarg(ClassEmitter ce, List constructors) { final CodeEmitter e = ce.begin_method(Constants.ACC_PUBLIC, MULTIARG_NEW_INSTANCE, null); final Type thisType = getThisType(e); e.load_arg(2); e.invoke_static(thisType, SET_THREAD_CALLBACKS); e.new_instance(thisType); 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(thisType, constructor.getSignature()); e.goTo(end); } public void processDefault() { e.throw_exception(ILLEGAL_ARGUMENT_EXCEPTION, "Constructor not found"); } }); e.aconst_null(); e.invoke_static(thisType, SET_THREAD_CALLBACKS); e.return_value(); e.end_method(); }
modifiers |= Constants.ACC_VARARGS; final CodeEmitter e = EmitUtils.begin_method(ce, method, modifiers); Type returnType = method.getSignature().getReturnType(); final boolean returns = returnType != Type.VOID_TYPE; 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));
Constants.SOURCE_FILE); ce.declare_field(Constants.PRIVATE_FINAL_STATIC, "eqMethod", Constants.TYPE_STRING, null); EmitUtils.null_constructor(ce); modifiers |= Constants.ACC_VARARGS; e = EmitUtils.begin_method(ce, proxied, modifiers); e.load_this(); e.super_getfield("target", Constants.TYPE_OBJECT);
public void processElement(Type type) { hash_code(e, type, multiplier, registry); } });
public void end_class() { if (!TypeUtils.isAbstract(getAccess())) { EmitUtils.add_properties(this, names, types); } super.end_class(); } }
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); }
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, customizers); e.checkcast_this(); e.getfield(getFieldName(i)); EmitUtils.not_equals(e, parameterTypes[i], fail, customizers); EmitUtils.append_string(e, parameterTypes[i], EmitUtils.DEFAULT_DELIMITERS, customizers);
public static void hash_code(CodeEmitter e, Type type, int multiplier, final CustomizerRegistry registry) { if (TypeUtils.isArray(type)) { hash_array(e, type, multiplier, registry); } 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, registry); } e.math(e.ADD, Type.INT_TYPE); } }
TypeUtils.getTypes(getInterfaces(classes)), Constants.SOURCE_FILE); EmitUtils.null_constructor(this); EmitUtils.factory_method(this, NEW_INSTANCE); modifiers |= Constants.ACC_VARARGS; e = EmitUtils.begin_method(this, method, modifiers); e.load_this(); e.getfield(FIELD_NAME);
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(); }
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); } }); }