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

📄 checkclassadapter.java

📁 jboss规则引擎
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        }
        checkState();
        checkAccess( access,
                     Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL + Opcodes.ACC_SUPER + Opcodes.ACC_INTERFACE + Opcodes.ACC_ABSTRACT + Opcodes.ACC_SYNTHETIC + Opcodes.ACC_ANNOTATION + Opcodes.ACC_ENUM + Opcodes.ACC_DEPRECATED );
        CheckMethodAdapter.checkInternalName( name,
                                              "class name" );
        if ( "java/lang/Object".equals( name ) ) {
            if ( superName != null ) {
                throw new IllegalArgumentException( "The super class name of the Object class must be 'null'" );
            }
        } else {
            CheckMethodAdapter.checkInternalName( superName,
                                                  "super class name" );
        }
        if ( signature != null ) {
            // TODO
        }
        if ( (access & Opcodes.ACC_INTERFACE) != 0 ) {
            if ( !"java/lang/Object".equals( superName ) ) {
                throw new IllegalArgumentException( "The super class name of interfaces must be 'java/lang/Object'" );
            }
        }
        if ( interfaces != null ) {
            for ( int i = 0; i < interfaces.length; ++i ) {
                CheckMethodAdapter.checkInternalName( interfaces[i],
                                                      "interface name at index " + i );
            }
        }
        this.cv.visit( version,
                       access,
                       name,
                       signature,
                       superName,
                       interfaces );
    }

    public void visitSource(final String file,
                            final String debug) {
        checkState();
        if ( this.source ) {
            throw new IllegalStateException( "visitSource can be called only once." );
        }
        this.source = true;
        this.cv.visitSource( file,
                             debug );
    }

    public void visitOuterClass(final String owner,
                                final String name,
                                final String desc) {
        checkState();
        if ( this.outer ) {
            throw new IllegalStateException( "visitSource can be called only once." );
        }
        this.outer = true;
        if ( owner == null ) {
            throw new IllegalArgumentException( "Illegal outer class owner" );
        }
        if ( desc != null ) {
            CheckMethodAdapter.checkMethodDesc( desc );
        }
        this.cv.visitOuterClass( owner,
                                 name,
                                 desc );
    }

    public void visitInnerClass(final String name,
                                final String outerName,
                                final String innerName,
                                final int access) {
        checkState();
        CheckMethodAdapter.checkInternalName( name,
                                              "class name" );
        if ( outerName != null ) {
            CheckMethodAdapter.checkInternalName( outerName,
                                                  "outer class name" );
        }
        if ( innerName != null ) {
            CheckMethodAdapter.checkIdentifier( innerName,
                                                "inner class name" );
        }
        checkAccess( access,
                     Opcodes.ACC_PUBLIC + Opcodes.ACC_PRIVATE + Opcodes.ACC_PROTECTED + Opcodes.ACC_STATIC + Opcodes.ACC_FINAL + Opcodes.ACC_INTERFACE + Opcodes.ACC_ABSTRACT + Opcodes.ACC_SYNTHETIC + Opcodes.ACC_ANNOTATION + Opcodes.ACC_ENUM );
        this.cv.visitInnerClass( name,
                                 outerName,
                                 innerName,
                                 access );
    }

    public FieldVisitor visitField(final int access,
                                   final String name,
                                   final String desc,
                                   final String signature,
                                   final Object value) {
        checkState();
        checkAccess( access,
                     Opcodes.ACC_PUBLIC + Opcodes.ACC_PRIVATE + Opcodes.ACC_PROTECTED + Opcodes.ACC_STATIC + Opcodes.ACC_FINAL + Opcodes.ACC_VOLATILE + Opcodes.ACC_TRANSIENT + Opcodes.ACC_SYNTHETIC + Opcodes.ACC_ENUM + Opcodes.ACC_DEPRECATED );
        CheckMethodAdapter.checkIdentifier( name,
                                            "field name" );
        CheckMethodAdapter.checkDesc( desc,
                                      false );
        if ( signature != null ) {
            // TODO
        }
        if ( value != null ) {
            CheckMethodAdapter.checkConstant( value );
        }
        final FieldVisitor av = this.cv.visitField( access,
                                                    name,
                                                    desc,
                                                    signature,
                                                    value );
        return new CheckFieldAdapter( av );
    }

    public MethodVisitor visitMethod(final int access,
                                     final String name,
                                     final String desc,
                                     final String signature,
                                     final String[] exceptions) {
        checkState();
        checkAccess( access,
                     Opcodes.ACC_PUBLIC + Opcodes.ACC_PRIVATE + Opcodes.ACC_PROTECTED + Opcodes.ACC_STATIC + Opcodes.ACC_FINAL + Opcodes.ACC_SYNCHRONIZED + Opcodes.ACC_BRIDGE + Opcodes.ACC_VARARGS + Opcodes.ACC_NATIVE + Opcodes.ACC_ABSTRACT
                             + Opcodes.ACC_STRICT + Opcodes.ACC_SYNTHETIC + Opcodes.ACC_DEPRECATED );
        CheckMethodAdapter.checkMethodIdentifier( name,
                                                  "method name" );
        CheckMethodAdapter.checkMethodDesc( desc );
        if ( signature != null ) {
            // TODO
        }
        if ( exceptions != null ) {
            for ( int i = 0; i < exceptions.length; ++i ) {
                CheckMethodAdapter.checkInternalName( exceptions[i],
                                                      "exception name at index " + i );
            }
        }
        return new CheckMethodAdapter( this.cv.visitMethod( access,
                                                            name,
                                                            desc,
                                                            signature,
                                                            exceptions ) );
    }

    public AnnotationVisitor visitAnnotation(final String desc,
                                             final boolean visible) {
        checkState();
        CheckMethodAdapter.checkDesc( desc,
                                      false );
        return new CheckAnnotationAdapter( this.cv.visitAnnotation( desc,
                                                                    visible ) );
    }

    public void visitAttribute(final Attribute attr) {
        checkState();
        if ( attr == null ) {
            throw new IllegalArgumentException( "Invalid attribute (must not be null)" );
        }
        this.cv.visitAttribute( attr );
    }

    public void visitEnd() {
        checkState();
        this.end = true;
        this.cv.visitEnd();
    }

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

    /**
     * Checks that the visit method has been called and that visitEnd has not
     * been called.
     */
    private void checkState() {
        if ( !this.start ) {
            throw new IllegalStateException( "Cannot visit member before visit has been called." );
        }
        if ( this.end ) {
            throw new IllegalStateException( "Cannot visit member after visitEnd has been called." );
        }
    }

    /**
     * Checks that the given access flags do not contain invalid flags. This
     * method also checks that mutually incompatible flags are not set
     * simultaneously.
     * 
     * @param access the access flags to be checked
     * @param possibleAccess the valid access flags.
     */
    static void checkAccess(final int access,
                            final int possibleAccess) {
        if ( (access & ~possibleAccess) != 0 ) {
            throw new IllegalArgumentException( "Invalid access flags: " + access );
        }
        final int pub = ((access & Opcodes.ACC_PUBLIC) != 0 ? 1 : 0);
        final int pri = ((access & Opcodes.ACC_PRIVATE) != 0 ? 1 : 0);
        final int pro = ((access & Opcodes.ACC_PROTECTED) != 0 ? 1 : 0);
        if ( pub + pri + pro > 1 ) {
            throw new IllegalArgumentException( "public private and protected are mutually exclusive: " + access );
        }
        final int fin = ((access & Opcodes.ACC_FINAL) != 0 ? 1 : 0);
        final int abs = ((access & Opcodes.ACC_ABSTRACT) != 0 ? 1 : 0);
        if ( fin + abs > 1 ) {
            throw new IllegalArgumentException( "final and abstract are mutually exclusive: " + access );
        }
    }
}

⌨️ 快捷键说明

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