Example usage for org.objectweb.asm Opcodes ACC_PRIVATE

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

Introduction

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

Prototype

int ACC_PRIVATE

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

Click Source Link

Usage

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

License:Apache License

public static Scope toScope(int access) {
    if ((access & Opcodes.ACC_PRIVATE) == Opcodes.ACC_PRIVATE) {
        return Scope.PRIVATE;
    } else if ((access & Opcodes.ACC_PROTECTED) == Opcodes.ACC_PROTECTED) {
        return Scope.PROTECTED;
    }/*from ww w .j av  a 2s  .  c  o  m*/
    if ((access & Opcodes.ACC_PUBLIC) == Opcodes.ACC_PUBLIC) {
        return Scope.PUBLIC;
    } else {
        return Scope.NO_SCOPE;
    }
}

From source file:com.googlecode.japi.checker.Utils.java

License:Apache License

public static Scope toScope(int access) {
    if ((access & Opcodes.ACC_PRIVATE) == Opcodes.ACC_PRIVATE) {
        return Scope.PRIVATE;
    } else if ((access & Opcodes.ACC_PROTECTED) == Opcodes.ACC_PROTECTED) {
        return Scope.PROTECTED;
    }/*from   w  w  w  .  j av a 2 s.  c  o  m*/
    if ((access & Opcodes.ACC_PUBLIC) == Opcodes.ACC_PUBLIC) {
        return Scope.PUBLIC;
    } else {
        return Scope.PACKAGE;
    }
}

From source file:com.lucidtechnics.blackboard.TargetConstructor.java

License:Apache License

private static final byte[] createWrapperObjectByteArray(String _targetName, Class _class) {
    ClassWriter classWriter = new ClassWriter(true);

    FieldVisitor fieldVisitor;//ww w . j a va 2 s  .c o  m
    MethodVisitor methodVisitor;
    String superClassName = _class.getCanonicalName().replaceAll("\\.", "/");

    String[] superClassNameParts = superClassName.split("/");
    String simpleClassName = superClassNameParts[superClassNameParts.length - 1];
    String blackboardSubClassName = "com/lucidtechnics/blackboard/wrapper/" + superClassName + "Wrapper";

    classWriter.visit(Opcodes.V1_5, Opcodes.ACC_PUBLIC + Opcodes.ACC_SUPER, blackboardSubClassName, null,
            superClassName, new String[] { "com/lucidtechnics/blackboard/Target" });

    classWriter.visitSource(simpleClassName, null);

    {
        fieldVisitor = classWriter.visitField(Opcodes.ACC_PRIVATE, "blackboardObject", "Ljava/lang/Object;",
                null, null);
        fieldVisitor.visitEnd();
    }

    {
        fieldVisitor = classWriter.visitField(Opcodes.ACC_PRIVATE, "intercepter",
                "Lcom/lucidtechnics/blackboard/Intercepter;", null, null);
        fieldVisitor.visitEnd();
    }

    {
        methodVisitor = classWriter.visitMethod(Opcodes.ACC_PUBLIC, "getBlackboardObject",
                "()Ljava/lang/Object;", null, null);
        methodVisitor.visitCode();
        methodVisitor.visitVarInsn(Opcodes.ALOAD, 0);
        methodVisitor.visitFieldInsn(Opcodes.GETFIELD, blackboardSubClassName, "blackboardObject",
                "Ljava/lang/Object;");
        methodVisitor.visitInsn(Opcodes.ARETURN);
        methodVisitor.visitMaxs(0, 0);
        methodVisitor.visitEnd();
    }

    {
        methodVisitor = classWriter.visitMethod(Opcodes.ACC_PUBLIC, "getIntercepter",
                "()Lcom/lucidtechnics/blackboard/Intercepter;", null, null);
        methodVisitor.visitCode();
        methodVisitor.visitVarInsn(Opcodes.ALOAD, 0);
        methodVisitor.visitFieldInsn(Opcodes.GETFIELD, blackboardSubClassName, "intercepter",
                "Lcom/lucidtechnics/blackboard/Intercepter;");
        methodVisitor.visitInsn(Opcodes.ARETURN);
        methodVisitor.visitMaxs(0, 0);
        methodVisitor.visitEnd();
    }

    {
        methodVisitor = classWriter.visitMethod(Opcodes.ACC_PUBLIC, "setBlackboardObject",
                "(Ljava/lang/Object;)V", null, null);
        methodVisitor.visitCode();
        methodVisitor.visitVarInsn(Opcodes.ALOAD, 0);
        methodVisitor.visitVarInsn(Opcodes.ALOAD, 1);
        methodVisitor.visitFieldInsn(Opcodes.PUTFIELD, blackboardSubClassName, "blackboardObject",
                "Ljava/lang/Object;");
        methodVisitor.visitInsn(Opcodes.RETURN);
        methodVisitor.visitMaxs(0, 0);
        methodVisitor.visitEnd();
    }

    {
        methodVisitor = classWriter.visitMethod(Opcodes.ACC_PUBLIC, "setIntercepter",
                "(Lcom/lucidtechnics/blackboard/Intercepter;)V", null, null);
        methodVisitor.visitCode();
        methodVisitor.visitVarInsn(Opcodes.ALOAD, 0);
        methodVisitor.visitVarInsn(Opcodes.ALOAD, 1);
        methodVisitor.visitFieldInsn(Opcodes.PUTFIELD, blackboardSubClassName, "intercepter",
                "Lcom/lucidtechnics/blackboard/Intercepter;");
        methodVisitor.visitInsn(Opcodes.RETURN);
        methodVisitor.visitMaxs(0, 0);
        methodVisitor.visitEnd();
    }

    {
        methodVisitor = classWriter.visitMethod(Opcodes.ACC_PUBLIC, "<init>", "()V", null, null);
        methodVisitor.visitCode();
        methodVisitor.visitVarInsn(Opcodes.ALOAD, 0);
        methodVisitor.visitMethodInsn(Opcodes.INVOKESPECIAL, superClassName, "<init>", "()V");
        methodVisitor.visitInsn(Opcodes.RETURN);
        methodVisitor.visitMaxs(0, 0);
        methodVisitor.visitEnd();
    }

    List mutatorMethodList = findMutatorMethods(_class);

    Iterator mutatorMethods = mutatorMethodList.iterator();

    while (mutatorMethods.hasNext() == true) {
        Method method = (Method) mutatorMethods.next();
        MethodInfo methodInfo = (MethodInfo) MethodInfoTransformer.getInstance().transform(method);
        Signature signature = methodInfo.getSignature();
        String methodName = signature.getName();

        String parameterType = signature.getArgumentTypes()[0].getDescriptor();
        String returnType = signature.getReturnType().getDescriptor();
        String[] exceptionTypeArray = createExceptionTypeArray(methodInfo.getExceptionTypes());

        {
            methodVisitor = classWriter.visitMethod(Opcodes.ACC_PUBLIC, methodName,
                    "(" + parameterType + ")" + returnType, null, exceptionTypeArray);

            methodVisitor.visitVarInsn(Opcodes.ALOAD, 0);
            methodVisitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, blackboardSubClassName, "getIntercepter",
                    "()Lcom/lucidtechnics/blackboard/Intercepter;");
            Label l1 = new Label();
            methodVisitor.visitJumpInsn(Opcodes.IFNULL, l1);

            methodVisitor.visitCode();
            methodVisitor.visitVarInsn(Opcodes.ALOAD, 0);
            methodVisitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, blackboardSubClassName, "getIntercepter",
                    "()Lcom/lucidtechnics/blackboard/Intercepter;");

            methodVisitor.visitLdcInsn(superClassName);
            methodVisitor.visitLdcInsn(blackboardSubClassName);
            methodVisitor.visitLdcInsn(methodName);
            methodVisitor.visitLdcInsn(_targetName);
            methodVisitor.visitVarInsn(Opcodes.ALOAD, 0);

            int tempOpCode = getLoadOpcode(parameterType);
            methodVisitor.visitVarInsn(tempOpCode, 1);

            if (tempOpCode == Opcodes.ALOAD) {
                //this is an object.
                methodVisitor.visitMethodInsn(Opcodes.INVOKEINTERFACE,
                        "com/lucidtechnics/blackboard/Intercepter", "monitor",
                        "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)V");
            } else {
                //it is a primitive.
                methodVisitor.visitMethodInsn(Opcodes.INVOKEINTERFACE,
                        "com/lucidtechnics/blackboard/Intercepter", "monitor",
                        "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/Object;"
                                + parameterType + ")V");
            }

            methodVisitor.visitVarInsn(Opcodes.ALOAD, 0);
            methodVisitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, blackboardSubClassName, "getBlackboardObject",
                    "()Ljava/lang/Object;");
            methodVisitor.visitTypeInsn(Opcodes.CHECKCAST, superClassName);
            methodVisitor.visitVarInsn(getLoadOpcode(parameterType), 1);
            methodVisitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, superClassName, methodName,
                    "(" + parameterType + ")" + returnType);

            methodVisitor.visitLabel(l1);

            methodVisitor.visitInsn(getReturnOpcode(returnType));
            methodVisitor.visitMaxs(0, 0);
            methodVisitor.visitEnd();
        }
    }

    List otherPublicMethodList = findOtherPublicMethods(_class);

    Iterator otherPublicMethods = otherPublicMethodList.iterator();

    while (otherPublicMethods.hasNext() == true) {
        Method method = (Method) otherPublicMethods.next();
        MethodInfo methodInfo = (MethodInfo) MethodInfoTransformer.getInstance().transform(method);
        Signature signature = methodInfo.getSignature();
        String methodName = signature.getName();

        String parameterTypes = constructParameterTypes(signature.getArgumentTypes());
        String returnType = signature.getReturnType().getDescriptor();
        String[] exceptionTypeArray = createExceptionTypeArray(methodInfo.getExceptionTypes());

        if (logger.isDebugEnabled() == true) {
            logger.debug("Processing method: " + methodName);
        }
        if (logger.isDebugEnabled() == true) {
            logger.debug("Parameter types are: " + parameterTypes);
        }

        if ("toString".equalsIgnoreCase(methodName) == false) {
            methodVisitor = classWriter.visitMethod(Opcodes.ACC_PUBLIC, methodName,
                    "(" + parameterTypes + ")" + returnType, null, exceptionTypeArray);

            methodVisitor.visitCode();
            methodVisitor.visitVarInsn(Opcodes.ALOAD, 0);
            methodVisitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, blackboardSubClassName, "getBlackboardObject",
                    "()Ljava/lang/Object;");
            methodVisitor.visitTypeInsn(Opcodes.CHECKCAST, superClassName);
            methodVisitor.visitVarInsn(Opcodes.ASTORE, signature.getArgumentTypes().length + 1);
            methodVisitor.visitVarInsn(Opcodes.ALOAD, signature.getArgumentTypes().length + 1);

            loadParameters(methodVisitor, signature.getArgumentTypes());

            methodVisitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, superClassName, methodName,
                    "(" + parameterTypes + ")" + returnType);
            methodVisitor.visitInsn(getReturnOpcode(returnType));
            methodVisitor.visitMaxs(0, 0);
            methodVisitor.visitEnd();
        }
    }

    List protectedMethodList = findProtectedMethods(_class);

    Iterator protectedMethods = protectedMethodList.iterator();

    while (protectedMethods.hasNext() == true) {
        Method method = (Method) protectedMethods.next();
        MethodInfo methodInfo = (MethodInfo) MethodInfoTransformer.getInstance().transform(method);
        Signature signature = methodInfo.getSignature();
        String methodName = signature.getName();

        String parameterTypes = constructParameterTypes(signature.getArgumentTypes());
        String returnType = signature.getReturnType().getDescriptor();
        String[] exceptionTypeArray = createExceptionTypeArray(methodInfo.getExceptionTypes());

        if (logger.isDebugEnabled() == true) {
            logger.debug("Processing method: " + methodName + " and parameter types are: " + parameterTypes);
        }

        {
            methodVisitor = classWriter.visitMethod(Opcodes.ACC_PROTECTED, methodName,
                    "(" + parameterTypes + ")" + returnType, null, exceptionTypeArray);

            methodVisitor.visitCode();
            methodVisitor.visitTypeInsn(Opcodes.NEW, "com/lucidtechnics/blackboard/BlackboardException");
            methodVisitor.visitInsn(Opcodes.DUP);
            methodVisitor.visitLdcInsn("Unable to access protected methods on Blackboard object");
            methodVisitor.visitMethodInsn(Opcodes.INVOKESPECIAL,
                    "com/lucidtechnics/blackboard/BlackboardException", "<init>", "(Ljava/lang/String;)V");
            methodVisitor.visitInsn(Opcodes.ATHROW);
            methodVisitor.visitMaxs(0, 0);
            methodVisitor.visitEnd();
        }
    }

    {
        methodVisitor = classWriter.visitMethod(Opcodes.ACC_PUBLIC, "toString", "()Ljava/lang/String;", null,
                null);
        methodVisitor.visitCode();
        methodVisitor.visitVarInsn(Opcodes.ALOAD, 0);
        methodVisitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, blackboardSubClassName, "getBlackboardObject",
                "()Ljava/lang/Object;");
        methodVisitor.visitMethodInsn(Opcodes.INVOKESTATIC, "com/lucidtechnics/blackboard/util/Utility",
                "toString", "(Ljava/lang/Object;)Ljava/lang/String;");
        methodVisitor.visitInsn(getReturnOpcode("Ljava/lang/String;"));
        methodVisitor.visitMaxs(0, 0);
        methodVisitor.visitEnd();
    }

    classWriter.visitEnd();

    if (logger.isDebugEnabled() == true) {
        logger.debug("Finished creating new class: " + blackboardSubClassName + " for target class: "
                + superClassName + ".");
    }

    return classWriter.toByteArray();
}

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

License:Apache License

public Access getAccess() {
    switch (modifier & ACCESS) {
    case 0://from ww w.ja v a2 s.c  o m
        return Access.DEFAULT;
    case Opcodes.ACC_PUBLIC:
        return Access.PUBLIC;
    case Opcodes.ACC_PRIVATE:
        return Access.PRIVATE;
    case Opcodes.ACC_PROTECTED:
        return Access.PROTECTED;
    }
    throw new IllegalStateException("Unreachanble");
}

From source file:com.mebigfatguy.baremetal4j.Sourcifier.java

License:Apache License

public String accessString(int access) {
    String separator = "";
    StringBuilder sb = new StringBuilder(32);
    if ((access & Opcodes.ACC_PUBLIC) != 0) {
        sb.append("public");
        separator = " ";
    } else if ((access & Opcodes.ACC_PROTECTED) != 0) {
        sb.append("protected");
        separator = " ";
    } else if ((access & Opcodes.ACC_PRIVATE) != 0) {
        sb.append("private");
        separator = " ";
    }/* w  w  w  .  jav a 2  s.c om*/

    if ((access & Opcodes.ACC_STATIC) != 0) {
        sb.append(separator).append("static");
        separator = " ";
    }

    if ((access & Opcodes.ACC_FINAL) != 0) {
        sb.append(separator).append("final");
        separator = " ";
    }

    return sb.toString();
}

From source file:com.mebigfatguy.junitflood.classpath.ClassDetails.java

License:Apache License

private Access convertAccess(int access) {
    switch (access) {
    case Opcodes.ACC_PRIVATE:
        return Access.PRIVATE;
    case Opcodes.ACC_PROTECTED:
        return Access.PROTECTED;
    case Opcodes.ACC_PUBLIC:
        return Access.PUBLIC;
    default:/*from   w  w w.j a  v a  2  s. co  m*/
        return Access.PACKAGE;
    }
}

From source file:com.microsoft.applicationinsights.agent.internal.agent.ByteCodeUtilsTest.java

License:Open Source License

@Test
public void testIsPrivate() throws Exception {
    assertTrue(ByteCodeUtils.isPrivate(Opcodes.ACC_PRIVATE));
}

From source file:com.microsoft.applicationinsights.agent.internal.agent.ByteCodeUtilsTest.java

License:Open Source License

@Test
public void testNotIsPrivate() throws Exception {
    assertFalse(ByteCodeUtils.isPrivate(~Opcodes.ACC_PRIVATE));
}

From source file:com.mogujie.instantrun.IncrementalChangeVisitor.java

License:Apache License

public IncrementalChangeVisitor(ClassNode classNode, List<ClassNode> parentNodes, ClassVisitor classVisitor) {
    super(classNode, parentNodes, classVisitor);
    methodNodes = classNode.methods;/*w ww  .  j a  v  a 2  s  . co m*/
    for (int i = 0; i < classNode.methods.size(); i++) {
        MethodNode methodNode = (MethodNode) classNode.methods.get(i);
        if ((methodNode.access & (Opcodes.ACC_NATIVE | Opcodes.ACC_PRIVATE)) == (Opcodes.ACC_NATIVE
                | Opcodes.ACC_PRIVATE)) {
            priNativeMtdSet.add(methodNode.name + "." + methodNode.desc);
            System.out.println("find private native mtd : " + methodNode.name + "." + methodNode.desc);
        }
        if ((methodNode.access & (Opcodes.ACC_SYNCHRONIZED | Opcodes.ACC_PRIVATE)) == (Opcodes.ACC_SYNCHRONIZED
                | Opcodes.ACC_PRIVATE)) {
            priSyncMtdSet.add(methodNode.name + "." + methodNode.desc);
            System.out.println("find private sync mtd : " + methodNode.name + "." + methodNode.desc);
        }
    }

}

From source file:com.mogujie.instantrun.IncrementalChangeVisitor.java

License:Apache License

@Override
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {

    if (instantRunDisabled || !isAccessCompatibleWithInstantRun(access)) {
        // Nothing to generate.
        return null;
    }//from   www .  j  av  a  2 s .co  m
    if (name.equals("<clinit>")) {
        // we skip the class init as it can reset static fields which we don't support right now
        return null;
    }
    Log.v("visit method " + name + "  " + desc);
    boolean isStatic = (access & Opcodes.ACC_STATIC) != 0;
    boolean isPrivate = (access & Opcodes.ACC_PRIVATE) != 0;
    boolean isSync = (access & Opcodes.ACC_SYNCHRONIZED) != 0;

    String newDesc = computeOverrideMethodDesc(desc, isStatic);

    // Do not carry on any access flags from the original method. For example synchronized
    // on the original method would translate into a static synchronized method here.
    access = Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC;

    //        MethodNode method = getMethodByNameInClass(name, desc, classNode);
    if (name.equals("<init>")) {
        return null;
    } else {
        String newName = isStatic ? computeOverrideMethodName(name, desc) : name;
        MethodVisitor original = super.visitMethod(access, newName, newDesc, signature, exceptions);
        for (MethodNode methodNode : methodNodes) {
            if (desc.equals(methodNode.desc) && name.equals(methodNode.name)) {
                processNew(methodNode);
            }
        }

        return new ISVisitor(original, access, newName, newDesc, IncrementalTool.getMtdSig(name, desc),
                isStatic, false /* isConstructor */);
    }
}