Package org.drools.asm

Examples of org.drools.asm.MethodVisitor


    protected static void buildCollectionEquals(final ClassWriter cw,
                                                final String className,
                                                final Class clazz) {

        final MethodVisitor mv = cw.visitMethod( Opcodes.ACC_PUBLIC,
                                                 "equals",
                                                 Type.getMethodDescriptor( Type.BOOLEAN_TYPE,
                                                                           new Type[]{Type.getType( Object.class )} ),
                                                 null,
                                                 null );
        // if ( this == object ) {
        Label l0 = new Label();
        mv.visitLabel( l0 );
        mv.visitVarInsn( Opcodes.ALOAD,
                         0 );
        mv.visitVarInsn( Opcodes.ALOAD,
                         1 );
        Label l1 = new Label();
        mv.visitJumpInsn( Opcodes.IF_ACMPNE,
                          l1 );
        //    return true;
        Label l2 = new Label();
        mv.visitLabel( l2 );
        mv.visitInsn( Opcodes.ICONST_1 );
        mv.visitInsn( Opcodes.IRETURN );
        // }
        mv.visitLabel( l1 );
        // return this.delegate.equals( object );
        mv.visitVarInsn( Opcodes.ALOAD,
                         0 );
        mv.visitFieldInsn( Opcodes.GETFIELD,
                           className,
                           DELEGATE_FIELD_NAME,
                           Type.getDescriptor( clazz ) );
        mv.visitVarInsn( Opcodes.ALOAD,
                         1 );
        if ( clazz.isInterface() ) {
            mv.visitMethodInsn( Opcodes.INVOKEINTERFACE,
                                Type.getInternalName( clazz ),
                                "equals",
                                Type.getMethodDescriptor( Type.BOOLEAN_TYPE,
                                                          new Type[]{Type.getType( Object.class )} ) );
        } else {
            mv.visitMethodInsn( Opcodes.INVOKEVIRTUAL,
                                Type.getInternalName( clazz ),
                                "equals",
                                Type.getMethodDescriptor( Type.BOOLEAN_TYPE,
                                                          new Type[]{Type.getType( Object.class )} ) );
        }
        mv.visitInsn( Opcodes.IRETURN );
        Label l3 = new Label();
        mv.visitLabel( l3 );
        mv.visitLocalVariable( "this",
                               "L" + className + ";",
                               null,
                               l0,
                               l3,
                               0 );
        mv.visitLocalVariable( "object",
                               Type.getDescriptor( Object.class ),
                               null,
                               l0,
                               l3,
                               1 );
        mv.visitMaxs( 0,
                      0 );
        mv.visitEnd();
    }
View Full Code Here


     */
    protected static void buildHashCode(final ClassWriter cw,
                                        final String className,
                                        final Class clazz,
                                        final Map fieldTypes) {
        MethodVisitor mv;
        // Building hashcode method
        {
            mv = cw.visitMethod( Opcodes.ACC_PUBLIC,
                                 "hashCode",
                                 Type.getMethodDescriptor( Type.INT_TYPE,
                                                           new Type[]{} ),
                                 null,
                                 null );
            mv.visitCode();

            // if( this.__hashCache == 0 ) {
            Label l0 = new Label();
            mv.visitLabel( l0 );
            mv.visitVarInsn( Opcodes.ALOAD,
                             0 );
            mv.visitFieldInsn( Opcodes.GETFIELD,
                               className,
                               HASHCACHE_FIELD_NAME,
                               Type.INT_TYPE.getDescriptor() );
            Label l1 = new Label();
            mv.visitJumpInsn( Opcodes.IFNE,
                              l1 );
            Label l2 = new Label();

            //    this.__hashCache = this.delegate.hashCode();
            mv.visitLabel( l2 );
            mv.visitVarInsn( Opcodes.ALOAD,
                             0 );
            mv.visitVarInsn( Opcodes.ALOAD,
                             0 );
            mv.visitFieldInsn( Opcodes.GETFIELD,
                               className,
                               DELEGATE_FIELD_NAME,
                               Type.getDescriptor( clazz ) );
            if ( clazz.isInterface() ) {
                mv.visitMethodInsn( Opcodes.INVOKEINTERFACE,
                                    Type.getInternalName( clazz ),
                                    "hashCode",
                                    Type.getMethodDescriptor( Type.INT_TYPE,
                                                              new Type[0] ) );
            } else {
                mv.visitMethodInsn( Opcodes.INVOKEVIRTUAL,
                                    Type.getInternalName( clazz ),
                                    "hashCode",
                                    Type.getMethodDescriptor( Type.INT_TYPE,
                                                              new Type[0] ) );
            }
            mv.visitFieldInsn( Opcodes.PUTFIELD,
                               className,
                               HASHCACHE_FIELD_NAME,
                               Type.INT_TYPE.getDescriptor() );
            // }
            mv.visitLabel( l1 );

            // return this.__hashCache;
            mv.visitVarInsn( Opcodes.ALOAD,
                             0 );
            mv.visitFieldInsn( Opcodes.GETFIELD,
                               className,
                               HASHCACHE_FIELD_NAME,
                               Type.INT_TYPE.getDescriptor() );
            mv.visitInsn( Opcodes.IRETURN );
            Label l3 = new Label();
            mv.visitLabel( l3 );
            mv.visitLocalVariable( "this",
                                   "L" + className + ";",
                                   null,
                                   l0,
                                   l3,
                                   0 );

            mv.visitMaxs( 0,
                          0 );
            mv.visitEnd();
        }
    }
View Full Code Here

    public MethodVisitor visitMethod(final int access,
                                     final String name,
                                     final String desc,
                                     final String signature,
                                     final String[] exceptions) {
        MethodVisitor mv;
        if ( name.equals( "<clinit>" ) ) {
            final int a = Opcodes.ACC_PRIVATE + Opcodes.ACC_STATIC;
            final String n = this.prefix + this.counter++;
            mv = this.cv.visitMethod( a,
                                      n,
View Full Code Here

     * @param cw
     */
    private static void build3ArgConstructor(final Class superClazz,
                                             final String className,
                                             final ClassWriter cw) {
        MethodVisitor mv;
        {
            mv = cw.visitMethod( Opcodes.ACC_PUBLIC,
                                 "<init>",
                                 Type.getMethodDescriptor( Type.VOID_TYPE,
                                                           new Type[]{Type.getType( int.class ), Type.getType( Class.class ), Type.getType( ValueType.class )} ),
                                 null,
                                 null );
            mv.visitCode();
            final Label l0 = new Label();
            mv.visitLabel( l0 );
            mv.visitVarInsn( Opcodes.ALOAD,
                             0 );
            mv.visitVarInsn( Opcodes.ILOAD,
                             1 );
            mv.visitVarInsn( Opcodes.ALOAD,
                             2 );
            mv.visitVarInsn( Opcodes.ALOAD,
                             3 );
            mv.visitMethodInsn( Opcodes.INVOKESPECIAL,
                                Type.getInternalName( superClazz ),
                                "<init>",
                                Type.getMethodDescriptor( Type.VOID_TYPE,
                                                          new Type[]{Type.getType( int.class ), Type.getType( Class.class ), Type.getType( ValueType.class )} ) );
            final Label l1 = new Label();
            mv.visitLabel( l1 );
            mv.visitInsn( Opcodes.RETURN );
            final Label l2 = new Label();
            mv.visitLabel( l2 );
            mv.visitLocalVariable( "this",
                                   "L" + className + ";",
                                   null,
                                   l0,
                                   l2,
                                   0 );
            mv.visitLocalVariable( "index",
                                   Type.getDescriptor( int.class ),
                                   null,
                                   l0,
                                   l2,
                                   1 );
            mv.visitLocalVariable( "fieldType",
                                   Type.getDescriptor( Class.class ),
                                   null,
                                   l0,
                                   l2,
                                   2 );
            mv.visitLocalVariable( "valueType",
                                   Type.getDescriptor( ValueType.class ),
                                   null,
                                   l0,
                                   l2,
                                   3 );
            mv.visitMaxs( 0,
                          0 );
            mv.visitEnd();
        }
    }
View Full Code Here

                                                     new Class[]{InternalWorkingMemory.class, Object.class} );
        } catch ( final Exception e ) {
            throw new RuntimeDroolsException( "This is a bug. Please report back to JBoss Rules team.",
                                              e );
        }
        final MethodVisitor mv = cw.visitMethod( Opcodes.ACC_PUBLIC,
                                                 overridingMethod.getName(),
                                                 Type.getMethodDescriptor( overridingMethod ),
                                                 null,
                                                 null );

        mv.visitCode();

        final Label l0 = new Label();
        mv.visitLabel( l0 );
        mv.visitVarInsn( Opcodes.ALOAD,
                         2 );
        mv.visitTypeInsn( Opcodes.CHECKCAST,
                          Type.getInternalName( originalClass ) );

        if ( originalClass.isInterface() ) {
            mv.visitMethodInsn( Opcodes.INVOKEINTERFACE,
                                Type.getInternalName( originalClass ),
                                getterMethod.getName(),
                                Type.getMethodDescriptor( getterMethod ) );
        } else {
            mv.visitMethodInsn( Opcodes.INVOKEVIRTUAL,
                                Type.getInternalName( originalClass ),
                                getterMethod.getName(),
                                Type.getMethodDescriptor( getterMethod ) );
        }
        mv.visitInsn( Type.getType( fieldType ).getOpcode( Opcodes.IRETURN ) );
        final Label l1 = new Label();
        mv.visitLabel( l1 );
        mv.visitLocalVariable( "this",
                               "L" + className + ";",
                               null,
                               l0,
                               l1,
                               0 );
        mv.visitLocalVariable( "workingMemory",
                               Type.getDescriptor( InternalWorkingMemory.class ),
                               null,
                               l0,
                               l1,
                               1 );
        mv.visitLocalVariable( "object",
                               Type.getDescriptor( Object.class ),
                               null,
                               l0,
                               l1,
                               2 );
        mv.visitMaxs( 0,
                      0 );
        mv.visitEnd();
    }
View Full Code Here

TOP

Related Classes of org.drools.asm.MethodVisitor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.