APIdia Launch Partner
Top Description Inners Methods
javax.lang.model.element

public Interface ModuleElement

extends Element, QualifiedNameable
Imports
java.util.List, javax.lang.model.type.TypeMirror

Represents a module program element. Provides access to information about the module, its directives, and its members.

API Note

The represented module may have an explicit reference representation (either source code or executable output) or may be created from implicit information. The explicit and standalone source code construct for a module is typically a module-info.java file (JLS 7.7). Automatic modules (JLS 7.7.1) are named modules that do not have a module-info file. Implicit information is used to model unnamed modules.

In the context of annotation processing, a module element can be:

Since
9
Java Language Specification
7.7 Module Declarations
See Also
javax.lang.model.util.Elements#getModuleOf

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static interface
ModuleElement.Directive

Represents a directive within the declaration of this module.

public static enum
ModuleElement.DirectiveKind

The kind of a directive.

public static interface
ModuleElement.DirectiveVisitor<
the return type of this visitor's methods. Use Void for visitors that do not need to return results.
R
,
the type of the additional parameter to this visitor's methods. Use Void for visitors that do not need an additional parameter.
P
>

A visitor of module directives, in the style of the visitor design pattern.

public static interface
ModuleElement.ExportsDirective

An exported package of a module.

public static interface
ModuleElement.OpensDirective

An opened package of a module.

public static interface
ModuleElement.ProvidesDirective

An implementation of a service provided by a module.

public static interface
ModuleElement.RequiresDirective

A dependency of a module.

public static interface
ModuleElement.UsesDirective

A reference to a service used by a module.

Method Summary

Modifier and TypeMethod and Description
public TypeMirror

Returns:

a pseudo-type for this module
asType
()

Redeclares javax.lang.model.element.Element.asType.

Returns a pseudo-type for this module.

public List<? extends ModuleElement.Directive>

Returns:

the directives in the declaration of this module
getDirectives
()

Returns the directives contained in the declaration of this module.

public List<? extends Element>

Returns:

the packages within this module
getEnclosedElements
()

Redeclares javax.lang.model.element.Element.getEnclosedElements.

Returns the packages within this module.

public Element

Returns:

null
getEnclosingElement
()

Redeclares javax.lang.model.element.Element.getEnclosingElement.

Returns null since a module is not enclosed by another element.

public Name

Returns:

the fully qualified name of this module, or an empty name if this is an unnamed module
getQualifiedName
()

Redeclares javax.lang.model.element.QualifiedNameable.getQualifiedName.

Returns the fully qualified name of this module.

public Name

Returns:

the simple name of this module or an empty name if this is an unnamed module
getSimpleName
()

Redeclares javax.lang.model.element.Element.getSimpleName.

Returns the simple name of this module.

public boolean

Returns:

true if this is an open module and false otherwise
isOpen
()

Returns true if this is an open module and false otherwise.

public boolean

Returns:

true if this is an unnamed module and false otherwise
isUnnamed
()

Returns true if this is an unnamed module and false otherwise.

Inherited from javax.lang.model.element.Element:
acceptequalsgetAnnotationgetAnnotationMirrorsgetAnnotationsByTypegetKindgetModifiershashCode

Method Detail

asTypeback to summary
public TypeMirror asType()

Redeclares javax.lang.model.element.Element.asType.

Returns a pseudo-type for this module.

Returns:TypeMirror

a pseudo-type for this module

Annotations
@Override
See Also
javax.lang.model.type.NoType, javax.lang.model.type.TypeKind#MODULE
getDirectivesback to summary
public List<? extends ModuleElement.Directive> getDirectives()

Returns the directives contained in the declaration of this module.

Returns:List<? extends ModuleElement.Directive>

the directives in the declaration of this module

getEnclosedElementsback to summary
public List<? extends Element> getEnclosedElements()

Redeclares javax.lang.model.element.Element.getEnclosedElements.

Returns the packages within this module.

Returns:List<? extends Element>

the packages within this module

Annotations
@Override
getEnclosingElementback to summary
public Element getEnclosingElement()

Redeclares javax.lang.model.element.Element.getEnclosingElement.

Returns null since a module is not enclosed by another element.

Returns:Element

null

Annotations
@Override
getQualifiedNameback to summary
public Name getQualifiedName()

Redeclares javax.lang.model.element.QualifiedNameable.getQualifiedName.

Returns the fully qualified name of this module. For an unnamed module, an empty name is returned.

API Note

If the module name consists of one identifier, then this method returns that identifier, which is deemed to be module's fully qualified name despite not being in qualified form. If the module name consists of more than one identifier, then this method returns the entire name.

Returns:Name

the fully qualified name of this module, or an empty name if this is an unnamed module

Annotations
@Override
Java Language Specification
6.2 Names and Identifiers
getSimpleNameback to summary
public Name getSimpleName()

Redeclares javax.lang.model.element.Element.getSimpleName.

Returns the simple name of this module. For an unnamed module, an empty name is returned.

API Note

If the module name consists of one identifier, then this method returns that identifier. If the module name consists of more than one identifier, then this method returns the rightmost such identifier, which is deemed to be the module's simple name.

Returns:Name

the simple name of this module or an empty name if this is an unnamed module

Annotations
@Override
Java Language Specification
6.2 Names and Identifiers
isOpenback to summary
public boolean isOpen()

Returns true if this is an open module and false otherwise.

Returns:boolean

true if this is an open module and false otherwise

isUnnamedback to summary
public boolean isUnnamed()

Returns true if this is an unnamed module and false otherwise.

Returns:boolean

true if this is an unnamed module and false otherwise

Java Language Specification
7.7.5 Unnamed Modules
javax.lang.model.element back to summary

public Interface ModuleElement.Directive

Known Direct Subinterfaces
javax.lang.model.element.ModuleElement.RequiresDirective, javax.lang.model.element.ModuleElement.ExportsDirective, javax.lang.model.element.ModuleElement.OpensDirective, javax.lang.model.element.ModuleElement.ProvidesDirective, javax.lang.model.element.ModuleElement.UsesDirective

Represents a directive within the declaration of this module. The directives of a module declaration configure the module in the Java Platform Module System.
Since
9

Method Summary

Modifier and TypeMethod and Description
public <
the return type of the visitor's methods
R
,
the type of the additional parameter to the visitor's methods
P
>
R

Returns:

a visitor-specified result
accept
(ModuleElement.DirectiveVisitor<R, P>
the visitor operating on this directive
v
,
P
additional parameter to the visitor
p
)

Applies a visitor to this directive.

public ModuleElement.DirectiveKind

Returns:

the kind of this directive
getKind
()

Returns the kind of this directive.

Method Detail

acceptback to summary
public <R, P> R accept(ModuleElement.DirectiveVisitor<R, P> v, P p)

Applies a visitor to this directive.

Parameters
<R>
the return type of the visitor's methods
<P>
the type of the additional parameter to the visitor's methods
v:ModuleElement.DirectiveVisitor<R, P>

the visitor operating on this directive

p:P

additional parameter to the visitor

Returns:R

a visitor-specified result

getKindback to summary
public ModuleElement.DirectiveKind getKind()

Returns the kind of this directive.

Returns:ModuleElement.DirectiveKind

the kind of this directive

javax.lang.model.element back to summary

public final Enum ModuleElement.DirectiveKind

extends Enum<ModuleElement.DirectiveKind>
Class Inheritance

The kind of a directive.

Note that it is possible additional directive kinds will be added to accommodate new, currently unknown, language structures added to future versions of the Java programming language.

Since
9

Field Summary

Modifier and TypeField and Description
public static final ModuleElement.DirectiveKind
EXPORTS

An "exports package-name [to module-name-list]" directive.

public static final ModuleElement.DirectiveKind
OPENS

An "opens package-name [to module-name-list]" directive.

public static final ModuleElement.DirectiveKind
PROVIDES

A "provides service-name with implementation-name" directive.

public static final ModuleElement.DirectiveKind
REQUIRES

A "requires (static|transitive)* module-name" directive.

public static final ModuleElement.DirectiveKind
USES

A "uses service-name" directive.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static ModuleElement.DirectiveKind
public static ModuleElement.DirectiveKind[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

EXPORTSback to summary
public static final ModuleElement.DirectiveKind EXPORTS

An "exports package-name [to module-name-list]" directive.

OPENSback to summary
public static final ModuleElement.DirectiveKind OPENS

An "opens package-name [to module-name-list]" directive.

PROVIDESback to summary
public static final ModuleElement.DirectiveKind PROVIDES

A "provides service-name with implementation-name" directive.

REQUIRESback to summary
public static final ModuleElement.DirectiveKind REQUIRES

A "requires (static|transitive)* module-name" directive.

USESback to summary
public static final ModuleElement.DirectiveKind USES

A "uses service-name" directive.

Constructor Detail

DirectiveKindback to summary
private DirectiveKind()

Method Detail

valueOfback to summary
public static ModuleElement.DirectiveKind valueOf(String name)
valuesback to summary
public static ModuleElement.DirectiveKind[] values()
javax.lang.model.element back to summary

public Interface ModuleElement.DirectiveVisitor<R, P>

Type Parameters
<R>
the return type of this visitor's methods. Use Void for visitors that do not need to return results.
<P>
the type of the additional parameter to this visitor's methods. Use Void for visitors that do not need an additional parameter.

A visitor of module directives, in the style of the visitor design pattern. Classes implementing this interface are used to operate on a directive when the kind of directive is unknown at compile time. When a visitor is passed to a directive's accept method, the visitXyz method applicable to that directive is invoked.

Classes implementing this interface may or may not throw a NullPointerException if the additional parameter p is null; see documentation of the implementing class for details.

Warning

It is possible that methods will be added to this interface to accommodate new, currently unknown, language structures added to future versions of the Java programming language. Methods to accommodate new language constructs will be added in a source compatible way using default methods.

Since
9

Method Summary

Modifier and TypeMethod and Description
public default R

Returns:

a visitor-specified result
visit
(ModuleElement.Directive
the directive to visit
d
)

Visits any directive as if by passing itself to that directive's accept method and passing null for the additional parameter.

public default R

Returns:

a visitor-specified result
visit
(ModuleElement.Directive
the directive to visit
d
,
P
a visitor-specified parameter
p
)

Visits any directive as if by passing itself to that directive's accept method.

public R

Returns:

a visitor-specified result
visitExports
(ModuleElement.ExportsDirective
the directive to visit
d
,
P
a visitor-specified parameter
p
)

Visits an exports directive.

public R

Returns:

a visitor-specified result
visitOpens
(ModuleElement.OpensDirective
the directive to visit
d
,
P
a visitor-specified parameter
p
)

Visits an opens directive.

public R

Returns:

a visitor-specified result
visitProvides
(ModuleElement.ProvidesDirective
the directive to visit
d
,
P
a visitor-specified parameter
p
)

Visits a provides directive.

public R

Returns:

a visitor-specified result
visitRequires
(ModuleElement.RequiresDirective
the directive to visit
d
,
P
a visitor-specified parameter
p
)

Visits a requires directive.

public default R

Returns:

a visitor-specified result
visitUnknown
(ModuleElement.Directive
the directive to visit
d
,
P
a visitor-specified parameter
p
)

Visits an unknown directive.

public R

Returns:

a visitor-specified result
visitUses
(ModuleElement.UsesDirective
the directive to visit
d
,
P
a visitor-specified parameter
p
)

Visits a uses directive.

Method Detail

visitback to summary
public default R visit(ModuleElement.Directive d)

Visits any directive as if by passing itself to that directive's accept method and passing null for the additional parameter.

Implementation Specification

The default implementation is d.accept(v, null).

Parameters
d:ModuleElement.Directive

the directive to visit

Returns:R

a visitor-specified result

visitback to summary
public default R visit(ModuleElement.Directive d, P p)

Visits any directive as if by passing itself to that directive's accept method.

Implementation Specification

The default implementation is d.accept(v, p).

Parameters
d:ModuleElement.Directive

the directive to visit

p:P

a visitor-specified parameter

Returns:R

a visitor-specified result

visitExportsback to summary
public R visitExports(ModuleElement.ExportsDirective d, P p)

Visits an exports directive.

Parameters
d:ModuleElement.ExportsDirective

the directive to visit

p:P

a visitor-specified parameter

Returns:R

a visitor-specified result

visitOpensback to summary
public R visitOpens(ModuleElement.OpensDirective d, P p)

Visits an opens directive.

Parameters
d:ModuleElement.OpensDirective

the directive to visit

p:P

a visitor-specified parameter

Returns:R

a visitor-specified result

visitProvidesback to summary
public R visitProvides(ModuleElement.ProvidesDirective d, P p)

Visits a provides directive.

Parameters
d:ModuleElement.ProvidesDirective

the directive to visit

p:P

a visitor-specified parameter

Returns:R

a visitor-specified result

visitRequiresback to summary
public R visitRequires(ModuleElement.RequiresDirective d, P p)

Visits a requires directive.

Parameters
d:ModuleElement.RequiresDirective

the directive to visit

p:P

a visitor-specified parameter

Returns:R

a visitor-specified result

visitUnknownback to summary
public default R visitUnknown(ModuleElement.Directive d, P p)

Visits an unknown directive. This can occur if the language evolves and new kinds of directive are added.

Implementation Specification

The default implementation throws new UnknownDirectiveException(d, p).

Parameters
d:ModuleElement.Directive

the directive to visit

p:P

a visitor-specified parameter

Returns:R

a visitor-specified result

Exceptions
UnknownDirectiveException:
a visitor implementation may optionally throw this exception
visitUsesback to summary
public R visitUses(ModuleElement.UsesDirective d, P p)

Visits a uses directive.

Parameters
d:ModuleElement.UsesDirective

the directive to visit

p:P

a visitor-specified parameter

Returns:R

a visitor-specified result

javax.lang.model.element back to summary

public Interface ModuleElement.ExportsDirective

extends Directive

An exported package of a module.
Since
9

Method Summary

Modifier and TypeMethod and Description
public PackageElement

Returns:

the package being exported
getPackage
()

Returns the package being exported.

public List<? extends ModuleElement>

Returns:

the specific modules to which the package is being exported
getTargetModules
()

Returns the specific modules to which the package is being exported, or null, if the package is exported to all modules which have readability to this module.

Inherited from javax.lang.model.element.ModuleElement.Directive:
acceptgetKind

Method Detail

getPackageback to summary
public PackageElement getPackage()

Returns the package being exported.

Returns:PackageElement

the package being exported

getTargetModulesback to summary
public List<? extends ModuleElement> getTargetModules()

Returns the specific modules to which the package is being exported, or null, if the package is exported to all modules which have readability to this module.

Returns:List<? extends ModuleElement>

the specific modules to which the package is being exported

javax.lang.model.element back to summary

public Interface ModuleElement.OpensDirective

extends Directive

An opened package of a module.
Since
9

Method Summary

Modifier and TypeMethod and Description
public PackageElement

Returns:

the package being opened
getPackage
()

Returns the package being opened.

public List<? extends ModuleElement>

Returns:

the specific modules to which the package is being opened
getTargetModules
()

Returns the specific modules to which the package is being open or null, if the package is open all modules which have readability to this module.

Inherited from javax.lang.model.element.ModuleElement.Directive:
acceptgetKind

Method Detail

getPackageback to summary
public PackageElement getPackage()

Returns the package being opened.

Returns:PackageElement

the package being opened

getTargetModulesback to summary
public List<? extends ModuleElement> getTargetModules()

Returns the specific modules to which the package is being open or null, if the package is open all modules which have readability to this module.

Returns:List<? extends ModuleElement>

the specific modules to which the package is being opened

javax.lang.model.element back to summary

public Interface ModuleElement.ProvidesDirective

extends Directive

An implementation of a service provided by a module.
Since
9

Method Summary

Modifier and TypeMethod and Description
public List<? extends TypeElement>

Returns:

the implementations of the service being provided
getImplementations
()

Returns the implementations of the service being provided.

public TypeElement

Returns:

the service being provided
getService
()

Returns the service being provided.

Inherited from javax.lang.model.element.ModuleElement.Directive:
acceptgetKind

Method Detail

getImplementationsback to summary
public List<? extends TypeElement> getImplementations()

Returns the implementations of the service being provided.

Returns:List<? extends TypeElement>

the implementations of the service being provided

getServiceback to summary
public TypeElement getService()

Returns the service being provided.

Returns:TypeElement

the service being provided

javax.lang.model.element back to summary

public Interface ModuleElement.RequiresDirective

extends Directive

A dependency of a module.
Since
9

Method Summary

Modifier and TypeMethod and Description
public ModuleElement

Returns:

the module that is required
getDependency
()

Returns the module that is required.

public boolean

Returns:

whether or not this is a static dependency
isStatic
()

Returns whether or not this is a static dependency.

public boolean

Returns:

whether or not this is a transitive dependency
isTransitive
()

Returns whether or not this is a transitive dependency.

Inherited from javax.lang.model.element.ModuleElement.Directive:
acceptgetKind

Method Detail

getDependencyback to summary
public ModuleElement getDependency()

Returns the module that is required.

Returns:ModuleElement

the module that is required

isStaticback to summary
public boolean isStatic()

Returns whether or not this is a static dependency.

Returns:boolean

whether or not this is a static dependency

isTransitiveback to summary
public boolean isTransitive()

Returns whether or not this is a transitive dependency.

Returns:boolean

whether or not this is a transitive dependency

javax.lang.model.element back to summary

public Interface ModuleElement.UsesDirective

extends Directive

A reference to a service used by a module.
Since
9

Method Summary

Modifier and TypeMethod and Description
public TypeElement

Returns:

the service that is used
getService
()

Returns the service that is used.

Inherited from javax.lang.model.element.ModuleElement.Directive:
acceptgetKind

Method Detail

getServiceback to summary
public TypeElement getService()

Returns the service that is used.

Returns:TypeElement

the service that is used