Java Code Examples for org.apache.bcel.Const#ACC_INTERFACE

The following examples show how to use org.apache.bcel.Const#ACC_INTERFACE . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Utility.java    From commons-bcel with Apache License 2.0 6 votes vote down vote up
/**
 * Convert bit field of flags into string such as `static final'.
 *
 * Special case: Classes compiled with new compilers and with the
 * `ACC_SUPER' flag would be said to be "synchronized". This is
 * because SUN used the same value for the flags `ACC_SUPER' and
 * `ACC_SYNCHRONIZED'.
 *
 * @param  access_flags Access flags
 * @param  for_class access flags are for class qualifiers ?
 * @return String representation of flags
 */
public static String accessToString( final int access_flags, final boolean for_class ) {
    final StringBuilder buf = new StringBuilder();
    int p = 0;
    for (int i = 0; p < Const.MAX_ACC_FLAG_I; i++) { // Loop through known flags
        p = pow2(i);
        if ((access_flags & p) != 0) {
            /* Special case: Classes compiled with new compilers and with the
             * `ACC_SUPER' flag would be said to be "synchronized". This is
             * because SUN used the same value for the flags `ACC_SUPER' and
             * `ACC_SYNCHRONIZED'.
             */
            if (for_class && ((p == Const.ACC_SUPER) || (p == Const.ACC_INTERFACE))) {
                continue;
            }
            buf.append(Const.getAccessName(i)).append(" ");
        }
    }
    return buf.toString().trim();
}
 
Example 2
Source File: ClassParser.java    From commons-bcel with Apache License 2.0 6 votes vote down vote up
/**
 * Reads information about the class and its super class.
 * @throws  IOException
 * @throws  ClassFormatException
 */
private void readClassInfo() throws IOException, ClassFormatException {
    accessFlags = dataInputStream.readUnsignedShort();
    /* Interfaces are implicitely abstract, the flag should be set
     * according to the JVM specification.
     */
    if ((accessFlags & Const.ACC_INTERFACE) != 0) {
        accessFlags |= Const.ACC_ABSTRACT;
    }
    if (((accessFlags & Const.ACC_ABSTRACT) != 0)
            && ((accessFlags & Const.ACC_FINAL) != 0)) {
        throw new ClassFormatException("Class " + fileName + " can't be both final and abstract");
    }
    classNameIndex = dataInputStream.readUnsignedShort();
    superclassNameIndex = dataInputStream.readUnsignedShort();
}
 
Example 3
Source File: ClassDumper.java    From commons-bcel with Apache License 2.0 5 votes vote down vote up
/**
 * Processes information about the class and its super class.
 * @throws  IOException
 * @throws  ClassFormatException
 */
private final void processClassInfo () throws IOException, ClassFormatException {
    access_flags = file.readUnsignedShort();
    /* Interfaces are implicitely abstract, the flag should be set
     * according to the JVM specification.
     */
    if ((access_flags & Const.ACC_INTERFACE) != 0) {
        access_flags |= Const.ACC_ABSTRACT;
    }
    if (((access_flags & Const.ACC_ABSTRACT) != 0)
            && ((access_flags & Const.ACC_FINAL) != 0)) {
        throw new ClassFormatException("Class " + file_name +
                " can't be both final and abstract");
    }

    System.out.printf("%nClass info:%n");
    System.out.println("  flags: " + BCELifier.printFlags(access_flags,
            BCELifier.FLAGS.CLASS));
    class_name_index = file.readUnsignedShort();
    System.out.printf("  this_class: %d (", class_name_index);
    System.out.println(constantToString(class_name_index) + ")");

    superclass_name_index = file.readUnsignedShort();
    System.out.printf("  super_class: %d (", superclass_name_index);
    if (superclass_name_index > 0) {
        System.out.printf("%s", constantToString(superclass_name_index));
    }
    System.out.println(")");
}
 
Example 4
Source File: Pass2Verifier.java    From commons-bcel with Apache License 2.0 5 votes vote down vote up
@Override
public void visitInnerClasses(final InnerClasses obj) {//vmspec2 4.7.5

    // exactly one InnerClasses attr per ClassFile if some inner class is refernced: see visitJavaClass()

    checkIndex(obj, obj.getNameIndex(), CONST_Utf8);

    final String name = ((ConstantUtf8) cp.getConstant(obj.getNameIndex())).getBytes();
    if (! name.equals("InnerClasses")) {
        throw new ClassConstraintException(
            "The InnerClasses attribute '"+tostring(obj)+"' is not correctly named 'InnerClasses' but '"+name+"'.");
    }

    final InnerClass[] ics = obj.getInnerClasses();

    for (final InnerClass ic : ics) {
        checkIndex(obj, ic.getInnerClassIndex(), CONST_Class);
        final int outer_idx = ic.getOuterClassIndex();
        if (outer_idx != 0) {
            checkIndex(obj, outer_idx, CONST_Class);
        }
        final int innername_idx = ic.getInnerNameIndex();
        if (innername_idx != 0) {
            checkIndex(obj, innername_idx, CONST_Utf8);
        }
        int acc = ic.getInnerAccessFlags();
        acc = acc & (~ (Const.ACC_PUBLIC | Const.ACC_PRIVATE | Const.ACC_PROTECTED |
                        Const.ACC_STATIC | Const.ACC_FINAL | Const.ACC_INTERFACE | Const.ACC_ABSTRACT));
        if (acc != 0) {
            addMessage(
                "Unknown access flag for inner class '"+tostring(ic)+"' set (InnerClasses attribute '"+tostring(obj)+"').");
        }
    }
    // Semantical consistency is not yet checked by Sun, see vmspec2 4.7.5.
    // [marked TODO in JustIce]
}
 
Example 5
Source File: AccessFlags.java    From commons-bcel with Apache License 2.0 4 votes vote down vote up
public final boolean isInterface() {
    return (access_flags & Const.ACC_INTERFACE) != 0;
}
 
Example 6
Source File: JavaClass.java    From commons-bcel with Apache License 2.0 4 votes vote down vote up
public final boolean isClass() {
    return (super.getAccessFlags() & Const.ACC_INTERFACE) == 0;
}
 
Example 7
Source File: Utility.java    From commons-bcel with Apache License 2.0 2 votes vote down vote up
/**
 * @param access_flags the class flags
 *
 * @return "class" or "interface", depending on the ACC_INTERFACE flag
 */
public static String classOrInterface( final int access_flags ) {
    return ((access_flags & Const.ACC_INTERFACE) != 0) ? "interface" : "class";
}