Refine search
public static void null_constructor(ClassEmitter ce) { CodeEmitter e = ce.begin_method(Constants.ACC_PUBLIC, CSTRUCT_NULL, null); e.load_this(); e.super_invoke_constructor(); e.return_value(); e.end_method(); }
private void generateConstructor() { CodeEmitter e = begin_method(Constants.ACC_PUBLIC, CSTRUCT_OBJECT, null); e.load_this(); e.load_arg(0); e.super_invoke_constructor(CSTRUCT_OBJECT); e.return_value(); e.end_method(); }
private void getField(String[] names) throws Exception { final CodeEmitter e = begin_method(Constants.ACC_PUBLIC, PROVIDER_GET, null); e.load_this(); e.load_arg(0); EmitUtils.string_switch(e, names, Constants.SWITCH_STYLE_HASH, new ObjectSwitchCallback() { public void processCase(Object key, Label end) { Type type = (Type)fields.get(key); e.getfield((String)key); e.box(type); e.return_value(); } public void processDefault() { e.throw_exception(ILLEGAL_ARGUMENT_EXCEPTION, "Unknown field name"); } }); e.end_method(); }
private void addDelegate(Method m) { Method delegate; try { delegate = delegateImpl.getMethod(m.getName(), m.getParameterTypes()); if (!delegate.getReturnType().getName().equals(m.getReturnType().getName())){ throw new IllegalArgumentException("Invalid delegate signature " + delegate); } } catch (NoSuchMethodException e) { throw new CodeGenerationException(e); } final Signature sig = ReflectUtils.getSignature(m); Type[] exceptions = TypeUtils.getTypes(m.getExceptionTypes()); CodeEmitter e = super.begin_method(Constants.ACC_PUBLIC, sig, exceptions); e.load_this(); e.getfield(DELEGATE); e.load_args(); e.invoke_virtual(delegateType, sig); e.return_value(); e.end_method(); } }
private void getByIndex(final String[] names, final int[] indexes) throws Exception { final CodeEmitter e = super.begin_method(Constants.ACC_PUBLIC, PROVIDER_GET_BY_INDEX, null); e.load_this(); e.load_arg(0); e.process_switch(indexes, new ProcessSwitchCallback() { public void processCase(int key, Label end) throws Exception { Type type = (Type)fields.get(names[key]); e.getfield(names[key]); e.box(type); e.return_value(); } public void processDefault() throws Exception { e.throw_exception(ILLEGAL_ARGUMENT_EXCEPTION, "Unknown field index"); } }); e.end_method(); }
private void emitGetCallback(ClassEmitter ce, int[] keys) { final CodeEmitter e = ce.begin_method(Constants.ACC_PUBLIC, GET_CALLBACK, null); e.load_this(); e.invoke_static_this(BIND_CALLBACKS); e.load_this(); e.load_arg(0); e.process_switch(keys, new ProcessSwitchCallback() { public void processCase(int key, Label end) { e.getfield(getCallbackField(key)); e.goTo(end); } public void processDefault() { e.pop(); // stack height e.aconst_null(); } }); e.return_value(); e.end_method(); }
private void setByIndex(final String[] names, final int[] indexes) throws Exception { final CodeEmitter e = super.begin_method(Constants.ACC_PUBLIC, PROVIDER_SET_BY_INDEX, null); e.load_this(); e.load_arg(1); e.load_arg(0); e.process_switch(indexes, new ProcessSwitchCallback() { public void processCase(int key, Label end) throws Exception { Type type = (Type)fields.get(names[key]); e.unbox(type); e.putfield(names[key]); e.return_value(); } public void processDefault() throws Exception { e.throw_exception(ILLEGAL_ARGUMENT_EXCEPTION, "Unknown field index"); } }); e.end_method(); }
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 void emitGetCallbacks(ClassEmitter ce) { CodeEmitter e = ce.begin_method(Constants.ACC_PUBLIC, GET_CALLBACKS, null); e.load_this(); e.invoke_static_this(BIND_CALLBACKS); e.load_this(); e.push(callbackTypes.length); e.newarray(CALLBACK); for (int i = 0; i < callbackTypes.length; i++) { e.dup(); e.push(i); e.load_this(); e.getfield(getCallbackField(i)); e.aastore(); } e.return_value(); e.end_method(); }
private void emitConstructors(ClassEmitter ce, List constructors) { boolean seenNull = false; for (Iterator it = constructors.iterator(); it.hasNext();) { MethodInfo constructor = (MethodInfo)it.next(); CodeEmitter e = EmitUtils.begin_method(ce, constructor, Constants.ACC_PUBLIC); e.load_this(); e.dup(); e.load_args(); Signature sig = constructor.getSignature(); seenNull = seenNull || sig.getDescriptor().equals("()V"); e.super_invoke_constructor(sig); e.invoke_static_this(BIND_CALLBACKS); if (!interceptDuringConstruction) { e.load_this(); e.push(1); e.putfield(CONSTRUCTED_FIELD); } e.return_value(); e.end_method(); } if (!classOnly && !seenNull && arguments == null) throw new IllegalArgumentException("Superclass has no null constructors but no arguments were given"); }
private void setField(String[] names) throws Exception { final CodeEmitter e = begin_method(Constants.ACC_PUBLIC, PROVIDER_SET, null); e.load_this(); e.load_arg(1); e.load_arg(0); EmitUtils.string_switch(e, names, Constants.SWITCH_STYLE_HASH, new ObjectSwitchCallback() { public void processCase(Object key, Label end) { Type type = (Type)fields.get(key); e.unbox(type); e.putfield((String)key); e.return_value(); } public void processDefault() { e.throw_exception(ILLEGAL_ARGUMENT_EXCEPTION, "Unknown field name"); } }); e.end_method(); } }
private void generateConstructor(Object[] arrays) { CodeEmitter e = begin_method(Constants.ACC_PUBLIC, CSTRUCT_OBJECT_ARRAY, null); e.load_this(); e.super_invoke_constructor(); e.load_this(); e.load_arg(0); e.super_putfield("a", Constants.TYPE_OBJECT_ARRAY); for (int i = 0; i < arrays.length; i++) { Type type = Type.getType(arrays[i].getClass()); declare_field(Constants.ACC_PRIVATE, getFieldName(i), type, null); e.load_this(); e.load_arg(0); e.push(i); e.aaload(); e.checkcast(type); e.putfield(getFieldName(i)); } e.return_value(); e.end_method(); }
public static void add_property(ClassEmitter ce, String name, Type type, String fieldName) { String property = TypeUtils.upperFirst(name); CodeEmitter e; e = ce.begin_method(Constants.ACC_PUBLIC, new Signature("get" + property, type, Constants.TYPES_EMPTY), null); e.load_this(); e.getfield(fieldName); e.return_value(); e.end_method(); e = ce.begin_method(Constants.ACC_PUBLIC, new Signature("set" + property, Type.VOID_TYPE, new Type[]{ type }), null); e.load_this(); e.load_arg(0); e.putfield(fieldName); e.return_value(); e.end_method(); }
public void begin_class(int version, int access, String className, Type superType, Type[] interfaces, String sourceFile) { if (!TypeUtils.isInterface(access)) { super.begin_class(version, access, className, superType, TypeUtils.add(interfaces, ENABLED), sourceFile); super.declare_field(Constants.ACC_PRIVATE | Constants.ACC_TRANSIENT, CALLBACK_FIELD, CALLBACK, null); CodeEmitter e; e = super.begin_method(Constants.ACC_PUBLIC, ENABLED_GET, null); e.load_this(); e.getfield(CALLBACK_FIELD); e.return_value(); e.end_method(); e = super.begin_method(Constants.ACC_PUBLIC, ENABLED_SET, null); e.load_this(); e.load_arg(0); e.putfield(CALLBACK_FIELD); e.return_value(); e.end_method(); } else { super.begin_class(version, access, className, superType, interfaces, sourceFile); } }
private void emitSetCallbacks(ClassEmitter ce) { CodeEmitter e = ce.begin_method(Constants.ACC_PUBLIC, SET_CALLBACKS, null); e.load_this(); e.load_arg(0); for (int i = 0; i < callbackTypes.length; i++) { e.dup2(); e.aaload(i); e.checkcast(callbackTypes[i]); e.putfield(getCallbackField(i)); } e.return_value(); e.end_method(); }
private void addReadMethod(String name, Type type) { CodeEmitter e = super.begin_method(Constants.ACC_PUBLIC, readMethodSig(name, type.getDescriptor()), null); e.load_this(); e.getfield(name); e.load_this(); e.invoke_interface(ENABLED,ENABLED_GET); Label intercept = e.make_label(); e.ifnonnull(intercept); e.return_value(); e.mark(intercept); Local result = e.make_local(type); e.store_local(result); e.load_this(); e.invoke_interface(ENABLED,ENABLED_GET); e.load_this(); e.push(name); e.load_local(result); e.invoke_interface(CALLBACK, readCallbackSig(type)); if (!TypeUtils.isPrimitive(type)) { e.checkcast(type); } e.return_value(); e.end_method(); }
indexes.add(new Integer(index)); CodeEmitter e = context.beginMethod(ce, method); e.load_this(); e.dup(); e.invoke_virtual_this(loadMethod(index)); e.invoke(method); e.return_value(); e.end_method(); loadMethod(index), null); e.load_this(); e.getfield(delegate); e.dup(); e.ifnonnull(end); e.pop(); e.load_this(); context.emitCallback(e, index); e.invoke_interface(LAZY_LOADER, LOAD_OBJECT); e.mark(end); e.return_value(); e.end_method();
public void generate(ClassEmitter ce, Context context, List methods) { for (Iterator it = methods.iterator(); it.hasNext();) { MethodInfo method = (MethodInfo)it.next(); if (!TypeUtils.isProtected(method.getModifiers())) { CodeEmitter e = context.beginMethod(ce, method); context.emitCallback(e, context.getIndex(method)); if (proxyRef) { e.load_this(); e.invoke_interface(PROXY_REF_DISPATCHER, PROXY_REF_LOAD_OBJECT); } else { e.invoke_interface(DISPATCHER, LOAD_OBJECT); } e.checkcast(method.getClassInfo().getType()); e.load_args(); e.invoke(method); e.return_value(); e.end_method(); } } }
public void declare_field(int access, final String name, Type type, Object value) { super.declare_field(access, name, type, value); String property = TypeUtils.upperFirst(callback.getPropertyName(getClassType(), name)); if (property != null) { CodeEmitter e; e = begin_method(Constants.ACC_PUBLIC, new Signature("get" + property, type, Constants.TYPES_EMPTY), null); e.load_this(); e.getfield(name); e.return_value(); e.end_method(); e = begin_method(Constants.ACC_PUBLIC, new Signature("set" + property, Type.VOID_TYPE, new Type[]{ type }), null); e.load_this(); e.load_arg(0); e.putfield(name); e.return_value(); e.end_method(); } } }
private void generateKeySet(String[] allNames) { // static initializer declare_field(Constants.ACC_STATIC | Constants.ACC_PRIVATE, "keys", FIXED_KEY_SET, null); CodeEmitter e = begin_static(); e.new_instance(FIXED_KEY_SET); e.dup(); EmitUtils.push_array(e, allNames); e.invoke_constructor(FIXED_KEY_SET, CSTRUCT_STRING_ARRAY); e.putfield("keys"); e.return_value(); e.end_method(); // keySet e = begin_method(Constants.ACC_PUBLIC, KEY_SET, null); e.load_this(); e.getfield("keys"); e.return_value(); e.end_method(); }