author Eric Bruneton
 *  author Eugene Kuleshov
  import { Label } from "./Label" ; import { ClassReader } from "./ClassReader" ; import { ClassWriter } from "./ClassWriter" ; import { ByteVector } from "./ByteVector" ; import { assert } from "./utils" ; export class Attribute { /**
     * The type of this attribute.
     */ public type : string | null ; /**
     * The raw value of this attribute, used only for unknown attributes.
     */ value ! : Uint8Array ; /**
     * The next attribute in this attribute list. May be <tt>null</tt>.
     */ next : Attribute | null = null ; param type constructor ( type ) { this . type = type ; } return public isUnknown ( ) { return true ; } return public isCodeAttribute ( ) { return false ; } return getLabels ( ) { return null ; } /**
     * Reads a  {@link #type type} attribute. This method must return a
     * <i>new</i>  Attribute object, of type  {@link #type type} ,
     * corresponding to the <tt>len</tt> bytes starting at the given offset, in
     * the given class reader.
     *
     *  param cr param off index of the first byte of the attribute's content in
     *  ClassReader . The 6 attribute header bytes,
     * containing the type and the length of the attribute, are not
     * taken into account here.
     *  param len param buf buffer to be used to call  ClassReader * readUTF8},  ClassReader * or  ClassReader .
     *  param codeOff index of the first byte of code's attribute content in
     *  ClassReader , or -1 if the attribute to be read
     * is not a code attribute. The 6 attribute header bytes,
     * containing the type and the length of the attribute, are not
     * taken into account here.
     *  param labels return a <i>new</i>  Attribute object corresponding to the given
     * bytes.
      read ( cr , off , len , buf , codeOff , labels ) { let attr = new Attribute ( this . type ) ; attr . value = cr . buf . slice ( 0 , len ) ; return attr ; } param cw param code param len param maxStack param maxLocals return write ( cw , code , len , maxStack , maxLocals ) { let v = new ByteVector ( ) ; v . data = this . value ; v . length = this . value . length ; return v ; } return getCount ( ) { let count = 0 ; let attr = this ; while ( ( attr != null ) ) { count += 1 ; attr = attr . next ; } ; return count ; } param cw the class writer to be used to convert the attributes into
     * byte arrays, with the  {@link #write write} method.
     *  param code param len param maxStack param maxLocals return getSize ( cw , code , len , maxStack , maxLocals ) { let attr = this ; let size = 0 ; while ( ( attr != null ) ) { assert ( attr . type ) ; cw . newUTF8 ( attr . type ) ; size += attr . write ( cw , code , len , maxStack , maxLocals ) . length + 6 ; attr = attr . next ; } ; return size ; } param cw the class writer to be used to convert the attributes into
     * byte arrays, with the  {@link #write write} method.
     *  param code param len param maxStack param maxLocals param out put ( cw , code , len , maxStack , maxLocals , out ) { let attr = this ; while ( ( attr != null ) ) { let b = attr . write ( cw , code , len , maxStack , maxLocals ) ; assert ( attr . type ) ; out . putShort ( cw . newUTF8 ( attr . type ) ) . putInt ( b . length ) ; out . putByteArray ( b . data , 0 , b . length ) ; attr = attr . next ; } ; } }