Search in sources :

Example 1 with ClassWriter

use of dyvilx.tools.asm.ClassWriter in project Dyvil by Dyvil.

the class PropertyReferenceMetafactory method spinInnerClass.

private Class<?> spinInnerClass() throws Exception {
    String refItf = TypeConverter.getInternalName(this.refClass);
    final ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_MAXS);
    classWriter.visit(CLASS_VERSION, PUBLIC | SYNTHETIC | ASMConstants.ACC_FINAL, this.className, null, "java/lang/Object", new String[] { refItf });
    if (this.receiverType != null) {
        classWriter.visitField(PRIVATE, RECEIVER_NAME, this.receiverType, null, null).visitEnd();
    }
    this.generateConstructor(classWriter);
    if (this.receiverType != null) {
        this.generateFactory(classWriter);
    }
    this.generateGetter(classWriter);
    this.generateSetter(classWriter);
    this.generateToString(classWriter);
    classWriter.visitEnd();
    final byte[] bytes = classWriter.toByteArray();
    BytecodeDump.dump(bytes, this.className);
    return UNSAFE.defineAnonymousClass(this.targetClass, bytes, null);
}
Also used : ClassWriter(dyvilx.tools.asm.ClassWriter)

Example 2 with ClassWriter

use of dyvilx.tools.asm.ClassWriter in project Dyvil by Dyvil.

the class AnnotationProxyFactory method spinInnerClass.

private Class<?> spinInnerClass() {
    final String annotationItf = this.annotationType.getName().replace('.', '/');
    final ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_MAXS);
    classWriter.visit(CLASSFILE_VERSION, ASMConstants.ACC_SUPER | FINAL | SYNTHETIC, this.className, null, "java/lang/Object", new String[] { annotationItf });
    if (this.parameterCount > 0) {
        for (int i = 0; i < this.parameterCount; i++) {
            FieldVisitor fv = classWriter.visitField(PRIVATE | FINAL, this.argNames[i], this.argDescs[i], null, null);
            fv.visitEnd();
        }
        this.generateFactory(classWriter);
    }
    this.generateConstructor(classWriter);
    this.generateAnnotationType(classWriter);
    this.generateMethods(classWriter);
    this.generateToString(classWriter);
    classWriter.visitEnd();
    final byte[] bytes = classWriter.toByteArray();
    BytecodeDump.dump(bytes, this.className);
    // Define the generated class in this VM.
    return UNSAFE.defineAnonymousClass(this.targetClass, bytes, null);
}
Also used : FieldVisitor(dyvilx.tools.asm.FieldVisitor) ClassWriter(dyvilx.tools.asm.ClassWriter)

Aggregations

ClassWriter (dyvilx.tools.asm.ClassWriter)2 FieldVisitor (dyvilx.tools.asm.FieldVisitor)1