# Interface ModuleAttribute

All Superinterfaces:
  `Attribute<ModuleAttribute>, ClassElement, ClassFileElement`

public sealed interface ModuleAttribute extends Attribute<ModuleAttribute>, ClassElement
Models the `Module` attribute (JVMS §4.7.25), which always appears on classes that represent module descriptors.

This attribute only appears on classes, and does not permit multiple instances in a class. It has a data dependency on the constant pool.

The attribute was introduced in the Java SE Platform version 9, major version 53.

See Java Virtual Machine Specification:
  4.7.25 The `Module` Attribute
Since:
  24
See Also:
  - `Attributes.module()`
  - `ModuleDescriptor`

## Nested Class Summary

Nested Classes
Modifier and Type
Interface
Description
`static interface`
`ModuleAttribute.ModuleAttributeBuilder`
A builder for `Module` attributes.

## Method Summary

Modifier and Type
Method
Description
`List<ModuleExportInfo>`
`exports()`
Returns the packages exported by this module.
`default boolean`
`has(AccessFlag flag)`
Tests presence of module flag.
`default Set<AccessFlag>`
`moduleFlags()`
Returns the module flags of the module, as a set of enum constants.
`int`
`moduleFlagsMask()`
Returns the module flags of the module, as a bit mask.
`ModuleEntry`
`moduleName()`
Returns the name of the module.
`Optional<Utf8Entry>`
`moduleVersion()`
Returns the version of the module, if present.
`static ModuleAttribute`
`of(ModuleEntry moduleName, int moduleFlags, Utf8Entry moduleVersion, Collection<ModuleRequireInfo> requires, Collection<ModuleExportInfo> exports, Collection<ModuleOpenInfo> opens, Collection<ClassEntry> uses, Collection<ModuleProvideInfo> provides)`
Returns a `Module` attribute.
`static ModuleAttribute`
`of(ModuleEntry moduleName, Consumer<ModuleAttribute.ModuleAttributeBuilder> attrHandler)`
Returns a `Module` attribute.
`static ModuleAttribute`
`of(ModuleDesc moduleName, Consumer<ModuleAttribute.ModuleAttributeBuilder> attrHandler)`
Returns a `Module` attribute.
`List<ModuleOpenInfo>`
`opens()`
Returns the packages opened by this module.
`List<ModuleProvideInfo>`
`provides()`
Returns the service implementations provided by this module.
`List<ModuleRequireInfo>`
`requires()`
Returns the modules required by this module.
`List<ClassEntry>`
`uses()`
Returns the services used by this module.

### Methods declared in interface Attribute

`attributeMapper, attributeName`
Modifier and Type
Method
Description
`AttributeMapper<ModuleAttribute>`
`attributeMapper()`
Returns the `AttributeMapper` associated with this attribute.
`Utf8Entry`
`attributeName()`
Returns the name of the attribute.

## Method Details

### moduleName

ModuleEntry moduleName()
Returns the name of the module.

Returns:
  the name of the module
See Also:
  - `ModuleDescriptor.name()`

### moduleFlagsMask

int moduleFlagsMask()
Returns the module flags of the module, as a bit mask. It is a `u2` value.

Returns:
  the module flags of the module, as a bit mask
See Also:
  - `ModuleDescriptor.modifiers()`
  - `AccessFlag.Location.MODULE`

### moduleFlags

default Set<AccessFlag> moduleFlags()
Returns the module flags of the module, as a set of enum constants.

Returns:
  the module flags of the module, as a set of enum constants
Throws:
  `IllegalArgumentException` - if the flags mask has any undefined bit set
See Also:
  - `ModuleDescriptor.accessFlags()`
  - `AccessFlag.Location.MODULE`

### has

default boolean has(AccessFlag flag)
Tests presence of module flag.

Parameters:
  `flag` - the module flag
Returns:
  true if the flag is set
See Also:
  - `AccessFlag.Location.MODULE`

### moduleVersion

Optional<Utf8Entry> moduleVersion()
Returns the version of the module, if present.

Returns:
  the version of the module, if present
See Also:
  - `ModuleDescriptor.version()`

### requires

List<ModuleRequireInfo> requires()
Returns the modules required by this module.

Returns:
  the modules required by this module
See Also:
  - `ModuleDescriptor.requires()`

### exports

List<ModuleExportInfo> exports()
Returns the packages exported by this module.

Returns:
  the packages exported by this module
See Also:
  - `ModuleDescriptor.packages()`

### opens

List<ModuleOpenInfo> opens()
Returns the packages opened by this module.

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.
Returns:
  the packages opened by this module
See Also:
  - `ModuleDescriptor.opens()`

### uses

List<ClassEntry> uses()
Returns the services used by this module. Services may be discovered via `ServiceLoader`.

Returns:
  the services used by this module
See Also:
  - `ModuleDescriptor.uses()`

### provides

List<ModuleProvideInfo> provides()
Returns the service implementations provided by this module.

Returns:
  the service implementations provided by this module
See Also:
  - `ModuleDescriptor.provides()`

### of

static ModuleAttribute of(ModuleEntry moduleName, int moduleFlags, Utf8Entry moduleVersion, Collection<ModuleRequireInfo> requires, Collection<ModuleExportInfo> exports, Collection<ModuleOpenInfo> opens, Collection<ClassEntry> uses, Collection<ModuleProvideInfo> provides)
Returns a `Module` attribute.

Parameters:
  `moduleName` - the module name
  `moduleFlags` - the module flags
  `moduleVersion` - the module version, may be `null`
  `requires` - the required packages
  `exports` - the exported packages
  `opens` - the opened packages
  `uses` - the consumed services
  `provides` - the provided services
Returns:
  a `Module` attribute
Throws:
  `IllegalArgumentException` - if `moduleFlags` is not `u2` or any of the collections has a size over the limit of `u2`

### of

static ModuleAttribute of(ModuleDesc moduleName, Consumer<ModuleAttribute.ModuleAttributeBuilder> attrHandler)
Returns a `Module` attribute.

Parameters:
  `moduleName` - the module name
  `attrHandler` - a handler that receives a `ModuleAttribute.ModuleAttributeBuilder`
Returns:
  a `Module` attribute
Throws:
  `IllegalArgumentException` - if `moduleName` represents an unnamed module; or if the information from the handler exceeds the `class` file format limit, such as a list with size over the limit of `u2`

### of

static ModuleAttribute of(ModuleEntry moduleName, Consumer<ModuleAttribute.ModuleAttributeBuilder> attrHandler)
Returns a `Module` attribute.

Parameters:
  `moduleName` - the module name
  `attrHandler` - a handler that receives a `ModuleAttribute.ModuleAttributeBuilder`
Returns:
  a `Module` attribute