public void buildCommonMethods( ClassVisitor cw, String wrapper ) {
{
MethodVisitor mv = cw.visitMethod( ACC_PUBLIC + ACC_BRIDGE + ACC_SYNTHETIC, "put",
"(" + Type.getDescriptor( Object.class ) + Type.getDescriptor( Object.class ) + ")" + Type.getDescriptor( Object.class ),
null, null );
mv.visitCode();
mv.visitVarInsn( ALOAD, 0 );
mv.visitVarInsn( ALOAD, 1 );
mv.visitTypeInsn( CHECKCAST, Type.getInternalName( String.class ) );
mv.visitVarInsn( ALOAD, 2 );
mv.visitMethodInsn( INVOKEVIRTUAL, BuildUtils.getInternalType( wrapper ), "put",
"(" + Type.getDescriptor( String.class ) + Type.getDescriptor( Object.class ) + ")" + Type.getDescriptor( Object.class ) );
mv.visitInsn( ARETURN );
// mv.visitMaxs( 3, 3 );
mv.visitMaxs( 0, 0 );
mv.visitEnd();
}
{
MethodVisitor mv = cw.visitMethod( ACC_PUBLIC, "equals", "(" + Type.getDescriptor( Object.class ) + ")Z", null, null );
mv.visitCode();
mv.visitVarInsn( ALOAD, 0 );
mv.visitVarInsn( ALOAD, 1 );
Label l0 = new Label();
mv.visitJumpInsn( IF_ACMPNE, l0 );
mv.visitInsn( ICONST_1 );
mv.visitInsn( IRETURN );
mv.visitLabel( l0 );
mv.visitVarInsn( ALOAD, 1 );
mv.visitTypeInsn( CHECKCAST, Type.getInternalName( MapWrapper.class ) );
mv.visitVarInsn( ASTORE, 2 );
mv.visitVarInsn( ALOAD, 0 );
mv.visitFieldInsn( GETFIELD, BuildUtils.getInternalType( wrapper ), "map", Type.getDescriptor( Map.class ) );
mv.visitVarInsn( ALOAD, 2 );
mv.visitMethodInsn( INVOKEINTERFACE, Type.getInternalName( MapWrapper.class ), "getInnerMap", "()" + Type.getDescriptor( Map.class ) );
mv.visitMethodInsn( INVOKEVIRTUAL, Type.getInternalName( Object.class ), "equals", "(" + Type.getDescriptor( Object.class ) + ")Z" );
mv.visitInsn( IRETURN );
// mv.visitMaxs( 2, 3 );
mv.visitMaxs( 0, 0 );
mv.visitEnd();
}
{
MethodVisitor mv = cw.visitMethod( ACC_PUBLIC, "hashCode", "()I", null, null );
mv.visitCode();
mv.visitVarInsn( ALOAD, 0 );
mv.visitFieldInsn( GETFIELD, BuildUtils.getInternalType( wrapper ), "map", Type.getDescriptor( Map.class ) );
mv.visitMethodInsn( INVOKEVIRTUAL, Type.getInternalName( Object.class ), "hashCode", "()I" );
mv.visitInsn( IRETURN );
// mv.visitMaxs( 1, 1 );
mv.visitMaxs( 0, 0 );
mv.visitEnd();
}
{
MethodVisitor mv = cw.visitMethod( ACC_PUBLIC, "getInnerMap", "()" + Type.getDescriptor( Map.class ),
"()Ljava/util/Map<Ljava/lang/String;Ljava/lang/Object;>;", null );
mv.visitCode();
mv.visitVarInsn( ALOAD, 0 );
mv.visitFieldInsn( GETFIELD, BuildUtils.getInternalType( wrapper ), "map", Type.getDescriptor( Map.class ) );
mv.visitInsn( ARETURN );
// mv.visitMaxs( 1, 1 );
mv.visitMaxs( 0, 0 );
mv.visitEnd();
}
{
MethodVisitor mv = cw.visitMethod( ACC_PUBLIC, "putAll", "(" + Type.getDescriptor( Map.class ) + ")V",
"(Ljava/util/Map<+Ljava/lang/String;+Ljava/lang/Object;>;)V",
null );
mv.visitCode();
mv.visitVarInsn( ALOAD, 1 );
mv.visitMethodInsn( INVOKEINTERFACE, Type.getInternalName( Map.class ), "keySet", "()" + Type.getDescriptor( Set.class ) );
mv.visitMethodInsn( INVOKEINTERFACE, Type.getInternalName( Set.class ), "iterator", "()" + Type.getDescriptor( Iterator.class ) );
mv.visitVarInsn( ASTORE, 2 );
Label l0 = new Label();
mv.visitLabel( l0 );
mv.visitVarInsn( ALOAD, 2 );
mv.visitMethodInsn( INVOKEINTERFACE, Type.getInternalName( Iterator.class ), "hasNext", "()Z" );
Label l1 = new Label();
mv.visitJumpInsn( IFEQ, l1 );
mv.visitVarInsn( ALOAD, 2 );
mv.visitMethodInsn( INVOKEINTERFACE, Type.getInternalName( Iterator.class ), "next", "()" + Type.getDescriptor( Object.class ) );
mv.visitTypeInsn( CHECKCAST, Type.getInternalName( String.class ) );
mv.visitVarInsn( ASTORE, 3 );
mv.visitVarInsn( ALOAD, 0 );
mv.visitVarInsn( ALOAD, 3 );
mv.visitVarInsn( ALOAD, 1 );
mv.visitVarInsn( ALOAD, 3 );
mv.visitMethodInsn( INVOKEINTERFACE, Type.getInternalName( Map.class ), "get",
"(" + Type.getDescriptor( Object.class ) + ")" + Type.getDescriptor( Object.class ) );
mv.visitMethodInsn( INVOKEVIRTUAL, BuildUtils.getInternalType( wrapper ), "put",
"(" + Type.getDescriptor( String.class ) + Type.getDescriptor( Object.class ) + ")" + Type.getDescriptor( Object.class ) );
mv.visitInsn( POP );
mv.visitJumpInsn( GOTO, l0 );
mv.visitLabel( l1 );
mv.visitInsn( RETURN );
// mv.visitMaxs( 4, 4 );
mv.visitMaxs( 0, 0 );
mv.visitEnd();
}
{
MethodVisitor mv = cw.visitMethod( ACC_PUBLIC, "toString", "()" + Type.getDescriptor( String.class ), null, null );
mv.visitCode();
mv.visitTypeInsn( NEW, Type.getInternalName( StringBuilder.class ) );
mv.visitInsn( DUP );
mv.visitMethodInsn( INVOKESPECIAL, Type.getInternalName( StringBuilder.class ), "<init>", "()V" );
mv.visitLdcInsn("[[");
mv.visitMethodInsn( INVOKEVIRTUAL, Type.getInternalName( StringBuilder.class ), "append",
"(" + Type.getDescriptor( String.class ) +")" + Type.getDescriptor( StringBuilder.class ) );
mv.visitVarInsn( ALOAD, 0 );
mv.visitMethodInsn( INVOKEVIRTUAL, BuildUtils.getInternalType( wrapper ), "entrySet", "()" + Type.getDescriptor( Set.class ) );
mv.visitMethodInsn( INVOKEVIRTUAL, Type.getInternalName( StringBuilder.class ), "append",
"(" + Type.getDescriptor( Object.class ) + ")" + Type.getDescriptor( StringBuilder.class ) );
mv.visitLdcInsn( "]]" );
mv.visitMethodInsn( INVOKEVIRTUAL, Type.getInternalName( StringBuilder.class ), "append",
"(" + Type.getDescriptor( String.class ) +")" + Type.getDescriptor( StringBuilder.class ));
mv.visitMethodInsn( INVOKEVIRTUAL, Type.getInternalName( StringBuilder.class ), "toString", "()" + Type.getDescriptor( String.class ) );
mv.visitInsn( ARETURN );
// mv.visitMaxs( 2, 1 );
mv.visitMaxs( 0, 0 );
mv.visitEnd();
}