private void internalSetFiled ( MethodVisitor mv , Accessor acc ) { /** * FNC params * * 1 -> object to alter * * 2 -> id of field * * 3 -> new value */ mv . visitVarInsn ( ALOAD , 1 ) ; mv . visitTypeInsn ( CHECKCAST , classNameInternal ) ; // get VELUE mv . visitVarInsn ( ALOAD , 3 ) ; Type fieldType = Type . getType ( acc . getType ( ) ) ; Class < ? > type = acc . getType ( ) ; String destClsName = Type . getInternalName ( type ) ; Method conMtd = convMtds . get ( type ) ; if ( conMtd != null ) { // external converion String clsSig = Type . getInternalName ( conMtd . getDeclaringClass ( ) ) ; String mtdName = conMtd . getName ( ) ; String mtdSig = Type . getMethodDescriptor ( conMtd ) ; mv . visitMethodInsn ( INVOKESTATIC , clsSig , mtdName , mtdSig ) ; } else if ( acc . isEnum ( ) ) { // builtIn Enum Conversion Label isNull = new Label ( ) ; mv . visitJumpInsn ( IFNULL , isNull ) ; mv . visitVarInsn ( ALOAD , 3 ) ; // mv.visitTypeInsn(CHECKCAST, "java/lang/String"); mv . visitMethodInsn ( INVOKEVIRTUAL , "java/lang/Object" , "toString" , "()Ljava/lang/String;" ) ; mv . visitMethodInsn ( INVOKESTATIC , destClsName , "valueOf" , "(Ljava/lang/String;)L" + destClsName + ";" ) ; mv . visitVarInsn ( ASTORE , 3 ) ; mv . visitLabel ( isNull ) ; mv . visitFrame ( Opcodes . F_SAME , 0 , null , 0 , null ) ; mv . visitVarInsn ( ALOAD , 1 ) ; mv . visitTypeInsn ( CHECKCAST , this . classNameInternal ) ; // "net/minidev/asm/bean/BEnumPriv" mv . visitVarInsn ( ALOAD , 3 ) ; mv . visitTypeInsn ( CHECKCAST , destClsName ) ; } else if ( type . equals ( String . class ) ) { // built In String Conversion Label isNull = new Label ( ) ; mv . visitJumpInsn ( IFNULL , isNull ) ; mv . visitVarInsn ( ALOAD , 3 ) ; mv . visitMethodInsn ( INVOKEVIRTUAL , "java/lang/Object" , "toString" , "()Ljava/lang/String;" ) ; mv . visitVarInsn ( ASTORE , 3 ) ; mv . visitLabel ( isNull ) ; mv . visitFrame ( Opcodes . F_SAME , 0 , null , 0 , null ) ; mv . visitVarInsn ( ALOAD , 1 ) ; mv . visitTypeInsn ( CHECKCAST , this . classNameInternal ) ; mv . visitVarInsn ( ALOAD , 3 ) ; mv . visitTypeInsn ( CHECKCAST , destClsName ) ; } else { // just check Cast mv . visitTypeInsn ( CHECKCAST , destClsName ) ; } if ( acc . isPublic ( ) ) { mv . visitFieldInsn ( PUTFIELD , classNameInternal , acc . getName ( ) , fieldType . getDescriptor ( ) ) ; } else { String sig = Type . getMethodDescriptor ( acc . setter ) ; mv . visitMethodInsn ( INVOKEVIRTUAL , classNameInternal , acc . setter . getName ( ) , sig ) ; } mv . visitInsn ( RETURN ) ; }
Dump Set Field Code