Example usage for org.objectweb.asm Opcodes ACC_ABSTRACT

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

Introduction

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

Prototype

int ACC_ABSTRACT

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

Click Source Link

Usage

From source file:cl.inria.stiq.instrumenter.BCIUtils.java

License:Open Source License

public static boolean isAbstract(int access) {
    return (access & Opcodes.ACC_ABSTRACT) != 0;
}

From source file:Client.JClassPatcher.java

License:Open Source License

private String decodeAccess(int access) {
    String res = "";

    if ((access & Opcodes.ACC_PUBLIC) == Opcodes.ACC_PUBLIC)
        res += "public ";
    if ((access & Opcodes.ACC_PRIVATE) == Opcodes.ACC_PRIVATE)
        res += "private ";
    if ((access & Opcodes.ACC_PROTECTED) == Opcodes.ACC_PROTECTED)
        res += "protected ";

    if ((access & Opcodes.ACC_STATIC) == Opcodes.ACC_STATIC)
        res += "static ";
    if ((access & Opcodes.ACC_FINAL) == Opcodes.ACC_FINAL)
        res += "final ";
    if ((access & Opcodes.ACC_VOLATILE) == Opcodes.ACC_VOLATILE)
        res += "protected ";
    if ((access & Opcodes.ACC_SYNCHRONIZED) == Opcodes.ACC_SYNCHRONIZED)
        res += "synchronized ";
    if ((access & Opcodes.ACC_ABSTRACT) == Opcodes.ACC_ABSTRACT)
        res += "abstract ";
    if ((access & Opcodes.ACC_INTERFACE) == Opcodes.ACC_INTERFACE)
        res += "interface ";

    return res;/*from w ww  .j  a v  a2s.c o  m*/
}

From source file:co.paralleluniverse.fibers.instrument.InstrumentClass.java

License:Open Source License

private static boolean checkAccess(int access) {
    return (access & (Opcodes.ACC_ABSTRACT | Opcodes.ACC_NATIVE)) == 0;
}

From source file:com.alibaba.hotswap.processor.v.VClassGenerateVisitor.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 v a 2s.c o m*/
    HotswapThreadLocalUtil.setClassName(name);
    super.visit(version, access, name, signature, superName, interfaces);
    boolean isInterface = ((access & Opcodes.ACC_INTERFACE) == Opcodes.ACC_INTERFACE);

    if (isInterface && (access & Opcodes.ACC_ABSTRACT) == Opcodes.ACC_ABSTRACT) {
        // If it is a interface, then transformer it to class
        access = access - Opcodes.ACC_INTERFACE;
    }

    ClassMeta classMeta = HotswapRuntime.getClassMeta(className);
    classMeta.isInterface = isInterface;
    if (!classMeta.isLoaded()) {
        // First load
        for (String key : classMeta.primaryFieldKeyList) {
            classMeta.primaryFieldNodes.get(key).accept(cv);
        }
    } else {
        // Reload
        Map<String, FieldNode> loadedFieldNodes = new HashMap<String, FieldNode>();
        loadedFieldNodes.putAll(classMeta.loadedFieldNodes);

        // 1. Visit the primary fields.
        for (String key : classMeta.primaryFieldKeyList) {
            FieldNode primaryFN = classMeta.primaryFieldNodes.get(key);
            FieldNode loadedFN = loadedFieldNodes.get(key);
            if (loadedFN != null) {
                if (loadedFN.access == primaryFN.access) {
                    // Primary field(may change annotation/signature) or change from other field
                    loadedFN.accept(cv);
                    loadedFieldNodes.remove(key);
                } else {
                    primaryFN.accept(cv);
                }
            } else {
                primaryFN.accept(cv);
            }
        }

        // 2. Add and remove modified field.
        for (FieldNode fn : loadedFieldNodes.values()) {
            // All these fields are the reloaded class's fields

            String fieldKey = HotswapFieldUtil.getFieldKey(fn.name, fn.desc);
            FieldMeta fm2 = classMeta.getFieldMeta(fieldKey);

            if (fm2 == null) {
                // This is a new field
                fn.accept(cv);
            } else {
                if (classMeta.primaryFieldKeyList.contains(fieldKey)) {
                    // It's a primary field
                    if (fn.access == fm2.access) {

                    } else {
                        // Modified field, alias it
                        fn.name = HotswapConstants.PREFIX_FIELD_ALIAS + fn.name;
                        fn.accept(cv);
                    }
                } else {
                    fn.accept(cv);
                }
            }
        }
    }
}

From source file:com.android.build.gradle.internal.incremental.IncrementalSupportVisitor.java

License:Apache License

/**
 * Find a suitable parent for a method reference. The method owner is not always a valid
 * parent to dispatch to. For instance, take the following example :
 * <code>/* ww w.  j  a v  a2  s  .  co m*/
 * package a;
 * public class A {
 *     public void publicMethod();
 * }
 *
 * package a;
 * class B extends A {
 *     public void publicMethod();
 * }
 *
 * package b;
 * public class C extends B {
 *     ...
 * }
 * </code>
 * when instrumenting C, the first method reference for "publicMethod" is on class B which we
 * cannot invoke directly since it's present on a private package B which is not located in the
 * same package as C. However C can still call the "publicMethod" since it's defined on A which
 * is a public class.
 *
 * We cannot just blindly take the top most definition of "publicMethod" hoping this is the
 * accessible one since you can very well do :
 * <code>
 * package a;
 * class A {
 *     public void publicMethod();
 * }
 *
 * package a;
 * public class B extends A {
 *     public void publicMethod();
 * }
 *
 * package b;
 * public class C extends B {
 *     ...
 * }
 * </code>
 *
 * In that case, the top most parent class is the one defined the unaccessible method reference.
 *
 * Therefore, the solution is to walk up the hierarchy until we find the same method defined on
 * an accessible class, if we cannot find such a method, the suitable parent is the parent class
 * of the visited class which is legal (but might consume a DEX id).
 *
 * @param methodReference the method reference to find a suitable parent for.
 * @return the parent class name
 */
@NonNull
String findParentClassForMethod(@NonNull MethodReference methodReference) {
    logger.verbose("MethodRef %1$s access(%2$s) -> owner %3$s access(%4$s)", methodReference.method.name,
            methodReference.method.access, methodReference.owner.name, methodReference.owner.access);
    // if the method owner class is accessible from the visited class, just use that.
    if (isParentClassVisible(methodReference.owner, classNode)) {
        return methodReference.owner.name;
    }
    logger.verbose("Found an inaccessible methodReference %1$s", methodReference.method.name);
    // walk up the hierarchy, starting at the method reference owner.
    Iterator<ClassNode> parentIterator = parentNodes.iterator();
    ClassNode parent = parentIterator.next();
    while (!parent.name.equals(methodReference.owner.name) && parentIterator.hasNext()) {
        parent = parentIterator.next();
    }
    while (parentIterator.hasNext()) {
        ClassNode node = parentIterator.next();
        // check that this parent is visible, there might be several layers of package
        // private classes.
        if (isParentClassVisible(node, classNode)) {
            //noinspection unchecked: ASM API
            for (MethodNode methodNode : (List<MethodNode>) node.methods) {
                // do not reference bridge methods, they might not be translated into dex, or
                // might disappear in the next javac compiler for that use case.
                if (methodNode.name.equals(methodReference.method.name)
                        && methodNode.desc.equals(methodReference.method.desc)
                        && (methodNode.access & (Opcodes.ACC_BRIDGE | Opcodes.ACC_ABSTRACT)) == 0) {
                    logger.verbose("Using class %1$s for dispatching %2$s:%3$s", node.name,
                            methodReference.method.name, methodReference.method.desc);
                    return node.name;
                }
            }
        }
    }
    logger.verbose("Using immediate parent for dispatching %1$s", methodReference.method.desc);
    return classNode.superName;
}

From source file:com.android.build.gradle.internal.incremental.IncrementalVisitor.java

License:Apache License

/**
 * Defines when a method access flags are compatible with InstantRun technology.
 *
 * - If the method is a bridge method, we do not enable it for instantReload.
 *   it is most likely only calling a twin method (same name, same parameters).
 * - if the method is abstract or native, we don't add a redirection.
 *
 * @param access the method access flags
 * @return true if the method should be InstantRun enabled, false otherwise.
 *//*from  w w  w  .ja va  2 s. c  o  m*/
protected static boolean isAccessCompatibleWithInstantRun(int access) {
    return (access & (Opcodes.ACC_ABSTRACT | Opcodes.ACC_BRIDGE | Opcodes.ACC_NATIVE)) == 0;
}

From source file:com.android.build.gradle.internal2.incremental.IncrementalSupportVisitor.java

License:Apache License

/**
 * Find a suitable parent for a method reference. The method owner is not always a valid
 * parent to dispatch to. For instance, take the following example :
 * <code>//from   ww w .j  a  v a  2s . co  m
 * package a;
 * public class A {
 *     public void publicMethod();
 * }
 *
 * package a;
 * class B extends A {
 *     public void publicMethod();
 * }
 *
 * package b;
 * public class C extends B {
 *     ...
 * }
 * </code>
 * when instrumenting C, the first method reference for "publicMethod" is on class B which we
 * cannot invoke directly since it's present on a private package B which is not located in the
 * same package as C. However C can still call the "publicMethod" since it's defined on A which
 * is a public class.
 *
 * We cannot just blindly take the top most definition of "publicMethod" hoping this is the
 * accessible one since you can very well do :
 * <code>
 * package a;
 * class A {
 *     public void publicMethod();
 * }
 *
 * package a;
 * public class B extends A {
 *     public void publicMethod();
 * }
 *
 * package b;
 * public class C extends B {
 *     ...
 * }
 * </code>
 *
 * In that case, the top most parent class is the one defined the unaccessible method reference.
 *
 * Therefore, the solution is to walk up the hierarchy until we find the same method defined on
 * an accessible class, if we cannot find such a method, the suitable parent is the parent class
 * of the visited class which is legal (but might consume a DEX id).
 *
 * @param methodReference the method reference to find a suitable parent for.
 * @return the parent class name
 */
@NonNull
String findParentClassForMethod(@NonNull MethodReference methodReference) {
    LOG.verbose("MethodRef %1$s access(%2$d) -> owner %3$s access(%4$d)", methodReference.method.name,
            methodReference.method.access, methodReference.owner.name, methodReference.owner.access);
    // if the method owner class is accessible from the visited class, just use that.
    if (isParentClassVisible(methodReference.owner, classNode)) {
        return methodReference.owner.name;
    }
    LOG.verbose("Found an inaccessible methodReference " + methodReference.method.name);
    // walk up the hierarchy, starting at the method reference owner.
    Iterator<ClassNode> parentIterator = parentNodes.iterator();
    ClassNode parent = parentIterator.next();
    while (!parent.name.equals(methodReference.owner.name) && parentIterator.hasNext()) {
        parent = parentIterator.next();
    }
    while (parentIterator.hasNext()) {
        ClassNode node = parentIterator.next();
        // check that this parent is visible, there might be several layers of package
        // private classes.
        if (isParentClassVisible(node, classNode)) {
            for (MethodNode methodNode : (List<MethodNode>) node.methods) {
                // do not reference bridge methods, they might not be translated into dex, or
                // might disappear in the next javac compiler for that use case.
                if (methodNode.name.equals(methodReference.method.name)
                        && methodNode.desc.equals(methodReference.method.desc)
                        && (methodNode.access & (Opcodes.ACC_BRIDGE | Opcodes.ACC_ABSTRACT)) == 0) {
                    LOG.verbose("Using class %1$s for dispatching %2$s:%3$s", node.name,
                            methodReference.method.name, methodReference.method.desc);
                    return node.name;
                }
            }
        }
    }
    LOG.verbose("Using immediate parent for dispatching %1$s", methodReference.method.desc);
    return classNode.superName;
}

From source file:com.android.builder.testing.MockableJarGenerator.java

License:Apache License

/**
 * Rewrites the method bytecode to remove the "Stub!" exception.
 *///  w w  w  .j a  v a 2  s.  c  o m
private void fixMethodBody(MethodNode methodNode, ClassNode classNode) {
    if ((methodNode.access & Opcodes.ACC_NATIVE) != 0 || (methodNode.access & Opcodes.ACC_ABSTRACT) != 0) {
        // Abstract and native method don't have bodies to rewrite.
        return;
    }

    if ((classNode.access & Opcodes.ACC_ENUM) != 0 && ENUM_METHODS.contains(methodNode.name)) {
        // Don't break enum classes.
        return;
    }

    Type returnType = Type.getReturnType(methodNode.desc);
    InsnList instructions = methodNode.instructions;

    if (methodNode.name.equals(CONSTRUCTOR)) {
        // Keep the call to parent constructor, delete the exception after that.

        boolean deadCode = false;
        for (AbstractInsnNode instruction : instructions.toArray()) {
            if (!deadCode) {
                if (instruction.getOpcode() == Opcodes.INVOKESPECIAL) {
                    instructions.insert(instruction, new InsnNode(Opcodes.RETURN));
                    // Start removing all following instructions.
                    deadCode = true;
                }
            } else {
                instructions.remove(instruction);
            }
        }
    } else {
        instructions.clear();

        if (returnDefaultValues || methodNode.name.equals(CLASS_CONSTRUCTOR)) {
            if (INTEGER_LIKE_TYPES.contains(returnType)) {
                instructions.add(new InsnNode(Opcodes.ICONST_0));
            } else if (returnType.equals(Type.LONG_TYPE)) {
                instructions.add(new InsnNode(Opcodes.LCONST_0));
            } else if (returnType.equals(Type.FLOAT_TYPE)) {
                instructions.add(new InsnNode(Opcodes.FCONST_0));
            } else if (returnType.equals(Type.DOUBLE_TYPE)) {
                instructions.add(new InsnNode(Opcodes.DCONST_0));
            } else {
                instructions.add(new InsnNode(Opcodes.ACONST_NULL));
            }

            instructions.add(new InsnNode(returnType.getOpcode(Opcodes.IRETURN)));
        } else {
            instructions.insert(throwExceptionsList(methodNode, classNode));
        }
    }
}

From source file:com.android.ide.eclipse.apt.internal.analysis.StaticVirtualAnalyzer.java

License:Apache License

@Override
protected Collection<Problem> analyzeMethod(final MethodNode methodNode) {
    final Collection<Problem> problems = new LinkedList<Problem>();
    final int acc = methodNode.access;
    if ((acc & Opcodes.ACC_STATIC) == 0 && (acc & Opcodes.ACC_ABSTRACT) == 0) {
        final InsnList instructions = methodNode.instructions;
        //find if a method load this (ALOAD 0)
        boolean aload0 = false;
        for (int i = 0; i < instructions.size(); i++) {
            final AbstractInsnNode instruction = instructions.get(i);
            if (instruction.getOpcode() == Opcodes.ALOAD) {
                final VarInsnNode aload = (VarInsnNode) instruction;
                aload0 = aload.var == 0;
                if (aload0) {
                    break;
                }//  w w  w. j  ava2  s  .  c o  m
            }
        }
        if (!aload0) {
            final Problem problem = new StaticVirtualProblem(instructions.get(1));
            problems.add(problem);
        }
    }
    return problems;
}

From source file:com.android.mkstubs.sourcer.AccessSourcerTest.java

License:Apache License

@Test
public void testAbstractPublic() throws Exception {
    mSourcer.write(Opcodes.ACC_ABSTRACT | Opcodes.ACC_PUBLIC, AccessSourcer.IS_CLASS);

    String s = mWriter.toString();
    Assert.assertEquals("public abstract", s);
}