Example usage for org.objectweb.asm Opcodes ACC_STATIC

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

Introduction

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

Prototype

int ACC_STATIC

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

Click Source Link

Usage

From source file:com.googlecode.ddom.weaver.ext.ModelExtensionFactoryImplementation.java

License:Apache License

public void accept(ClassVisitor classVisitor) {
    // Note: the name chosen here must match what is expected in ExtensionFactoryLocator
    String name = Util.classNameToInternalName(implementationInfo.getFactoryInterface().getName() + "$$Impl");
    String factoryInterfaceName = Util
            .classNameToInternalName(implementationInfo.getFactoryInterface().getName());
    classVisitor.visit(Opcodes.V1_5, Opcodes.ACC_PUBLIC, name, null, "java/lang/Object",
            new String[] { factoryInterfaceName });
    {//from   w  w w.j av  a 2s .c om
        FieldVisitor fw = classVisitor.visitField(Opcodes.ACC_PUBLIC | Opcodes.ACC_FINAL | Opcodes.ACC_STATIC,
                "INSTANCE", "L" + factoryInterfaceName + ";", null, null);
        if (fw != null) {
            fw.visitEnd();
        }
    }
    {
        FieldVisitor fw = classVisitor.visitField(Opcodes.ACC_PRIVATE | Opcodes.ACC_FINAL, "delegates",
                "Ljava/util/Map;", null, null);
        if (fw != null) {
            fw.visitEnd();
        }
    }
    {
        MethodVisitor mv = classVisitor.visitMethod(Opcodes.ACC_PRIVATE, "<init>", "()V", null, null);
        if (mv != null) {
            mv.visitCode();
            Label l0 = new Label();
            mv.visitLabel(l0);
            // Call constructor from superclass
            mv.visitVarInsn(Opcodes.ALOAD, 0);
            mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/Object", "<init>", "()V");
            // Create delegates map
            mv.visitVarInsn(Opcodes.ALOAD, 0);
            mv.visitTypeInsn(Opcodes.NEW, "java/util/HashMap");
            mv.visitInsn(Opcodes.DUP);
            mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/util/HashMap", "<init>", "()V");
            mv.visitFieldInsn(Opcodes.PUTFIELD, name, "delegates", "Ljava/util/Map;");
            // Populate delegates map
            for (ModelExtensionInfo modelExtensionInfo : implementationInfo.getModelExtensions()) {
                for (ModelExtensionInterfaceInfo extensionInterface : modelExtensionInfo
                        .getExtensionInterfaces()) {
                    if (!extensionInterface.isAbstract()) {
                        // TODO: this is stupid; we should not recreate the info object here
                        ModelExtensionClassInfo modelExtensionClassInfo = new ModelExtensionClassInfo(
                                implementationInfo.getImplementation(), modelExtensionInfo.getRootInterface(),
                                extensionInterface);
                        String factoryDelegateImplName = Util.classNameToInternalName(
                                modelExtensionClassInfo.getFactoryDelegateImplementationClassName());
                        mv.visitVarInsn(Opcodes.ALOAD, 0);
                        mv.visitFieldInsn(Opcodes.GETFIELD, name, "delegates", "Ljava/util/Map;");
                        mv.visitLdcInsn(Type.getObjectType(Util.classNameToInternalName(
                                modelExtensionClassInfo.getExtensionInterface().getClassInfo().getName())));
                        mv.visitTypeInsn(Opcodes.NEW, factoryDelegateImplName);
                        mv.visitInsn(Opcodes.DUP);
                        mv.visitMethodInsn(Opcodes.INVOKESPECIAL, factoryDelegateImplName, "<init>", "()V");
                        mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/Map", "put",
                                "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;");
                        mv.visitInsn(Opcodes.POP);
                    }
                }
            }
            mv.visitInsn(Opcodes.RETURN);
            Label l1 = new Label();
            mv.visitLabel(l1);
            mv.visitLocalVariable("this", "L" + name + ";", null, l0, l1, 0);
            mv.visitMaxs(4, 1);
            mv.visitEnd();
        }
    }
    String factoryDelegateInterfaceName = Util
            .classNameToInternalName(implementationInfo.getFactoryDelegateInterfaceName());
    String getDelegateDesc = "(Ljava/lang/Class;)L" + factoryDelegateInterfaceName + ";";
    {
        MethodVisitor mv = classVisitor.visitMethod(Opcodes.ACC_PRIVATE, "getDelegate", getDelegateDesc, null,
                null);
        if (mv != null) {
            mv.visitCode();
            Label l0 = new Label();
            mv.visitLabel(l0);
            mv.visitVarInsn(Opcodes.ALOAD, 0);
            mv.visitFieldInsn(Opcodes.GETFIELD, name, "delegates", "Ljava/util/Map;");
            mv.visitVarInsn(Opcodes.ALOAD, 1);
            mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/Map", "get",
                    "(Ljava/lang/Object;)Ljava/lang/Object;");
            mv.visitTypeInsn(Opcodes.CHECKCAST, factoryDelegateInterfaceName);
            mv.visitInsn(Opcodes.ARETURN);
            Label l1 = new Label();
            mv.visitLabel(l1);
            mv.visitLocalVariable("this", "L" + name + ";", null, l0, l1, 0);
            mv.visitLocalVariable("extensionInterface", "Ljava/lang/Class;", null, l0, l1, 1);
            mv.visitMaxs(2, 2);
            mv.visitEnd();
        }
    }
    String implementationName = Util.classNameToInternalName(implementationInfo.getImplementation().getName());
    for (ConstructorInfo constructor : implementationInfo.getConstructors()) {
        Type[] constructorArgumentTypes = constructor.getArgumentTypes();
        Type[] argumentTypes = new Type[constructorArgumentTypes.length + 1];
        argumentTypes[0] = Type.getObjectType("java/lang/Class");
        System.arraycopy(constructorArgumentTypes, 0, argumentTypes, 1, constructorArgumentTypes.length);
        MethodVisitor mv = classVisitor.visitMethod(Opcodes.ACC_PUBLIC, "create",
                Type.getMethodDescriptor(Type.getObjectType(implementationName), argumentTypes), null, null);
        if (mv != null) {
            mv.visitCode();
            Label l0 = new Label();
            mv.visitLabel(l0);
            mv.visitVarInsn(Opcodes.ALOAD, 1);
            Label l1 = new Label();
            mv.visitJumpInsn(Opcodes.IFNONNULL, l1);
            mv.visitTypeInsn(Opcodes.NEW, implementationName);
            mv.visitInsn(Opcodes.DUP);
            for (int i = 0; i < constructorArgumentTypes.length; i++) {
                mv.visitVarInsn(constructorArgumentTypes[i].getOpcode(Opcodes.ILOAD), i + 2);
            }
            mv.visitMethodInsn(Opcodes.INVOKESPECIAL, implementationName, "<init>",
                    constructor.getDescriptor());
            mv.visitInsn(Opcodes.ARETURN);
            mv.visitLabel(l1);
            mv.visitVarInsn(Opcodes.ALOAD, 0);
            mv.visitVarInsn(Opcodes.ALOAD, 1);
            mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, name, "getDelegate", getDelegateDesc);
            for (int i = 0; i < constructorArgumentTypes.length; i++) {
                mv.visitVarInsn(constructorArgumentTypes[i].getOpcode(Opcodes.ILOAD), i + 2);
            }
            mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, factoryDelegateInterfaceName, "create",
                    constructor.getFactoryDelegateMethodDescriptor());
            mv.visitInsn(Opcodes.ARETURN);
            Label l3 = new Label();
            mv.visitLabel(l3);
            mv.visitLocalVariable("this", "L" + name + ";", null, l0, l3, 0);
            mv.visitLocalVariable("extensionInterface", "Ljava/lang/Class;", null, l0, l3, 1);
            for (int i = 0; i < constructorArgumentTypes.length; i++) {
                mv.visitLocalVariable("arg" + i, constructorArgumentTypes[i].getDescriptor(), null, l0, l3,
                        i + 2);
            }
            mv.visitMaxs(argumentTypes.length + 1, argumentTypes.length + 1);
            mv.visitEnd();
        }
    }
    {
        MethodVisitor mv = classVisitor.visitMethod(Opcodes.ACC_STATIC, "<clinit>", "()V", null, null);
        if (mv != null) {
            mv.visitCode();
            mv.visitTypeInsn(Opcodes.NEW, name);
            mv.visitInsn(Opcodes.DUP);
            mv.visitMethodInsn(Opcodes.INVOKESPECIAL, name, "<init>", "()V");
            mv.visitFieldInsn(Opcodes.PUTSTATIC, name, "INSTANCE", "L" + factoryInterfaceName + ";");
            mv.visitInsn(Opcodes.RETURN);
            mv.visitMaxs(2, 0);
            mv.visitEnd();
        }
    }
    classVisitor.visitEnd();
}

From source file:com.googlecode.ddom.weaver.inject.InjectionAdapter.java

License:Apache License

@Override
public void visitEnd() {
    for (InjectableFieldInfo fieldInfo : injectionInfo.getInjectableFields()) {
        MethodVisitor mv = cv.visitMethod(Opcodes.ACC_PRIVATE | Opcodes.ACC_STATIC,
                fieldInfo.getFactoryMethodName(), fieldInfo.getFactoryMethodDesc(), null, new String[0]);
        if (mv != null) {
            fieldInfo.getInjector().generateFactoryMethodCode(mv);
        }//from  w w  w . j  a v a  2  s.c o  m
    }
    if (injectionInfo.hasInjectableInstanceFields()) {
        MethodVisitor mv = cv.visitMethod(Opcodes.ACC_PRIVATE, "inject$$instance", "()V", null, new String[0]);
        if (mv != null) {
            mv.visitCode();
            Label l0 = new Label();
            mv.visitLabel(l0);
            for (InjectableFieldInfo fieldInfo : injectionInfo.getInjectableFields()) {
                if (!fieldInfo.isStatic()) {
                    mv.visitVarInsn(Opcodes.ALOAD, 0);
                    mv.visitMethodInsn(Opcodes.INVOKESTATIC, className, fieldInfo.getFactoryMethodName(),
                            fieldInfo.getFactoryMethodDesc());
                    mv.visitFieldInsn(Opcodes.PUTFIELD, className, fieldInfo.getFieldName(),
                            fieldInfo.getFieldDesc());
                }
            }
            mv.visitInsn(Opcodes.RETURN);
            Label l1 = new Label();
            mv.visitLabel(l1);
            mv.visitLocalVariable("this", "L" + className + ";", null, l0, l1, 0);
            mv.visitMaxs(2, 1);
            mv.visitEnd();
        }
    }
    if (injectionInfo.hasInjectableClassFields()) {
        MethodVisitor mv = cv.visitMethod(Opcodes.ACC_PRIVATE | Opcodes.ACC_STATIC,
                hasClassInitializer ? "inject$$class" : "<clinit>", "()V", null, new String[0]);
        if (mv != null) {
            mv.visitCode();
            for (InjectableFieldInfo fieldInfo : injectionInfo.getInjectableFields()) {
                if (fieldInfo.isStatic()) {
                    mv.visitMethodInsn(Opcodes.INVOKESTATIC, className, fieldInfo.getFactoryMethodName(),
                            fieldInfo.getFactoryMethodDesc());
                    mv.visitFieldInsn(Opcodes.PUTSTATIC, className, fieldInfo.getFieldName(),
                            fieldInfo.getFieldDesc());
                }
            }
            mv.visitInsn(Opcodes.RETURN);
            mv.visitMaxs(1, 0);
            mv.visitEnd();
        }
    }
    super.visitEnd();
}

From source file:com.googlecode.ddom.weaver.inject.InjectionInfoBuilder.java

License:Apache License

@Override
public FieldVisitor visitField(final int access, final String fieldName, final String fieldDesc,
        String signature, Object value) {
    return new AbstractFieldVisitor() {
        public AnnotationVisitor visitAnnotation(String desc, boolean visible) {
            if (desc.equals("Lcom/googlecode/ddom/backend/Inject;")) {
                String fieldType = Type.getType(fieldDesc).getClassName();
                if (!bindings.containsKey(fieldType)) {
                    throw new ReactorException("Don't know how to inject a field with type " + fieldType);
                }//from  ww w . j a  v  a  2 s.c  o  m
                Injector injector = bindings.get(fieldType);
                // A null value means ignoring the @Inject annotation and inject nothing
                if (injector != null) {
                    if (fieldInfos == null) {
                        fieldInfos = new ArrayList<InjectableFieldInfo>();
                    }
                    fieldInfos.add(new InjectableFieldInfo((access & Opcodes.ACC_STATIC) != 0, fieldName,
                            fieldDesc, injector));
                }
            }
            return null;
        }
    };
}

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 ");
    }/*ww  w  .  j a va  2s.com*/
    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 w  w w .j  a va  2s .co 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.dex2jar.v3.V3ClassAdapter.java

License:Apache License

private int clearClassAccess(boolean isInner, int access) {
    if ((access & Opcodes.ACC_INTERFACE) == 0) { // issue 55
        access |= Opcodes.ACC_SUPER;// ?classdx????
    }//from   w  w w .j a v  a2  s . c  o  m
    // access in class has no acc_static or acc_private
    access &= ~(Opcodes.ACC_STATIC | Opcodes.ACC_PRIVATE);
    if (isInner && (access & Opcodes.ACC_PROTECTED) != 0) {// protected inner class are public
        access &= ~Opcodes.ACC_PROTECTED;
        access |= Opcodes.ACC_PUBLIC;
    }
    return access;
}

From source file:com.googlecode.dex2jar.v3.V3CodeAdapter.java

License:Apache License

@Override
public void visitArguments(int total, int[] args) {
    Local[] locals = new Local[total + 1];
    this.locals = locals;
    this.tmp_reg = total;
    {/*from  www .  j ava2s  .c  o m*/
        int i = 0;
        if ((irMethod.access & Opcodes.ACC_STATIC) == 0) {
            Local _this = nLocal("this");
            list.add(nIdentity(_this, nThisRef(this.irMethod.owner)));
            locals[args[i]] = _this;
            i++;
        }
        int j = 0;
        for (; i < args.length; i++, j++) {
            Local _arg = nLocal("arg_" + args[i]);
            list.add(nIdentity(_arg, nParameterRef(this.irMethod.args[j], j)));
            locals[args[i]] = _arg;
        }
    }
    for (int i = 0; i < locals.length; i++) {
        if (locals[i] == null) {
            locals[i] = nLocal("a" + i);
        }
    }
}

From source file:com.googlecode.gwt.test.internal.rewrite.WriteJsoImpl.java

License:Apache License

/**
 * Mangle all instance methods declared in JavaScriptObject types.
 *///w  w  w.  j a va2  s .  co  m
@Override
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
    boolean isCtor = isCtor(name);
    if (!isCtor && !isStatic(access) && !isObjectMethod(name + desc)) {
        access |= Opcodes.ACC_STATIC;
        desc = OverlayTypesRewriter.addSyntheticThisParam(getOriginalName(), desc);
        name = name + "$";
    }
    return super.visitMethod(access, name, desc, signature, exceptions);
}

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;
    }// ww  w.j  a v a2 s  .  c o  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);
            }
        }
    };
}