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:de.sanandrew.core.manpack.transformer.AnnotationChecker.java

License:Creative Commons License

private static int getAccessLevelInt(int access) {
    if (checkBitwiseEqual(access, Opcodes.ACC_PRIVATE)) {
        return 0;
    } else if (checkBitwiseEqual(access, Opcodes.ACC_PROTECTED)) {
        return 2;
    } else if (checkBitwiseEqual(access, Opcodes.ACC_PUBLIC)) {
        return 3;
    } else { // if ACC_PACKAGE_LOCAL
        return 1;
    }/*from  ww  w.  j a  va  2s .  c  om*/
}

From source file:de.sanandrew.core.manpack.transformer.AnnotationChecker.java

License:Creative Commons License

private static String getAccessLevelName(int access) {
    if (checkBitwiseEqual(access, Opcodes.ACC_PRIVATE)) {
        return "private";
    } else if (checkBitwiseEqual(access, Opcodes.ACC_PROTECTED)) {
        return "protected";
    } else if (checkBitwiseEqual(access, Opcodes.ACC_PUBLIC)) {
        return "public";
    } else { // if ACC_PACKAGE_LOCAL
        return "packageLocal";
    }//  ww w.  j a v  a2  s .  com
}

From source file:de.sanandrew.core.manpack.transformer.AnnotationChecker.java

License:Creative Commons License

private static int getAccessLevelOpcode(String accessName) {
    String[] accessSplit = accessName.split(";");
    int ret = 0;/*from  w w  w.j a v  a 2  s  .  c  o  m*/
    for (String acc : accessSplit) {
        switch (acc) {
        case "private":
            ret |= Opcodes.ACC_PRIVATE;
            break;
        case "protected":
            ret |= Opcodes.ACC_PROTECTED;
            break;
        case "public":
            ret |= Opcodes.ACC_PUBLIC;
            break;
        case "deprecated":
            ret |= Opcodes.ACC_DEPRECATED;
            break;
        }
    }

    return ret;
}

From source file:de.sanandrew.core.manpack.transformer.TransformHorseArmor.java

License:Creative Commons License

private static MethodNode injectMethodGetCustomArmorItem() {
    MethodNode method = ASMHelper.getMethodNode(Opcodes.ACC_PRIVATE, ASMNames.MD_SAP_GET_CUSTOM_ARMOR_ITEM);
    method.visitCode();//from   w ww.  j  av  a  2  s.com
    Label l0 = new Label();
    method.visitLabel(l0);
    method.visitVarInsn(Opcodes.ALOAD, 0);
    ASMHelper.visitFieldInsn(method, Opcodes.GETFIELD, ASMNames.FD_HORSE_DATAWATCHER);
    method.visitIntInsn(Opcodes.BIPUSH, 23);
    ASMHelper.visitMethodInsn(method, Opcodes.INVOKEVIRTUAL, ASMNames.MD_DATAWATCHER_GET_OBJ_STACK, false);
    method.visitInsn(Opcodes.ARETURN);
    Label l1 = new Label();
    method.visitLabel(l1);
    method.visitLocalVariable("this", ASMNames.CL_T_ENTITY_HORSE, null, l0, l1, 0);
    method.visitMaxs(2, 1);
    method.visitEnd();

    return method;
}

From source file:de.sanandrew.core.manpack.transformer.TransformHorseArmor.java

License:Creative Commons License

private static MethodNode injectMethodSetCustomArmorItem() {
    MethodNode method = ASMHelper.getMethodNode(Opcodes.ACC_PRIVATE, ASMNames.MD_SAP_SET_CUSTOM_ARMOR_ITEM);
    method.visitCode();//from w  ww. j  av a  2 s .  c o  m
    Label l0 = new Label();
    method.visitLabel(l0);
    method.visitVarInsn(Opcodes.ALOAD, 1);
    Label l1 = new Label();
    method.visitJumpInsn(Opcodes.IFNONNULL, l1);
    method.visitTypeInsn(Opcodes.NEW, ASMNames.CL_ITEM_STACK);
    method.visitInsn(Opcodes.DUP);
    ASMHelper.visitFieldInsn(method, Opcodes.GETSTATIC, ASMNames.FD_ITEMS_IRON_SHOVEL);
    method.visitInsn(Opcodes.ICONST_0);
    ASMHelper.visitMethodInsn(method, Opcodes.INVOKESPECIAL, ASMNames.MD_ITEMSTACK_INIT, false);
    method.visitVarInsn(Opcodes.ASTORE, 1);
    method.visitLabel(l1);
    method.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
    method.visitVarInsn(Opcodes.ALOAD, 0);
    ASMHelper.visitFieldInsn(method, Opcodes.GETFIELD, ASMNames.FD_HORSE_DATAWATCHER);
    method.visitIntInsn(Opcodes.BIPUSH, 23);
    method.visitVarInsn(Opcodes.ALOAD, 1);
    ASMHelper.visitMethodInsn(method, Opcodes.INVOKEVIRTUAL, ASMNames.MD_DATAWATCHER_UPDATE_OBJ, false);
    Label l3 = new Label();
    method.visitLabel(l3);
    method.visitInsn(Opcodes.RETURN);
    Label l4 = new Label();
    method.visitLabel(l4);
    method.visitLocalVariable("this", ASMNames.CL_T_ENTITY_HORSE, null, l0, l3, 0);
    method.visitLocalVariable("stack", ASMNames.CL_T_ITEM_STACK, null, l0, l3, 1);
    method.visitMaxs(5, 2);
    method.visitEnd();

    return method;
}

From source file:de.scoopgmbh.copper.instrument.MethodInfo.java

License:Apache License

public String getDeclaration() {
    StringBuilder sb = new StringBuilder();
    if ((access & Opcodes.ACC_PRIVATE) != 0)
        sb.append("private ");
    if ((access & Opcodes.ACC_PROTECTED) != 0)
        sb.append("protected ");
    if ((access & Opcodes.ACC_PUBLIC) != 0)
        sb.append("public ");
    if ((access & Opcodes.ACC_STATIC) != 0)
        sb.append("static ");
    if ((access & Opcodes.ACC_FINAL) != 0)
        sb.append("final ");
    sb.append(Type.getReturnType(descriptor).getClassName()).append(' ').append(methodName).append('(');

    boolean first = true;
    for (Type t : Type.getArgumentTypes(descriptor)) {
        if (!first)
            sb.append(", ");
        first = false;//  ww  w .  j ava2 s .c  o m
        sb.append(t.getClassName());
    }
    sb.append(')');
    return sb.toString();
}

From source file:de.tuberlin.uebb.jbop.optimizer.array.LocalArrayLengthInlinerTest.java

License:Open Source License

/**
 * Tests that LocalArrayLengthInliner is working correctly.
 * //  w  w w.  ja va 2 s. c o m
 * @throws Exception
 *           the exception
 */
@Test
public void test_newarrayAndSubarray() throws Exception {
    // INIT
    final String owner = "de.tuberlin.uebb.jbop.optimizer.array.LocalArrayLengthTestClass";
    final ClassNodeBuilder builder = ClassNodeBuilder.createClass(owner).//
            addField("doubleArray", "[[D").initArray(15, 42)
            .withModifiers(Opcodes.ACC_PRIVATE, Opcodes.ACC_FINAL).//
            addMethod("getArrayLength", "()I").withAnnotation(Optimizable.class).//
            addArray("[D", 15).// 3 -> 3
            addInsn(new VarInsnNode(Opcodes.ALOAD, 1)).// 1 -> 0|
            addInsn(new InsnNode(Opcodes.ARRAYLENGTH)).// 1 -> 0|1
            addGetClassField("doubleArray").// 2 -> 2
            addInsn(new InsnNode(Opcodes.ICONST_0)).// 1 -> 1
            addInsn(new InsnNode(Opcodes.AALOAD)).// 1 -> 1
            addInsn(new VarInsnNode(Opcodes.ASTORE, 2)).// 1 -> 1
            addInsn(new VarInsnNode(Opcodes.ALOAD, 2)).// 1 -> 0|
            addInsn(new InsnNode(Opcodes.ARRAYLENGTH)).// 1 -> 0|1
            addInsn(new InsnNode(Opcodes.IADD)).// 1 -> 1
            addInsn(new InsnNode(Opcodes.IRETURN));// 1 -> 1
    // 14 -> 12
    final LocalArrayLengthInliner inliner = new LocalArrayLengthInliner();
    inliner.setInputObject(builder.toClass().instance());

    // RUN STEP 1
    final MethodNode method = builder.getMethod("getArrayLength");
    assertEquals(14, method.instructions.size());
    final InsnList optimized = inliner.optimize(method.instructions, method);
    method.instructions = optimized;

    // ASSERT STEP 1
    assertEquals(12, optimized.size());
    assertEquals(15, NodeHelper.getNumberValue(optimized.get(3)).intValue());
    assertEquals(42, NodeHelper.getNumberValue(optimized.get(9)).intValue());

    // RUN STEP 2
    final InsnList optimized2 = inliner.optimize(method.instructions, method);

    // ASSERT STEP 2
    assertEquals(12, optimized2.size());
}

From source file:de.tuberlin.uebb.jbop.optimizer.array.LocalArrayValueInlinerTest.java

License:Open Source License

/**
 * Tests that LocalArrayValueInliner is working correctly.
 * //ww w. j a  v a  2  s .c  o m
 * @throws Exception
 *           the exception
 */
@Test
public void testLocalArrayValueInliner() throws Exception {
    // INIT
    final String owner = "de.tuberlin.uebb.jbop.optimizer.array.LocalArrayValueTestClass";
    final ClassNodeBuilder builder = ClassNodeBuilder.createClass(owner).//
            addField("doubleArray", "[[D").//
            withAnnotation(ImmutableArray.class).//
            withModifiers(Opcodes.ACC_PRIVATE, Opcodes.ACC_FINAL).//
            initArray(2, 2).//
            initMultiArrayWith(1.0, 0, 0).//
            initMultiArrayWith(2.0, 0, 1).//
            initMultiArrayWith(3.0, 1, 0).//
            initMultiArrayWith(4.0, 1, 1).//
            addMethod("getArrayValue", "()D").withAnnotation(Optimizable.class).//
            addGetClassField("doubleArray").// 2 -> 2
            addInsn(new InsnNode(Opcodes.ICONST_0)).// 1 -> 1
            addInsn(new InsnNode(Opcodes.AALOAD)).// 1 -> 1
            addInsn(new VarInsnNode(Opcodes.ASTORE, 2)).// 1 -> 1
            addInsn(new VarInsnNode(Opcodes.ALOAD, 2)).// 1 -> 0|
            addInsn(new InsnNode(Opcodes.ICONST_1)).// 1 -> 0|
            addInsn(new InsnNode(Opcodes.DALOAD)).// 1 -> 0| 1
            addInsn(new InsnNode(Opcodes.DRETURN));// 1 -> 1
    // 14 -> 12
    final LocalArrayValueInliner inliner = new LocalArrayValueInliner();
    inliner.setInputObject(builder.toClass().instance());

    // RUN STEP 1
    final MethodNode method = builder.getMethod("getArrayValue");
    assertEquals(9, method.instructions.size());
    final InsnList optimized = inliner.optimize(method.instructions, method);

    // ASSERT STEP 1

    assertEquals(7, optimized.size());
    assertEquals(2.0, NodeHelper.getNumberValue(optimized.get(5)).doubleValue(), .0001);

    // RUN STEP 2
    final InsnList optimized2 = inliner.optimize(method.instructions, method);

    // ASSERT STEP 2
    assertEquals(7, optimized2.size());
}

From source file:de.tuberlin.uebb.jbop.optimizer.ClassNodeBuilder.java

License:Open Source License

/**
 * Adds a new Field with the given name and descriptor to the classNode.
 * for primitive Types and String a default value can be given via value.
 * /*from w  ww  .  j  ava  2  s  . co m*/
 * @param fieldName
 *          the field name
 * @param descriptor
 *          the descriptor
 * @param value
 *          the value
 * @return the abstract optimizer test
 */
public ClassNodeBuilder addField(final String fieldName, final String descriptor, final Object... value) {
    if (isInterface) {
        return this;
    }
    final FieldNode fieldNode = new FieldNode(Opcodes.ACC_PRIVATE, fieldName, descriptor, null,
            value == null ? null : value.length > 0 ? value[0] : null);
    classNode.fields.add(fieldNode);
    lastField = fieldNode;
    lastElement = fieldNode;
    fieldNode.invisibleAnnotations = new ArrayList<>();
    fieldNode.visibleAnnotations = new ArrayList<>();
    return this;
}

From source file:de.unisb.cs.st.javalanche.coverage.CoverageMethodAdapter.java

License:Open Source License

public CoverageMethodAdapter(MethodVisitor visitor, String className, String methodName, String signature,
        int classAccess, int methodAccess) {
    super(visitor);
    this.className = className.replace('/', '.');
    this.methodName = methodName;

    // don't instrument private classes / methods for data coverage
    if ((classAccess & Opcodes.ACC_PRIVATE) == Opcodes.ACC_PRIVATE
            || (methodAccess & Opcodes.ACC_PRIVATE) == Opcodes.ACC_PRIVATE) {
        logger.debug("not instrumenting method " + this.className + "@" + this.methodName
                + " (cause: only private access)");
        instrumentReturns = false;//from w  w w .j  a  va 2 s .  co  m
        // instrumentLine = false;
    }

    // don't instrument classes for data coverage that throw an exception

    if (InstrumentExclude.shouldExcludeLines(this.className, methodName)) {
        logger.debug("Not instrumenting line coverage for: " + className + "  " + methodName);
        instrumentLine = false;
    }
    if (InstrumentExclude.shouldExcludeReturns(this.className, methodName)) {
        logger.debug("Not instrumenting return coverage for: " + this.className + "  " + methodName);
        instrumentReturns = false;
    }

}