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:org.spongepowered.mod.asm.util.ASMEventListenerFactory.java

License:MIT License

@SuppressWarnings("unchecked")
private static <T> Class<T> createClass(Class<T> interf, Method input, Method output) {

    String className = getClassName(interf, input, output);

    ClassWriter cwBase = new ClassWriter(0);
    CheckClassAdapter cw = new CheckClassAdapter(cwBase);

    MethodVisitor mv;/*from   w w w . j a  va2s . c  o m*/

    String classNameDesc = className.replace('.', '/');

    String interfaceInternalName = Type.getInternalName(interf);

    String inputName = input.getName();
    String inputMethodDescriptor = Type.getMethodDescriptor(input);

    String outputParameterTypeIntName = Type.getInternalName(output.getParameterTypes()[0]);
    String outputTargetTypeIntName = Type.getInternalName(output.getDeclaringClass());
    String outputMethodDescriptor = Type.getMethodDescriptor(output);
    String outputName = output.getName();

    boolean isOutputInterface = output.getDeclaringClass().isInterface();

    // A new class of the following form is created, with a unique name
    //
    // package org.spongepowered.mod.asm;
    // public class <className> extends java.lang.Object implements <interf>
    //
    //     private final Object target
    //
    //     public <className> (java.lang.Object target) {
    //         super();
    //         this.target = target;
    //         return;
    //     }
    //
    //     public void <inputMethod> (<inputMethodType event) {
    //         ((outputTargetType) this.target).outputMethod((outputParameteType) event);
    //         return
    //     }
    // }

    // package org.spongepowered.mod.asm;
    // public class <className> extends java.lang.Object implements <interf>
    cw.visit(Opcodes.V1_6, Opcodes.ACC_PUBLIC | Opcodes.ACC_SUPER, classNameDesc, null, "java/lang/Object",
            new String[] { interfaceInternalName });

    // private final Object target
    cw.visitField(Opcodes.ACC_PRIVATE | Opcodes.ACC_FINAL, "target", "Ljava/lang/Object;", null, null);

    // Constructor

    // public UniqueClass (java.lang.Object target) {
    mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "<init>", "(Ljava/lang/Object;)V", null, null);
    mv.visitCode();

    // super();
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false);

    // this.target = target;
    mv.visitVarInsn(Opcodes.ALOAD, 0); // Loads this
    mv.visitVarInsn(Opcodes.ALOAD, 1); // Loads target (from input)
    mv.visitFieldInsn(Opcodes.PUTFIELD, classNameDesc, "target", "Ljava/lang/Object;");

    // return;
    mv.visitInsn(Opcodes.RETURN);

    // }
    // 2 localvars due to inputs: this, target
    // 2 items on stack after double ALOAD
    mv.visitMaxs(2, 2);
    mv.visitEnd();

    // Callback method

    // public void <inputMethod> (<inputMethodType event) {
    mv = cw.visitMethod(Opcodes.ACC_PUBLIC, inputName, inputMethodDescriptor, null, null);
    mv.visitCode();

    // push((casted) this.target)
    mv.visitVarInsn(Opcodes.ALOAD, 0); // Loads this
    mv.visitFieldInsn(Opcodes.GETFIELD, classNameDesc, "target", "Ljava/lang/Object;");
    mv.visitTypeInsn(Opcodes.CHECKCAST, outputTargetTypeIntName);

    // push((casted) event)
    mv.visitVarInsn(Opcodes.ALOAD, 1); // Loads method parameter 0
    mv.visitTypeInsn(Opcodes.CHECKCAST, outputParameterTypeIntName);

    // ((outputTargetType) this.target).outputMethod((outputParameteType) event);
    mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, outputTargetTypeIntName, outputName, outputMethodDescriptor,
            isOutputInterface);

    // return
    mv.visitInsn(Opcodes.RETURN);

    // }
    mv.visitMaxs(2, 2);
    mv.visitEnd();

    cw.visitEnd();

    byte[] bytes = cwBase.toByteArray();

    return (Class<T>) loader.defineClass(className, bytes);
}

From source file:org.springframework.core.type.classreading.MethodMetadataReadingVisitor.java

License:Apache License

public boolean isOverridable() {
    return (!isStatic() && !isFinal() && ((this.access & Opcodes.ACC_PRIVATE) == 0));
}

From source file:org.springframework.migrationanalyzer.contributions.bytecode.AsmUtils.java

License:Apache License

/**
 * Converts the given bitwise ORed <code>modifiers</code> into a {@link String}.
 * /*w  w w .  j  a v  a 2s. c  om*/
 * <p/>
 * 
 * The returned String should reflect the ordering recommended in the JLS:
 * 
 * <ul>
 * <li>Classes: <code>public protected private abstract static final strictfp</code></li>
 * <li>Fields: <code>public protected private static final transient volatile</code></li>
 * <li>Constructors: <code>public protected private</code></li>
 * <li>Methods: <code>public protected private abstract static final synchronized native strictfp</code></li>
 * </ul>
 * 
 * @param modifiers the modifiers
 * 
 * @return The String representation of the modifiers
 * 
 * @see Opcodes
 */
// CHECKSTYLE:OFF
static final String modifiersToString(int modifiers) {
    StringBuilder accessBuilder = new StringBuilder();

    if ((modifiers & Opcodes.ACC_PUBLIC) == Opcodes.ACC_PUBLIC) {
        accessBuilder.append("public ");
    }
    if ((modifiers & Opcodes.ACC_PROTECTED) == Opcodes.ACC_PROTECTED) {
        accessBuilder.append("protected ");
    }
    if ((modifiers & Opcodes.ACC_PRIVATE) == Opcodes.ACC_PRIVATE) {
        accessBuilder.append("private ");
    }
    if ((modifiers & Opcodes.ACC_ABSTRACT) == Opcodes.ACC_ABSTRACT) {
        accessBuilder.append("abstract ");
    }
    if ((modifiers & Opcodes.ACC_STATIC) == Opcodes.ACC_STATIC) {
        accessBuilder.append("static ");
    }
    if ((modifiers & Opcodes.ACC_FINAL) == Opcodes.ACC_FINAL) {
        accessBuilder.append("final ");
    }
    if ((modifiers & Opcodes.ACC_SYNCHRONIZED) == Opcodes.ACC_SYNCHRONIZED) {
        accessBuilder.append("synchronized ");
    }
    if ((modifiers & Opcodes.ACC_NATIVE) == Opcodes.ACC_NATIVE) {
        accessBuilder.append("native ");
    }
    if ((modifiers & Opcodes.ACC_TRANSIENT) == Opcodes.ACC_TRANSIENT) {
        accessBuilder.append("transient ");
    }
    if ((modifiers & Opcodes.ACC_VOLATILE) == Opcodes.ACC_VOLATILE) {
        accessBuilder.append("volatile ");
    }
    if ((modifiers & Opcodes.ACC_STRICT) == Opcodes.ACC_STRICT) {
        accessBuilder.append("strictfp ");
    }

    return accessBuilder.toString().trim();
}

From source file:org.springframework.migrationanalyzer.contributions.bytecode.AsmUtilsTests.java

License:Apache License

@Test
public void privateAccess() {
    assertEquals("private", AsmUtils.modifiersToString(Opcodes.ACC_PRIVATE));
}

From source file:org.springframework.migrationanalyzer.contributions.bytecode.AsmUtilsTests.java

License:Apache License

@Test
public void classAccessOrdering() {
    assertEquals("public protected private abstract static final strictfp",
            AsmUtils.modifiersToString(Opcodes.ACC_PUBLIC | Opcodes.ACC_PROTECTED | Opcodes.ACC_PRIVATE
                    | Opcodes.ACC_ABSTRACT | Opcodes.ACC_STATIC | Opcodes.ACC_FINAL | Opcodes.ACC_STRICT));
}

From source file:org.springframework.migrationanalyzer.contributions.bytecode.AsmUtilsTests.java

License:Apache License

@Test
public void fieldAccessOrdering() {
    assertEquals("public protected private static final transient volatile",
            AsmUtils.modifiersToString(Opcodes.ACC_PUBLIC | Opcodes.ACC_PROTECTED | Opcodes.ACC_PRIVATE
                    | Opcodes.ACC_STATIC | Opcodes.ACC_FINAL | Opcodes.ACC_TRANSIENT | Opcodes.ACC_VOLATILE));
}

From source file:org.springframework.migrationanalyzer.contributions.bytecode.AsmUtilsTests.java

License:Apache License

@Test
public void methodAccessOrdering() {
    assertEquals("public protected private abstract static final synchronized native strictfp",
            AsmUtils.modifiersToString(Opcodes.ACC_PUBLIC | Opcodes.ACC_PROTECTED | Opcodes.ACC_PRIVATE
                    | Opcodes.ACC_ABSTRACT | Opcodes.ACC_STATIC | Opcodes.ACC_FINAL | Opcodes.ACC_SYNCHRONIZED
                    | Opcodes.ACC_NATIVE | Opcodes.ACC_STRICT));
}

From source file:org.springsource.loaded.test.infra.ClassPrinter.java

License:Apache License

private String toAccessForClass(int flags) {
    StringBuilder sb = new StringBuilder();
    if ((flags & Opcodes.ACC_PUBLIC) != 0) {
        sb.append("public ");
    }/*from ww w.jav  a 2s.  c o  m*/
    if ((flags & Opcodes.ACC_PRIVATE) != 0) {
        sb.append("private ");
    }
    if ((flags & Opcodes.ACC_PROTECTED) != 0) {
        sb.append("protected ");
    }
    if ((flags & Opcodes.ACC_STATIC) != 0) {
        sb.append("static ");
    }
    if ((flags & Opcodes.ACC_FINAL) != 0) {
        sb.append("final ");
    }
    if ((flags & Opcodes.ACC_SYNCHRONIZED) != 0) {
        sb.append("synchronized ");
    }
    if ((flags & Opcodes.ACC_BRIDGE) != 0) {
        sb.append("bridge ");
    }
    if ((flags & Opcodes.ACC_VARARGS) != 0) {
        sb.append("varargs ");
    }
    if ((flags & Opcodes.ACC_NATIVE) != 0) {
        sb.append("native ");
    }
    if ((flags & Opcodes.ACC_ABSTRACT) != 0) {
        sb.append("abstract ");
    }
    if ((flags & Opcodes.ACC_SYNTHETIC) != 0) {
        sb.append("synthetic ");
    }
    if ((flags & Opcodes.ACC_DEPRECATED) != 0) {
        sb.append("deprecated ");
    }
    if ((flags & Opcodes.ACC_INTERFACE) != 0) {
        sb.append("interface ");
    }
    return sb.toString().trim();
}

From source file:org.springsource.loaded.test.infra.ClassPrinter.java

License:Apache License

public static String toAccessForMember(int flags) {
    StringBuilder sb = new StringBuilder();
    if ((flags & Opcodes.ACC_PUBLIC) != 0) {
        sb.append("public ");
    }//from w  ww  .  j  a v  a  2  s .c  o  m
    if ((flags & Opcodes.ACC_PRIVATE) != 0) {
        sb.append("private ");
    }
    if ((flags & Opcodes.ACC_STATIC) != 0) {
        sb.append("static ");
    }
    if ((flags & Opcodes.ACC_PROTECTED) != 0) {
        sb.append("protected ");
    }
    if ((flags & Opcodes.ACC_FINAL) != 0) {
        sb.append("final ");
    }
    if ((flags & Opcodes.ACC_SUPER) != 0) {
        sb.append("super ");
    }
    if ((flags & Opcodes.ACC_INTERFACE) != 0) {
        sb.append("interface ");
    }
    if ((flags & Opcodes.ACC_ABSTRACT) != 0) {
        sb.append("abstract ");
    }
    if ((flags & Opcodes.ACC_SYNTHETIC) != 0) {
        sb.append("synthetic ");
    }
    if ((flags & Opcodes.ACC_ANNOTATION) != 0) {
        sb.append("annotation ");
    }
    if ((flags & Opcodes.ACC_ENUM) != 0) {
        sb.append("enum ");
    }
    if ((flags & Opcodes.ACC_DEPRECATED) != 0) {
        sb.append("deprecated ");
    }
    return sb.toString().trim();
}

From source file:org.summer.aop.PointcutExpressionParser.java

License:Open Source License

private static boolean matchVisibility(int access, String visibility) {
    if (visibility == null || "*".equals(visibility))
        return true; // visibility is optional; the asterisk has the same effect as omitting the visibility
    switch (access) {
    case Opcodes.ACC_PUBLIC:
        return visibility.equals("public");
    case Opcodes.ACC_PROTECTED:
        return visibility.equals("protected");
    case Opcodes.ACC_PRIVATE:
        return visibility.equals("private");
    case 0x0000:/*from   ww w .  ja  v a 2  s  .c  o  m*/
        return visibility.equals("package-private");
    }
    return false;
}