/**
 * An  FieldVisitor that generates Java fields in bytecode form.
 *
 *  author Eric Bruneton
  import { AnnotationVisitor } from "./AnnotationVisitor" ; import { AnnotationWriter } from "./AnnotationWriter" ; import { Attribute } from "./Attribute" ; import { ByteVector } from "./ByteVector" ; import { ClassReader } from "./ClassReader" ; import { ClassWriter } from "./ClassWriter" ; import { FieldVisitor } from "./FieldVisitor" ; import { Opcodes } from "./Opcodes" ; import { TypePath } from "./TypePath" ; export class FieldWriter extends FieldVisitor { /**
     * The class writer to which this field must be added.
     */ private cw : ClassWriter ; /**
     * Access flags of this field.
     */ private access : number ; /**
     * The index of the constant pool item that contains the name of this
     * method.
     */ private name : number ; /**
     * The index of the constant pool item that contains the descriptor of this
     * field.
     */ private desc : number ; /**
     * The index of the constant pool item that contains the signature of this
     * field.
     */ private signature : number ; /**
     * The index of the constant pool item that contains the constant value of
     * this field.
     */ private value : number ; /**
     * The runtime visible annotations of this field. May be <tt>null</tt>.
     */ private anns ! : AnnotationWriter ; /**
     * The runtime invisible annotations of this field. May be <tt>null</tt>.
     */ private ianns ! : AnnotationWriter ; /**
     * The runtime visible type annotations of this field. May be <tt>null</tt>.
     */ private tanns ! : AnnotationWriter ; /**
     * The runtime invisible type annotations of this field. May be
     * <tt>null</tt>.
     */ private itanns ! : AnnotationWriter ; /**
     * The non standard attributes of this field. May be <tt>null</tt>.
     */ private attrs ! : Attribute ; /**
     * Constructs a new  FieldWriter .
     *
     *  param cw param access the field's access flags (see  Opcodes ).
     *  param name param desc the field's descriptor (see  Type ).
     *  param signature param value constructor ( cw , access , name , desc , signature , value ) { super ( Opcodes . ASM5 ) ; this . access = 0 ; this . name = 0 ; this . desc = 0 ; this . signature = 0 ; this . value = 0 ; if ( cw . firstField == null ) { cw . firstField = this ; } else { cw . lastField . fv = this ; } cw . lastField = this ; this . cw = cw ; this . access = access ; this . name = cw . newUTF8 ( name ) ; this . desc = cw . newUTF8 ( desc ) ; if ( ClassReader . SIGNATURES && signature != null ) { this . signature = cw . newUTF8 ( signature ) ; } if ( value != null ) { this . value = cw . newConstItem ( value ) . index ; } } public visitAnnotation ( desc , visible ) { if ( ! ClassReader . ANNOTATIONS ) { return null ; } let bv = new ByteVector ( ) ; bv . putShort ( this . cw . newUTF8 ( desc ) ) . putShort ( 0 ) ; let aw = new AnnotationWriter ( this . cw , true , bv , bv , 2 ) ; if ( visible ) { aw . next = this . anns ; this . anns = aw ; } else { aw . next = this . ianns ; this . ianns = aw ; } return aw ; } public visitTypeAnnotation ( typeRef , typePath , desc , visible ) { if ( ! ClassReader . ANNOTATIONS ) { return null ; } let bv = new ByteVector ( ) ; AnnotationWriter . putTarget ( typeRef , typePath , bv ) ; bv . putShort ( this . cw . newUTF8 ( desc ) ) . putShort ( 0 ) ; let aw = new AnnotationWriter ( this . cw , true , bv , bv , bv . length - 2 ) ; if ( visible ) { aw . next = this . tanns ; this . tanns = aw ; } else { aw . next = this . itanns ; this . itanns = aw ; } return aw ; } public visitAttribute ( attr ) { attr . next = this . attrs ; this . attrs = attr ; } public visitEnd ( ) { } return getSize ( ) { let size = 8 ; if ( this . value !== 0 ) { this . cw . newUTF8 ( "ConstantValue" ) ; size += 8 ; } if ( ( this . access & Opcodes . ACC_SYNTHETIC ) !== 0 ) { if ( ( this . cw . version & 65535 ) < Opcodes . V1_5 || ( this . access & ClassWriter . ACC_SYNTHETIC_ATTRIBUTE ) !== 0 ) { this . cw . newUTF8 ( "Synthetic" ) ; size += 6 ; } } if ( ( this . access & Opcodes . ACC_DEPRECATED ) !== 0 ) { this . cw . newUTF8 ( "Deprecated" ) ; size += 6 ; } if ( ClassReader . SIGNATURES && this . signature !== 0 ) { this . cw . newUTF8 ( "Signature" ) ; size += 8 ; } if ( ClassReader . ANNOTATIONS && this . anns != null ) { this . cw . newUTF8 ( "RuntimeVisibleAnnotations" ) ; size += 8 + this . anns . getSize ( ) ; } if ( ClassReader . ANNOTATIONS && this . ianns != null ) { this . cw . newUTF8 ( "RuntimeInvisibleAnnotations" ) ; size += 8 + this . ianns . getSize ( ) ; } if ( ClassReader . ANNOTATIONS && this . tanns != null ) { this . cw . newUTF8 ( "RuntimeVisibleTypeAnnotations" ) ; size += 8 + this . tanns . getSize ( ) ; } if ( ClassReader . ANNOTATIONS && this . itanns != null ) { this . cw . newUTF8 ( "RuntimeInvisibleTypeAnnotations" ) ; size += 8 + this . itanns . getSize ( ) ; } if ( this . attrs != null ) { size += this . attrs . getSize ( this . cw , null , 0 , - 1 , - 1 ) ; } return size ; } param out put ( out ) { let FACTOR = ClassWriter . TO_ACC_SYNTHETIC_$LI$ ( ) ; let mask = Opcodes . ACC_DEPRECATED | ClassWriter . ACC_SYNTHETIC_ATTRIBUTE | ( ( ( this . access & ClassWriter . ACC_SYNTHETIC_ATTRIBUTE ) / FACTOR | 0 ) ) ; out . putShort ( this . access & ~ mask ) . putShort ( this . name ) . putShort ( this . desc ) ; let attributeCount = 0 ; if ( this . value !== 0 ) { ++ attributeCount ; } if ( ( this . access & Opcodes . ACC_SYNTHETIC ) !== 0 ) { if ( ( this . cw . version & 65535 ) < Opcodes . V1_5 || ( this . access & ClassWriter . ACC_SYNTHETIC_ATTRIBUTE ) !== 0 ) { ++ attributeCount ; } } if ( ( this . access & Opcodes . ACC_DEPRECATED ) !== 0 ) { ++ attributeCount ; } if ( ClassReader . SIGNATURES && this . signature !== 0 ) { ++ attributeCount ; } if ( ClassReader . ANNOTATIONS && this . anns != null ) { ++ attributeCount ; } if ( ClassReader . ANNOTATIONS && this . ianns != null ) { ++ attributeCount ; } if ( ClassReader . ANNOTATIONS && this . tanns != null ) { ++ attributeCount ; } if ( ClassReader . ANNOTATIONS && this . itanns != null ) { ++ attributeCount ; } if ( this . attrs != null ) { attributeCount += this . attrs . getCount ( ) ; } out . putShort ( attributeCount ) ; if ( this . value !== 0 ) { out . putShort ( this . cw . newUTF8 ( "ConstantValue" ) ) ; out . putInt ( 2 ) . putShort ( this . value ) ; } if ( ( this . access & Opcodes . ACC_SYNTHETIC ) !== 0 ) { if ( ( this . cw . version & 65535 ) < Opcodes . V1_5 || ( this . access & ClassWriter . ACC_SYNTHETIC_ATTRIBUTE ) !== 0 ) { out . putShort ( this . cw . newUTF8 ( "Synthetic" ) ) . putInt ( 0 ) ; } } if ( ( this . access & Opcodes . ACC_DEPRECATED ) !== 0 ) { out . putShort ( this . cw . newUTF8 ( "Deprecated" ) ) . putInt ( 0 ) ; } if ( ClassReader . SIGNATURES && this . signature !== 0 ) { out . putShort ( this . cw . newUTF8 ( "Signature" ) ) ; out . putInt ( 2 ) . putShort ( this . signature ) ; } if ( ClassReader . ANNOTATIONS && this . anns != null ) { out . putShort ( this . cw . newUTF8 ( "RuntimeVisibleAnnotations" ) ) ; this . anns . put ( out ) ; } if ( ClassReader . ANNOTATIONS && this . ianns != null ) { out . putShort ( this . cw . newUTF8 ( "RuntimeInvisibleAnnotations" ) ) ; this . ianns . put ( out ) ; } if ( ClassReader . ANNOTATIONS && this . tanns != null ) { out . putShort ( this . cw . newUTF8 ( "RuntimeVisibleTypeAnnotations" ) ) ; this . tanns . put ( out ) ; } if ( ClassReader . ANNOTATIONS && this . itanns != null ) { out . putShort ( this . cw . newUTF8 ( "RuntimeInvisibleTypeAnnotations" ) ) ; this . itanns . put ( out ) ; } if ( this . attrs != null ) { this . attrs . put ( this . cw , null , 0 , - 1 , - 1 , out ) ; } } }