All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.opalj.bi.reader.BootstrapMethods_attributeReader.scala Maven / Gradle / Ivy

The newest version!
/* BSD 2-Clause License - see OPAL/LICENSE for details. */
package org.opalj
package bi
package reader

import java.io.DataInputStream

import org.opalj.collection.immutable.RefArray
import org.opalj.control.fillRefArray

/**
 * Template method to read the (Java 7) ''BootstrapMethods'' attribute.
 *
 * '''From the Specification'''
 * The `BootstrapMethods` attribute is a variable-length attribute in the
 * attributes table of a `ClassFile` structure. The `BootstrapMethods` attribute
 * records bootstrap method specifiers referenced by `invokedynamic` instructions.
 */
trait BootstrapMethods_attributeReader extends AttributeReader {

    //
    // TYPE DEFINITIONS AND FACTORY METHODS
    //

    type BootstrapMethods_attribute >: Null <: Attribute

    type BootstrapMethod <: AnyRef
    type BootstrapMethods = RefArray[BootstrapMethod]

    type BootstrapArgument <: AnyRef
    type BootstrapArguments = RefArray[BootstrapArgument]

    def BootstrapMethods_attribute(
        constant_pool:        Constant_Pool,
        ap_name_index:        Constant_Pool_Index,
        ap_descriptor_index:  Constant_Pool_Index,
        attribute_name_index: Int,
        bootstrap_methods:    BootstrapMethods
    ): BootstrapMethods_attribute

    def BootstrapMethod(
        constant_pool:        Constant_Pool,
        bootstrap_method_ref: Int,
        bootstrap_arguments:  BootstrapArguments
    ): BootstrapMethod

    def BootstrapArgument(
        constant_pool:     Constant_Pool,
        constant_pool_ref: Int
    ): BootstrapArgument

    //
    // IMPLEMENTATION
    //

    def BootstrapArgument(cp: Constant_Pool, in: DataInputStream): BootstrapArgument = {
        BootstrapArgument(cp, in.readUnsignedShort)
    }

    def BootstrapMethod(cp: Constant_Pool, in: DataInputStream): BootstrapMethod = {
        BootstrapMethod(
            cp,
            in.readUnsignedShort,
            fillRefArray(in.readUnsignedShort) {
                BootstrapArgument(cp, in)
            }
        )
    }

    /**
     * 
     * BootstrapMethods_attribute {
     *  u2 attribute_name_index;
     *  u4 attribute_length;
     *  u2 num_bootstrap_methods;
     *  {   u2 bootstrap_method_ref;
     *      u2 num_bootstrap_arguments;
     *      u2 bootstrap_arguments[num_bootstrap_arguments];
     *  } bootstrap_methods[num_bootstrap_methods];
     * }
     * 
*/ private[this] def parserFactory() = ( cp: Constant_Pool, ap: AttributeParent, ap_name_index: Constant_Pool_Index, ap_descriptor_index: Constant_Pool_Index, attribute_name_index: Constant_Pool_Index, in: DataInputStream ) ⇒ { /*val attribute_length =*/ in.readInt val num_bootstrap_methods = in.readUnsignedShort if (num_bootstrap_methods > 0 || reifyEmptyAttributes) { BootstrapMethods_attribute( cp, ap_name_index, ap_descriptor_index, attribute_name_index, fillRefArray(num_bootstrap_methods) { BootstrapMethod(cp, in) } ) } else { null } } registerAttributeReader(BootstrapMethodsAttribute.Name → parserFactory()) }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy