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:com.googlecode.ddom.weaver.mixin.MixinInfoBuilder.java

License:Apache License

@Override
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
    if (name.equals("<init>")) {
        if (desc.equals("()V")) {
            initMethod = new MethodNode(Opcodes.ACC_PRIVATE, "init$$" + mixinName.replace('/', '$'), desc,
                    signature, exceptions);
            return new ConstructorToMethodConverter(initMethod);
        } else {//ww  w .  ja v  a 2s.co  m
            log.warn("Encountered non default constructor");
            return null;
        }
    } else {
        if ((access & Opcodes.ACC_ABSTRACT) != 0) {
            errorHandler.handleError("Mixin " + mixinName + " declares an abstract method " + name + desc
                    + ". This is disallowed; use an interface instead.");
        }
        MethodNode method = new MethodNode(access, name, desc, signature, exceptions);
        methods.add(method);
        return method;
    }
}

From source file:com.googlecode.dex2jar.ir.ToStringUtil.java

License:Apache License

public static String getAccDes(int acc) {
    StringBuilder sb = new StringBuilder();
    if ((acc & Opcodes.ACC_PUBLIC) != 0) {
        sb.append("public ");
    }//from w  w  w.j  a va2  s .c  o m
    if ((acc & Opcodes.ACC_PROTECTED) != 0) {
        sb.append("protected ");
    }
    if ((acc & Opcodes.ACC_PRIVATE) != 0) {
        sb.append("private ");
    }
    if ((acc & Opcodes.ACC_STATIC) != 0) {
        sb.append("static ");
    }
    if ((acc & Opcodes.ACC_ABSTRACT) != 0 && (acc & Opcodes.ACC_INTERFACE) == 0) {
        sb.append("abstract ");
    }
    if ((acc & Opcodes.ACC_ANNOTATION) != 0) {
        sb.append("annotation ");
    }
    if ((acc & Opcodes.ACC_BRIDGE) != 0) {
        sb.append("bridge ");
    }
    if ((acc & Opcodes.ACC_DEPRECATED) != 0) {
        sb.append("deprecated ");
    }
    if ((acc & Opcodes.ACC_ENUM) != 0) {
        sb.append("enum ");
    }
    if ((acc & Opcodes.ACC_FINAL) != 0) {
        sb.append("final ");
    }
    if ((acc & Opcodes.ACC_INTERFACE) != 0) {
        sb.append("interace ");
    }
    if ((acc & Opcodes.ACC_NATIVE) != 0) {
        sb.append("native ");
    }
    if ((acc & Opcodes.ACC_STRICT) != 0) {
        sb.append("strict ");
    }
    if ((acc & Opcodes.ACC_SYNCHRONIZED) != 0) {
        sb.append("synchronized ");
    }
    if ((acc & Opcodes.ACC_TRANSIENT) != 0) {
        sb.append("transient ");
    }
    if ((acc & Opcodes.ACC_VARARGS) != 0) {
        sb.append("varargs ");
    }
    if ((acc & Opcodes.ACC_VOLATILE) != 0) {
        sb.append("volatile ");
    }
    return sb.toString();
}

From source file:com.googlecode.dex2jar.tools.JarAccessCmd.java

License:Apache License

static int str2acc(String s) {
    if (s == null) {
        return 0;
    }/*from   ww w .ja v a 2s . c  o  m*/
    int result = 0;
    s = s.toLowerCase();
    if (s.contains("public")) {
        result |= Opcodes.ACC_PUBLIC;
    }
    if (s.contains("private")) {
        result |= Opcodes.ACC_PRIVATE;
    }
    if (s.contains("protected")) {
        result |= Opcodes.ACC_PROTECTED;
    }
    if (s.contains("final")) {
        result |= Opcodes.ACC_FINAL;
    }
    if (s.contains("static")) {
        result |= Opcodes.ACC_STATIC;
    }
    if (s.contains("super")) {
        result |= Opcodes.ACC_SUPER;
    }
    if (s.contains("synchronized")) {
        result |= Opcodes.ACC_SYNCHRONIZED;
    }
    if (s.contains("volatile")) {
        result |= Opcodes.ACC_VOLATILE;
    }
    if (s.contains("bridge")) {
        result |= Opcodes.ACC_BRIDGE;
    }
    if (s.contains("transient")) {
        result |= Opcodes.ACC_TRANSIENT;
    }
    if (s.contains("varargs")) {
        result |= Opcodes.ACC_VARARGS;
    }
    if (s.contains("native")) {
        result |= Opcodes.ACC_NATIVE;
    }
    if (s.contains("strict")) {
        result |= Opcodes.ACC_STRICT;
    }
    if (s.contains("interface")) {
        result |= Opcodes.ACC_INTERFACE;
    }
    if (s.contains("abstract")) {
        result |= Opcodes.ACC_ABSTRACT;
    }
    if (s.contains("synthetic")) {
        result |= Opcodes.ACC_SYNTHETIC;
    }
    if (s.contains("annotation")) {
        result |= Opcodes.ACC_ANNOTATION;
    }
    if (s.contains("enum")) {
        result |= Opcodes.ACC_ENUM;
    }
    if (s.contains("deprecated")) {
        result |= Opcodes.ACC_DEPRECATED;
    }
    return result;
}

From source file:com.googlecode.japi.checker.model.JavaItem.java

License:Apache License

protected JavaItem(ClassDataLoader loader, ClassData owner, int access, String name) {
    this.setOwner(owner);
    this.setName(name);
    this.setVisibility(toScope(access));
    this.setAbstract((access & Opcodes.ACC_ABSTRACT) == Opcodes.ACC_ABSTRACT);
    this.setInterface((access & Opcodes.ACC_INTERFACE) == Opcodes.ACC_INTERFACE);
    this.setFinal((access & Opcodes.ACC_FINAL) == Opcodes.ACC_FINAL);
    this.setStatic((access & Opcodes.ACC_STATIC) == Opcodes.ACC_STATIC);
    this.setTransient((access & Opcodes.ACC_TRANSIENT) == Opcodes.ACC_TRANSIENT);
    this.setVariableArity((access & Opcodes.ACC_VARARGS) == Opcodes.ACC_VARARGS);
    this.setClassDataLoader(loader);
}

From source file:com.igormaznitsa.jute.TestClassProcessor.java

License:Apache License

@Override
public MethodVisitor visitMethod(final int access, final String name, final String desc, final String signature,
        final String[] exceptions) {
    if (this.inappropriateClass) {
        return null;
    }//from   w ww.  jav  a2s.  co  m

    if (((access & (Opcodes.ACC_ABSTRACT | Opcodes.ACC_NATIVE | Opcodes.ACC_STATIC)) != 0)
            || !desc.equals("()V") || name.startsWith("<")) {
        return null;
    }
    final boolean foundInExcludedList = isTestIncluded(desc);
    final boolean testExcluded = isTestExcluded(desc);

    final String logTestName = this.className + '#' + name;

    if (!foundInExcludedList) {
        this.logger.info("Test method " + logTestName + " is ignored because not presented in include list");
        return null;
    }

    if (testExcluded) {
        this.logger.info("Test " + logTestName + " is ignored because presented in exclude list");
        return null;
    }

    return new MethodVisitor(Opcodes.ASM5) {
        private boolean junitTest;
        private boolean juteTest;
        private boolean junitIgnore;
        private TestContainer detectedMethod;

        @Override
        public AnnotationVisitor visitAnnotation(final String desc, final boolean visible) {
            if (detectedMethod == null) {
                detectedMethod = new TestContainer(classFilePath, className, name,
                        clazzJuteTestParameters == null ? baseParameters : clazzJuteTestParameters, null);
            }

            AnnotationVisitor result = null;
            if (desc.equals(JuteMojo.ANNO_TEST)) {
                this.junitTest = true;
            } else if (desc.equals(JuteMojo.ANNO_IGNORE)) {
                this.junitIgnore = true;
            } else if (desc.equals(JuteMojo.ANNO_JUTE)) {
                this.juteTest = true;
                result = detectedMethod;
            }
            return result;
        }

        @Override
        public void visitEnd() {
            if (this.detectedMethod == null) {
                this.detectedMethod = new TestContainer(classFilePath, className, name,
                        clazzJuteTestParameters == null ? baseParameters : clazzJuteTestParameters, null);
            }
            this.juteTest = this.juteTest || clazzJuteTestParameters != null;

            this.detectedMethod.setJUnitIgnore(this.junitIgnore);
            this.detectedMethod.setJUnitTest(this.junitTest);
            this.detectedMethod.setJuteTest(this.juteTest);

            if ((this.junitTest || this.juteTest)
                    && Utils.checkClassAndMethodForPattern(juteTestParameter,
                            this.detectedMethod.getClassName(), this.detectedMethod.getMethodName(), false)
                    && isTestCanBeListed(this.detectedMethod)) {
                detectedTestMethodList.add(detectedMethod);
            }
        }
    };
}

From source file:com.igormaznitsa.jute.TestClassProcessor.java

License:Apache License

@Override
public void visit(final int version, final int access, final String name, final String signature,
        final String superName, final String[] interfaces) {
    this.className = name.replace('/', '.');
    this.inappropriateClass = (access
            & (Opcodes.ACC_INTERFACE | Opcodes.ACC_ABSTRACT | Opcodes.ACC_ANNOTATION | Opcodes.ACC_ENUM)) != 0;
}

From source file:com.liferay.portal.nio.intraband.proxy.IntrabandProxyUtil.java

License:Open Source License

protected static Class<? extends IntrabandProxySkeleton> generateSkeletonClass(ClassLoader classLoader,
        Class<?> clazz) {/*from  ww w .  j  a v a2  s  .  c o m*/

    Type targetType = Type.getType(clazz);

    String internalName = targetType.getInternalName();

    ClassNode classNode = ASMUtil.loadAndRename(TemplateSkeleton.class, internalName.concat(SKELETON_POSTFIX));

    classNode.access &= ~Opcodes.ACC_ABSTRACT;
    classNode.access |= Opcodes.ACC_PUBLIC;

    FieldNode proxyMethodsMappingFieldNode = ASMUtil.findFieldNode(classNode.fields, "_PROXY_METHODS_MAPPING");

    proxyMethodsMappingFieldNode.access |= Opcodes.ACC_FINAL;

    FieldNode targetLocatorFieldNode = ASMUtil.findFieldNode(classNode.fields, "_targetLocator");

    targetLocatorFieldNode.access |= Opcodes.ACC_FINAL;

    MethodNode doDispatchMethodNode = ASMUtil.findMethodNode(classNode.methods, "doDispatch", Type.VOID_TYPE,
            _REGISTRATION_REFERENCE_TYPE, _DATAGRAM_TYPE, _DESERIALIZER_TYPE);

    doDispatchMethodNode.access &= ~Opcodes.ACC_ABSTRACT;

    MethodNodeGenerator methodNodeGenerator = new MethodNodeGenerator(doDispatchMethodNode);

    // T target = (T)_targetLocator.getTarget()

    methodNodeGenerator.loadThis();

    methodNodeGenerator.getField(Type.getObjectType(classNode.name), "_targetLocator", _TARGET_LOCATOR_TYPE);

    methodNodeGenerator.loadArg(2);

    deserializerRead(methodNodeGenerator, _STRING_TYPE);

    methodNodeGenerator.invokeInterface(_TARGET_LOCATOR_TYPE.getInternalName(), "getTarget", _OBJECT_TYPE,
            _STRING_TYPE);

    methodNodeGenerator.checkCast(targetType);

    int typedTargetIndex = methodNodeGenerator.newLocal(targetType);

    methodNodeGenerator.storeLocal(typedTargetIndex);

    // int index = deserializer.readInt();

    methodNodeGenerator.loadArg(2);

    deserializerRead(methodNodeGenerator, Type.INT_TYPE);

    methodNodeGenerator.dup();

    int indexIndex = methodNodeGenerator.newLocal(Type.INT_TYPE);

    methodNodeGenerator.storeLocal(indexIndex);

    // switch (index)

    MethodsBag methodsBag = extractMethods(clazz);

    List<Method> proxyMethods = methodsBag.proxyMethods;

    int[] keys = new int[proxyMethods.size()];

    for (int i = 0; i < keys.length; i++) {
        keys[i] = i;
    }

    methodNodeGenerator.tableSwitch(keys, new SkeletonDispatchTableSwitchGenerator(methodNodeGenerator,
            proxyMethods, classNode.name, typedTargetIndex, indexIndex), true);

    methodNodeGenerator.returnValue();

    methodNodeGenerator.endMethod();

    rewriteGetProxyMethodSignaturesMethodNode(classNode, methodsBag.proxyMethodSignatures);

    return (Class<? extends IntrabandProxySkeleton>) toClass(classNode, classLoader);
}

From source file:com.liferay.portal.nio.intraband.proxy.IntrabandProxyUtil.java

License:Open Source License

protected static Class<?> generateStubClass(ClassLoader classLoader, Class<?> clazz, String skeletonId) {

    String internalName = Type.getInternalName(clazz);

    ClassNode classNode = ASMUtil.loadAndRename(clazz, internalName.concat(STUB_POSTFIX));

    // Class modifiers and hierarchy

    classNode.access &= ~(Opcodes.ACC_ABSTRACT | Opcodes.ACC_INTERFACE);
    classNode.access |= Opcodes.ACC_PUBLIC;

    if (clazz.isInterface()) {
        List<String> interfaces = classNode.interfaces;

        interfaces.clear();/*from   w w  w . j  a  va  2  s  .  c o  m*/

        interfaces.add(internalName);
    }

    // Clean up MethodNodes that are going to be generated

    List<MethodNode> methodNodes = classNode.methods;

    MethodNode defaultInitMethodNode = ASMUtil.removeMethodNode(methodNodes, "<init>", Type.VOID_TYPE);

    ASMUtil.removeMethodNodes(methodNodes, "<init>");
    ASMUtil.removeMethodNodes(methodNodes, Opcodes.ACC_ABSTRACT);
    ASMUtil.removeMethodNodes(methodNodes, _annotationDescriptors);

    // Apply template class

    ClassNode templateClassNode = ASMUtil.loadAndRename(TemplateStub.class, classNode.name);

    List<FieldNode> templateFieldNodes = templateClassNode.fields;

    FieldNode idFieldNode = ASMUtil.findFieldNode(templateFieldNodes, "_id");

    idFieldNode.access |= Opcodes.ACC_FINAL;

    FieldNode intrabandFieldNode = ASMUtil.findFieldNode(templateFieldNodes, "_intraband");

    intrabandFieldNode.access |= Opcodes.ACC_FINAL;

    FieldNode registrationReferenceFieldNode = ASMUtil.findFieldNode(templateFieldNodes,
            "_registrationReference");

    registrationReferenceFieldNode.access |= Opcodes.ACC_FINAL;

    ASMUtil.addFieldNodes(classNode.fields, templateFieldNodes);

    List<MethodNode> templateMethodNodes = templateClassNode.methods;

    MethodNode templateInitMethodNode = ASMUtil.findMethodNode(templateMethodNodes, "<init>", Type.VOID_TYPE,
            _STRING_TYPE, _REGISTRATION_REFERENCE_TYPE, _EXCEPTION_HANDLER_TYPE);

    if (defaultInitMethodNode != null) {
        ASMUtil.mergeMethods(templateInitMethodNode, defaultInitMethodNode, templateInitMethodNode);
    }

    MethodNode defaultClinitMethodNode = ASMUtil.removeMethodNode(methodNodes, "<clinit>", Type.VOID_TYPE);

    if (defaultClinitMethodNode != null) {
        MethodNode templateClinitMethodNode = ASMUtil.findMethodNode(templateMethodNodes, "<clinit>",
                Type.VOID_TYPE);

        ASMUtil.mergeMethods(templateClinitMethodNode, defaultClinitMethodNode, templateClinitMethodNode);
    }

    methodNodes.addAll(templateMethodNodes);

    Type stubType = Type.getType(classNode.name);

    // Id methods

    MethodsBag methodsBag = extractMethods(clazz);

    for (Method idMethod : methodsBag.idMethods) {
        MethodNodeGenerator methodNodeGenerator = new MethodNodeGenerator(idMethod);

        methodNodeGenerator.loadThis();

        methodNodeGenerator.getField(stubType, "_id", _STRING_TYPE);

        methodNodeGenerator.returnValue();

        methodNodeGenerator.endMethod();

        methodNodes.add(methodNodeGenerator.getMethodNode());
    }

    // Proxy methods

    List<Method> proxyMethods = methodsBag.proxyMethods;

    for (int i = 0; i < proxyMethods.size(); i++) {
        methodNodes.add(createProxyMethodNode(proxyMethods.get(i), i, skeletonId, stubType));
    }

    // Empty methods

    for (Method emptyMethod : methodsBag.emptyMethods) {
        MethodNodeGenerator methodNodeGenerator = new MethodNodeGenerator(emptyMethod);

        ASMUtil.addDefaultReturnInsns(methodNodeGenerator, Type.getType(emptyMethod.getReturnType()));

        methodNodeGenerator.endMethod();

        methodNodes.add(methodNodeGenerator.getMethodNode());
    }

    rewriteGetProxyMethodSignaturesMethodNode(classNode, methodsBag.proxyMethodSignatures);

    return toClass(classNode, classLoader);
}

From source file:com.masetta.spann.metadata.reader.asm3_2.ClassModifierImpl.java

License:Apache License

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

From source file:com.masetta.spann.metadata.reader.asm3_2.MethodModifierImpl.java

License:Apache License

/**
 * <p>isAbstract</p>
 *
 * @return a boolean.
 */
public boolean isAbstract() {
    return (modifier & Opcodes.ACC_ABSTRACT) != 0;
}