Java Code Examples for jdk.internal.org.objectweb.asm.FieldVisitor

The following examples show how to use jdk.internal.org.objectweb.asm.FieldVisitor. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@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 + 0x40000); // ClassWriter.ACC_SYNTHETIC_ATTRIBUTE
    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);
}
 
Example 2
Source Project: Bytecoder   Source File: ClassRemapper.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public FieldVisitor visitField(
        final int access,
        final String name,
        final String descriptor,
        final String signature,
        final Object value) {
    FieldVisitor fieldVisitor =
            super.visitField(
                    access,
                    remapper.mapFieldName(className, name, descriptor),
                    remapper.mapDesc(descriptor),
                    remapper.mapSignature(signature, true),
                    (value == null) ? null : remapper.mapValue(value));
    return fieldVisitor == null ? null : createFieldRemapper(fieldVisitor);
}
 
Example 3
@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 + 0x40000); // ClassWriter.ACC_SYNTHETIC_ATTRIBUTE
    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);
}
 
Example 4
@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 + 0x40000); // ClassWriter.ACC_SYNTHETIC_ATTRIBUTE
    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);
}
 
Example 5
@Override
public FieldVisitor visitField(final int access, final String name,
        final String desc, final String signature, final Object value) {
    if (computeSVUID) {
        if ("serialVersionUID".equals(name)) {
            // since the class already has SVUID, we won't be computing it.
            computeSVUID = false;
            hasSVUID = true;
        }
        /*
         * Remember field for SVUID computation For field modifiers, only
         * the ACC_PUBLIC, ACC_PRIVATE, ACC_PROTECTED, ACC_STATIC,
         * ACC_FINAL, ACC_VOLATILE, and ACC_TRANSIENT flags are used when
         * computing serialVersionUID values.
         */
        if ((access & Opcodes.ACC_PRIVATE) == 0
                || (access & (Opcodes.ACC_STATIC | Opcodes.ACC_TRANSIENT)) == 0) {
            int mods = access
                    & (Opcodes.ACC_PUBLIC | Opcodes.ACC_PRIVATE
                            | Opcodes.ACC_PROTECTED | Opcodes.ACC_STATIC
                            | Opcodes.ACC_FINAL | Opcodes.ACC_VOLATILE | Opcodes.ACC_TRANSIENT);
            svuidFields.add(new Item(name, mods, desc));
        }
    }

    return super.visitField(access, name, desc, signature, value);
}
 
Example 6
protected void addSVUID(long svuid) {
    FieldVisitor fv = super.visitField(Opcodes.ACC_FINAL
            + Opcodes.ACC_STATIC, "serialVersionUID", "J", null, svuid);
    if (fv != null) {
        fv.visitEnd();
    }
}
 
Example 7
@Override
public FieldVisitor visitField(int access, String name, String desc,
        String signature, Object value) {
    FieldVisitor fv = super.visitField(access,
            remapper.mapFieldName(className, name, desc),
            remapper.mapDesc(desc), remapper.mapSignature(signature, true),
            remapper.mapValue(value));
    return fv == null ? null : createRemappingFieldAdapter(fv);
}
 
Example 8
Source Project: openjdk-jdk9   Source File: ClassGenerator.java    License: GNU General Public License v2.0 5 votes vote down vote up
static void addMapField(final ClassVisitor cv) {
    // add a PropertyMap static field
    final FieldVisitor fv = cv.visitField(ACC_PRIVATE | ACC_STATIC | ACC_FINAL,
        PROPERTYMAP_FIELD_NAME, PROPERTYMAP_DESC, null, null);
    if (fv != null) {
        fv.visitEnd();
    }
}
 
Example 9
Source Project: openjdk-jdk9   Source File: ClassRemapper.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public FieldVisitor visitField(int access, String name, String desc,
        String signature, Object value) {
    FieldVisitor fv = super.visitField(access,
            remapper.mapFieldName(className, name, desc),
            remapper.mapDesc(desc), remapper.mapSignature(signature, true),
            remapper.mapValue(value));
    return fv == null ? null : createFieldRemapper(fv);
}
 
Example 10
@Override
public FieldVisitor visitField(final int access, final String name,
        final String desc, final String signature, final Object value) {
    Printer p = this.p.visitField(access, name, desc, signature, value);
    FieldVisitor fv = cv == null ? null : cv.visitField(access, name, desc,
            signature, value);
    return new TraceFieldVisitor(fv, p);
}
 
Example 11
Source Project: openjdk-jdk9   Source File: NullVisitor.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public FieldVisitor visitField(
    final int access,
    final String name,
    final String desc,
    final String signature,
    final Object value) {
    return new FieldVisitor(Main.ASM_VERSION) {
        @Override
        public AnnotationVisitor visitAnnotation(final String descriptor, final boolean visible) {
            return new NullAnnotationVisitor();
        }
    };
}
 
Example 12
protected void addSVUID(long svuid) {
    FieldVisitor fv = super.visitField(Opcodes.ACC_FINAL
            + Opcodes.ACC_STATIC, "serialVersionUID", "J", null, svuid);
    if (fv != null) {
        fv.visitEnd();
    }
}
 
Example 13
@Override
public FieldVisitor visitField(final int access, final String name,
        final String desc, final String signature, final Object value) {
    if (computeSVUID) {
        if ("serialVersionUID".equals(name)) {
            // since the class already has SVUID, we won't be computing it.
            computeSVUID = false;
            hasSVUID = true;
        }
        /*
         * Remember field for SVUID computation For field modifiers, only
         * the ACC_PUBLIC, ACC_PRIVATE, ACC_PROTECTED, ACC_STATIC,
         * ACC_FINAL, ACC_VOLATILE, and ACC_TRANSIENT flags are used when
         * computing serialVersionUID values.
         */
        if ((access & Opcodes.ACC_PRIVATE) == 0
                || (access & (Opcodes.ACC_STATIC | Opcodes.ACC_TRANSIENT)) == 0) {
            int mods = access
                    & (Opcodes.ACC_PUBLIC | Opcodes.ACC_PRIVATE
                            | Opcodes.ACC_PROTECTED | Opcodes.ACC_STATIC
                            | Opcodes.ACC_FINAL | Opcodes.ACC_VOLATILE | Opcodes.ACC_TRANSIENT);
            svuidFields.add(new Item(name, mods, desc));
        }
    }

    return super.visitField(access, name, desc, signature, value);
}
 
Example 14
Source Project: Bytecoder   Source File: SerialVersionUIDAdder.java    License: Apache License 2.0 5 votes vote down vote up
/**
  * Adds a final static serialVersionUID field to the class, with the given value.
  *
  * @param svuid the serialVersionUID field value.
  */
// DontCheck(AbbreviationAsWordInName): can't be renamed (for backward binary compatibility).
protected void addSVUID(final long svuid) {
    FieldVisitor fieldVisitor =
            super.visitField(
                    Opcodes.ACC_FINAL + Opcodes.ACC_STATIC, "serialVersionUID", "J", null, svuid);
    if (fieldVisitor != null) {
        fieldVisitor.visitEnd();
    }
}
 
Example 15
Source Project: TencentKona-8   Source File: ClassNode.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public FieldVisitor visitField(final int access, final String name,
        final String desc, final String signature, final Object value) {
    FieldNode fn = new FieldNode(access, name, desc, signature, value);
    fields.add(fn);
    return fn;
}
 
Example 16
protected void addSVUID(long svuid) {
    FieldVisitor fv = super.visitField(Opcodes.ACC_FINAL
            + Opcodes.ACC_STATIC, "serialVersionUID", "J", null, svuid);
    if (fv != null) {
        fv.visitEnd();
    }
}
 
Example 17
Source Project: TencentKona-8   Source File: ClassGenerator.java    License: GNU General Public License v2.0 5 votes vote down vote up
static void addMapField(final ClassVisitor cv) {
    // add a PropertyMap static field
    final FieldVisitor fv = cv.visitField(ACC_PRIVATE | ACC_STATIC | ACC_FINAL,
        PROPERTYMAP_FIELD_NAME, PROPERTYMAP_DESC, null, null);
    if (fv != null) {
        fv.visitEnd();
    }
}
 
Example 18
Source Project: TencentKona-8   Source File: NullVisitor.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public FieldVisitor visitField(
    final int access,
    final String name,
    final String desc,
    final String signature,
    final Object value) {
    return new FieldVisitor(Opcodes.ASM4) {
        @Override
        public AnnotationVisitor visitAnnotation(final String descriptor, final boolean visible) {
            return new NullAnnotationVisitor();
        }
    };
}
 
Example 19
@Override
public FieldVisitor visitField(final int access, final String name,
        final String desc, final String signature, final Object value) {
    if (computeSVUID) {
        if ("serialVersionUID".equals(name)) {
            // since the class already has SVUID, we won't be computing it.
            computeSVUID = false;
            hasSVUID = true;
        }
        /*
         * Remember field for SVUID computation For field modifiers, only
         * the ACC_PUBLIC, ACC_PRIVATE, ACC_PROTECTED, ACC_STATIC,
         * ACC_FINAL, ACC_VOLATILE, and ACC_TRANSIENT flags are used when
         * computing serialVersionUID values.
         */
        if ((access & Opcodes.ACC_PRIVATE) == 0
                || (access & (Opcodes.ACC_STATIC | Opcodes.ACC_TRANSIENT)) == 0) {
            int mods = access
                    & (Opcodes.ACC_PUBLIC | Opcodes.ACC_PRIVATE
                            | Opcodes.ACC_PROTECTED | Opcodes.ACC_STATIC
                            | Opcodes.ACC_FINAL | Opcodes.ACC_VOLATILE | Opcodes.ACC_TRANSIENT);
            svuidFields.add(new Item(name, mods, desc));
        }
    }

    return super.visitField(access, name, desc, signature, value);
}
 
Example 20
Source Project: jdk8u60   Source File: RedefineAnnotations.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override public FieldVisitor visitField(int access, String name,
        String desc, String signature, Object value) {
    if (name.startsWith("dummy")) {
        // Remove dummy field
        fields.addLast(new F(access, name, desc, signature, value));
        return null;
    }
    return cv.visitField(access, name, desc, signature, value);
}
 
Example 21
@Override
public FieldVisitor visitField(final int fieldAccess, final String fieldName,
        final String fieldDesc, final String signature, final Object value) {
    final MemberInfo memInfo = scriptClassInfo.find(fieldName, fieldDesc, fieldAccess);
    if (memInfo != null && memInfo.getKind() == Kind.PROPERTY &&
            memInfo.getWhere() != Where.INSTANCE && !memInfo.isStaticFinal()) {
        // non-instance @Property fields - these have to go elsewhere unless 'static final'
        return null;
    }

    final FieldVisitor delegateFV = super.visitField(fieldAccess, fieldName, fieldDesc,
            signature, value);
    return new FieldVisitor(Opcodes.ASM4, delegateFV) {
        @Override
        public AnnotationVisitor visitAnnotation(final String desc, final boolean visible) {
            if (ScriptClassInfo.annotations.containsKey(desc)) {
                // ignore script field annotations
                return null;
            }

            return fv.visitAnnotation(desc, visible);
        }

        @Override
        public void visitAttribute(final Attribute attr) {
            fv.visitAttribute(attr);
        }

        @Override
        public void visitEnd() {
            fv.visitEnd();
        }
    };
}
 
Example 22
protected void addSVUID(long svuid) {
    FieldVisitor fv = super.visitField(Opcodes.ACC_FINAL
            + Opcodes.ACC_STATIC, "serialVersionUID", "J", null, svuid);
    if (fv != null) {
        fv.visitEnd();
    }
}
 
Example 23
Source Project: Bytecoder   Source File: SerialVersionUIDAdder.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public FieldVisitor visitField(
        final int access,
        final String name,
        final String desc,
        final String signature,
        final Object value) {
    // Get the class field information for step 4 of the algorithm. Also determine if the class
    // already has a SVUID.
    if (computeSvuid) {
        if ("serialVersionUID".equals(name)) {
            // Since the class already has SVUID, we won't be computing it.
            computeSvuid = false;
            hasSvuid = true;
        }
        // Collect the non private fields. Only the ACC_PUBLIC, ACC_PRIVATE, ACC_PROTECTED,
        // ACC_STATIC, ACC_FINAL, ACC_VOLATILE, and ACC_TRANSIENT flags are used when computing
        // serialVersionUID values.
        if ((access & Opcodes.ACC_PRIVATE) == 0
                || (access & (Opcodes.ACC_STATIC | Opcodes.ACC_TRANSIENT)) == 0) {
            int mods =
                    access
                            & (Opcodes.ACC_PUBLIC
                                    | Opcodes.ACC_PRIVATE
                                    | Opcodes.ACC_PROTECTED
                                    | Opcodes.ACC_STATIC
                                    | Opcodes.ACC_FINAL
                                    | Opcodes.ACC_VOLATILE
                                    | Opcodes.ACC_TRANSIENT);
            svuidFields.add(new Item(name, mods, desc));
        }
    }

    return super.visitField(access, name, desc, signature, value);
}
 
Example 24
@Override
public FieldVisitor visitField(int access, String name, String desc,
        String signature, Object value) {
    FieldVisitor fv = super.visitField(access,
            remapper.mapFieldName(className, name, desc),
            remapper.mapDesc(desc), remapper.mapSignature(signature, true),
            remapper.mapValue(value));
    return fv == null ? null : createRemappingFieldAdapter(fv);
}
 
Example 25
@Override
public FieldVisitor visitField(final int fieldAccess, final String fieldName,
        final String fieldDesc, final String signature, final Object value) {
    final MemberInfo memInfo = scriptClassInfo.find(fieldName, fieldDesc, fieldAccess);
    if (memInfo != null && memInfo.getKind() == Kind.PROPERTY &&
            memInfo.getWhere() != Where.INSTANCE && !memInfo.isStaticFinal()) {
        // non-instance @Property fields - these have to go elsewhere unless 'static final'
        return null;
    }

    final FieldVisitor delegateFV = super.visitField(fieldAccess, fieldName, fieldDesc,
            signature, value);
    return new FieldVisitor(Main.ASM_VERSION, delegateFV) {
        @Override
        public AnnotationVisitor visitAnnotation(final String desc, final boolean visible) {
            if (ScriptClassInfo.annotations.containsKey(desc)) {
                // ignore script field annotations
                return null;
            }

            return fv.visitAnnotation(desc, visible);
        }

        @Override
        public void visitAttribute(final Attribute attr) {
            fv.visitAttribute(attr);
        }

        @Override
        public void visitEnd() {
            fv.visitEnd();
        }
    };
}
 
Example 26
Source Project: jdk8u60   Source File: TraceClassVisitor.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public FieldVisitor visitField(final int access, final String name,
        final String desc, final String signature, final Object value) {
    Printer p = this.p.visitField(access, name, desc, signature, value);
    FieldVisitor fv = cv == null ? null : cv.visitField(access, name, desc,
            signature, value);
    return new TraceFieldVisitor(fv, p);
}
 
Example 27
Source Project: jdk8u60   Source File: ClassGenerator.java    License: GNU General Public License v2.0 5 votes vote down vote up
static void addMapField(final ClassVisitor cv) {
    // add a PropertyMap static field
    final FieldVisitor fv = cv.visitField(ACC_PRIVATE | ACC_STATIC | ACC_FINAL,
        PROPERTYMAP_FIELD_NAME, PROPERTYMAP_DESC, null, null);
    if (fv != null) {
        fv.visitEnd();
    }
}
 
Example 28
Source Project: Bytecoder   Source File: TraceClassVisitor.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public FieldVisitor visitField(
        final int access,
        final String name,
        final String descriptor,
        final String signature,
        final Object value) {
    Printer fieldPrinter = p.visitField(access, name, descriptor, signature, value);
    return new TraceFieldVisitor(
            super.visitField(access, name, descriptor, signature, value), fieldPrinter);
}
 
Example 29
@Override
public FieldVisitor visitField(final int fieldAccess, final String fieldName,
        final String fieldDesc, final String signature, final Object value) {
    final MemberInfo memInfo = scriptClassInfo.find(fieldName, fieldDesc, fieldAccess);
    if (memInfo != null && memInfo.getKind() == Kind.PROPERTY &&
            memInfo.getWhere() != Where.INSTANCE && !memInfo.isStaticFinal()) {
        // non-instance @Property fields - these have to go elsewhere unless 'static final'
        return null;
    }

    final FieldVisitor delegateFV = super.visitField(fieldAccess, fieldName, fieldDesc,
            signature, value);
    return new FieldVisitor(Opcodes.ASM4, delegateFV) {
        @Override
        public AnnotationVisitor visitAnnotation(final String desc, final boolean visible) {
            if (ScriptClassInfo.annotations.containsKey(desc)) {
                // ignore script field annotations
                return null;
            }

            return fv.visitAnnotation(desc, visible);
        }

        @Override
        public void visitAttribute(final Attribute attr) {
            fv.visitAttribute(attr);
        }

        @Override
        public void visitEnd() {
            fv.visitEnd();
        }
    };
}
 
Example 30
@Override public FieldVisitor visitField(int access, String name,
        String desc, String signature, Object value) {
    if (name.startsWith("dummy")) {
        // Remove dummy field
        fields.addLast(new F(access, name, desc, signature, value));
        return null;
    }
    return cv.visitField(access, name, desc, signature, value);
}