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

The following examples show how to use jdk.internal.org.objectweb.asm.FieldVisitor. 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
Source File: ClassRemapper.java    From Bytecoder with 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 #2
Source File: CheckClassAdapter.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@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 #3
Source File: CheckClassAdapter.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
@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
Source File: CheckClassAdapter.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
@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
Source File: SerialVersionUIDAdder.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
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 #6
Source File: ClassGenerator.java    From openjdk-jdk8u-backup with 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 #7
Source File: TraceClassVisitor.java    From openjdk-jdk8u-backup with 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 #8
Source File: ByteCodeVisitor.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public byte[] visit(Initialization node) {
    VariableInfo vi = node.getVariableInfo();
    if (vi.isLocal()) {
        return visitLocalVar(node);
    }
    String ownerName = vi.getOwner().getName();
    ContextDependedClassWriter cw = classWriters.get(ownerName);
    String typeName = new String(vi.type.accept(this));
    // constant value used only for final static fields
    FieldVisitor fw = cw.visitField(asAccessFlags(vi), vi.name,
            typeName,
            null /* Generic */,
            null /* Constant value */);
    fw.visitEnd(); // doesn't need visitAnnotation and visitAttribute
    if (vi.isStatic()) {
        node.getChild(0).accept(this); // put value to stack
        emitDup(vi.type);
        currentMV.visitFieldInsn(Opcodes.PUTSTATIC,
                asInternalName(vi.getOwner().getName()),
                vi.name,
                new String(vi.type.accept(this)));
    } else {
        // TODO : can it be another object?
        currentMV.visitVarInsn(Opcodes.ALOAD, 0); // put this to stack
        node.getChild(0).accept(this); // put value to stack
        emitDupX1(vi.type);
        currentMV.visitFieldInsn(Opcodes.PUTFIELD,
                asInternalName(vi.getOwner().getName()),
                vi.name,
                new String(vi.type.accept(this)));
    }
    return EMPTY_BYTE_ARRAY;
}
 
Example #9
Source File: ClassNode.java    From openjdk-jdk8u-backup with 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 #10
Source File: RemappingClassAdapter.java    From openjdk-jdk8u-backup with 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 : createRemappingFieldAdapter(fv);
}
 
Example #11
Source File: ScriptClassInstrumentor.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@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 #12
Source File: ClassGenerator.java    From openjdk-jdk8u with 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 #13
Source File: RemappingClassAdapter.java    From openjdk-jdk8u with 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 : createRemappingFieldAdapter(fv);
}
 
Example #14
Source File: TraceClassVisitor.java    From openjdk-jdk8u with 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 #15
Source File: RemappingClassAdapter.java    From openjdk-jdk9 with 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 : createRemappingFieldAdapter(fv);
}
 
Example #16
Source File: NullVisitor.java    From openjdk-jdk8u with 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 #17
Source File: ScriptClassInstrumentor.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@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 #18
Source File: RedefineAnnotations.java    From openjdk-jdk8u-backup with 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 #19
Source File: SerialVersionUIDAdder.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
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 #20
Source File: SerialVersionUIDAdder.java    From openjdk-jdk8u with 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) {
    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 #21
Source File: RedefineAnnotations.java    From openjdk-jdk8u with 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 #22
Source File: ScriptClassInstrumentor.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@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 #23
Source File: TraceClassVisitor.java    From Bytecoder with 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 #24
Source File: ClassGenerator.java    From jdk8u60 with 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 #25
Source File: TraceClassVisitor.java    From jdk8u60 with 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 #26
Source File: ScriptClassInstrumentor.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@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 #27
Source File: RemappingClassAdapter.java    From jdk8u60 with 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 : createRemappingFieldAdapter(fv);
}
 
Example #28
Source File: SerialVersionUIDAdder.java    From Bytecoder with 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 #29
Source File: SerialVersionUIDAdder.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
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 #30
Source File: SerialVersionUIDAdder.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
protected void addSVUID(long svuid) {
    FieldVisitor fv = super.visitField(Opcodes.ACC_FINAL
            + Opcodes.ACC_STATIC, "serialVersionUID", "J", null, svuid);
    if (fv != null) {
        fv.visitEnd();
    }
}