String fieldName = field.getName();
String fieldType = field.getTypeName();
String getter = BuildUtils.getterName( fieldName, fieldType );
MethodVisitor mv = cw.visitMethod( ACC_PUBLIC, getter, "()" + BuildUtils.getTypeDescriptor( fieldType ), null, null );
mv.visitCode();
mv.visitVarInsn( ALOAD, 0 );
mv.visitFieldInsn( GETFIELD, BuildUtils.getInternalType( proxy ), "object", Type.getDescriptor( core.getDefinedClass() ) );
mv.visitTypeInsn( CHECKCAST, Type.getInternalName( TraitableBean.class ) );
mv.visitMethodInsn( INVOKEINTERFACE, Type.getInternalName( TraitableBean.class ), "_getFieldTMS", Type.getMethodDescriptor( Type.getType( TraitFieldTMS.class ), new Type[] {} ) );
mv.visitLdcInsn( field.resolveAlias() );
if ( BuildUtils.isPrimitive( fieldType ) ) {
// mv.visitFieldInsn( GETSTATIC, BuildUtils.getInternalType( BuildUtils.box( fieldType ) ), "TYPE", Type.getDescriptor( Class.class ) );
mv.visitLdcInsn( Type.getType( BuildUtils.getTypeDescriptor( BuildUtils.box( field.getTypeName() ) ) ) );
} else {
mv.visitLdcInsn( Type.getType( Type.getDescriptor( field.getType() ) ) );
}
mv.visitMethodInsn( INVOKEINTERFACE,
Type.getInternalName( TraitFieldTMS.class ),
"get",
Type.getMethodDescriptor( Type.getType( Object.class ), new Type[] { Type.getType( String.class ), Type.getType( Class.class ) } ) );
mv.visitVarInsn( ASTORE, 1 );
mv.visitVarInsn( ALOAD, 1 );
if ( BuildUtils.isPrimitive( fieldType ) ) {
Label l0 = new Label();
mv.visitJumpInsn( IFNULL, l0 );
mv.visitVarInsn( ALOAD, 1 );
Label l1 = new Label();
mv.visitJumpInsn( GOTO, l1 );
mv.visitLabel( l0 );
mv.visitInsn( BuildUtils.zero( fieldType ) );
mv.visitMethodInsn( Opcodes.INVOKESTATIC,
BuildUtils.getInternalType( BuildUtils.box( fieldType ) ),
"valueOf",
Type.getMethodDescriptor( Type.getType( BuildUtils.getTypeDescriptor( BuildUtils.box( fieldType ) ) ), new Type[] { Type.getType( BuildUtils.getTypeDescriptor( fieldType ) ) } ) );
mv.visitLabel( l1 );
mv.visitTypeInsn( CHECKCAST, BuildUtils.getInternalType( BuildUtils.box( fieldType ) ) );
mv.visitMethodInsn( INVOKEVIRTUAL,
BuildUtils.getInternalType( BuildUtils.box( fieldType ) ),
BuildUtils.numericMorph( BuildUtils.box( fieldType ) ),
Type.getMethodDescriptor( Type.getType( field.getType() ), new Type[] {} ) );
mv.visitInsn( BuildUtils.returnType( fieldType ) );
} else {
mv.visitTypeInsn( CHECKCAST, BuildUtils.getInternalType( fieldType ) );
mv.visitInsn( ARETURN );
}
mv.visitMaxs( 0, 0 );
mv.visitEnd();
}