Example usage for org.objectweb.asm Opcodes ACC_INTERFACE

List of usage examples for org.objectweb.asm Opcodes ACC_INTERFACE

Introduction

In this page you can find the example usage for org.objectweb.asm Opcodes ACC_INTERFACE.

Prototype

int ACC_INTERFACE

To view the source code for org.objectweb.asm Opcodes ACC_INTERFACE.

Click Source Link

Usage

From source file:com.sun.fortress.runtimeSystem.InstantiatingClassloader.java

License:Open Source License

private static byte[] instantiateAnyTuple(String dename, List<String> parameters) {
    /*//from   w w w. j a  v a  2  s.  co m
     * Single parameter, N, which is the arity of the tuple.
     * 
     * implements Ljava/util/List;
     * implements Lfortress/AnyType$Any;
     * abstract methods o1 ... oN (or 0 ... N-1, depending on tuple origin)
     */
    int n = Integer.parseInt(parameters.get(0));

    ManglingClassWriter cw = new ManglingClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES);
    String[] superInterfaces = {
            //        "java/util/List",
            "fortress/AnyType$Any" };
    cw.visit(JVM_BYTECODE_VERSION, Opcodes.ACC_PUBLIC | Opcodes.ACC_ABSTRACT | Opcodes.ACC_INTERFACE, dename,
            null, "java/lang/Object", superInterfaces);

    for (int i = 0; i < n; i++) {
        String m = TUPLE_OBJECT_ELT_PFX + (i + Naming.TUPLE_ORIGIN);
        String sig = UNTYPED_GETTER_SIG;
        interfaceMethod(cw, m, sig);
    }

    cw.visitEnd();
    return cw.toByteArray();
}

From source file:com.sun.tdk.jcov.instrument.DataClass.java

License:Open Source License

/**
 * XML Generation. Not supposed to use outside.
 */// w  ww  .ja v a2 s .  c o m
@Override
public String kind() {
    if (differentiateClass) {
        return (access & Opcodes.ACC_INTERFACE) == 0 ? XmlNames.CLASS : XmlNames.INTERFACE;
    } else {
        return XmlNames.CLASS;
    }
}

From source file:com.sun.tdk.jcov.instrument.DataClass.java

License:Open Source License

/**
 * XML Generation. Not supposed to use outside.
 *//*from  w  ww . ja  v  a 2 s . c o  m*/
@Override
void xmlGen(XmlContext ctx) {

    if ((!ctx.skipNotCoveredClasses || wasHit() && methods.size() > 0)) {

        // check abstract on
        if (ctx.showAbstract) {
            super.xmlGen(ctx);
        } else if ((access & Opcodes.ACC_INTERFACE) == 0) {
            super.xmlGen(ctx);
        } else {
            // cheking interface
            // find default methods even when abstract off
            List<DataMethod> onlyDefaultMethods = new ArrayList<DataMethod>();
            for (DataMethod method : methods) {
                if ((method.getAccess() & Opcodes.ACC_ABSTRACT) == 0) {
                    onlyDefaultMethods.add(method);
                }
            }
            this.methods.retainAll(onlyDefaultMethods);

            if (methods.size() > 0) {
                super.xmlGen(ctx);
            }
        }
    }

}

From source file:com.sun.tdk.jcov.instrument.DataClass.java

License:Open Source License

/**
 * XML Generation. Not supposed to use outside.
 *///  w ww.  j  a v a2  s.  co  m
@Override
void xmlAttrs(XmlContext ctx) {
    ctx.attr(XmlNames.NAME, name);
    ctx.attr(XmlNames.SUPERNAME, superName == null ? "" : superName);
    if (checksum != -1) {
        ctx.attr(XmlNames.CHECKSUM, checksum);
    }
    if (!differentiateClass && (access & Opcodes.ACC_INTERFACE) != 0) {
        ctx.attr(XmlNames.INTERFACE, true);
    }
    if (signature != null) {
        ctx.attrNormalized(XmlNames.SIGNATURE, signature);
    }
    if (source != null) {
        ctx.attrNormalized(XmlNames.SOURCE, source);
    }
    if (inner) {
        if (anonym) {
            ctx.attr(XmlNames.INNER_CLASS, "anon");
        } else {
            ctx.attr(XmlNames.INNER_CLASS, "inner");
        }
    }
    xmlAccessFlags(ctx, access);

    super.xmlAttrs(ctx);
}

From source file:com.tencent.tinker.build.auxiliaryclass.AuxiliaryClassInjectAdapter.java

License:Open Source License

@Override
public void visit(int version, int access, String name, String signature, String superName,
        String[] interfaces) {/*from www  .j  a v  a2  s  .co m*/
    super.visit(version, access, name, signature, superName, interfaces);
    this.isClInitExists = false;
    this.isInitExists = false;
    this.isTargetClass = ((access & Opcodes.ACC_INTERFACE) == 0);
    this.isInjected = false;
}

From source file:com.tngtech.archunit.core.importer.JavaClassProcessor.java

License:Apache License

@Override
public void visit(int version, int access, String name, String signature, String superName,
        String[] interfaces) {/*from   w  ww. j  a  v  a  2s . c o m*/
    LOG.info("Analysing class '{}'", name);
    JavaType javaType = JavaTypeImporter.createFromAsmObjectTypeName(name);
    if (alreadyImported(javaType)) {
        return;
    }

    ImmutableSet<String> interfaceNames = createInterfaceNames(interfaces);
    LOG.debug("Found interfaces {} on class '{}'", interfaceNames, name);
    boolean opCodeForInterfaceIsPresent = (access & Opcodes.ACC_INTERFACE) != 0;
    boolean opCodeForEnumIsPresent = (access & Opcodes.ACC_ENUM) != 0;
    Optional<String> superClassName = getSuperClassName(superName, opCodeForInterfaceIsPresent);
    LOG.debug("Found superclass {} on class '{}'", superClassName.orNull(), name);

    javaClassBuilder = new DomainBuilders.JavaClassBuilder().withSourceUri(sourceURI).withType(javaType)
            .withInterface(opCodeForInterfaceIsPresent).withEnum(opCodeForEnumIsPresent)
            .withModifiers(JavaModifier.getModifiersForClass(access));

    className = javaType.getName();
    declarationHandler.onNewClass(className, superClassName, interfaceNames);
}

From source file:cz.vutbr.fit.xhriba01.bc.lib.Utils.java

License:Open Source License

/**
 * Creates text representation of asm class access flag.
 * /* w  w w.jav  a 2  s.c  o  m*/
 * @param flag asm class access flag
 * @return formatted string representing the access flag
 */
public static String formatClassAccessFlags(int flag) {
    List<String> accesses = new ArrayList<>();
    if ((flag & Opcodes.ACC_PUBLIC) != 0) {
        accesses.add("public");
    }
    if ((flag & Opcodes.ACC_PROTECTED) != 0) {
        accesses.add("protected");
    }
    if ((flag & Opcodes.ACC_PRIVATE) != 0) {
        accesses.add("private");
    }
    if ((flag & Opcodes.ACC_STATIC) != 0) {
        accesses.add("static");
    }
    if ((flag & Opcodes.ACC_ABSTRACT) != 0) {
        accesses.add("abstract");
    }
    if ((flag & Opcodes.ACC_FINAL) != 0) {
        accesses.add("final");
    }
    if ((flag & Opcodes.ACC_ENUM) != 0) {
        accesses.add("enum");
    } else if ((flag & Opcodes.ACC_INTERFACE) != 0) {
        accesses.add("interface");
    } else {
        accesses.add("class");
    }
    return join(accesses.toArray(new String[accesses.size()]), " ");
}

From source file:edu.ubc.mirrors.holograms.HologramClassGenerator.java

License:Open Source License

@Override
public void visit(int version, int access, String name, String signature, String superName,
        String[] interfaces) {//from w w  w .  j a  va 2s .c  o m
    this.name = name;
    this.isInterface = (Opcodes.ACC_INTERFACE & access) != 0;
    this.superName = getHologramSuperclassName(isInterface, name, superName);
    interfaces = getHologramInterfaces(name, isInterface, interfaces);

    // Force everything to be public, since HologramClassLoader has to reflectively
    // construct holograms. Again, not a problem because the VM will see the original flags on the ClassMirror instead.
    // Also remove enum flags.
    int hologramAccess = forcePublic(access);
    // Also remove abstract flag. Shouldn't be necessary, but the VM (OpenJDK at least)
    // creates objects that claim to be an instance of VirtualMachineError, which is abstract.
    if (name.equals("hologram/java/lang/VirtualMachineError")) {
        hologramAccess = ~Opcodes.ACC_ABSTRACT & access;
    }

    // We need at least 1.5 to use class literal constants
    // TODO-RS: Work out a better way to interpret 45.X numbers correctly
    if (version == Opcodes.V1_1 || version < Opcodes.V1_5) {
        version = 49;
    }

    super.visit(version, hologramAccess, name, signature, this.superName, interfaces);

    if (this.name.equals(hologramThrowableType.getInternalName())) {
        // Generate aliases for the original superclass' fillInStackTrace and getStackTrace methods,
        // so we can call them in stubs without hitting hologram code.
        MethodVisitor v = super.visitMethod(Opcodes.ACC_PUBLIC, "superFillInStackTrace",
                Type.getMethodDescriptor(Type.VOID_TYPE), null, null);
        v.visitCode();
        v.visitVarInsn(Opcodes.ALOAD, 0);
        v.visitMethodInsn(Opcodes.INVOKESPECIAL, Type.getInternalName(Throwable.class), "fillInStackTrace",
                Type.getMethodDescriptor(Type.getType(Throwable.class)));
        v.visitInsn(Opcodes.RETURN);
        v.visitMaxs(1, 1);
        v.visitEnd();

        v = super.visitMethod(Opcodes.ACC_PUBLIC, "superGetStackTrace",
                Type.getMethodDescriptor(Type.getType(StackTraceElement[].class)), null, null);
        v.visitCode();
        v.visitVarInsn(Opcodes.ALOAD, 0);
        v.visitMethodInsn(Opcodes.INVOKESPECIAL, Type.getInternalName(Throwable.class), "getStackTrace",
                Type.getMethodDescriptor(Type.getType(StackTraceElement[].class)));
        v.visitInsn(Opcodes.ARETURN);
        v.visitMaxs(1, 1);
        v.visitEnd();
    }
}

From source file:edu.ubc.mirrors.holograms.HologramClassGenerator.java

License:Open Source License

public static void generateArray(ClassVisitor visitor, HologramClassLoader loader,
        HologramClassMirror hologramClassMirror) {
    boolean isInterface = !hologramClassMirror.isImplementationClass();
    ClassMirror classMirror = hologramClassMirror.getOriginal();

    Type originalType = Reflection.typeForClassMirror(classMirror);
    Type originalElementType = originalType.getElementType();
    int dims = originalType.getDimensions();

    String internalName = getHologramType(originalType, !isInterface).getInternalName();

    ClassMirror superClassMirror = null;
    String superName = isInterface ? Type.getInternalName(Object.class)
            : Type.getInternalName(ObjectArrayHologram.class);
    Set<String> interfaces = new HashSet<String>();
    int access = Opcodes.ACC_PUBLIC | (isInterface ? Opcodes.ACC_INTERFACE : 0);

    if (originalElementType.getSort() == Type.OBJECT || originalElementType.getSort() == Type.ARRAY) {
        ClassMirror elementClass = loader.loadOriginalClassMirror(originalElementType.getClassName());
        superClassMirror = elementClass.getSuperClassMirror();

        if (isInterface) {
            if (superClassMirror != null) {
                Type superType = Reflection.makeArrayType(dims,
                        Type.getObjectType(superClassMirror.getClassName().replace('.', '/')));
                String superInterfaceName = getHologramType(superType).getInternalName();
                interfaces.add(superInterfaceName);
            }//from  w  ww  .  ja  v a 2s  .c  om

            for (ClassMirror interfaceMirror : elementClass.getInterfaceMirrors()) {
                Type superType = Reflection.makeArrayType(dims,
                        Type.getObjectType(interfaceMirror.getClassName().replace('.', '/')));
                String interfaceName = getHologramType(superType).getInternalName();
                interfaces.add(interfaceName);
            }

            interfaces.add(hologramType.getInternalName());

            Type nMinus1Type = Reflection.makeArrayType(dims - 1, Type.getType(Object.class));
            interfaces.add(getHologramType(nMinus1Type).getInternalName());
        }
    }
    if (!isInterface) {
        interfaces.add(getHologramType(originalType, false).getInternalName());
    }

    visitor.visit(Opcodes.V1_5, access, internalName, null, superName, interfaces.toArray(new String[0]));

    if (isInterface) {
        // Generate clone()
        String cloneDesc = Type.getMethodDescriptor(objectType);
        MethodVisitor mv = visitor.visitMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_ABSTRACT, "clone", cloneDesc,
                null, null);
        mv.visitEnd();
    } else {
        // Generate thunk constructors
        String initDesc = Type.getMethodDescriptor(Type.VOID_TYPE, Type.getType(ObjectArrayMirror.class));
        MethodVisitor mv = visitor.visitMethod(Opcodes.ACC_PUBLIC, "<init>", initDesc, null, null);
        mv.visitCode();
        mv.visitVarInsn(Opcodes.ALOAD, 0);
        mv.visitVarInsn(Opcodes.ALOAD, 1);
        mv.visitMethodInsn(Opcodes.INVOKESPECIAL, superName, "<init>", initDesc);
        mv.visitInsn(Opcodes.RETURN);
        mv.visitMaxs(2, 2);
        mv.visitEnd();

        initDesc = Type.getMethodDescriptor(Type.VOID_TYPE, Type.INT_TYPE);
        mv = visitor.visitMethod(Opcodes.ACC_PUBLIC, "<init>", initDesc, null, null);
        mv.visitCode();
        mv.visitVarInsn(Opcodes.ALOAD, 0);
        mv.visitVarInsn(Opcodes.ILOAD, 1);
        mv.visitMethodInsn(Opcodes.INVOKESPECIAL, superName, "<init>", initDesc);
        mv.visitInsn(Opcodes.RETURN);
        mv.visitMaxs(2, 2);
        mv.visitEnd();
    }

    // Generate the static field used to store the corresponding ClassMirror and the static initializer to set it
    int staticAccess = Opcodes.ACC_PUBLIC | Opcodes.ACC_FINAL | Opcodes.ACC_STATIC;
    visitor.visitField(staticAccess, "classMirror", classMirrorType.getDescriptor(), null, null);

    InstructionAdapter mv = new InstructionAdapter(
            visitor.visitMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, "<clinit>", "()V", null, null));
    mv.visitCode();
    HologramMethodGenerator.initializeStaticFields(Type.getObjectType(internalName), mv);
    mv.areturn(Type.VOID_TYPE);
    mv.visitMaxs(2, 2);
    mv.visitEnd();

    visitor.visitEnd();
}

From source file:edu.ubc.mirrors.raw.NativeClassGenerator.java

License:Open Source License

@Override
public void visit(int version, int access, String name, String signature, String superName,
        String[] interfaces) {//from www. ja va 2 s  .  com

    this.className = getNativeInternalClassName(name);
    this.superName = getNativeInternalClassName(superName);
    this.isInterface = (Opcodes.ACC_INTERFACE & access) != 0;

    super.visit(version, access, this.className, signature, this.superName, interfaces);
}