Example usage for org.objectweb.asm FieldVisitor visitAnnotation

List of usage examples for org.objectweb.asm FieldVisitor visitAnnotation

Introduction

In this page you can find the example usage for org.objectweb.asm FieldVisitor visitAnnotation.

Prototype

public AnnotationVisitor visitAnnotation(final String descriptor, final boolean visible) 

Source Link

Document

Visits an annotation of the field.

Usage

From source file:com.centimia.orm.jaqu.ext.asm.JaquClassAdapter.java

License:Open Source License

@Override
public void visitEnd() {
    if (isEntityAnnotationPresent) {
        FieldVisitor fv = cv.visitField(ACC_PUBLIC + ACC_TRANSIENT, "db", "Lcom/centimia/orm/jaqu/Db;", null,
                null);//from w  w w. j ava  2 s . c om
        fv.visitEnd();

        fv = cv.visitField(ACC_PUBLIC, "isLazy", "Z", null, null);
        // add the jaquIgnore annotaion to the lazy field because we need to carry this field around the network but not persist it
        AnnotationVisitor av = fv.visitAnnotation("Lcom/centimia/orm/jaqu/annotation/JaquIgnore;", true);
        av.visitEnd();
        fv.visitEnd();
    }

    super.visitEnd();
}

From source file:com.facebook.buck.java.abi.AnnotationMirror.java

License:Apache License

public void appendTo(FieldVisitor field) {
    AnnotationVisitor visitor = field.visitAnnotation(desc, visible);
    visitValues(visitor);
    visitor.visitEnd();
}

From source file:com.facebook.presto.byteCode.AnnotationDefinition.java

License:Apache License

public void visitFieldAnnotation(FieldVisitor visitor) {
    AnnotationVisitor annotationVisitor = visitor.visitAnnotation(type.getType(), true);
    visit(annotationVisitor);//from ww  w  .  jav  a2s.  c o  m
    annotationVisitor.visitEnd();
}

From source file:com.googlecode.ddom.weaver.asm.FieldVisitorTee.java

License:Apache License

public AnnotationVisitor visitAnnotation(String desc, boolean visible) {
    AnnotationVisitor result = null;//from   w w w.java2  s.  c  om
    for (FieldVisitor visitor : visitors) {
        result = AnnotationVisitorTee.mergeVisitors(result, visitor.visitAnnotation(desc, visible));
    }
    return result;
}

From source file:com.googlecode.dex2jar.v3.AnnotationNode.java

License:Apache License

public void accept(FieldVisitor fv) {
    AnnotationVisitor av = fv.visitAnnotation(type, visible);
    accept(items, av);
    av.visitEnd();
}

From source file:erjang.beam.CompilerVisitor.java

License:Apache License

@Override
public void visitEnd() {

    // wow, this is where we generate <clinit>

    for (Map.Entry<String, ExtFun> ent : imported.entrySet()) {
        String field_name = ent.getKey();
        ExtFun f = ent.getValue();//from  w  ww. j a  v a2 s.c o m

        FieldVisitor fv = cv.visitField(ACC_STATIC, ent.getKey(), "L" + EFUN_NAME + f.arity + ";", null, null);
        EFun.ensure(f.arity);
        AnnotationVisitor av = fv.visitAnnotation(IMPORT_ANN_TYPE.getDescriptor(), true);
        av.visit("module", f.mod.getName());
        av.visit("fun", f.fun.getName());
        av.visit("arity", f.arity);
        av.visitEnd();
        fv.visitEnd();
    }

    generate_classinit();

    cv.visitEnd();
}

From source file:one.nio.serial.gen.StubGenerator.java

License:Apache License

public static Class generateRegular(String className, String superName, FieldDescriptor[] fds) {
    String internalClassName = getStubName(className);

    ClassWriter cv = new ClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES);
    cv.visit(V1_6, ACC_PUBLIC | ACC_FINAL, internalClassName, null, superName,
            new String[] { "java/io/Serializable" });

    MethodVisitor mv = cv.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
    mv.visitCode();/*w w  w. ja v a2  s . c o  m*/
    mv.visitVarInsn(ALOAD, 0);
    mv.visitMethodInsn(INVOKESPECIAL, superName, "<init>", "()V");
    mv.visitInsn(RETURN);
    mv.visitMaxs(0, 0);
    mv.visitEnd();

    if (fds != null) {
        for (FieldDescriptor fd : fds) {
            String name = fd.name();
            String oldName = null;

            int p = name.indexOf('|');
            if (p >= 0) {
                oldName = name.substring(p + 1);
                name = name.substring(0, p);
            }

            FieldVisitor fv = cv.visitField(ACC_PRIVATE, name, Type.getDescriptor(fd.type().resolve()), null,
                    null);
            if (oldName != null) {
                AnnotationVisitor av = fv.visitAnnotation("Lone/nio/serial/Renamed;", true);
                av.visit("from", oldName);
                av.visitEnd();
            }
            fv.visitEnd();
        }
    }

    cv.visitEnd();
    return INSTANCE.defineClassIfNotExists(internalClassName.replace('/', '.'), cv.toByteArray());
}

From source file:org.adjective.stout.writer.ByteCodeWriter.java

License:Apache License

private void writeField(ClassVisitor cv, FieldDescriptor field) {
    String signature = null; // @TODO
    FieldVisitor fv = cv.visitField(getModifierCode(field.getModifiers(), MemberType.FIELD), field.getName(),
            field.getType().getDescriptor(), signature, null);

    for (AnnotationDescriptor annotation : field.getAnnotations()) {
        AnnotationVisitor av = fv.visitAnnotation(Type.getDescriptor(annotation.getType()),
                annotation.isRuntime());
        processAnnotation(annotation, av);
    }/*from   w ww  .  jav a 2 s.  c o m*/

    fv.visitEnd();
}

From source file:org.apache.aries.proxy.impl.common.AbstractWovenProxyAdapter.java

License:Apache License

/**
 * Generate an instance field that should be "invisible" to normal code
 * // w  ww. j av a  2s . c o m
 * @param fieldName
 * @param fieldDescriptor
 */
private final void generateField(String fieldName, String fieldDescriptor) {
    FieldVisitor fv = cv.visitField(ACC_PROTECTED | ACC_TRANSIENT | ACC_SYNTHETIC | ACC_FINAL, fieldName,
            fieldDescriptor, null, null);
    for (String s : annotationTypeDescriptors)
        fv.visitAnnotation(s, true).visitEnd();
    fv.visitEnd();
}

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;/* w w w .  ja v  a 2 s.  c  o m*/
    }
    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();

}