public void push(double value) { if (value == 0d || value == 1d) { mv.visitInsn(TypeUtils.DCONST(value)); } else { mv.visitLdcInsn(new Double(value)); } }
public void push(float value) { if (value == 0f || value == 1f || value == 2f) { mv.visitInsn(TypeUtils.FCONST(value)); } else { mv.visitLdcInsn(new Float(value)); } } public void push(double value) {
public void push(int i) { if (i < -1) { mv.visitLdcInsn(new Integer(i)); } else if (i <= 5) { mv.visitInsn(TypeUtils.ICONST(i)); } else if (i <= Byte.MAX_VALUE) { mv.visitIntInsn(Constants.BIPUSH, i); } else if (i <= Short.MAX_VALUE) { mv.visitIntInsn(Constants.SIPUSH, i); } else { mv.visitLdcInsn(new Integer(i)); } }
public void begin_class(int version, int access, String className, Type superType, Type[] interfaces, String sourceFile) { if (!TypeUtils.isAbstract(access)) { interfaces = TypeUtils.add(interfaces, FIELD_PROVIDER); } this.access = access; fields = new HashMap(); super.begin_class(version, access, className, superType, interfaces, sourceFile); }
public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) { begin_class(version, access, name.replace('/', '.'), TypeUtils.fromInternalName(superName), TypeUtils.fromInternalNames(interfaces), null); // TODO }
public void newarray(Type type) { if (TypeUtils.isPrimitive(type)) { mv.visitIntInsn(Constants.NEWARRAY, TypeUtils.NEWARRAY(type)); } else { emit_type(Constants.ANEWARRAY, type); } }
public void begin_class(int version, int access, String className, Type superType, Type[] interfaces, String sourceFile) { if(!TypeUtils.isInterface(access)){ Type[] all = TypeUtils.add(interfaces, TypeUtils.getTypes(delegateIf)); super.begin_class(version, access, className, superType, all, sourceFile); declare_field(Constants.ACC_PRIVATE | Constants.ACC_TRANSIENT, DELEGATE, delegateType, null); for (int i = 0; i < delegateIf.length; i++) { Method[] methods = delegateIf[i].getMethods(); for (int j = 0; j < methods.length; j++) { if (Modifier.isAbstract(methods[j].getModifiers())) { addDelegate(methods[j]); } } } }else{ super.begin_class(version, access, className, superType, interfaces, sourceFile); } }
public void generateClass(ClassVisitor v) throws Exception { Class sc = (superclass == null) ? Object.class : superclass; if (TypeUtils.isFinal(sc.getModifiers())) throw new IllegalArgumentException("Cannot subclass final class " + sc.getName()); List constructors = new ArrayList(Arrays.asList(sc.getDeclaredConstructors())); Type.getType(sc), (useFactory ? TypeUtils.add(TypeUtils.getTypes(interfaces), FACTORY) : TypeUtils.getTypes(interfaces)), Constants.SOURCE_FILE); } else {
private static void load_class_helper(CodeEmitter e, final Type type) { if (e.isStaticHook()) { // have to fall back on non-optimized load e.push(TypeUtils.emulateClassGetName(type)); e.invoke_static(Constants.TYPE_CLASS, FOR_NAME); } else { ClassEmitter ce = e.getClassEmitter(); String typeName = TypeUtils.emulateClassGetName(type); // TODO: can end up with duplicated field names when using chained transformers; incorporate static hook # somehow String fieldName = "CGLIB$load_class$" + TypeUtils.escapeType(typeName); if (!ce.isFieldDeclared(fieldName)) { ce.declare_field(Constants.PRIVATE_FINAL_STATIC, fieldName, Constants.TYPE_CLASS, null); CodeEmitter hook = ce.getStaticHook(); hook.push(typeName); hook.invoke_static(Constants.TYPE_CLASS, FOR_NAME); hook.putstatic(ce.getClassType(), fieldName, Constants.TYPE_CLASS); } e.getfield(fieldName); } }
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); } }
public static Type[] fromInternalNames(String[] names) { if (names == null) { return null; } Type[] types = new Type[names.length]; for (int i = 0; i < names.length; i++) { types[i] = fromInternalName(names[i]); } return types; }
public Object transform(Object value) { return TypeUtils.emulateClassGetName(typer.getParameterTypes((MethodInfo)value)[j]); } });
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { return begin_method(access, new Signature(name, desc), TypeUtils.fromInternalNames(exceptions)); } }
public void push(long value) { if (value == 0L || value == 1L) { mv.visitInsn(TypeUtils.LCONST(value)); } else { mv.visitLdcInsn(new Long(value)); } }
public void begin_class(int version, int access, String className, Type superType, Type[] interfaces, String sourceFile) { if(!TypeUtils.isInterface(access)){ Type[] all = TypeUtils.add(interfaces, TypeUtils.getTypes(delegateIf)); super.begin_class(version, access, className, superType, all, sourceFile); declare_field(Constants.ACC_PRIVATE | Constants.ACC_TRANSIENT, DELEGATE, delegateType, null); for (int i = 0; i < delegateIf.length; i++) { Method[] methods = delegateIf[i].getMethods(); for (int j = 0; j < methods.length; j++) { if (Modifier.isAbstract(methods[j].getModifiers())) { addDelegate(methods[j]); } } } }else{ super.begin_class(version, access, className, superType, interfaces, sourceFile); } }
public void generateClass(ClassVisitor v) throws Exception { Class sc = (superclass == null) ? Object.class : superclass; if (TypeUtils.isFinal(sc.getModifiers())) throw new IllegalArgumentException("Cannot subclass final class " + sc.getName()); List constructors = new ArrayList(Arrays.asList(sc.getDeclaredConstructors())); Type.getType(sc), (useFactory ? TypeUtils.add(TypeUtils.getTypes(interfaces), FACTORY) : TypeUtils.getTypes(interfaces)), Constants.SOURCE_FILE); } else {
public void begin_class(int version, int access, String className, Type superType, Type[] interfaces, String sourceFile) { if (!TypeUtils.isAbstract(access)) { interfaces = TypeUtils.add(interfaces, FIELD_PROVIDER); } this.access = access; fields = new HashMap(); super.begin_class(version, access, className, superType, interfaces, sourceFile); }
public void newarray(Type type) { if (TypeUtils.isPrimitive(type)) { mv.visitIntInsn(Constants.NEWARRAY, TypeUtils.NEWARRAY(type)); } else { emit_type(Constants.ANEWARRAY, type); } }
public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) { begin_class(version, access, name.replace('/', '.'), TypeUtils.fromInternalName(superName), TypeUtils.fromInternalNames(interfaces), null); // TODO }
private static void load_class_helper(CodeEmitter e, final Type type) { if (e.isStaticHook()) { // have to fall back on non-optimized load e.push(TypeUtils.emulateClassGetName(type)); e.invoke_static(Constants.TYPE_CLASS, FOR_NAME); } else { ClassEmitter ce = e.getClassEmitter(); String typeName = TypeUtils.emulateClassGetName(type); // TODO: can end up with duplicated field names when using chained transformers; incorporate static hook # somehow String fieldName = "CGLIB$load_class$" + TypeUtils.escapeType(typeName); if (!ce.isFieldDeclared(fieldName)) { ce.declare_field(Constants.PRIVATE_FINAL_STATIC, fieldName, Constants.TYPE_CLASS, null); CodeEmitter hook = ce.getStaticHook(); hook.push(typeName); hook.invoke_static(Constants.TYPE_CLASS, FOR_NAME); hook.putstatic(ce.getClassType(), fieldName, Constants.TYPE_CLASS); } e.getfield(fieldName); } }