Example usage for org.objectweb.asm Opcodes GETFIELD

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

Introduction

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

Prototype

int GETFIELD

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

Click Source Link

Usage

From source file:org.actorsguildframework.internal.codegenerator.BeanCreator.java

License:Apache License

/**
 * Writes the accessor methods for @Prop generated properties.
 * @param bcd the class descriptor/*from  w w w  .j  a v a2 s .  c  o m*/
 * @param classNameInternal the internal name of this class
 * @param cw the ClassWriter to write to
 */
public static void writePropAccessors(BeanClassDescriptor bcd, String classNameInternal, ClassWriter cw) {
    String classNameDescriptor = "L" + classNameInternal + ";";

    MethodVisitor mv;
    for (int i = 0; i < bcd.getPropertyCount(); i++) {
        PropertyDescriptor pd = bcd.getProperty(i);
        if (!pd.getPropertySource().isGenerating())
            continue;

        {
            Type t = Type.getType(pd.getPropertyClass());
            Method orig = pd.getGetter();
            mv = cw.visitMethod(
                    GenerationUtils.convertAccessModifiers(orig.getModifiers())
                            + (bcd.isThreadSafe() ? Opcodes.ACC_SYNCHRONIZED : 0),
                    orig.getName(), Type.getMethodDescriptor(orig), GenericTypeHelper.getSignature(orig), null);

            mv.visitCode();
            Label l0 = new Label();
            mv.visitLabel(l0);
            mv.visitVarInsn(Opcodes.ALOAD, 0);
            mv.visitFieldInsn(Opcodes.GETFIELD, classNameInternal,
                    String.format(PROP_FIELD_NAME_TEMPLATE, pd.getName()),
                    Type.getDescriptor(pd.getPropertyClass()));
            mv.visitInsn(t.getOpcode(Opcodes.IRETURN));
            Label l1 = new Label();
            mv.visitLabel(l1);
            mv.visitLocalVariable("this", classNameDescriptor, null, l0, l1, 0);
            mv.visitMaxs(0, 0);
            mv.visitEnd();
        }

        if (pd.getAccess().isWritable()) {
            Type t = Type.getType(pd.getPropertyClass());
            Method orig = pd.getSetter();
            mv = cw.visitMethod(
                    GenerationUtils.convertAccessModifiers(orig.getModifiers())
                            + (bcd.isThreadSafe() ? Opcodes.ACC_SYNCHRONIZED : 0),
                    orig.getName(), Type.getMethodDescriptor(orig), GenericTypeHelper.getSignature(orig), null);

            mv.visitCode();
            Label l0 = new Label();
            mv.visitLabel(l0);
            mv.visitVarInsn(Opcodes.ALOAD, 0);
            mv.visitVarInsn(t.getOpcode(Opcodes.ILOAD), 1);
            mv.visitFieldInsn(Opcodes.PUTFIELD, classNameInternal,
                    String.format(PROP_FIELD_NAME_TEMPLATE, pd.getName()),
                    Type.getDescriptor(pd.getPropertyClass()));
            mv.visitInsn(Opcodes.RETURN);
            Label l1 = new Label();
            mv.visitLabel(l1);
            mv.visitLocalVariable("this", classNameDescriptor, null, l0, l1, 0);
            mv.visitLocalVariable("value", Type.getDescriptor(pd.getPropertyClass()), null, l0, l1, 1);
            mv.visitMaxs(0, 0);
            mv.visitEnd();
        }
    }
}

From source file:org.adjective.stout.operation.GetFieldExpression.java

License:Apache License

public void getInstructions(ExecutionStack stack, InstructionCollector collector) {
    _target.getInstructions(stack, collector);
    String from = (_from == null ? stack.currentClass().getInternalName() : _from.getInternalName());
    addInstruction(collector, new FieldInstruction(Opcodes.GETFIELD, from, _name, _type.getDescriptor()));
}

From source file:org.adjective.stout.tools.StackVisualiserMethodVisitor.java

License:Apache License

public void visitFieldInsn(int opcode, String owner, String name, String desc) {
    String description = owner + "." + name;
    switch (opcode) {
    case Opcodes.GETFIELD:
        pop();/* w  w  w.jav  a2 s. c o m*/
        push(description, desc);
        break;
    case Opcodes.PUTFIELD:
        pop(2);
        break;
    case Opcodes.GETSTATIC:
        push(description, desc);
        break;
    case Opcodes.PUTSTATIC:
        pop(1);
        break;
    }
    print(opcode, description);
}

From source file:org.apache.cxf.binding.corba.utils.CorbaAnyHelper.java

License:Apache License

private static void addReadOverride(ClassWriter cw) {
    MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "read_value",
            "(Lorg/omg/CORBA/portable/InputStream;Lorg/omg/CORBA/TypeCode;)V", null, null);
    mv.visitCode();/*from  www  .jav  a 2 s .co m*/
    Label l0 = new Label();
    mv.visitLabel(l0);
    mv.visitLineNumber(54, l0);
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitFieldInsn(Opcodes.GETFIELD, "org/apache/cxf/binding/corba/utils/FixedAnyImpl", "obj",
            "Lorg/omg/CORBA/portable/Streamable;");
    Label l1 = new Label();
    mv.visitJumpInsn(Opcodes.IFNULL, l1);
    Label l2 = new Label();
    mv.visitLabel(l2);
    mv.visitLineNumber(55, l2);
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitFieldInsn(Opcodes.GETFIELD, "org/apache/cxf/binding/corba/utils/FixedAnyImpl", "obj",
            "Lorg/omg/CORBA/portable/Streamable;");
    mv.visitVarInsn(Opcodes.ALOAD, 1);
    mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "org/omg/CORBA/portable/Streamable", "_read",
            "(Lorg/omg/CORBA/portable/InputStream;)V");
    Label l3 = new Label();
    mv.visitJumpInsn(Opcodes.GOTO, l3);
    mv.visitLabel(l1);
    mv.visitLineNumber(57, l1);
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitVarInsn(Opcodes.ALOAD, 1);
    mv.visitVarInsn(Opcodes.ALOAD, 2);
    mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "com/sun/corba/se/impl/corba/AnyImpl", "read_value",
            "(Lorg/omg/CORBA/portable/InputStream;Lorg/omg/CORBA/TypeCode;)V");
    mv.visitLabel(l3);
    mv.visitLineNumber(59, l3);
    mv.visitInsn(Opcodes.RETURN);
    Label l4 = new Label();
    mv.visitLabel(l4);
    mv.visitLocalVariable("this", "Lorg/apache/cxf/binding/corba/utils/FixedAnyImpl;", null, l0, l4, 0);
    mv.visitLocalVariable("is", "Lorg/omg/CORBA/portable/InputStream;", null, l0, l4, 1);
    mv.visitLocalVariable("t", "Lorg/omg/CORBA/TypeCode;", null, l0, l4, 2);
    mv.visitMaxs(3, 3);
    mv.visitEnd();
}

From source file:org.apache.cxf.binding.corba.utils.CorbaAnyHelper.java

License:Apache License

private static void addWriteOverride(ClassWriter cw) {
    MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "write_value",
            "(Lorg/omg/CORBA/portable/OutputStream;)V", null, null);
    mv.visitCode();//from www.  ja  v a2s.c  o  m
    Label l0 = new Label();
    mv.visitLabel(l0);
    mv.visitLineNumber(61, l0);
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitFieldInsn(Opcodes.GETFIELD, "org/apache/cxf/binding/corba/utils/FixedAnyImpl", "obj",
            "Lorg/omg/CORBA/portable/Streamable;");
    Label l1 = new Label();
    mv.visitJumpInsn(Opcodes.IFNULL, l1);
    Label l2 = new Label();
    mv.visitLabel(l2);
    mv.visitLineNumber(62, l2);
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitFieldInsn(Opcodes.GETFIELD, "org/apache/cxf/binding/corba/utils/FixedAnyImpl", "obj",
            "Lorg/omg/CORBA/portable/Streamable;");
    mv.visitVarInsn(Opcodes.ALOAD, 1);
    mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "org/omg/CORBA/portable/Streamable", "_write",
            "(Lorg/omg/CORBA/portable/OutputStream;)V");
    Label l3 = new Label();
    mv.visitJumpInsn(Opcodes.GOTO, l3);
    mv.visitLabel(l1);
    mv.visitLineNumber(64, l1);
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitVarInsn(Opcodes.ALOAD, 1);
    mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "com/sun/corba/se/impl/corba/AnyImpl", "write_value",
            "(Lorg/omg/CORBA/portable/OutputStream;)V");
    mv.visitLabel(l3);
    mv.visitLineNumber(66, l3);
    mv.visitInsn(Opcodes.RETURN);
    Label l4 = new Label();
    mv.visitLabel(l4);
    mv.visitLocalVariable("this", "Lorg/apache/cxf/binding/corba/utils/FixedAnyImpl;", null, l0, l4, 0);
    mv.visitLocalVariable("os", "Lorg/omg/CORBA/portable/OutputStream;", null, l0, l4, 1);
    mv.visitMaxs(2, 2);
    mv.visitEnd();

}

From source file:org.apache.cxf.binding.corba.utils.CorbaAnyHelper.java

License:Apache License

private static void addExtractOverride(ClassWriter cw) {
    // TODO Auto-generated method stub
    MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "extract_Streamable",
            "()Lorg/omg/CORBA/portable/Streamable;", null, null);
    mv.visitCode();/*ww  w .j  av a2  s.  co m*/
    Label l0 = new Label();
    mv.visitLabel(l0);
    mv.visitLineNumber(47, l0);
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitFieldInsn(Opcodes.GETFIELD, "org/apache/cxf/binding/corba/utils/FixedAnyImpl", "obj",
            "Lorg/omg/CORBA/portable/Streamable;");
    Label l1 = new Label();
    mv.visitJumpInsn(Opcodes.IFNULL, l1);
    Label l2 = new Label();
    mv.visitLabel(l2);
    mv.visitLineNumber(48, l2);
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitFieldInsn(Opcodes.GETFIELD, "org/apache/cxf/binding/corba/utils/FixedAnyImpl", "obj",
            "Lorg/omg/CORBA/portable/Streamable;");
    mv.visitInsn(Opcodes.ARETURN);
    mv.visitLabel(l1);
    mv.visitLineNumber(50, l1);
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "com/sun/corba/se/impl/corba/AnyImpl", "extract_Streamable",
            "()Lorg/omg/CORBA/portable/Streamable;");
    mv.visitInsn(Opcodes.ARETURN);
    Label l3 = new Label();
    mv.visitLabel(l3);
    mv.visitLocalVariable("this", "Lorg/apache/cxf/binding/corba/utils/FixedAnyImpl;", null, l0, l3, 0);
    mv.visitMaxs(1, 1);
    mv.visitEnd();

}

From source file:org.apache.cxf.jaxb.JAXBUtils.java

License:Apache License

private static Class<?> createNamespaceWrapperInternal(ASMHelper helper, ClassWriter cw) {
    String className = "org.apache.cxf.jaxb.NamespaceMapperInternal";
    FieldVisitor fv;//from  w  ww. j  a v a  2  s.  c o  m
    MethodVisitor mv;
    cw.visit(Opcodes.V1_5, Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL + Opcodes.ACC_SUPER,
            "org/apache/cxf/jaxb/NamespaceMapperInternal", null,
            "com/sun/xml/internal/bind/marshaller/NamespacePrefixMapper", null);

    cw.visitSource("NamespaceMapper.java", null);

    fv = cw.visitField(Opcodes.ACC_PRIVATE + Opcodes.ACC_FINAL, "nspref", "Ljava/util/Map;",
            "Ljava/util/Map<Ljava/lang/String;Ljava/lang/String;>;", null);
    fv.visitEnd();

    mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "<init>", "(Ljava/util/Map;)V",
            "(Ljava/util/Map<Ljava/lang/String;Ljava/lang/String;>;)V", null);
    mv.visitCode();
    Label l0 = new Label();
    mv.visitLabel(l0);
    mv.visitLineNumber(30, l0);
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "com/sun/xml/internal/bind/marshaller/NamespacePrefixMapper",
            "<init>", "()V");
    Label l1 = new Label();
    mv.visitLabel(l1);
    mv.visitLineNumber(31, l1);
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitVarInsn(Opcodes.ALOAD, 1);
    mv.visitFieldInsn(Opcodes.PUTFIELD, "org/apache/cxf/jaxb/NamespaceMapperInternal", "nspref",
            "Ljava/util/Map;");
    Label l2 = new Label();
    mv.visitLabel(l2);
    mv.visitLineNumber(32, l2);
    mv.visitInsn(Opcodes.RETURN);
    Label l3 = new Label();
    mv.visitLabel(l3);
    mv.visitLocalVariable("this", "Lorg/apache/cxf/jaxb/NamespaceMapperInternal;", null, l0, l3, 0);
    mv.visitLocalVariable("nspref", "Ljava/util/Map;", "Ljava/util/Map<Ljava/lang/String;Ljava/lang/String;>;",
            l0, l3, 1);
    mv.visitMaxs(2, 2);
    mv.visitEnd();

    mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "getPreferredPrefix",
            "(Ljava/lang/String;Ljava/lang/String;Z)Ljava/lang/String;", null, null);
    mv.visitCode();
    l0 = new Label();
    mv.visitLabel(l0);
    mv.visitLineNumber(38, l0);
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitFieldInsn(Opcodes.GETFIELD, "org/apache/cxf/jaxb/NamespaceMapperInternal", "nspref",
            "Ljava/util/Map;");
    mv.visitVarInsn(Opcodes.ALOAD, 1);
    mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/Map", "get",
            "(Ljava/lang/Object;)Ljava/lang/Object;");
    mv.visitTypeInsn(Opcodes.CHECKCAST, "java/lang/String");
    mv.visitVarInsn(Opcodes.ASTORE, 4);
    l1 = new Label();
    mv.visitLabel(l1);
    mv.visitLineNumber(39, l1);
    mv.visitVarInsn(Opcodes.ALOAD, 4);
    l2 = new Label();
    mv.visitJumpInsn(Opcodes.IFNULL, l2);
    l3 = new Label();
    mv.visitLabel(l3);
    mv.visitLineNumber(40, l3);
    mv.visitVarInsn(Opcodes.ALOAD, 4);
    mv.visitInsn(Opcodes.ARETURN);
    mv.visitLabel(l2);
    mv.visitLineNumber(42, l2);
    mv.visitVarInsn(Opcodes.ALOAD, 2);
    mv.visitInsn(Opcodes.ARETURN);
    Label l4 = new Label();
    mv.visitLabel(l4);
    mv.visitLocalVariable("this", "Lorg/apache/cxf/jaxb/NamespaceMapperInternal;", null, l0, l4, 0);
    mv.visitLocalVariable("namespaceUri", "Ljava/lang/String;", null, l0, l4, 1);
    mv.visitLocalVariable("suggestion", "Ljava/lang/String;", null, l0, l4, 2);
    mv.visitLocalVariable("requirePrefix", "Z", null, l0, l4, 3);
    mv.visitLocalVariable("prefix", "Ljava/lang/String;", null, l1, l4, 4);
    mv.visitMaxs(2, 5);
    mv.visitEnd();
    cw.visitEnd();

    byte bts[] = cw.toByteArray();
    return helper.loadClass(className, JAXBUtils.class, bts);
}

From source file:org.apache.cxf.jaxb.WrapperHelperCompiler.java

License:Apache License

private boolean addCreateWrapperObject(String newClassName, Class<?> objectFactoryClass) {

    MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "createWrapperObject",
            "(Ljava/util/List;)Ljava/lang/Object;", "(Ljava/util/List<*>;)Ljava/lang/Object;",
            new String[] { "org/apache/cxf/interceptor/Fault" });
    mv.visitCode();//from w w w .  j  a  v a2 s . c o m
    Label lBegin = new Label();
    mv.visitLabel(lBegin);
    mv.visitLineNumber(104, lBegin);

    mv.visitTypeInsn(Opcodes.NEW, periodToSlashes(wrapperType.getName()));
    mv.visitInsn(Opcodes.DUP);
    mv.visitMethodInsn(Opcodes.INVOKESPECIAL, periodToSlashes(wrapperType.getName()), "<init>", "()V");
    mv.visitVarInsn(Opcodes.ASTORE, 2);

    for (int x = 0; x < setMethods.length; x++) {
        if (getMethods[x] == null) {
            if (setMethods[x] == null && fields[x] == null) {
                // null placeholder
                continue;
            } else {
                return false;
            }
        }
        Class<?> tp = getMethods[x].getReturnType();
        mv.visitVarInsn(Opcodes.ALOAD, 2);

        if (List.class.isAssignableFrom(tp)) {
            doCollection(mv, x);
        } else {
            if (JAXBElement.class.isAssignableFrom(tp)) {
                mv.visitVarInsn(Opcodes.ALOAD, 0);
                mv.visitFieldInsn(Opcodes.GETFIELD, periodToSlashes(newClassName), "factory",
                        "L" + periodToSlashes(objectFactoryClass.getName()) + ";");
            }
            mv.visitVarInsn(Opcodes.ALOAD, 1);
            mv.visitIntInsn(Opcodes.BIPUSH, x);
            mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/List", "get", "(I)Ljava/lang/Object;");

            if (tp.isPrimitive()) {
                mv.visitTypeInsn(Opcodes.CHECKCAST, NONPRIMITIVE_MAP.get(tp));
                mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, NONPRIMITIVE_MAP.get(tp), tp.getName() + "Value",
                        "()" + PRIMITIVE_MAP.get(tp));
            } else if (JAXBElement.class.isAssignableFrom(tp)) {
                mv.visitTypeInsn(Opcodes.CHECKCAST,
                        periodToSlashes(jaxbMethods[x].getParameterTypes()[0].getName()));
                mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, periodToSlashes(objectFactoryClass.getName()),
                        jaxbMethods[x].getName(), getMethodSignature(jaxbMethods[x]));
            } else if (tp.isArray()) {
                mv.visitTypeInsn(Opcodes.CHECKCAST, getClassCode(tp));
            } else {
                mv.visitTypeInsn(Opcodes.CHECKCAST, periodToSlashes(tp.getName()));
            }
            mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, periodToSlashes(wrapperType.getName()),
                    setMethods[x].getName(), "(" + getClassCode(tp) + ")V");
        }
    }

    mv.visitVarInsn(Opcodes.ALOAD, 2);
    mv.visitInsn(Opcodes.ARETURN);

    Label lEnd = new Label();
    mv.visitLabel(lEnd);
    mv.visitLocalVariable("this", "L" + newClassName + ";", null, lBegin, lEnd, 0);
    mv.visitLocalVariable("lst", "Ljava/util/List;", "Ljava/util/List<*>;", lBegin, lEnd, 1);
    mv.visitLocalVariable("ok", "L" + periodToSlashes(wrapperType.getName()) + ";", null, lBegin, lEnd, 2);
    mv.visitMaxs(0, 0);
    mv.visitEnd();
    return true;
}

From source file:org.apache.cxf.jaxws.WrapperClassGenerator.java

License:Apache License

private void generateMessagePart(ClassWriter cw, MessagePartInfo mpi, Method method, String className) {
    if (Boolean.TRUE.equals(mpi.getProperty(ReflectionServiceFactoryBean.HEADER))) {
        return;// ww  w .j a  v  a2  s.  com
    }
    String classFileName = periodToSlashes(className);
    String name = mpi.getName().getLocalPart();
    Class clz = mpi.getTypeClass();
    Object obj = mpi.getProperty(ReflectionServiceFactoryBean.RAW_CLASS);
    if (obj != null) {
        clz = (Class) obj;
    }
    Type genericType = (Type) mpi.getProperty(ReflectionServiceFactoryBean.GENERIC_TYPE);
    if (genericType instanceof ParameterizedType) {
        ParameterizedType tp = (ParameterizedType) genericType;
        if (tp.getRawType() instanceof Class && Holder.class.isAssignableFrom((Class) tp.getRawType())) {
            genericType = tp.getActualTypeArguments()[0];
        }
    }
    String classCode = getClassCode(clz);
    String fieldDescriptor = null;

    if (genericType instanceof ParameterizedType) {
        if (Collection.class.isAssignableFrom(clz) || clz.isArray()) {
            ParameterizedType ptype = (ParameterizedType) genericType;

            Type[] types = ptype.getActualTypeArguments();
            // TODO: more complex Parameterized type
            if (types.length > 0) {
                if (types[0] instanceof Class) {
                    fieldDescriptor = getClassCode(genericType);
                } else if (types[0] instanceof GenericArrayType) {
                    fieldDescriptor = getClassCode(genericType);
                } else if (types[0] instanceof ParameterizedType) {
                    classCode = getClassCode(((ParameterizedType) types[0]).getRawType());
                    fieldDescriptor = getClassCode(genericType);
                }
            }
        } else {
            classCode = getClassCode(((ParameterizedType) genericType).getRawType());
            fieldDescriptor = getClassCode(genericType);
        }
    }
    String fieldName = JavaUtils.isJavaKeyword(name) ? JavaUtils.makeNonJavaKeyword(name) : name;

    FieldVisitor fv = cw.visitField(Opcodes.ACC_PRIVATE, fieldName, classCode, fieldDescriptor, null);

    AnnotationVisitor av0 = fv.visitAnnotation("Ljavax/xml/bind/annotation/XmlElement;", true);
    av0.visit("name", name);
    if (factory.isWrapperPartQualified(mpi)) {
        av0.visit("namespace", mpi.getConcreteName().getNamespaceURI());
    }
    if (factory.isWrapperPartNillable(mpi)) {
        av0.visit("nillable", Boolean.TRUE);
    }
    if (factory.getWrapperPartMinOccurs(mpi) == 1) {
        av0.visit("required", Boolean.TRUE);
    }
    av0.visitEnd();

    List<Annotation> jaxbAnnos = getJaxbAnnos(mpi);
    addJAXBAnnotations(fv, jaxbAnnos);
    fv.visitEnd();

    String methodName = JAXBUtils.nameToIdentifier(name, JAXBUtils.IdentifierType.GETTER);
    MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, methodName, "()" + classCode,
            fieldDescriptor == null ? null : "()" + fieldDescriptor, null);
    mv.visitCode();

    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitFieldInsn(Opcodes.GETFIELD, classFileName, fieldName, classCode);
    mv.visitInsn(org.objectweb.asm.Type.getType(classCode).getOpcode(Opcodes.IRETURN));
    mv.visitMaxs(0, 0);
    mv.visitEnd();

    methodName = JAXBUtils.nameToIdentifier(name, JAXBUtils.IdentifierType.SETTER);
    mv = cw.visitMethod(Opcodes.ACC_PUBLIC, methodName, "(" + classCode + ")V",
            fieldDescriptor == null ? null : "(" + fieldDescriptor + ")V", null);
    mv.visitCode();
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    org.objectweb.asm.Type setType = org.objectweb.asm.Type.getType(classCode);
    mv.visitVarInsn(setType.getOpcode(Opcodes.ILOAD), 1);
    mv.visitFieldInsn(Opcodes.PUTFIELD, className, fieldName, classCode);
    mv.visitInsn(Opcodes.RETURN);
    mv.visitMaxs(0, 0);
    mv.visitEnd();

}

From source file:org.apache.drill.exec.compile.bytecode.InstructionModifier.java

License:Apache License

@Override
public void visitFieldInsn(int opcode, String owner, String name, String desc) {
    ReplacingBasicValue v;/*  w  ww .ja va 2s  . c o  m*/

    switch (opcode) {
    case Opcodes.PUTFIELD:
        // pop twice for put.
        v = popCurrent(true);
        if (v != null) {
            if (v.isFunctionReturn) {
                super.visitFieldInsn(opcode, owner, name, desc);
                return;
            } else {
                // we are trying to store a replaced variable in an external context, we need to generate an instance and
                // transfer it out.
                ValueHolderSub sub = oldToNew.get(v.getIndex());
                sub.transferToExternal(adder, owner, name, desc);
                return;
            }
        }

    case Opcodes.GETFIELD:
        // pop again.
        v = popCurrent();
        if (v != null) {
            // super.visitFieldInsn(opcode, owner, name, desc);
            ValueHolderSub sub = oldToNew.get(v.getIndex());
            sub.addInsn(name, this, opcode);
            return;
        }
    }

    super.visitFieldInsn(opcode, owner, name, desc);
}