⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 asmifierclassvisitor.java

📁 jboss规则引擎
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    public void visitOuterClass(final String owner,
                                final String name,
                                final String desc) {
        this.buf.setLength( 0 );
        this.buf.append( "cw.visitOuterClass(" );
        appendConstant( owner );
        this.buf.append( ", " );
        appendConstant( name );
        this.buf.append( ", " );
        appendConstant( desc );
        this.buf.append( ");\n\n" );
        this.text.add( this.buf.toString() );
    }

    public void visitInnerClass(final String name,
                                final String outerName,
                                final String innerName,
                                final int access) {
        this.buf.setLength( 0 );
        this.buf.append( "cw.visitInnerClass(" );
        appendConstant( name );
        this.buf.append( ", " );
        appendConstant( outerName );
        this.buf.append( ", " );
        appendConstant( innerName );
        this.buf.append( ", " );
        appendAccess( access | ASMifierClassVisitor.ACCESS_INNER );
        this.buf.append( ");\n\n" );
        this.text.add( this.buf.toString() );
    }

    public FieldVisitor visitField(final int access,
                                   final String name,
                                   final String desc,
                                   final String signature,
                                   final Object value) {
        this.buf.setLength( 0 );
        this.buf.append( "{\n" );
        this.buf.append( "fv = cw.visitField(" );
        appendAccess( access | ASMifierClassVisitor.ACCESS_FIELD );
        this.buf.append( ", " );
        appendConstant( name );
        this.buf.append( ", " );
        appendConstant( desc );
        this.buf.append( ", " );
        appendConstant( signature );
        this.buf.append( ", " );
        appendConstant( value );
        this.buf.append( ");\n" );
        this.text.add( this.buf.toString() );
        final ASMifierFieldVisitor aav = new ASMifierFieldVisitor();
        this.text.add( aav.getText() );
        this.text.add( "}\n" );
        return aav;
    }

    public MethodVisitor visitMethod(final int access,
                                     final String name,
                                     final String desc,
                                     final String signature,
                                     final String[] exceptions) {
        this.buf.setLength( 0 );
        this.buf.append( "{\n" );
        this.buf.append( "mv = cw.visitMethod(" );
        appendAccess( access );
        this.buf.append( ", " );
        appendConstant( name );
        this.buf.append( ", " );
        appendConstant( desc );
        this.buf.append( ", " );
        appendConstant( signature );
        this.buf.append( ", " );
        if ( exceptions != null && exceptions.length > 0 ) {
            this.buf.append( "new String[] {" );
            for ( int i = 0; i < exceptions.length; ++i ) {
                this.buf.append( i == 0 ? " " : ", " );
                appendConstant( exceptions[i] );
            }
            this.buf.append( " }" );
        } else {
            this.buf.append( "null" );
        }
        this.buf.append( ");\n" );
        this.text.add( this.buf.toString() );
        final ASMifierMethodVisitor acv = new ASMifierMethodVisitor();
        this.text.add( acv.getText() );
        this.text.add( "}\n" );
        return acv;
    }

    public AnnotationVisitor visitAnnotation(final String desc,
                                             final boolean visible) {
        this.buf.setLength( 0 );
        this.buf.append( "{\n" );
        this.buf.append( "av0 = cw.visitAnnotation(" );
        appendConstant( desc );
        this.buf.append( ", " );
        this.buf.append( visible );
        this.buf.append( ");\n" );
        this.text.add( this.buf.toString() );
        final ASMifierAnnotationVisitor av = new ASMifierAnnotationVisitor( 0 );
        this.text.add( av.getText() );
        this.text.add( "}\n" );
        return av;
    }

    public void visitEnd() {
        this.text.add( "cw.visitEnd();\n\n" );
        this.text.add( "return cw.toByteArray();\n" );
        this.text.add( "}\n" );
        this.text.add( "}\n" );
        printList( this.pw,
                   this.text );
        this.pw.flush();
    }

    // ------------------------------------------------------------------------
    // Utility methods
    // ------------------------------------------------------------------------

    /**
     * Appends a string representation of the given access modifiers to {@link
     * #buf buf}.
     * 
     * @param access some access modifiers.
     */
    void appendAccess(final int access) {
        boolean first = true;
        if ( (access & Opcodes.ACC_PUBLIC) != 0 ) {
            this.buf.append( "ACC_PUBLIC" );
            first = false;
        }
        if ( (access & Opcodes.ACC_PRIVATE) != 0 ) {
            if ( !first ) {
                this.buf.append( " + " );
            }
            this.buf.append( "ACC_PRIVATE" );
            first = false;
        }
        if ( (access & Opcodes.ACC_PROTECTED) != 0 ) {
            if ( !first ) {
                this.buf.append( " + " );
            }
            this.buf.append( "ACC_PROTECTED" );
            first = false;
        }
        if ( (access & Opcodes.ACC_FINAL) != 0 ) {
            if ( !first ) {
                this.buf.append( " + " );
            }
            this.buf.append( "ACC_FINAL" );
            first = false;
        }
        if ( (access & Opcodes.ACC_STATIC) != 0 ) {
            if ( !first ) {
                this.buf.append( " + " );
            }
            this.buf.append( "ACC_STATIC" );
            first = false;
        }
        if ( (access & Opcodes.ACC_SYNCHRONIZED) != 0 ) {
            if ( !first ) {
                this.buf.append( " + " );
            }
            if ( (access & ASMifierClassVisitor.ACCESS_CLASS) != 0 ) {
                this.buf.append( "ACC_SUPER" );
            } else {
                this.buf.append( "ACC_SYNCHRONIZED" );
            }
            first = false;
        }
        if ( (access & Opcodes.ACC_VOLATILE) != 0 && (access & ASMifierClassVisitor.ACCESS_FIELD) != 0 ) {
            if ( !first ) {
                this.buf.append( " + " );
            }
            this.buf.append( "ACC_VOLATILE" );
            first = false;
        }
        if ( (access & Opcodes.ACC_BRIDGE) != 0 && (access & ASMifierClassVisitor.ACCESS_CLASS) == 0 && (access & ASMifierClassVisitor.ACCESS_FIELD) == 0 ) {
            if ( !first ) {
                this.buf.append( " + " );
            }
            this.buf.append( "ACC_BRIDGE" );
            first = false;
        }
        if ( (access & Opcodes.ACC_VARARGS) != 0 && (access & ASMifierClassVisitor.ACCESS_CLASS) == 0 && (access & ASMifierClassVisitor.ACCESS_FIELD) == 0 ) {
            if ( !first ) {
                this.buf.append( " + " );
            }
            this.buf.append( "ACC_VARARGS" );
            first = false;
        }
        if ( (access & Opcodes.ACC_TRANSIENT) != 0 && (access & ASMifierClassVisitor.ACCESS_FIELD) != 0 ) {
            if ( !first ) {
                this.buf.append( " + " );
            }
            this.buf.append( "ACC_TRANSIENT" );
            first = false;
        }
        if ( (access & Opcodes.ACC_NATIVE) != 0 && (access & ASMifierClassVisitor.ACCESS_CLASS) == 0 && (access & ASMifierClassVisitor.ACCESS_FIELD) == 0 ) {
            if ( !first ) {
                this.buf.append( " + " );
            }
            this.buf.append( "ACC_NATIVE" );
            first = false;
        }
        if ( (access & Opcodes.ACC_ENUM) != 0 && ((access & ASMifierClassVisitor.ACCESS_CLASS) != 0 || (access & ASMifierClassVisitor.ACCESS_FIELD) != 0 || (access & ASMifierClassVisitor.ACCESS_INNER) != 0) ) {
            if ( !first ) {
                this.buf.append( " + " );
            }
            this.buf.append( "ACC_ENUM" );
            first = false;
        }
        if ( (access & Opcodes.ACC_ANNOTATION) != 0 && ((access & ASMifierClassVisitor.ACCESS_CLASS) != 0) ) {
            if ( !first ) {
                this.buf.append( " + " );
            }
            this.buf.append( "ACC_ANNOTATION" );
            first = false;
        }
        if ( (access & Opcodes.ACC_ABSTRACT) != 0 ) {
            if ( !first ) {
                this.buf.append( " + " );
            }
            this.buf.append( "ACC_ABSTRACT" );
            first = false;
        }
        if ( (access & Opcodes.ACC_INTERFACE) != 0 ) {
            if ( !first ) {
                this.buf.append( " + " );
            }
            this.buf.append( "ACC_INTERFACE" );
            first = false;
        }
        if ( (access & Opcodes.ACC_STRICT) != 0 ) {
            if ( !first ) {
                this.buf.append( " + " );
            }
            this.buf.append( "ACC_STRICT" );
            first = false;
        }
        if ( (access & Opcodes.ACC_SYNTHETIC) != 0 ) {
            if ( !first ) {
                this.buf.append( " + " );
            }
            this.buf.append( "ACC_SYNTHETIC" );
            first = false;
        }
        if ( (access & Opcodes.ACC_DEPRECATED) != 0 ) {
            if ( !first ) {
                this.buf.append( " + " );
            }
            this.buf.append( "ACC_DEPRECATED" );
            first = false;
        }
        if ( first ) {
            this.buf.append( "0" );
        }
    }

    /**
     * Appends a string representation of the given constant to the given
     * buffer.
     * 
     * @param buf a string buffer.
     * @param cst an {@link java.lang.Integer Integer}, {@link java.lang.Float
     *        Float}, {@link java.lang.Long Long},
     *        {@link java.lang.Double Double} or {@link String String} object.
     *        May be <tt>null</tt>.
     */
    static void appendConstant(final StringBuffer buf,
                               final Object cst) {
        if ( cst == null ) {
            buf.append( "null" );
        } else if ( cst instanceof String ) {
            AbstractVisitor.appendString( buf,
                                          (String) cst );
        } else if ( cst instanceof Type ) {
            buf.append( "Type.getType(\"" ).append( ((Type) cst).getDescriptor() ).append( "\")" );
        } else if ( cst instanceof Integer ) {
            buf.append( "new Integer(" ).append( cst ).append( ")" );
        } else if ( cst instanceof Float ) {
            buf.append( "new Float(\"" ).append( cst ).append( "\")" );
        } else if ( cst instanceof Long ) {
            buf.append( "new Long(" ).append( cst ).append( "L)" );
        } else if ( cst instanceof Double ) {
            buf.append( "new Double(\"" ).append( cst ).append( "\")" );
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -