Example usage for org.objectweb.asm Opcodes ASM5

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

Introduction

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

Prototype

int ASM5

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

Click Source Link

Usage

From source file:com.github.fge.grappa.transform.base.RuleMethod.java

License:Open Source License

public RuleMethod(Class<?> ownerClass, int access, String name, String desc, String signature,
        String[] exceptions, Set<ParserAnnotation> classAnnotations) {
    super(Opcodes.ASM5, access, name, desc, signature, exceptions);
    this.ownerClass = ownerClass;
    parameterCount = Type.getArgumentTypes(desc).length;

    if (parameterCount == 0)
        annotations.add(CACHED);/*from   ww w.  jav a 2s.  c  o m*/
    Set<ParserAnnotation> set = EnumSet.copyOf(classAnnotations);
    set.retainAll(COPY_FROM_CLASS);
    annotations.addAll(set);
    skipGeneration = isSuperMethod();
}

From source file:com.github.fge.grappa.transform.generate.ClassNodeInitializer.java

License:Open Source License

public ClassNodeInitializer() {
    super(Opcodes.ASM5);
}

From source file:com.github.fge.grappa.transform.hash.InstructionGroupHasher.java

License:Apache License

private InstructionGroupHasher(@Nonnull InstructionGroup group, @Nonnull String className) {
    super(Opcodes.ASM5);
    this.group = Objects.requireNonNull(group);
    this.className = Objects.requireNonNull(className);
    hasher = SHA1.newHasher();/* w ww .  java 2s.  c  o  m*/
}

From source file:com.github.jonathanxd.codeapi.test.asm.LocalsReuseTest.java

License:Open Source License

@SuppressWarnings("unchecked")
@Test/*  ww  w .  ja v a  2s .  c o m*/
public void test() {
    ClassDeclaration declaration = ClassDeclarationBuilder.builder().withModifiers(CodeModifier.PUBLIC)
            .withQualifiedName("codeapi.LocalsReuse")
            .withBody(CodeAPI.sourceOfParts(MethodDeclarationBuilder.builder()
                    .withModifiers(CodeModifier.PUBLIC).withName("test").withReturnType(Types.INT)
                    .withParameters(CodeAPI.parameter(Types.BOOLEAN, "bool"))
                    .withBody(CodeAPI.sourceOfParts(CodeAPI.ifStatement(
                            CodeAPI.checkTrue(CodeAPI.accessLocalVariable(Types.BOOLEAN, "bool")),
                            CodeAPI.sourceOfParts(VariableFactory.variable(Types.INT, "i", Literals.INT(10)),
                                    CodeAPI.returnValue(Types.INT,
                                            CodeAPI.accessLocalVariable(Types.INT, "i"))),
                            CodeAPI.sourceOfParts(VariableFactory.variable(Types.INT, "i", Literals.INT(17)),
                                    CodeAPI.returnValue(Types.INT,
                                            CodeAPI.accessLocalVariable(Types.INT, "i"))))))
                    .build()

            )).build();

    BytecodeGenerator bytecodeGenerator = new BytecodeGenerator();

    bytecodeGenerator.getOptions().set(BytecodeOptions.VISIT_LINES, VisitLineType.FOLLOW_CODE_SOURCE);

    BytecodeClass[] gen = bytecodeGenerator.gen(declaration);

    ResultSaver.save(this.getClass(), gen);

    ClassReader cr = new ClassReader(gen[0].getBytecode());

    ClassNode cn = new ClassNode(Opcodes.ASM5);
    cr.accept(cn, 0);

    MethodNode node = ((List<MethodNode>) cn.methods).stream()
            .filter(methodNode -> methodNode.name.equals("test")).findFirst()
            .orElseThrow(NullPointerException::new);

    Assert.assertEquals("Locals reuse", 3, node.maxLocals);
}

From source file:com.github.jonathanxd.codeapi.test.asm.Transformer.java

License:Open Source License

@Test
public void transform() throws Throwable {

    WrappedPrintStream wrappedPrintStream = new WrappedPrintStream(System.out);
    System.setOut(wrappedPrintStream);

    BytecodeGenerator bytecodeGenerator = new BytecodeGenerator();

    bytecodeGenerator.getOptions().set(BytecodeOptions.VISIT_LINES, VisitLineType.FOLLOW_CODE_SOURCE);

    BytecodeClass[] bytecodeClasses = bytecodeGenerator.gen(InvocationsTest_.$()._2());

    byte[] bytes = bytecodeClasses[0].getBytecode();

    ClassReader cr = new ClassReader(bytes);
    ClassWriter cw = new ClassWriter(cr, ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);

    cr.accept(new MyClassVisitor(Opcodes.ASM5, cw), 0);

    byte[] bytes1 = cw.toByteArray();

    ResultSaver.save(this.getClass(), bytes1);

    BCLoader bcLoader = new BCLoader();

    Class<?> define = bcLoader.define("fullName.InvocationsTest__Generated", bytes1);

    Object o = define.newInstance();

    MethodHandle check = MethodHandles.lookup().findVirtual(define, "check",
            MethodType.methodType(Boolean.TYPE, Integer.TYPE));

    try {/*from w w w .j a va 2s . co m*/
        boolean b = (boolean) check.bindTo(o).invoke(9);
    } catch (Exception e) {
        e.printStackTrace();
    }

    Assert.assertTrue(wrappedPrintStream.printed.contains("Inicializado!"));
    Assert.assertTrue(wrappedPrintStream.printed.contains("XSD"));
}

From source file:com.github.malamut2.low.AllocationClassAdapter.java

License:Apache License

public AllocationClassAdapter(ClassVisitor cv, String recorderClass, String recorderMethod) {
    super(Opcodes.ASM5, cv);
    this.recorderClass = recorderClass;
    this.recorderMethod = recorderMethod;
}

From source file:com.github.malamut2.low.AllocationMethodAdapter.java

License:Apache License

/**
 * A new AllocationMethodAdapter is created for each method that gets visited.
 *//*from   ww w  .ja va  2  s  . c  o  m*/
public AllocationMethodAdapter(MethodVisitor mv, String recorderClass, String recorderMethod) {
    super(Opcodes.ASM5, mv);
    this.recorderClass = recorderClass;
    this.recorderMethod = recorderMethod;
}

From source file:com.github.malamut2.low.VerifyingClassAdapter.java

License:Apache License

/**
 * @param cw A class writer that is wrapped by this class adapter
 * @param original the original bytecode
 * @param className the name of the class being examined.
 *//*from   w ww .ja v  a2  s  .  co m*/
public VerifyingClassAdapter(ClassWriter cw, byte[] original, String className) {
    super(Opcodes.ASM5, cw);
    state = State.UNKNOWN;
    message = "The class has not finished being examined";
    this.cw = cw;
    this.original = original;
    this.className = className.replace('/', '.');
}

From source file:com.github.megatronking.stringfog.plugin.ClassVisitorFactory.java

License:Apache License

private static ClassVisitor createEmpty(ClassWriter cw) {
    return new ClassVisitor(Opcodes.ASM5, cw) {
    };
}

From source file:com.github.megatronking.stringfog.plugin.StringFogClassVisitor.java

License:Apache License

StringFogClassVisitor(IStringFog stringFogImpl, StringFogMappingPrinter mappingPrinter,
        String fogClassName, String key, ClassWriter cw) {
    super(Opcodes.ASM5, cw);
    this.mStringFogImpl = stringFogImpl;
    this.mMappingPrinter = mappingPrinter;
    this.mKey = key;
    this.mFogClassName = fogClassName.replace('.', '/');
}