Example usage for org.objectweb.asm Opcodes INVOKEVIRTUAL

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

Introduction

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

Prototype

int INVOKEVIRTUAL

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

Click Source Link

Usage

From source file:com.asakusafw.dag.compiler.codegen.VertexAdapterGenerator.java

License:Apache License

private static void putConf(MethodVisitor method, ClassDescription target, LocalVarRef self,
        ClassDescription value, String name) {
    self.load(method);/*from   ww w.  java  2  s .co m*/
    getConst(method, value);
    method.visitMethodInsn(Opcodes.INVOKEVIRTUAL, target.getInternalName(), name,
            Type.getMethodDescriptor(typeOf(VertexAdapter.class), typeOf(Class.class)), false);
    method.visitInsn(Opcodes.POP);
}

From source file:com.asakusafw.dag.compiler.directio.DirectFileInputAdapterGenerator.java

License:Apache License

/**
 * Generates {@link DirectFileInputAdapter} class.
 * @param context the current context/* w w  w . ja  v  a 2s  . com*/
 * @param input the target input spec
 * @param target the target class
 * @return the generated class data
 */
public ClassData generate(ClassGeneratorContext context, Spec input, ClassDescription target) {
    ClassWriter writer = newWriter(target, DirectFileInputAdapter.class);
    defineAdapterConstructor(writer, DirectFileInputAdapter.class, v -> {
        v.visitVarInsn(Opcodes.ALOAD, 0);
        getConst(v, input.id);
        getConst(v, input.basePath);
        getConst(v, input.resourcePattern);
        getConst(v, input.dataFormat);
        getConst(v, input.dataFilter);
        getConst(v, input.optional);
        v.visitMethodInsn(Opcodes.INVOKEVIRTUAL, target.getInternalName(), "bind", //$NON-NLS-1$
                Type.getMethodDescriptor(typeOf(DirectFileInputAdapter.class), typeOf(String.class),
                        typeOf(String.class), typeOf(String.class), typeOf(Class.class), typeOf(Class.class),
                        typeOf(boolean.class)),
                false);
        v.visitInsn(Opcodes.POP);
    });
    writer.visitEnd();
    return new ClassData(target, writer::toByteArray);
}

From source file:com.asakusafw.dag.compiler.directio.DirectFileOutputCommitGenerator.java

License:Apache License

/**
 * Generates {@link DirectFileOutputCommit} class.
 * @param context the current context//ww  w. jav a 2s  .c o  m
 * @param specs the binding specs
 * @param target the target class
 * @return the generated class data
 */
public ClassData generate(ClassGeneratorContext context, List<Spec> specs, ClassDescription target) {
    ClassWriter writer = newWriter(target, DirectFileOutputCommit.class);
    defineEmptyConstructor(writer, DirectFileOutputCommit.class, v -> {
        LocalVarRef self = new LocalVarRef(Opcodes.ALOAD, 0);
        for (Spec spec : specs) {
            self.load(v);
            getConst(v, spec.id);
            getConst(v, spec.basePath);
            v.visitMethodInsn(Opcodes.INVOKEVIRTUAL, target.getInternalName(), "bind", //$NON-NLS-1$
                    Type.getMethodDescriptor(typeOf(DirectFileOutputCommit.class), typeOf(String.class),
                            typeOf(String.class)),
                    false);
            v.visitInsn(Opcodes.POP);
        }
    });
    return new ClassData(target, writer::toByteArray);
}

From source file:com.asakusafw.dag.compiler.directio.DirectFileOutputPrepareGenerator.java

License:Apache License

/**
 * Generates {@link DirectFileOutputPrepare} class.
 * @param context the current context/*from   ww w .j a  v a  2  s  .  c  o  m*/
 * @param specs the binding specs
 * @param target the target class
 * @return the generated class data
 */
public ClassData generate(ClassGeneratorContext context, List<Spec> specs, ClassDescription target) {
    ClassWriter writer = newWriter(target, DirectFileOutputPrepare.class);
    defineEmptyConstructor(writer, DirectFileOutputPrepare.class, v -> {
        LocalVarRef self = new LocalVarRef(Opcodes.ALOAD, 0);
        for (Spec spec : specs) {
            self.load(v);
            getConst(v, spec.id);
            getConst(v, spec.basePath);
            getConst(v, spec.outputPattern);
            getConst(v, spec.formatType);
            v.visitMethodInsn(Opcodes.INVOKEVIRTUAL, target.getInternalName(), "bind", //$NON-NLS-1$
                    Type.getMethodDescriptor(typeOf(DirectFileOutputPrepare.class), typeOf(String.class),
                            typeOf(String.class), typeOf(String.class), typeOf(Class.class)),
                    false);
            v.visitInsn(Opcodes.POP);
        }
    });
    return new ClassData(target, writer::toByteArray);
}

From source file:com.asakusafw.dag.compiler.directio.DirectFileOutputSetupGenerator.java

License:Apache License

/**
 * Generates {@link DirectFileOutputSetup} class.
 * @param context the current context/*from   w w w .  j  a  va2 s . com*/
 * @param specs the binding specs
 * @param target the target class
 * @return the generated class data
 */
public ClassData generate(ClassGeneratorContext context, List<Spec> specs, ClassDescription target) {
    ClassWriter writer = newWriter(target, DirectFileOutputSetup.class);
    defineEmptyConstructor(writer, DirectFileOutputSetup.class, v -> {
        LocalVarRef self = new LocalVarRef(Opcodes.ALOAD, 0);
        for (Spec spec : specs) {
            self.load(v);
            getConst(v, spec.id);
            getConst(v, spec.basePath);
            getArray(v, spec.deletePatterns.stream().toArray(String[]::new));
            v.visitMethodInsn(Opcodes.INVOKEVIRTUAL, target.getInternalName(), "bind", //$NON-NLS-1$
                    Type.getMethodDescriptor(typeOf(DirectFileOutputSetup.class), typeOf(String.class),
                            typeOf(String.class), typeOf(String[].class)),
                    false);
            v.visitInsn(Opcodes.POP);
        }
    });
    return new ClassData(target, writer::toByteArray);
}

From source file:com.asakusafw.dag.compiler.directio.OutputPatternSerDeGenerator.java

License:Apache License

private static void putCtor(ClassWriter writer, DataModelReference reference, FieldRef buffer,
        OutputPattern pattern, ClassDescription target) {
    defineEmptyConstructor(writer, OutputPatternSerDe.class, v -> {
        LocalVarRef self = new LocalVarRef(Opcodes.ALOAD, 0);
        self.load(v);//from   w ww . j  a v a  2s. co  m
        getNew(v, reference.getDeclaration());
        putField(v, buffer);

        for (CompiledSegment segment : pattern.getResourcePattern()) {
            self.load(v);
            switch (segment.getKind()) {
            case NOTHING:
                getConst(v, segment.getArgument());
                v.visitMethodInsn(Opcodes.INVOKEVIRTUAL, target.getInternalName(), "text", //$NON-NLS-1$
                        Type.getMethodDescriptor(typeOf(OutputPatternSerDe.class), typeOf(String.class)),
                        false);
                break;
            case PROPERTY:
                switch (segment.getFormat()) {
                case NATURAL:
                    getEnumConstant(v, OutputPatternSerDe.Format.NATURAL);
                    break;
                case BYTE:
                    getEnumConstant(v, OutputPatternSerDe.Format.BYTE);
                    break;
                case SHORT:
                    getEnumConstant(v, OutputPatternSerDe.Format.SHORT);
                    break;
                case INT:
                    getEnumConstant(v, OutputPatternSerDe.Format.INT);
                    break;
                case LONG:
                    getEnumConstant(v, OutputPatternSerDe.Format.LONG);
                    break;
                case FLOAT:
                    getEnumConstant(v, OutputPatternSerDe.Format.FLOAT);
                    break;
                case DOUBLE:
                    getEnumConstant(v, OutputPatternSerDe.Format.DOUBLE);
                    break;
                case DECIMAL:
                    getEnumConstant(v, OutputPatternSerDe.Format.DECIMAL);
                    break;
                case DATE:
                    getEnumConstant(v, OutputPatternSerDe.Format.DATE);
                    break;
                case DATETIME:
                    getEnumConstant(v, OutputPatternSerDe.Format.DATETIME);
                    break;
                default:
                    throw new AssertionError(pattern.getResourcePatternString());
                }
                getConst(v, segment.getArgument());
                v.visitMethodInsn(Opcodes.INVOKEVIRTUAL, target.getInternalName(), "property", //$NON-NLS-1$
                        Type.getMethodDescriptor(typeOf(OutputPatternSerDe.class),
                                typeOf(OutputPatternSerDe.Format.class), typeOf(String.class)),
                        false);
                break;
            case RANDOM:
                getInt(v, segment.getRandomNumber().getLowerBound());
                getInt(v, segment.getRandomNumber().getUpperBound());
                v.visitMethodInsn(Opcodes.INVOKEVIRTUAL, target.getInternalName(), "random", //$NON-NLS-1$
                        Type.getMethodDescriptor(typeOf(OutputPatternSerDe.class), typeOf(int.class),
                                typeOf(int.class)),
                        false);
                break;
            default:
                throw new AssertionError(pattern.getResourcePatternString());
            }
            v.visitInsn(Opcodes.POP);
        }
    });
}

From source file:com.asakusafw.dag.compiler.internalio.InternalInputAdapterGenerator.java

License:Apache License

/**
 * Generates {@link InternalInputAdapter} class.
 * @param context the current context//from w w  w .  ja va  2s.c  o m
 * @param spec the target input spec
 * @param target the target class
 * @return the generated class data
 */
public ClassData generate(ClassGeneratorContext context, Spec spec, ClassDescription target) {
    ClassWriter writer = newWriter(target, InternalInputAdapter.class);
    defineAdapterConstructor(writer, InternalInputAdapter.class, v -> {
        v.visitVarInsn(Opcodes.ALOAD, 0);
        getConst(v, spec.id);
        getArray(v, spec.paths.stream().toArray(String[]::new));
        getConst(v, spec.dataType);
        v.visitMethodInsn(Opcodes.INVOKEVIRTUAL, target.getInternalName(), "bind", //$NON-NLS-1$
                Type.getMethodDescriptor(typeOf(InternalInputAdapter.class), typeOf(String.class),
                        typeOf(String[].class), typeOf(Class.class)),
                false);
        v.visitInsn(Opcodes.POP);
    });
    return new ClassData(target, writer::toByteArray);
}

From source file:com.asakusafw.dag.compiler.internalio.InternalOutputAdapterGenerator.java

License:Apache License

/**
 * Generates {@link InternalOutputAdapter} class.
 * @param context the current context/*from w w  w  . j ava2 s  .com*/
 * @param outputs the target output specs
 * @param target the target class
 * @return the generated class data
 */
public ClassData generate(ClassGeneratorContext context, List<Spec> outputs, ClassDescription target) {
    ClassWriter writer = newWriter(target, InternalOutputAdapter.class);
    defineAdapterConstructor(writer, InternalOutputAdapter.class, v -> {
        for (Spec spec : outputs) {
            v.visitVarInsn(Opcodes.ALOAD, 0);
            getConst(v, spec.id);
            getConst(v, spec.path);
            getConst(v, spec.dataType);
            v.visitMethodInsn(Opcodes.INVOKEVIRTUAL, target.getInternalName(), "bind", //$NON-NLS-1$
                    Type.getMethodDescriptor(typeOf(InternalOutputAdapter.class), typeOf(String.class),
                            typeOf(String.class), typeOf(Class.class)),
                    false);
            v.visitInsn(Opcodes.POP);
        }
    });
    return new ClassData(target, writer::toByteArray);
}

From source file:com.asakusafw.dag.compiler.internalio.InternalOutputPrepareGenerator.java

License:Apache License

/**
 * Generates {@link InternalOutputPrepare} class.
 * @param context the current context/*from   w  ww .j  av  a2 s.  c o m*/
 * @param specs the target output specs
 * @param target the target class
 * @return the generated class data
 */
public ClassData generate(ClassGeneratorContext context, List<Spec> specs, ClassDescription target) {
    ClassWriter writer = newWriter(target, InternalOutputPrepare.class);
    defineEmptyConstructor(writer, InternalOutputPrepare.class, v -> {
        LocalVarRef self = new LocalVarRef(Opcodes.ALOAD, 0);
        for (Spec spec : specs) {
            self.load(v);
            getConst(v, spec.id);
            getConst(v, spec.path);
            getConst(v, spec.dataType);
            v.visitMethodInsn(Opcodes.INVOKEVIRTUAL, target.getInternalName(), "bind", //$NON-NLS-1$
                    Type.getMethodDescriptor(typeOf(InternalOutputPrepare.class), typeOf(String.class),
                            typeOf(String.class), typeOf(Class.class)),
                    false);
            v.visitInsn(Opcodes.POP);
        }
    });
    return new ClassData(target, writer::toByteArray);
}

From source file:com.asakusafw.dag.compiler.jdbc.PreparedStatementAdapterGenerator.java

License:Apache License

private static void defineBody(ClassWriter writer, DataModelReference dataType,
        List<PropertyReference> properties, Optional<FieldRef> dateBuf) {
    MethodVisitor v = writer.visitMethod(Opcodes.ACC_PUBLIC, "drive", //$NON-NLS-1$
            Type.getMethodDescriptor(typeOf(void.class), typeOf(PreparedStatement.class), typeOf(Object.class)),
            null, new String[] { typeOf(SQLException.class).getInternalName(), });
    LocalVarRef row = new LocalVarRef(Opcodes.ALOAD, 1);
    LocalVarRef object = cast(v, 2, dataType.getDeclaration());

    int columnIndex = 0;
    for (PropertyReference property : properties) {
        columnIndex++;/*from  w  w w.  j a v a 2s .  com*/

        object.load(v);
        getOption(v, property);
        LocalVarRef option = putLocalVar(v, Type.OBJECT, 3);

        Label elseIf = new Label();
        Label endIf = new Label();

        // if (option.isNull()) {
        option.load(v);
        v.visitMethodInsn(Opcodes.INVOKEVIRTUAL, typeOf(ValueOption.class).getInternalName(), "isNull", //$NON-NLS-1$
                Type.getMethodDescriptor(typeOf(boolean.class)), false);
        v.visitJumpInsn(Opcodes.IFEQ, elseIf);

        row.load(v);
        getConst(v, columnIndex);
        doSetNull(v, property);

        v.visitJumpInsn(Opcodes.GOTO, endIf);

        // } else { @elseIf
        v.visitLabel(elseIf);

        row.load(v);
        getConst(v, columnIndex);
        option.load(v);
        doSetValue(v, property, dateBuf);

        // } @endIf
        v.visitLabel(endIf);
    }

    v.visitInsn(Opcodes.RETURN);
    v.visitMaxs(0, 0);
    v.visitEnd();
}