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:fi.luontola.buildtest.AsmUtils.java

License:Open Source License

public static boolean isInterface(ClassNode cn) {
    return hasFlag(cn.access, Opcodes.ACC_INTERFACE);
}

From source file:fr.insalyon.telecom.jooflux.InvokeClassAdapter.java

License:Mozilla Public License

@Override
public void visit(int version, int access, String name, String signature, String superName,
        String[] interfaces) {//from  w  w w. j a  v a  2s  .  com
    this.cv.visit(Opcodes.V1_7, access, name, signature, superName, interfaces);
    this.isInterface = (access & Opcodes.ACC_INTERFACE) != 0;
    //        this.isClassLoader = "java/lang/ClassLoader".equals(superName);
}

From source file:graph.Modifier.java

License:Apache License

/**
 * Returns an integer bit field for the EnumSet, where the bit values are
 * defined as in the class file format./*from  w w  w  .j ava2  s  .co m*/
 *
 * @param  set   Set of modifiers to convert to a bit field.
 * @return       Integer bit field.
 */
public static int getBitField(EnumSet<Modifier> set) {
    int access = 0;

    if (set.contains(PUBLIC)) {
        access |= Opcodes.ACC_PUBLIC;
    }

    if (set.contains(PROTECTED)) {
        access |= Opcodes.ACC_PROTECTED;
    }

    if (set.contains(PRIVATE)) {
        access |= Opcodes.ACC_PRIVATE;
    }

    if (set.contains(STATIC)) {
        access |= Opcodes.ACC_STATIC;
    }

    if (set.contains(FINAL)) {
        access |= Opcodes.ACC_FINAL;
    }

    if (set.contains(SUPER)) {
        access |= Opcodes.ACC_SUPER;
    }

    if (set.contains(INTERFACE)) {
        access |= Opcodes.ACC_INTERFACE;
    }

    if (set.contains(ABSTRACT)) {
        access |= Opcodes.ACC_ABSTRACT;
    }

    if (set.contains(SYNTHETIC)) {
        access |= Opcodes.ACC_SYNTHETIC;
    }

    if (set.contains(ANNOTATION)) {
        access |= Opcodes.ACC_ANNOTATION;
    }

    if (set.contains(ENUM)) {
        access |= Opcodes.ACC_ENUM;
    }

    if (set.contains(VOLATILE)) {
        access |= Opcodes.ACC_VOLATILE;
    }

    if (set.contains(TRANSIENT)) {
        access |= Opcodes.ACC_TRANSIENT;
    }

    if (set.contains(SYNCHRONIZED)) {
        access |= Opcodes.ACC_SYNCHRONIZED;
    }

    if (set.contains(BRIDGE)) {
        access |= Opcodes.ACC_BRIDGE;
    }

    if (set.contains(VARARGS)) {
        access |= Opcodes.ACC_VARARGS;
    }

    if (set.contains(NATIVE)) {
        access |= Opcodes.ACC_NATIVE;
    }

    return access;
}

From source file:graph.Modifier.java

License:Apache License

/**
 * Returns an EnumSet of the modifiers, based on the given bit field (where
 * the bit values are defined as in the class file format).
 *
 * @param access Integer bit field giving access modifiers.
 * @return       Set of modifiers.//  ww  w. j  a  v  a  2  s .c  o  m
 */
public static EnumSet<Modifier> getSet(int access) {
    EnumSet<Modifier> modifiers = EnumSet.noneOf(Modifier.class);

    if ((access & Opcodes.ACC_PUBLIC) != 0) {
        modifiers.add(Modifier.PUBLIC);
    }

    if ((access & Opcodes.ACC_PROTECTED) != 0) {
        modifiers.add(Modifier.PROTECTED);
    }

    if ((access & Opcodes.ACC_PRIVATE) != 0) {
        modifiers.add(Modifier.PRIVATE);
    }

    if ((access & Opcodes.ACC_STATIC) != 0) {
        modifiers.add(Modifier.STATIC);
    }

    if ((access & Opcodes.ACC_FINAL) != 0) {
        modifiers.add(Modifier.FINAL);
    }

    if ((access & Opcodes.ACC_SUPER) != 0) {
        modifiers.add(Modifier.SUPER);
    }

    if ((access & Opcodes.ACC_INTERFACE) != 0) {
        modifiers.add(Modifier.INTERFACE);
    }

    if ((access & Opcodes.ACC_ABSTRACT) != 0) {
        modifiers.add(Modifier.ABSTRACT);
    }

    if ((access & Opcodes.ACC_SYNTHETIC) != 0) {
        modifiers.add(Modifier.SYNTHETIC);
    }

    if ((access & Opcodes.ACC_ANNOTATION) != 0) {
        modifiers.add(Modifier.ANNOTATION);
    }

    if ((access & Opcodes.ACC_ENUM) != 0) {
        modifiers.add(Modifier.ENUM);
    }

    if ((access & Opcodes.ACC_VOLATILE) != 0) {
        modifiers.add(Modifier.VOLATILE);
    }

    if ((access & Opcodes.ACC_TRANSIENT) != 0) {
        modifiers.add(Modifier.TRANSIENT);
    }

    if ((access & Opcodes.ACC_SYNCHRONIZED) != 0) {
        modifiers.add(Modifier.SYNCHRONIZED);
    }

    if ((access & Opcodes.ACC_BRIDGE) != 0) {
        modifiers.add(Modifier.BRIDGE);
    }

    if ((access & Opcodes.ACC_VARARGS) != 0) {
        modifiers.add(Modifier.VARARGS);
    }

    if ((access & Opcodes.ACC_NATIVE) != 0) {
        modifiers.add(Modifier.NATIVE);
    }

    if ((access & Opcodes.ACC_STRICT) != 0) {
        modifiers.add(Modifier.STRICT);
    }

    return modifiers;
}

From source file:io.awacs.plugin.stacktrace.FilteredClassTransformer.java

License:Apache License

/**
 * //from  www . j av a 2s  .c o  m
 * (!?)&&(!)&&(!)&&(!?)&&(!?)&&(!main)
 */
@Override
protected boolean filterMethod(ClassNode cn, MethodNode mn) {
    return ((cn.access & Opcodes.ACC_INTERFACE) != Opcodes.ACC_INTERFACE
            && (cn.access & Opcodes.ACC_ABSTRACT) != Opcodes.ACC_ABSTRACT
            && (mn.access & Opcodes.ACC_NATIVE) != Opcodes.ACC_NATIVE
            && (mn.access & Opcodes.ACC_ABSTRACT) != Opcodes.ACC_ABSTRACT && !isConstructor(mn)
            && !isMainMethod(mn));
}

From source file:jaspex.speculation.newspec.ClassHierarchy.java

License:Open Source License

public static boolean isInterface(Type type) {
    if (type.isArray())
        return false;
    return (getTypeInfo(type)._access & Opcodes.ACC_INTERFACE) != 0;
}

From source file:jp.co.dgic.testing.common.virtualmock.asm.AsmClassChecker.java

License:Open Source License

public void visit(int version, int access, String name, String signature, String superName,
        String[] interfaces) {/*  ww w  .  jav a 2 s  . co  m*/
    _className = name.replace('/', '.');
    _superClassName = superName;
    _interfaces = interfaces;

    isInterface = (access & Opcodes.ACC_INTERFACE) > 0;
    isAnnotation = (access & Opcodes.ACC_ANNOTATION) > 0;
    isEnum = (access & Opcodes.ACC_ENUM) > 0;

    if (isInterface && interfaces != null && interfaces.length > 0) {
        _superClassName = interfaces[0];
    }
    if (_superClassName != null) {
        _superClassName = _superClassName.replace('/', '.');
    }

    InternalMockObjectManager.printConsole(
            "[AsmClassChecker] " + _className + ".class is " + (isInterface ? "<INTERFACE>" : "<CLASS>"));

    collectSuperClassInfo();
}

From source file:kilim.analysis.ClassFlow.java

License:Open Source License

boolean isInterface() {
    return (this.access & Opcodes.ACC_INTERFACE) != 0;
}

From source file:net.sf.cglib.proxy.TestEnhancer.java

License:Apache License

public void testBridgeParameterCheckcast() throws Exception {

    // If the compiler used for Z omits the bridge method, and X is compiled with javac,
    // javac will generate an invokespecial bridge in X.

    // public interface I<A, B> {
    //   public A f(B b);
    // }//from w  w  w .  ja  va  2  s .  c om
    // public abstract class Z<U extends Number> implements I<U, Long> {
    //   public U f(Long id) {
    //     return null;
    //   }
    // }
    // public class X extends Z<Integer> {}

    final Map<String, byte[]> classes = new HashMap<String, byte[]>();

    {
        ClassWriter cw = new ClassWriter(0);
        cw.visit(49, Opcodes.ACC_PUBLIC | Opcodes.ACC_ABSTRACT | Opcodes.ACC_INTERFACE, "I",
                "<A:Ljava/lang/Object;B:Ljava/lang/Object;>Ljava/lang/Object;", "java/lang/Object", null);
        {
            MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_ABSTRACT, "f",
                    "(Ljava/lang/Object;)Ljava/lang/Object;", "(TB;)TA;", null);
            mv.visitEnd();
        }
        cw.visitEnd();
        classes.put("I.class", cw.toByteArray());
    }
    {
        ClassWriter cw = new ClassWriter(0);
        cw.visit(49, Opcodes.ACC_PUBLIC | Opcodes.ACC_SUPER | Opcodes.ACC_ABSTRACT, "Z",
                "<U:Ljava/lang/Number;>Ljava/lang/Object;LI<TU;Ljava/lang/String;>;", "java/lang/Object",
                new String[] { "I" });
        {
            MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "<init>", "()V", null, null);
            mv.visitCode();
            mv.visitVarInsn(Opcodes.ALOAD, 0);
            mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false);
            mv.visitInsn(Opcodes.RETURN);
            mv.visitMaxs(1, 1);
            mv.visitEnd();
        }
        {
            MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "f", "(Ljava/lang/String;)Ljava/lang/Number;",
                    "(Ljava/lang/String;)TU;", null);
            mv.visitCode();
            mv.visitInsn(Opcodes.ACONST_NULL);
            mv.visitInsn(Opcodes.ARETURN);
            mv.visitMaxs(1, 2);
            mv.visitEnd();
        }
        cw.visitEnd();
        classes.put("Z.class", cw.toByteArray());
    }
    {
        ClassWriter cw = new ClassWriter(0);
        cw.visit(49, Opcodes.ACC_PUBLIC | Opcodes.ACC_SUPER, "X", "LZ<Ljava/lang/Integer;>;", "Z", null);
        {
            MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "<init>", "()V", null, null);
            mv.visitCode();
            mv.visitVarInsn(Opcodes.ALOAD, 0);
            mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "Z", "<init>", "()V", false);
            mv.visitInsn(Opcodes.RETURN);
            mv.visitMaxs(1, 1);
            mv.visitEnd();
        }
        {
            MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_BRIDGE | Opcodes.ACC_SYNTHETIC,
                    "f", "(Ljava/lang/Object;)Ljava/lang/Object;", null, null);
            mv.visitCode();
            mv.visitVarInsn(Opcodes.ALOAD, 0);
            mv.visitVarInsn(Opcodes.ALOAD, 1);
            mv.visitTypeInsn(Opcodes.CHECKCAST, "java/lang/String");
            mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "Z", "f", "(Ljava/lang/String;)Ljava/lang/Number;",
                    false);
            mv.visitInsn(Opcodes.ARETURN);
            mv.visitMaxs(2, 2);
            mv.visitEnd();
        }

        cw.visitEnd();

        classes.put("X.class", cw.toByteArray());
    }

    ClassLoader classLoader = new ClassLoader(getClass().getClassLoader()) {
        @Override
        public InputStream getResourceAsStream(String name) {
            InputStream is = super.getResourceAsStream(name);
            if (is != null) {
                return is;
            }
            if (classes.containsKey(name)) {
                return new ByteArrayInputStream(classes.get(name));
            }
            return null;
        }

        public Class findClass(String name) throws ClassNotFoundException {
            byte[] ba = classes.get(name.replace('.', '/') + ".class");
            if (ba != null) {
                return defineClass(name, ba, 0, ba.length);
            }
            throw new ClassNotFoundException(name);
        }
    };

    List<Class> retTypes = new ArrayList<Class>();
    List<Class> paramTypes = new ArrayList<Class>();
    Interceptor interceptor = new Interceptor(retTypes, paramTypes);

    Enhancer e = new Enhancer();
    e.setClassLoader(classLoader);
    e.setSuperclass(classLoader.loadClass("X"));
    e.setCallback(interceptor);

    Object c = e.create();

    for (Method m : c.getClass().getDeclaredMethods()) {
        if (m.getName().equals("f") && m.getReturnType().equals(Object.class)) {
            m.invoke(c, new Object[] { null });
        }
    }

    // f(Object)Object should bridge to f(Number)String
    assertEquals(Arrays.asList(Object.class, Number.class), retTypes);
    assertEquals(Arrays.asList(Object.class, String.class), paramTypes);
}

From source file:net.sf.clirr.core.internal.asm.AsmJavaType.java

License:Open Source License

public boolean isInterface() {
    return checkFlag(Opcodes.ACC_INTERFACE);
}