ModuleAttribute.ModuleAttributeBuilder (Java SE 26 & JDK 26)
Description: declaration: module: java.base, package: java.lang.classfile.attribute, interface: ModuleAttribute, interface: ModuleAttributeBuilder
Keywords: java.lang.classfile.attribute.ModuleAttribute.ModuleAttributeBuilder interface

# Interface ModuleAttribute.ModuleAttributeBuilder

Enclosing interface:
  `ModuleAttribute`

public static sealed interface ModuleAttribute.ModuleAttributeBuilder
A builder for `Module` attributes.

See Java Virtual Machine Specification:
  4.7.25 The `Module` Attribute
Since:
  24
See Also:
  - `ModuleDescriptor.Builder`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `ModuleAttribute.ModuleAttributeBuilder`
  `exports(ModuleExportInfo exports)`
  Adds an exported package.
  `ModuleAttribute.ModuleAttributeBuilder`
  `exports(PackageDesc pkge, int exportsFlagsMask, ModuleDesc... exportsToModules)`
  Adds an exported package.
  `default ModuleAttribute.ModuleAttributeBuilder`
  `exports(PackageDesc pkge, Collection<AccessFlag> exportsFlags, ModuleDesc... exportsToModules)`
  Adds an exported package.
  `ModuleAttribute.ModuleAttributeBuilder`
  `moduleFlags(int flagsMask)`
  Sets the module flags.
  `default ModuleAttribute.ModuleAttributeBuilder`
  `moduleFlags(AccessFlag... moduleFlags)`
  Sets the module flags.
  `ModuleAttribute.ModuleAttributeBuilder`
  `moduleName(ModuleDesc moduleName)`
  Sets the module name.
  `ModuleAttribute.ModuleAttributeBuilder`
  `moduleVersion(String version)`
  Sets the module version, which may be `null`.
  `ModuleAttribute.ModuleAttributeBuilder`
  `opens(ModuleOpenInfo opens)`
  Opens a package.
  `ModuleAttribute.ModuleAttributeBuilder`
  `opens(PackageDesc pkge, int opensFlagsMask, ModuleDesc... opensToModules)`
  Opens a package.
  `default ModuleAttribute.ModuleAttributeBuilder`
  `opens(PackageDesc pkge, Collection<AccessFlag> opensFlags, ModuleDesc... opensToModules)`
  Opens a package.
  `ModuleAttribute.ModuleAttributeBuilder`
  `provides(ModuleProvideInfo provides)`
  Declares provision of a service.
  `ModuleAttribute.ModuleAttributeBuilder`
  `provides(ClassDesc service, ClassDesc... implClasses)`
  Declares provision of a service.
  `ModuleAttribute.ModuleAttributeBuilder`
  `requires(ModuleRequireInfo requires)`
  Adds module requirement.
  `ModuleAttribute.ModuleAttributeBuilder`
  `requires(ModuleDesc module, int requiresFlagsMask, String version)`
  Adds a module requirement.
  `default ModuleAttribute.ModuleAttributeBuilder`
  `requires(ModuleDesc module, Collection<AccessFlag> requiresFlags, String version)`
  Adds a module requirement.
  `ModuleAttribute.ModuleAttributeBuilder`
  `uses(ClassEntry uses)`
  Declares use of a service.
  `ModuleAttribute.ModuleAttributeBuilder`
  `uses(ClassDesc service)`
  Declares use of a service.

- ## Method Details

  - ### moduleName

    ModuleAttribute.ModuleAttributeBuilder moduleName(ModuleDesc moduleName)
    Sets the module name.
    Parameters:
      `moduleName` - the module name
    Returns:
      this builder

  - ### moduleFlags

    ModuleAttribute.ModuleAttributeBuilder moduleFlags(int flagsMask)
    Sets the module flags.
    Parameters:
      `flagsMask` - the module flags
    Returns:
      this builder
    Throws:
      `IllegalArgumentException` - if `flagsMask` is not `u2`

  - ### moduleFlags

    default ModuleAttribute.ModuleAttributeBuilder moduleFlags(AccessFlag... moduleFlags)
    Sets the module flags.
    Parameters:
      `moduleFlags` - the module flags
    Returns:
      this builder
    Throws:
      `IllegalArgumentException` - if any flag cannot be applied to the `AccessFlag.Location.MODULE` location

  - ### moduleVersion

    ModuleAttribute.ModuleAttributeBuilder moduleVersion(String version)
    Sets the module version, which may be `null`.
    Parameters:
      `version` - the module version, may be `null`
    Returns:
      this builder

  - ### requires

    ModuleAttribute.ModuleAttributeBuilder requires(ModuleDesc module, int requiresFlagsMask, String version)
    Adds a module requirement.
    Parameters:
      `module` - the required module
      `requiresFlagsMask` - the requires flags
      `version` - the required module version, may be `null`
    Returns:
      this builder

  - ### requires

    default ModuleAttribute.ModuleAttributeBuilder requires(ModuleDesc module, Collection<AccessFlag> requiresFlags, String version)
    Adds a module requirement.
    Parameters:
      `module` - the required module
      `requiresFlags` - the requires flags
      `version` - the required module version, may be `null`
    Returns:
      this builder
    Throws:
      `IllegalArgumentException` - if any flag cannot be applied to the `AccessFlag.Location.MODULE_REQUIRES` location

  - ### requires

    ModuleAttribute.ModuleAttributeBuilder requires(ModuleRequireInfo requires)
    Adds module requirement.
    Parameters:
      `requires` - the module require info
    Returns:
      this builder

  - ### exports

    ModuleAttribute.ModuleAttributeBuilder exports(PackageDesc pkge, int exportsFlagsMask, ModuleDesc... exportsToModules)
    Adds an exported package.
    Parameters:
      `pkge` - the exported package
      `exportsFlagsMask` - the export flags
      `exportsToModules` - the modules to export to, or empty for an unqualified export
    Returns:
      this builder
    Throws:
      `IllegalArgumentException` - if the number of modules exceeds the limit of `u2`

  - ### exports

    default ModuleAttribute.ModuleAttributeBuilder exports(PackageDesc pkge, Collection<AccessFlag> exportsFlags, ModuleDesc... exportsToModules)
    Adds an exported package.
    Parameters:
      `pkge` - the exported package
      `exportsFlags` - the export flags
      `exportsToModules` - the modules to export to, or empty for an unqualified export
    Returns:
      this builder
    Throws:
      `IllegalArgumentException` - if any flag cannot be applied to the `AccessFlag.Location.MODULE_EXPORTS` location or the number of modules exceeds the limit of `u2`

  - ### exports

    ModuleAttribute.ModuleAttributeBuilder exports(ModuleExportInfo exports)
    Adds an exported package.
    Parameters:
      `exports` - the module export info
    Returns:
      this builder

  - ### opens

    ModuleAttribute.ModuleAttributeBuilder opens(PackageDesc pkge, int opensFlagsMask, ModuleDesc... opensToModules)
    Opens a package.
    API Note:
      Opening a package to another module allows that other module to gain the same full privilege access as members in this module. See `MethodHandles.privateLookupIn(Class, MethodHandles.Lookup)` for more details.
    Parameters:
      `pkge` - the opened package
      `opensFlagsMask` - the open package flags
      `opensToModules` - the modules to open to, or empty for an unqualified open
    Returns:
      this builder
    Throws:
      `IllegalArgumentException` - if the number of modules exceeds the limit of `u2`

  - ### opens

    default ModuleAttribute.ModuleAttributeBuilder opens(PackageDesc pkge, Collection<AccessFlag> opensFlags, ModuleDesc... opensToModules)
    Opens a package.
    API Note:
      Opening a package to another module allows that other module to gain the same full privilege access as members in this module. See `MethodHandles.privateLookupIn(Class, MethodHandles.Lookup)` for more details.
    Parameters:
      `pkge` - the opened package
      `opensFlags` - the open package flags
      `opensToModules` - the modules to open to, or empty for an unqualified open
    Returns:
      this builder
    Throws:
      `IllegalArgumentException` - if any flag cannot be applied to the `AccessFlag.Location.MODULE_OPENS` location, or if the number of modules exceeds the limit of `u2`

  - ### opens

    ModuleAttribute.ModuleAttributeBuilder opens(ModuleOpenInfo opens)
    Opens a package.
    API Note:
      Opening a package to another module allows that other module to gain the same full privilege access as members in this module. See `MethodHandles.privateLookupIn(Class, MethodHandles.Lookup)` for more details.
    Parameters:
      `opens` - the module open info
    Returns:
      this builder

  - ### uses

    ModuleAttribute.ModuleAttributeBuilder uses(ClassDesc service)
    Declares use of a service.
    Parameters:
      `service` - the service class used
    Returns:
      this builder
    Throws:
      `IllegalArgumentException` - if `service` represents a primitive type

  - ### uses

    ModuleAttribute.ModuleAttributeBuilder uses(ClassEntry uses)
    Declares use of a service.
    Parameters:
      `uses` - the service class used
    Returns:
      this builder

  - ### provides

    ModuleAttribute.ModuleAttributeBuilder provides(ClassDesc service, ClassDesc... implClasses)
    Declares provision of a service.
    Parameters:
      `service` - the service class provided
      `implClasses` - the implementation classes
    Returns:
      this builder
    Throws:
      `IllegalArgumentException` - if `service` or any of the `implClasses` represents a primitive type, or the number of implementations exceeds the limit of `u2`

  - ### provides

    ModuleAttribute.ModuleAttributeBuilder provides(ModuleProvideInfo provides)
    Declares provision of a service.
    Parameters:
      `provides` - the module provides info
    Returns:
      this builder