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: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.//  w  w  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:instrumentation.InstrumentationClassAdapter.java

License:Open Source License

public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
    MethodVisitor mv;// w w  w. j a  v a2 s .  com
    boolean sync = ((access & Opcodes.ACC_SYNCHRONIZED) != 0);
    boolean stat = ((access & Opcodes.ACC_STATIC) != 0);
    //boolean nat = ((access & Opcodes.ACC_NATIVE) != 0); 

    //remove sync modifier if method is not native
    if (sync && clTrans.canRemoveSyncModifier) {
        access ^= Opcodes.ACC_SYNCHRONIZED;
    }
    mv = cv.visitMethod(access, name, desc, signature, exceptions);
    if (name.equals("<init>")) {
        return mv;
    }
    if (mv != null) {
        mv = new InstrumentationMethodAdapter(mv, sync, stat);
    }

    return mv;
}

From source file:interactivespaces.workbench.project.test.JunitTestClassVisitor.java

License:Apache License

@Override
public void visitInnerClass(String name, String outerName, String innerName, int access) {
    if (name.equals(className) && (access & Opcodes.ACC_STATIC) == 0) {
        abstractClass = true;//w  w  w .j  a  va  2  s  .  com
    }
}

From source file:io.awacs.plugin.springmvc.ServiceWrapper.java

License:Apache License

private int getParamCount(String desc, int access) {
    String params = desc.substring(1, desc.indexOf(')'));
    int count = 0;
    for (int i = 0; i < params.length(); i++) {
        if (params.charAt(i) == 'L') {
            count++;//from   w ww.jav  a  2 s  .c o  m
            while (params.charAt(i) != ';')
                i++;
        } else if (params.charAt(i) != '[') {
            count++;
        }
    }
    return count + ((access & Opcodes.ACC_STATIC) == Opcodes.ACC_STATIC ? 0 : 1);
}

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

License:Apache License

protected boolean isMainMethod(MethodNode mn) {
    return mn.name.equals("main") && mn.desc.equals("([Ljava/lang/String;)V")
            && (mn.access & Opcodes.ACC_STATIC) == Opcodes.ACC_STATIC;
}

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

License:Apache License

/**
 * ?/*from   w  ww .  j av  a  2s . c  o m*/
 * 1?try catch?                 try{
 * 2????        io.awacs.plugin.stacktrace.StackFrames.init();
 * 3????                io.awacs.plugin.stacktrace.StackFrames.push(className,methodName,0);
 * 4?                          Object val = methodName_origin_className(args);
 * 5?????                io.awacs.plugin.stacktrace.StackFrames.push(className,methodName,1);
 * 5???          List list = io.awacs.plugin.stacktrace.StackFrames.dump();
 * 7?????          io.awacs.plugin.stacktrace.StackTracePlugin.incrAccess(list);
 * 8?                          return val;
 * }catch(java.lang.Exception e){
 * 9??                io.awacs.plugin.stacktrace.StackTracePlugin.incrFailure(e);
 * 10?               throw e;
 * }
 */
private void transformTerminatedMethod(MethodNode origin, MethodNode proxy, ClassNode owner) {
    LabelNode l0 = new LabelNode();
    LabelNode l1 = new LabelNode();
    LabelNode l2 = new LabelNode();
    //try catch?
    proxy.tryCatchBlocks.add(new TryCatchBlockNode(l0, l1, l2, "java/lang/Exception"));
    proxy.instructions.add(l0);
    //?
    proxy.instructions.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "io/awacs/plugin/stacktrace/StackFrames",
            "init", "()V", false));
    proxy.instructions.add(new LdcInsnNode(owner.name.replaceAll("/", ".")));
    proxy.instructions.add(new LdcInsnNode(proxy.name));
    proxy.instructions.add(new LdcInsnNode(0));
    //
    proxy.instructions.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "io/awacs/plugin/stacktrace/StackFrames",
            "push", "(Ljava/lang/String;Ljava/lang/String;I)V", false));
    int varIndex = 0;//???
    //???,????this?
    if ((proxy.access & Opcodes.ACC_STATIC) != Opcodes.ACC_STATIC) {
        proxy.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0));
        varIndex = 1;
    }
    List<String> parameters = resolveParameters(proxy.desc);
    //???
    for (String param : parameters) {
        VarInsnNode insnNode;
        switch (param) {
        case "J":
            insnNode = new VarInsnNode(Opcodes.LLOAD, varIndex);
            varIndex += 2;
            break;
        case "D":
            insnNode = new VarInsnNode(Opcodes.DLOAD, varIndex);
            varIndex += 2;
            break;
        case "F":
            insnNode = new VarInsnNode(Opcodes.FLOAD, varIndex++);
            break;
        case "I":
            insnNode = new VarInsnNode(Opcodes.ILOAD, varIndex++);
            break;
        case "S":
            insnNode = new VarInsnNode(Opcodes.ILOAD, varIndex++);
            break;
        case "Z":
            insnNode = new VarInsnNode(Opcodes.ILOAD, varIndex++);
            break;
        case "B":
            insnNode = new VarInsnNode(Opcodes.ILOAD, varIndex++);
            break;
        case "C":
            insnNode = new VarInsnNode(Opcodes.ILOAD, varIndex++);
            break;
        default:
            insnNode = new VarInsnNode(Opcodes.ALOAD, varIndex++);
            break;
        }
        proxy.instructions.add(insnNode);
    }
    //
    if ((origin.access & Opcodes.ACC_STATIC) == Opcodes.ACC_STATIC)
        proxy.instructions
                .add(new MethodInsnNode(Opcodes.INVOKESTATIC, owner.name, origin.name, origin.desc, false));
    else
        proxy.instructions
                .add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, owner.name, origin.name, origin.desc, false));
    proxy.instructions.add(new LdcInsnNode(owner.name.replaceAll("/", ".")));
    proxy.instructions.add(new LdcInsnNode(proxy.name));
    proxy.instructions.add(new LdcInsnNode(1));
    //?
    proxy.instructions.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "io/awacs/plugin/stacktrace/StackFrames",
            "push", "(Ljava/lang/String;Ljava/lang/String;I)V", false));
    //??
    proxy.instructions.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "io/awacs/plugin/stacktrace/StackFrames",
            "dump", "()Ljava/util/List;", false));
    //???
    proxy.instructions.add(new MethodInsnNode(Opcodes.INVOKESTATIC,
            "io/awacs/plugin/stacktrace/StackTracePlugin", "incrAccess", "(Ljava/util/List;)V", false));
    proxy.instructions.add(l1);
    //
    String returnType = origin.desc.substring(origin.desc.indexOf(')') + 1);
    switch (returnType) {
    case "J":
        proxy.instructions.add(new InsnNode(Opcodes.LRETURN));
        break;
    case "D":
        proxy.instructions.add(new InsnNode(Opcodes.DRETURN));
        break;
    case "F":
        proxy.instructions.add(new InsnNode(Opcodes.FRETURN));
        break;
    case "I":
        proxy.instructions.add(new InsnNode(Opcodes.IRETURN));
        break;
    case "S":
        proxy.instructions.add(new InsnNode(Opcodes.IRETURN));
        break;
    case "C":
        proxy.instructions.add(new InsnNode(Opcodes.IRETURN));
        break;
    case "B":
        proxy.instructions.add(new InsnNode(Opcodes.IRETURN));
        break;
    case "Z":
        proxy.instructions.add(new InsnNode(Opcodes.IRETURN));
        break;
    case "V":
        proxy.instructions.add(new InsnNode(Opcodes.RETURN));
        break;
    default:
        proxy.instructions.add(new InsnNode(Opcodes.ARETURN));
        break;
    }
    proxy.instructions.add(l2);
    //?
    proxy.instructions.add(new FrameNode(Opcodes.F_SAME1, 0, null, 1, new Object[] { "java/lang/Exception" }));
    proxy.instructions.add(new VarInsnNode(Opcodes.ASTORE, varIndex));
    proxy.instructions.add(new VarInsnNode(Opcodes.ALOAD, varIndex));
    proxy.instructions.add(new MethodInsnNode(Opcodes.INVOKESTATIC,
            "io/awacs/plugin/stacktrace/StackTracePlugin", "incrFailure", "(Ljava/lang/Throwable;)V", false));
    proxy.instructions.add(new VarInsnNode(Opcodes.ALOAD, varIndex));
    proxy.instructions.add(new InsnNode(Opcodes.ATHROW));
    proxy.maxLocals = varIndex + 1;
    proxy.maxStack = Math.max(varIndex, 5);
}

From source file:io.syncframework.optimizer.OControllerClassVisitor.java

License:Apache License

/**
 * Add code to the end of the class. We are adding the IController methods
 * @see org.objectweb.asm.ClassVisitor#visitEnd()
 *//*ww  w.  j av  a 2 s .  c  om*/
@Override
public void visitEnd() {
    //
    // private static Map<String,Boolean> _asActions;
    //
    {
        // private static Ljava/util/Map; _asActions
        FieldVisitor fv = cv.visitField(Opcodes.ACC_PRIVATE + Opcodes.ACC_STATIC, "_asActions",
                "Ljava/util/Map;", "Ljava/util/Map<Ljava/lang/String;Ljava/lang/Boolean;>;", null);
        fv.visitEnd();
    }
    //
    // private static Map<String,Class<?>> _asConverters;
    //
    {
        FieldVisitor fv = cv.visitField(Opcodes.ACC_PRIVATE + Opcodes.ACC_STATIC, "_asConverters",
                "Ljava/util/Map;", "Ljava/util/Map<Ljava/lang/String;Ljava/lang/Class<*>;>;", null);
        fv.visitEnd();
    }
    //
    // private static Map<String,Class<?>[]> _asInterceptors;
    //
    {
        FieldVisitor fv = cv.visitField(Opcodes.ACC_PRIVATE + Opcodes.ACC_STATIC, "_asInterceptors",
                "Ljava/util/Map;", "Ljava/util/Map<Ljava/lang/String;[Ljava/lang/Class<*>;>;", null);
        fv.visitEnd();
    }
    //
    // private static Map<String,Class<?>> _asParameters;
    //
    {
        FieldVisitor fv = cv.visitField(Opcodes.ACC_PRIVATE + Opcodes.ACC_STATIC, "_asParameters",
                "Ljava/util/Map;", "Ljava/util/Map<Ljava/lang/String;Ljava/lang/Class<*>;>;", null);
        fv.visitEnd();
    }

    if (!createdStaticMethod) {
        MethodVisitor mv = cv.visitMethod(Opcodes.ACC_STATIC, "<clinit>", "()V", null, null);
        mv.visitCode();
        mv = new OControllerStaticMethodVisitor(mv, reflector);
        mv.visitInsn(Opcodes.RETURN);
        mv.visitMaxs(0, 0);
        mv.visitEnd();
    }

    createUrlMethod();

    createContextMethod("_asApplicationContext", Type.getDescriptor(ApplicationContext.class),
            reflector.getApplicationContext());
    createContextMethod("_asErrorContext", Type.getDescriptor(ErrorContext.class), reflector.getErrorContext());
    createContextMethod("_asCookieContext", Type.getDescriptor(CookieContext.class),
            reflector.getCookieContext());
    createContextMethod("_asMessageContext", Type.getDescriptor(MessageContext.class),
            reflector.getMessageContext());
    createContextMethod("_asRequestContext", Type.getDescriptor(RequestContext.class),
            reflector.getRequestContext());
    createContextMethod("_asSessionContext", Type.getDescriptor(SessionContext.class),
            reflector.getSessionContext());

    createParametersMethod();
    createParametersSetterMethod();
    createParametersGetterMethod();
    createParameterConverterMethod();

    createActionMethod();
    createActionInterceptorsMethod();
    createActionIsDefinedMethod();
}

From source file:io.syncframework.optimizer.OInterceptorClassVisitor.java

License:Apache License

/**
 * Add code to the end of the class. We are adding the IController methods
 * @see org.objectweb.asm.ClassVisitor#visitEnd()
 *///  w w  w. j  av  a  2  s  .c om
@Override
public void visitEnd() {
    //
    // private static Map<String,Class<?>> _asConverters;
    //
    {
        FieldVisitor fv = cv.visitField(Opcodes.ACC_PRIVATE + Opcodes.ACC_STATIC, "_asConverters",
                "Ljava/util/Map;", "Ljava/util/Map<Ljava/lang/String;Ljava/lang/Class<*>;>;", null);
        fv.visitEnd();
    }
    //
    // private static Map<String,Class<?>> _asParameters;
    //
    {
        FieldVisitor fv = cv.visitField(Opcodes.ACC_PRIVATE + Opcodes.ACC_STATIC, "_asParameters",
                "Ljava/util/Map;", "Ljava/util/Map<Ljava/lang/String;Ljava/lang/Class<*>;>;", null);
        fv.visitEnd();
    }

    createStaticMethod();

    if (!createdStaticMethod) {
        MethodVisitor mv = cv.visitMethod(Opcodes.ACC_STATIC, "<clinit>", "()V", null, null);
        mv.visitCode();
        mv = new OInterceptorStaticMethodVisitor(mv, reflector);
        mv.visitInsn(Opcodes.RETURN);
        mv.visitMaxs(0, 0);
        mv.visitEnd();
    }

    createContextMethod("_asApplicationContext", Type.getDescriptor(ApplicationContext.class),
            reflector.getApplicationContext());
    createContextMethod("_asErrorContext", Type.getDescriptor(ErrorContext.class), reflector.getErrorContext());
    createContextMethod("_asCookieContext", Type.getDescriptor(CookieContext.class),
            reflector.getCookieContext());
    createContextMethod("_asMessageContext", Type.getDescriptor(MessageContext.class),
            reflector.getMessageContext());
    createContextMethod("_asRequestContext", Type.getDescriptor(RequestContext.class),
            reflector.getRequestContext());
    createContextMethod("_asSessionContext", Type.getDescriptor(SessionContext.class),
            reflector.getSessionContext());

    createParametersMethod();
    createParametersSetterMethod();
    createParametersGetterMethod();
    createParameterConverterMethod();

    createBeforeMethod();
    createAfterMethod();
}

From source file:jaspex.speculation.Cache.java

License:Open Source License

public static void saveClass(final Type className, byte[] classBytes) {
    new File(CACHE_DIR).mkdir();
    try {/*from   w  ww.  j a va2 s  .  com*/
        ClassReader cr = new ClassReader(classBytes);
        ClassWriter cw = new ClassWriter(cr, 0);

        cr.accept(new ClassVisitor(Opcodes.ASM4, cw) {
            @Override
            public void visitEnd() {
                visitField(Opcodes.ACC_FINAL | Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, CLASS_HASH_FIELD,
                        asmlib.Type.STRING.bytecodeName(), null, hashClass(className));
                cv.visitEnd();
            }
        }, 0);

        FileOutputStream fos = new FileOutputStream(CACHE_DIR + className.commonName() + ".class");
        fos.write(cw.toByteArray());
        fos.close();
    } catch (IOException e) {
        throw new Error(e);
    }
}

From source file:jasy.lang.ASMCompiler.java

private static int getAccessModifier(JasyParser.AccessModifierContext ctx,
        JasyParser.ModStaticContext statCtx) {
    int mod = Opcodes.ACC_PRIVATE;

    if (ctx != null) {
        switch (((TerminalNode) ctx.getChild(0)).getSymbol().getType()) {
        case JasyLexer.ACC_MOD_PRIVATE:
            mod = Opcodes.ACC_PRIVATE;//from   w ww. java 2  s  . c  o m
            break;
        case JasyLexer.ACC_MOD_PROTECTED:
            mod = Opcodes.ACC_PROTECTED;
            break;
        case JasyLexer.ACC_MOD_PUBLIC:
            mod = Opcodes.ACC_PUBLIC;
            break;
        }
    }

    if (statCtx != null)
        return mod | Opcodes.ACC_STATIC;

    return mod;
}