Java Code Examples for jdk.internal.org.objectweb.asm.Opcodes#ACC_INTERFACE

The following examples show how to use jdk.internal.org.objectweb.asm.Opcodes#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: SerialVersionUIDAdder.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void visit(final int version, final int access, final String name,
        final String signature, final String superName,
        final String[] interfaces) {
    computeSVUID = (access & Opcodes.ACC_INTERFACE) == 0;

    if (computeSVUID) {
        this.name = name;
        this.access = access;
        this.interfaces = new String[interfaces.length];
        System.arraycopy(interfaces, 0, this.interfaces, 0,
                interfaces.length);
    }

    super.visit(version, access, name, signature, superName, interfaces);
}
 
Example 2
Source File: CheckClassAdapter.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Checks a given class.
 *
 * @param cr
 *            a <code>ClassReader</code> that contains bytecode for the
 *            analysis.
 * @param loader
 *            a <code>ClassLoader</code> which will be used to load
 *            referenced classes. This is useful if you are verifiying
 *            multiple interdependent classes.
 * @param dump
 *            true if bytecode should be printed out not only when errors
 *            are found.
 * @param pw
 *            write where results going to be printed
 */
public static void verify(final ClassReader cr, final ClassLoader loader,
        final boolean dump, final PrintWriter pw) {
    ClassNode cn = new ClassNode();
    cr.accept(new CheckClassAdapter(cn, false), ClassReader.SKIP_DEBUG);

    Type syperType = cn.superName == null ? null : Type
            .getObjectType(cn.superName);
    List<MethodNode> methods = cn.methods;

    List<Type> interfaces = new ArrayList<Type>();
    for (Iterator<String> i = cn.interfaces.iterator(); i.hasNext();) {
        interfaces.add(Type.getObjectType(i.next()));
    }

    for (int i = 0; i < methods.size(); ++i) {
        MethodNode method = methods.get(i);
        SimpleVerifier verifier = new SimpleVerifier(
                Type.getObjectType(cn.name), syperType, interfaces,
                (cn.access & Opcodes.ACC_INTERFACE) != 0);
        Analyzer<BasicValue> a = new Analyzer<BasicValue>(verifier);
        if (loader != null) {
            verifier.setClassLoader(loader);
        }
        try {
            a.analyze(cn.name, method);
            if (!dump) {
                continue;
            }
        } catch (Exception e) {
            e.printStackTrace(pw);
        }
        printAnalyzerResult(method, a, pw);
    }
    pw.flush();
}
 
Example 3
Source File: CheckClassAdapter.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Checks a given class.
 *
 * @param cr
 *            a <code>ClassReader</code> that contains bytecode for the
 *            analysis.
 * @param loader
 *            a <code>ClassLoader</code> which will be used to load
 *            referenced classes. This is useful if you are verifiying
 *            multiple interdependent classes.
 * @param dump
 *            true if bytecode should be printed out not only when errors
 *            are found.
 * @param pw
 *            write where results going to be printed
 */
public static void verify(final ClassReader cr, final ClassLoader loader,
        final boolean dump, final PrintWriter pw) {
    ClassNode cn = new ClassNode();
    cr.accept(new CheckClassAdapter(cn, false), ClassReader.SKIP_DEBUG);

    Type syperType = cn.superName == null ? null : Type
            .getObjectType(cn.superName);
    List<MethodNode> methods = cn.methods;

    List<Type> interfaces = new ArrayList<Type>();
    for (Iterator<String> i = cn.interfaces.iterator(); i.hasNext();) {
        interfaces.add(Type.getObjectType(i.next()));
    }

    for (int i = 0; i < methods.size(); ++i) {
        MethodNode method = methods.get(i);
        SimpleVerifier verifier = new SimpleVerifier(
                Type.getObjectType(cn.name), syperType, interfaces,
                (cn.access & Opcodes.ACC_INTERFACE) != 0);
        Analyzer<BasicValue> a = new Analyzer<BasicValue>(verifier);
        if (loader != null) {
            verifier.setClassLoader(loader);
        }
        try {
            a.analyze(cn.name, method);
            if (!dump) {
                continue;
            }
        } catch (Exception e) {
            e.printStackTrace(pw);
        }
        printAnalyzerResult(method, a, pw);
    }
    pw.flush();
}
 
Example 4
Source File: ByteCodeVisitor.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private static int asAccessFlags(TypeKlass klass) {
    int attr = Opcodes.ACC_SUPER;
    attr |= klass.isFinal() ? Opcodes.ACC_FINAL : 0;
    attr |= klass.isAbstract() ? Opcodes.ACC_ABSTRACT : 0;
    attr |= klass.isInterface() ? Opcodes.ACC_INTERFACE : 0;

    return attr;
}
 
Example 5
Source File: CheckClassAdapter.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Checks a given class.
 *
 * @param cr
 *            a <code>ClassReader</code> that contains bytecode for the
 *            analysis.
 * @param loader
 *            a <code>ClassLoader</code> which will be used to load
 *            referenced classes. This is useful if you are verifiying
 *            multiple interdependent classes.
 * @param dump
 *            true if bytecode should be printed out not only when errors
 *            are found.
 * @param pw
 *            write where results going to be printed
 */
public static void verify(final ClassReader cr, final ClassLoader loader,
        final boolean dump, final PrintWriter pw) {
    ClassNode cn = new ClassNode();
    cr.accept(new CheckClassAdapter(cn, false), ClassReader.SKIP_DEBUG);

    Type syperType = cn.superName == null ? null : Type
            .getObjectType(cn.superName);
    List<MethodNode> methods = cn.methods;

    List<Type> interfaces = new ArrayList<Type>();
    for (Iterator<String> i = cn.interfaces.iterator(); i.hasNext();) {
        interfaces.add(Type.getObjectType(i.next()));
    }

    for (int i = 0; i < methods.size(); ++i) {
        MethodNode method = methods.get(i);
        SimpleVerifier verifier = new SimpleVerifier(
                Type.getObjectType(cn.name), syperType, interfaces,
                (cn.access & Opcodes.ACC_INTERFACE) != 0);
        Analyzer<BasicValue> a = new Analyzer<BasicValue>(verifier);
        if (loader != null) {
            verifier.setClassLoader(loader);
        }
        try {
            a.analyze(cn.name, method);
            if (!dump) {
                continue;
            }
        } catch (Exception e) {
            e.printStackTrace(pw);
        }
        printAnalyzerResult(method, a, pw);
    }
    pw.flush();
}
 
Example 6
Source File: CheckClassAdapter.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Checks a given class.
 *
 * @param cr
 *            a <code>ClassReader</code> that contains bytecode for the
 *            analysis.
 * @param loader
 *            a <code>ClassLoader</code> which will be used to load
 *            referenced classes. This is useful if you are verifiying
 *            multiple interdependent classes.
 * @param dump
 *            true if bytecode should be printed out not only when errors
 *            are found.
 * @param pw
 *            write where results going to be printed
 */
public static void verify(final ClassReader cr, final ClassLoader loader,
        final boolean dump, final PrintWriter pw) {
    ClassNode cn = new ClassNode();
    cr.accept(new CheckClassAdapter(cn, false), ClassReader.SKIP_DEBUG);

    Type syperType = cn.superName == null ? null : Type
            .getObjectType(cn.superName);
    List<MethodNode> methods = cn.methods;

    List<Type> interfaces = new ArrayList<Type>();
    for (Iterator<String> i = cn.interfaces.iterator(); i.hasNext();) {
        interfaces.add(Type.getObjectType(i.next()));
    }

    for (int i = 0; i < methods.size(); ++i) {
        MethodNode method = methods.get(i);
        SimpleVerifier verifier = new SimpleVerifier(
                Type.getObjectType(cn.name), syperType, interfaces,
                (cn.access & Opcodes.ACC_INTERFACE) != 0);
        Analyzer<BasicValue> a = new Analyzer<BasicValue>(verifier);
        if (loader != null) {
            verifier.setClassLoader(loader);
        }
        try {
            a.analyze(cn.name, method);
            if (!dump) {
                continue;
            }
        } catch (Exception e) {
            e.printStackTrace(pw);
        }
        printAnalyzerResult(method, a, pw);
    }
    pw.flush();
}
 
Example 7
Source File: TraceSignatureVisitor.java    From nashorn with GNU General Public License v2.0 4 votes vote down vote up
public TraceSignatureVisitor(final int access) {
    super(Opcodes.ASM4);
    isInterface = (access & Opcodes.ACC_INTERFACE) != 0;
    this.declaration = new StringBuffer();
}
 
Example 8
Source File: Textifier.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void visit(final int version, final int access, final String name,
        final String signature, final String superName,
        final String[] interfaces) {
    this.access = access;
    int major = version & 0xFFFF;
    int minor = version >>> 16;
    buf.setLength(0);
    buf.append("// class version ").append(major).append('.').append(minor)
            .append(" (").append(version).append(")\n");
    if ((access & Opcodes.ACC_DEPRECATED) != 0) {
        buf.append("// DEPRECATED\n");
    }
    buf.append("// access flags 0x")
            .append(Integer.toHexString(access).toUpperCase()).append('\n');

    appendDescriptor(CLASS_SIGNATURE, signature);
    if (signature != null) {
        TraceSignatureVisitor sv = new TraceSignatureVisitor(access);
        SignatureReader r = new SignatureReader(signature);
        r.accept(sv);
        buf.append("// declaration: ").append(name)
                .append(sv.getDeclaration()).append('\n');
    }

    appendAccess(access & ~Opcodes.ACC_SUPER);
    if ((access & Opcodes.ACC_ANNOTATION) != 0) {
        buf.append("@interface ");
    } else if ((access & Opcodes.ACC_INTERFACE) != 0) {
        buf.append("interface ");
    } else if ((access & Opcodes.ACC_ENUM) == 0) {
        buf.append("class ");
    }
    appendDescriptor(INTERNAL_NAME, name);

    if (superName != null && !"java/lang/Object".equals(superName)) {
        buf.append(" extends ");
        appendDescriptor(INTERNAL_NAME, superName);
        buf.append(' ');
    }
    if (interfaces != null && interfaces.length > 0) {
        buf.append(" implements ");
        for (int i = 0; i < interfaces.length; ++i) {
            appendDescriptor(INTERNAL_NAME, interfaces[i]);
            buf.append(' ');
        }
    }
    buf.append(" {\n\n");

    text.add(buf.toString());
}
 
Example 9
Source File: CheckClassAdapter.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void visit(final int version, final int access, final String name,
        final String signature, final String superName,
        final String[] interfaces) {
    if (start) {
        throw new IllegalStateException("visit must be called only once");
    }
    start = true;
    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 + 0x40000); // ClassWriter.ACC_SYNTHETIC_ATTRIBUTE
    if (name == null || !name.endsWith("package-info")) {
        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) {
        checkClassSignature(signature);
    }
    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.version = version;
    super.visit(version, access, name, signature, superName, interfaces);
}
 
Example 10
Source File: TraceSignatureVisitor.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public TraceSignatureVisitor(final int access) {
    super(Opcodes.ASM5);
    isInterface = (access & Opcodes.ACC_INTERFACE) != 0;
    this.declaration = new StringBuffer();
}
 
Example 11
Source File: Textifier.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Override
public Textifier visitMethod(final int access, final String name,
        final String desc, final String signature, final String[] exceptions) {
    buf.setLength(0);
    buf.append('\n');
    if ((access & Opcodes.ACC_DEPRECATED) != 0) {
        buf.append(tab).append("// DEPRECATED\n");
    }
    buf.append(tab).append("// access flags 0x")
            .append(Integer.toHexString(access).toUpperCase()).append('\n');

    if (signature != null) {
        buf.append(tab);
        appendDescriptor(METHOD_SIGNATURE, signature);

        TraceSignatureVisitor v = new TraceSignatureVisitor(0);
        SignatureReader r = new SignatureReader(signature);
        r.accept(v);
        String genericDecl = v.getDeclaration();
        String genericReturn = v.getReturnType();
        String genericExceptions = v.getExceptions();

        buf.append(tab).append("// declaration: ").append(genericReturn)
                .append(' ').append(name).append(genericDecl);
        if (genericExceptions != null) {
            buf.append(" throws ").append(genericExceptions);
        }
        buf.append('\n');
    }

    buf.append(tab);
    appendAccess(access & ~Opcodes.ACC_VOLATILE);
    if ((access & Opcodes.ACC_NATIVE) != 0) {
        buf.append("native ");
    }
    if ((access & Opcodes.ACC_VARARGS) != 0) {
        buf.append("varargs ");
    }
    if ((access & Opcodes.ACC_BRIDGE) != 0) {
        buf.append("bridge ");
    }
    if ((this.access & Opcodes.ACC_INTERFACE) != 0
            && (access & Opcodes.ACC_ABSTRACT) == 0
            && (access & Opcodes.ACC_STATIC) == 0) {
        buf.append("default ");
    }

    buf.append(name);
    appendDescriptor(METHOD_DESCRIPTOR, desc);
    if (exceptions != null && exceptions.length > 0) {
        buf.append(" throws ");
        for (int i = 0; i < exceptions.length; ++i) {
            appendDescriptor(INTERNAL_NAME, exceptions[i]);
            buf.append(' ');
        }
    }

    buf.append('\n');
    text.add(buf.toString());

    Textifier t = createTextifier();
    text.add(t.getText());
    return t;
}
 
Example 12
Source File: Textifier.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void visit(final int version, final int access, final String name,
        final String signature, final String superName,
        final String[] interfaces) {
    this.access = access;
    int major = version & 0xFFFF;
    int minor = version >>> 16;
    buf.setLength(0);
    buf.append("// class version ").append(major).append('.').append(minor)
            .append(" (").append(version).append(")\n");
    if ((access & Opcodes.ACC_DEPRECATED) != 0) {
        buf.append("// DEPRECATED\n");
    }
    buf.append("// access flags 0x")
            .append(Integer.toHexString(access).toUpperCase()).append('\n');

    appendDescriptor(CLASS_SIGNATURE, signature);
    if (signature != null) {
        TraceSignatureVisitor sv = new TraceSignatureVisitor(access);
        SignatureReader r = new SignatureReader(signature);
        r.accept(sv);
        buf.append("// declaration: ").append(name)
                .append(sv.getDeclaration()).append('\n');
    }

    appendAccess(access & ~Opcodes.ACC_SUPER);
    if ((access & Opcodes.ACC_ANNOTATION) != 0) {
        buf.append("@interface ");
    } else if ((access & Opcodes.ACC_INTERFACE) != 0) {
        buf.append("interface ");
    } else if ((access & Opcodes.ACC_ENUM) == 0) {
        buf.append("class ");
    }
    appendDescriptor(INTERNAL_NAME, name);

    if (superName != null && !"java/lang/Object".equals(superName)) {
        buf.append(" extends ");
        appendDescriptor(INTERNAL_NAME, superName);
        buf.append(' ');
    }
    if (interfaces != null && interfaces.length > 0) {
        buf.append(" implements ");
        for (int i = 0; i < interfaces.length; ++i) {
            appendDescriptor(INTERNAL_NAME, interfaces[i]);
            buf.append(' ');
        }
    }
    buf.append(" {\n\n");

    text.add(buf.toString());
}
 
Example 13
Source File: CheckClassAdapter.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void visit(final int version, final int access, final String name,
        final String signature, final String superName,
        final String[] interfaces) {
    if (start) {
        throw new IllegalStateException("visit must be called only once");
    }
    start = true;
    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 + 0x40000); // ClassWriter.ACC_SYNTHETIC_ATTRIBUTE
    if (name == null || !name.endsWith("package-info")) {
        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) {
        checkClassSignature(signature);
    }
    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.version = version;
    super.visit(version, access, name, signature, superName, interfaces);
}
 
Example 14
Source File: TraceSignatureVisitor.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public TraceSignatureVisitor(final int access) {
    super(Opcodes.ASM5);
    isInterface = (access & Opcodes.ACC_INTERFACE) != 0;
    this.declaration = new StringBuffer();
}
 
Example 15
Source File: NashornTextifier.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void visit(final int version, final int access, final String name, final String signature, final String superName, final String[] interfaces) {
    final int major = version & 0xFFFF;
    final int minor = version >>> 16;

    currentClassName = name;

    final StringBuilder sb = new StringBuilder();
    sb.append("// class version ").
        append(major).
        append('.').
        append(minor).append(" (").
        append(version).
        append(")\n");

    if ((access & Opcodes.ACC_DEPRECATED) != 0) {
        sb.append("// DEPRECATED\n");
    }

    sb.append("// access flags 0x"). //TODO TRANSLATE TO WHAT THEY MEAN
        append(Integer.toHexString(access).toUpperCase()).
        append('\n');

    appendDescriptor(sb, CLASS_SIGNATURE, signature);
    if (signature != null) {
        final TraceSignatureVisitor sv = new TraceSignatureVisitor(access);
        final SignatureReader r = new SignatureReader(signature);
        r.accept(sv);
        sb.append("// declaration: ").
            append(name).
            append(sv.getDeclaration()).
            append('\n');
    }

    appendAccess(sb, access & ~Opcodes.ACC_SUPER);
    if ((access & Opcodes.ACC_ANNOTATION) != 0) {
        sb.append("@interface ");
    } else if ((access & Opcodes.ACC_INTERFACE) != 0) {
        sb.append("interface ");
    } else if ((access & Opcodes.ACC_ENUM) == 0) {
        sb.append("class ");
    }
    appendDescriptor(sb, INTERNAL_NAME, name);

    if (superName != null && !"java/lang/Object".equals(superName)) {
        sb.append(" extends ");
        appendDescriptor(sb, INTERNAL_NAME, superName);
        sb.append(' ');
    }
    if (interfaces != null && interfaces.length > 0) {
        sb.append(" implements ");
        for (final String interface1 : interfaces) {
            appendDescriptor(sb, INTERNAL_NAME, interface1);
            sb.append(' ');
        }
    }
    sb.append(" {\n");

    addText(sb);
}
 
Example 16
Source File: NashornTextifier.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void visit(final int version, final int access, final String name, final String signature, final String superName, final String[] interfaces) {
    final int major = version & 0xFFFF;
    final int minor = version >>> 16;

    currentClassName = name;

    final StringBuilder sb = new StringBuilder();
    sb.append("// class version ").
        append(major).
        append('.').
        append(minor).append(" (").
        append(version).
        append(")\n");

    if ((access & Opcodes.ACC_DEPRECATED) != 0) {
        sb.append("// DEPRECATED\n");
    }

    sb.append("// access flags 0x"). //TODO TRANSLATE TO WHAT THEY MEAN
        append(Integer.toHexString(access).toUpperCase()).
        append('\n');

    appendDescriptor(sb, CLASS_SIGNATURE, signature);
    if (signature != null) {
        final TraceSignatureVisitor sv = new TraceSignatureVisitor(access);
        final SignatureReader r = new SignatureReader(signature);
        r.accept(sv);
        sb.append("// declaration: ").
            append(name).
            append(sv.getDeclaration()).
            append('\n');
    }

    appendAccess(sb, access & ~Opcodes.ACC_SUPER);
    if ((access & Opcodes.ACC_ANNOTATION) != 0) {
        sb.append("@interface ");
    } else if ((access & Opcodes.ACC_INTERFACE) != 0) {
        sb.append("interface ");
    } else if ((access & Opcodes.ACC_ENUM) == 0) {
        sb.append("class ");
    }
    appendDescriptor(sb, INTERNAL_NAME, name);

    if (superName != null && !"java/lang/Object".equals(superName)) {
        sb.append(" extends ");
        appendDescriptor(sb, INTERNAL_NAME, superName);
        sb.append(' ');
    }
    if (interfaces != null && interfaces.length > 0) {
        sb.append(" implements ");
        for (final String interface1 : interfaces) {
            appendDescriptor(sb, INTERNAL_NAME, interface1);
            sb.append(' ');
        }
    }
    sb.append(" {\n");

    addText(sb);
}
 
Example 17
Source File: Textifier.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void visit(final int version, final int access, final String name,
        final String signature, final String superName,
        final String[] interfaces) {
    this.access = access;
    int major = version & 0xFFFF;
    int minor = version >>> 16;
    buf.setLength(0);
    buf.append("// class version ").append(major).append('.').append(minor)
            .append(" (").append(version).append(")\n");
    if ((access & Opcodes.ACC_DEPRECATED) != 0) {
        buf.append("// DEPRECATED\n");
    }
    buf.append("// access flags 0x")
            .append(Integer.toHexString(access).toUpperCase()).append('\n');

    appendDescriptor(CLASS_SIGNATURE, signature);
    if (signature != null) {
        TraceSignatureVisitor sv = new TraceSignatureVisitor(access);
        SignatureReader r = new SignatureReader(signature);
        r.accept(sv);
        buf.append("// declaration: ").append(name)
                .append(sv.getDeclaration()).append('\n');
    }

    appendAccess(access & ~Opcodes.ACC_SUPER);
    if ((access & Opcodes.ACC_ANNOTATION) != 0) {
        buf.append("@interface ");
    } else if ((access & Opcodes.ACC_INTERFACE) != 0) {
        buf.append("interface ");
    } else if ((access & Opcodes.ACC_ENUM) == 0) {
        buf.append("class ");
    }
    appendDescriptor(INTERNAL_NAME, name);

    if (superName != null && !"java/lang/Object".equals(superName)) {
        buf.append(" extends ");
        appendDescriptor(INTERNAL_NAME, superName);
        buf.append(' ');
    }
    if (interfaces != null && interfaces.length > 0) {
        buf.append(" implements ");
        for (int i = 0; i < interfaces.length; ++i) {
            appendDescriptor(INTERNAL_NAME, interfaces[i]);
            buf.append(' ');
        }
    }
    buf.append(" {\n\n");

    text.add(buf.toString());
}
 
Example 18
Source File: Textifier.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void visit(final int version, final int access, final String name,
        final String signature, final String superName,
        final String[] interfaces) {
    this.access = access;
    int major = version & 0xFFFF;
    int minor = version >>> 16;
    buf.setLength(0);
    buf.append("// class version ").append(major).append('.').append(minor)
            .append(" (").append(version).append(")\n");
    if ((access & Opcodes.ACC_DEPRECATED) != 0) {
        buf.append("// DEPRECATED\n");
    }
    buf.append("// access flags 0x")
            .append(Integer.toHexString(access).toUpperCase()).append('\n');

    appendDescriptor(CLASS_SIGNATURE, signature);
    if (signature != null) {
        TraceSignatureVisitor sv = new TraceSignatureVisitor(access);
        SignatureReader r = new SignatureReader(signature);
        r.accept(sv);
        buf.append("// declaration: ").append(name)
                .append(sv.getDeclaration()).append('\n');
    }

    appendAccess(access & ~Opcodes.ACC_SUPER);
    if ((access & Opcodes.ACC_ANNOTATION) != 0) {
        buf.append("@interface ");
    } else if ((access & Opcodes.ACC_INTERFACE) != 0) {
        buf.append("interface ");
    } else if ((access & Opcodes.ACC_ENUM) == 0) {
        buf.append("class ");
    }
    appendDescriptor(INTERNAL_NAME, name);

    if (superName != null && !"java/lang/Object".equals(superName)) {
        buf.append(" extends ");
        appendDescriptor(INTERNAL_NAME, superName);
        buf.append(' ');
    }
    if (interfaces != null && interfaces.length > 0) {
        buf.append(" implements ");
        for (int i = 0; i < interfaces.length; ++i) {
            appendDescriptor(INTERNAL_NAME, interfaces[i]);
            buf.append(' ');
        }
    }
    buf.append(" {\n\n");

    text.add(buf.toString());
}
 
Example 19
Source File: CheckClassAdapter.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void visit(final int version, final int access, final String name,
        final String signature, final String superName,
        final String[] interfaces) {
    if (start) {
        throw new IllegalStateException("visit must be called only once");
    }
    start = true;
    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 + 0x40000); // ClassWriter.ACC_SYNTHETIC_ATTRIBUTE
    if (name == null || !name.endsWith("package-info")) {
        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) {
        checkClassSignature(signature);
    }
    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.version = version;
    super.visit(version, access, name, signature, superName, interfaces);
}
 
Example 20
Source File: Textifier.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
@Override
public Textifier visitMethod(final int access, final String name,
        final String desc, final String signature, final String[] exceptions) {
    buf.setLength(0);
    buf.append('\n');
    if ((access & Opcodes.ACC_DEPRECATED) != 0) {
        buf.append(tab).append("// DEPRECATED\n");
    }
    buf.append(tab).append("// access flags 0x")
            .append(Integer.toHexString(access).toUpperCase()).append('\n');

    if (signature != null) {
        buf.append(tab);
        appendDescriptor(METHOD_SIGNATURE, signature);

        TraceSignatureVisitor v = new TraceSignatureVisitor(0);
        SignatureReader r = new SignatureReader(signature);
        r.accept(v);
        String genericDecl = v.getDeclaration();
        String genericReturn = v.getReturnType();
        String genericExceptions = v.getExceptions();

        buf.append(tab).append("// declaration: ").append(genericReturn)
                .append(' ').append(name).append(genericDecl);
        if (genericExceptions != null) {
            buf.append(" throws ").append(genericExceptions);
        }
        buf.append('\n');
    }

    buf.append(tab);
    appendAccess(access & ~Opcodes.ACC_VOLATILE);
    if ((access & Opcodes.ACC_NATIVE) != 0) {
        buf.append("native ");
    }
    if ((access & Opcodes.ACC_VARARGS) != 0) {
        buf.append("varargs ");
    }
    if ((access & Opcodes.ACC_BRIDGE) != 0) {
        buf.append("bridge ");
    }
    if ((this.access & Opcodes.ACC_INTERFACE) != 0
            && (access & Opcodes.ACC_ABSTRACT) == 0
            && (access & Opcodes.ACC_STATIC) == 0) {
        buf.append("default ");
    }

    buf.append(name);
    appendDescriptor(METHOD_DESCRIPTOR, desc);
    if (exceptions != null && exceptions.length > 0) {
        buf.append(" throws ");
        for (int i = 0; i < exceptions.length; ++i) {
            appendDescriptor(INTERNAL_NAME, exceptions[i]);
            buf.append(' ');
        }
    }

    buf.append('\n');
    text.add(buf.toString());

    Textifier t = createTextifier();
    text.add(t.getText());
    return t;
}