Search in sources :

Example 76 with FieldVisitor

use of org.objectweb.asm.FieldVisitor in project groovy-core by groovy.

the class AsmClassGenerator method visitField.

public void visitField(FieldNode fieldNode) {
    onLineNumber(fieldNode, "visitField: " + fieldNode.getName());
    ClassNode t = fieldNode.getType();
    String signature = BytecodeHelper.getGenericsBounds(t);
    Expression initialValueExpression = fieldNode.getInitialValueExpression();
    ConstantExpression cexp = initialValueExpression instanceof ConstantExpression ? (ConstantExpression) initialValueExpression : null;
    if (cexp != null) {
        cexp = Verifier.transformToPrimitiveConstantIfPossible(cexp);
    }
    Object value = cexp != null && ClassHelper.isStaticConstantInitializerType(cexp.getType()) && cexp.getType().equals(t) && fieldNode.isStatic() && fieldNode.isFinal() ? // GROOVY-5150
    cexp.getValue() : null;
    if (value != null) {
        // byte, char and short require an extra cast
        if (ClassHelper.byte_TYPE.equals(t) || ClassHelper.short_TYPE.equals(t)) {
            value = ((Number) value).intValue();
        } else if (ClassHelper.char_TYPE.equals(t)) {
            value = Integer.valueOf((Character) value);
        }
    }
    FieldVisitor fv = cv.visitField(fieldNode.getModifiers(), fieldNode.getName(), BytecodeHelper.getTypeDescription(t), signature, value);
    visitAnnotations(fieldNode, fv);
    fv.visitEnd();
}
Also used : InnerClassNode(org.codehaus.groovy.ast.InnerClassNode) InterfaceHelperClassNode(org.codehaus.groovy.ast.InterfaceHelperClassNode) ClassNode(org.codehaus.groovy.ast.ClassNode) FieldVisitor(org.objectweb.asm.FieldVisitor)

Example 77 with FieldVisitor

use of org.objectweb.asm.FieldVisitor in project gravel by gravel-st.

the class ASMClassWriter method createField.

private void createField(JVMField field) {
    FieldVisitor fv = cw.visitField(ACC_PUBLIC | (field.isStatic() ? ACC_STATIC : 0), field.varName(), field.type().descriptorString(), null, null);
    fv.visitEnd();
}
Also used : FieldVisitor(org.objectweb.asm.FieldVisitor)

Example 78 with FieldVisitor

use of org.objectweb.asm.FieldVisitor in project maple-ir by LLVM-but-worse.

the class FieldNode method accept.

/**
 * Makes the given class visitor visit this field.
 *
 * @param cv
 *            a class visitor.
 */
public void accept(final ClassVisitor cv) {
    FieldVisitor fv = cv.visitField(access, name, desc, signature, value);
    if (fv == null) {
        return;
    }
    int i, n;
    n = visibleAnnotations == null ? 0 : visibleAnnotations.size();
    for (i = 0; i < n; ++i) {
        AnnotationNode an = visibleAnnotations.get(i);
        an.accept(fv.visitAnnotation(an.desc, true));
    }
    n = invisibleAnnotations == null ? 0 : invisibleAnnotations.size();
    for (i = 0; i < n; ++i) {
        AnnotationNode an = invisibleAnnotations.get(i);
        an.accept(fv.visitAnnotation(an.desc, false));
    }
    n = visibleTypeAnnotations == null ? 0 : visibleTypeAnnotations.size();
    for (i = 0; i < n; ++i) {
        TypeAnnotationNode an = visibleTypeAnnotations.get(i);
        an.accept(fv.visitTypeAnnotation(an.typeRef, an.typePath, an.desc, true));
    }
    n = invisibleTypeAnnotations == null ? 0 : invisibleTypeAnnotations.size();
    for (i = 0; i < n; ++i) {
        TypeAnnotationNode an = invisibleTypeAnnotations.get(i);
        an.accept(fv.visitTypeAnnotation(an.typeRef, an.typePath, an.desc, false));
    }
    n = attrs == null ? 0 : attrs.size();
    for (i = 0; i < n; ++i) {
        fv.visitAttribute(attrs.get(i));
    }
    fv.visitEnd();
}
Also used : FieldVisitor(org.objectweb.asm.FieldVisitor)

Example 79 with FieldVisitor

use of org.objectweb.asm.FieldVisitor in project maple-ir by LLVM-but-worse.

the class CheckClassAdapter method visitField.

@Override
public FieldVisitor visitField(final int access, final String name, final String desc, final String signature, final Object value) {
    checkState();
    checkAccess(access, Opcodes.ACC_PUBLIC + Opcodes.ACC_PRIVATE + Opcodes.ACC_PROTECTED + Opcodes.ACC_STATIC + Opcodes.ACC_FINAL + Opcodes.ACC_VOLATILE + Opcodes.ACC_TRANSIENT + Opcodes.ACC_SYNTHETIC + Opcodes.ACC_ENUM + Opcodes.ACC_DEPRECATED + // ClassWriter.ACC_SYNTHETIC_ATTRIBUTE
    0x40000);
    CheckMethodAdapter.checkUnqualifiedName(version, name, "field name");
    CheckMethodAdapter.checkDesc(desc, false);
    if (signature != null) {
        checkFieldSignature(signature);
    }
    if (value != null) {
        CheckMethodAdapter.checkConstant(value);
    }
    FieldVisitor av = super.visitField(access, name, desc, signature, value);
    return new CheckFieldAdapter(av);
}
Also used : FieldVisitor(org.objectweb.asm.FieldVisitor)

Example 80 with FieldVisitor

use of org.objectweb.asm.FieldVisitor in project neo4j by neo4j.

the class ByteCodeClassWriter method field.

@Override
public void field(FieldReference field, Expression value) {
    // keep track of all static field->value, and initiate in <clinit> in done
    if (Modifier.isStatic(field.modifiers()) && value != null) {
        staticFields.put(field, value);
    }
    FieldVisitor fieldVisitor = classVisitor.visitField(field.modifiers(), field.name(), typeName(field.type()), signature(field.type()), null);
    fieldVisitor.visitEnd();
}
Also used : FieldVisitor(org.objectweb.asm.FieldVisitor)

Aggregations

FieldVisitor (org.objectweb.asm.FieldVisitor)90 MethodVisitor (org.objectweb.asm.MethodVisitor)59 Label (org.objectweb.asm.Label)33 ClassWriter (org.objectweb.asm.ClassWriter)28 AnnotationVisitor (org.objectweb.asm.AnnotationVisitor)9 ClassReader (org.objectweb.asm.ClassReader)8 Type (org.objectweb.asm.Type)7 Method (java.lang.reflect.Method)6 ClassVisitor (org.objectweb.asm.ClassVisitor)6 IOException (java.io.IOException)4 GeneratorAdapter (org.objectweb.asm.commons.GeneratorAdapter)4 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 LitString (lucee.transformer.expression.literal.LitString)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 File (java.io.File)2 FileOutputStream (java.io.FileOutputStream)2 PrintWriter (java.io.PrintWriter)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 URL (java.net.URL)2