Path: blob/master/src/java.compiler/share/classes/javax/lang/model/element/ModuleElement.java
41161 views
/*1* Copyright (c) 2005, 2020, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package javax.lang.model.element;2627import java.util.List;28import javax.lang.model.type.TypeMirror;2930/**31* Represents a module program element. Provides access to32* information about the module, its directives, and its members.33*34* @see javax.lang.model.util.Elements#getModuleOf35* @since 936* @jls 7.7 Module Declarations37*/38public interface ModuleElement extends Element, QualifiedNameable {39/**40* {@return a {@linkplain javax.lang.model.type.NoType pseudo-type}41* for this module}42*43* @see javax.lang.model.type.NoType44* @see javax.lang.model.type.TypeKind#MODULE45*/46@Override47TypeMirror asType();4849/**50* Returns the fully qualified name of this module. For an51* {@linkplain #isUnnamed() unnamed module}, an <a52* href=Name.html#empty_name>empty name</a> is returned.53*54* @apiNote If the module name consists of one identifier, then55* this method returns that identifier, which is deemed to be56* module's fully qualified name despite not being in qualified57* form. If the module name consists of more than one identifier,58* then this method returns the entire name.59*60* @return the fully qualified name of this module, or an61* empty name if this is an unnamed module62*63* @jls 6.2 Names and Identifiers64*/65@Override66Name getQualifiedName();6768/**69* Returns the simple name of this module. For an {@linkplain70* #isUnnamed() unnamed module}, an <a71* href=Name.html#empty_name>empty name</a> is returned.72*73* @apiNote If the module name consists of one identifier, then74* this method returns that identifier. If the module name75* consists of more than one identifier, then this method returns76* the rightmost such identifier, which is deemed to be the77* module's simple name.78*79* @return the simple name of this module or an empty name if80* this is an unnamed module81*82* @jls 6.2 Names and Identifiers83*/84@Override85Name getSimpleName();8687/**88* {@return the packages within this module}89*/90@Override91List<? extends Element> getEnclosedElements();9293/**94* {@return {@code true} if this is an open module and {@code95* false} otherwise}96*/97boolean isOpen();9899/**100* {@return {@code true} if this is an unnamed module and {@code101* false} otherwise}102*103* @jls 7.7.5 Unnamed Modules104*/105boolean isUnnamed();106107/**108* Returns {@code null} since a module is not enclosed by another109* element.110*111* @return {@code null}112*/113@Override114Element getEnclosingElement();115116/**117* Returns the directives contained in the declaration of this module.118* @return the directives in the declaration of this module119*/120List<? extends Directive> getDirectives();121122/**123* The {@code kind} of a directive.124*125* <p>Note that it is possible additional directive kinds will be added126* to accommodate new, currently unknown, language structures added to127* future versions of the Java programming language.128*129* @since 9130*/131enum DirectiveKind {132/** A "requires (static|transitive)* module-name" directive. */133REQUIRES,134/** An "exports package-name [to module-name-list]" directive. */135EXPORTS,136/** An "opens package-name [to module-name-list]" directive. */137OPENS,138/** A "uses service-name" directive. */139USES,140/** A "provides service-name with implementation-name" directive. */141PROVIDES142};143144/**145* Represents a directive within the declaration of this146* module. The directives of a module declaration configure the147* module in the Java Platform Module System.148*149* @since 9150*/151interface Directive {152/**153* {@return the {@code kind} of this directive}154* <ul>155*156* <li> The kind of a {@linkplain RequiresDirective requires157* directive} is {@link DirectiveKind#REQUIRES REQUIRES}.158*159* <li> The kind of an {@linkplain ExportsDirective exports160* directive} is {@link DirectiveKind#EXPORTS EXPORTS}.161*162* <li> The kind of an {@linkplain OpensDirective opens163* directive} is {@link DirectiveKind#OPENS OPENS}.164*165* <li> The kind of a {@linkplain UsesDirective uses166* directive} is {@link DirectiveKind#USES USES}.167*168* <li> The kind of a {@linkplain ProvidesDirective provides169* directive} is {@link DirectiveKind#PROVIDES PROVIDES}.170*171* </ul>172*/173DirectiveKind getKind();174175/**176* Applies a visitor to this directive.177*178* @param <R> the return type of the visitor's methods179* @param <P> the type of the additional parameter to the visitor's methods180* @param v the visitor operating on this directive181* @param p additional parameter to the visitor182* @return a visitor-specified result183*/184<R, P> R accept(DirectiveVisitor<R, P> v, P p);185}186187/**188* A visitor of module directives, in the style of the visitor design189* pattern. Classes implementing this interface are used to operate190* on a directive when the kind of directive is unknown at compile time.191* When a visitor is passed to a directive's {@link Directive#accept192* accept} method, the <code>visit<i>Xyz</i></code> method applicable193* to that directive is invoked.194*195* <p> Classes implementing this interface may or may not throw a196* {@code NullPointerException} if the additional parameter {@code p}197* is {@code null}; see documentation of the implementing class for198* details.199*200* <p> <b>WARNING:</b> It is possible that methods will be added to201* this interface to accommodate new, currently unknown, language202* structures added to future versions of the Java programming203* language. Methods to accommodate new language constructs will204* be added in a source <em>compatible</em> way using205* <em>default methods</em>.206*207* @param <R> the return type of this visitor's methods. Use {@link208* Void} for visitors that do not need to return results.209* @param <P> the type of the additional parameter to this visitor's210* methods. Use {@code Void} for visitors that do not need an211* additional parameter.212*213* @since 9214*/215interface DirectiveVisitor<R, P> {216/**217* Visits any directive as if by passing itself to that218* directive's {@link Directive#accept accept} method and passing219* {@code null} for the additional parameter.220*221* @param d the directive to visit222* @return a visitor-specified result223* @implSpec The default implementation is {@code d.accept(v, null)}.224*/225default R visit(Directive d) {226return d.accept(this, null);227}228229/**230* Visits any directive as if by passing itself to that231* directive's {@link Directive#accept accept} method.232*233* @param d the directive to visit234* @param p a visitor-specified parameter235* @return a visitor-specified result236* @implSpec The default implementation is {@code d.accept(v, p)}.237*/238default R visit(Directive d, P p) {239return d.accept(this, p);240}241242/**243* Visits a {@code requires} directive.244* @param d the directive to visit245* @param p a visitor-specified parameter246* @return a visitor-specified result247*/248R visitRequires(RequiresDirective d, P p);249250/**251* Visits an {@code exports} directive.252* @param d the directive to visit253* @param p a visitor-specified parameter254* @return a visitor-specified result255*/256R visitExports(ExportsDirective d, P p);257258/**259* Visits an {@code opens} directive.260* @param d the directive to visit261* @param p a visitor-specified parameter262* @return a visitor-specified result263*/264R visitOpens(OpensDirective d, P p);265266/**267* Visits a {@code uses} directive.268* @param d the directive to visit269* @param p a visitor-specified parameter270* @return a visitor-specified result271*/272R visitUses(UsesDirective d, P p);273274/**275* Visits a {@code provides} directive.276* @param d the directive to visit277* @param p a visitor-specified parameter278* @return a visitor-specified result279*/280R visitProvides(ProvidesDirective d, P p);281282/**283* Visits an unknown directive.284* This can occur if the language evolves and new kinds of directive are added.285* @param d the directive to visit286* @param p a visitor-specified parameter287* @return a visitor-specified result288* @throws UnknownDirectiveException a visitor implementation may optionally throw this exception289* @implSpec The default implementation throws {@code new UnknownDirectiveException(d, p)}.290*/291default R visitUnknown(Directive d, P p) {292throw new UnknownDirectiveException(d, p);293}294}295296/**297* A dependency of a module.298* @since 9299*/300interface RequiresDirective extends Directive {301/**302* {@return whether or not this is a static dependency}303*/304boolean isStatic();305306/**307* {@return whether or not this is a transitive dependency}308*/309boolean isTransitive();310311/**312* {@return the module that is required}313*/314ModuleElement getDependency();315}316317/**318* An exported package of a module.319* @since 9320*/321interface ExportsDirective extends Directive {322323/**324* {@return the package being exported}325*/326PackageElement getPackage();327328/**329* Returns the specific modules to which the package is being exported,330* or {@code null}, if the package is exported to all modules which331* have readability to this module.332* @return the specific modules to which the package is being exported333*/334List<? extends ModuleElement> getTargetModules();335}336337/**338* An opened package of a module.339* @since 9340*/341interface OpensDirective extends Directive {342343/**344* {@return the package being opened}345*/346PackageElement getPackage();347348/**349* Returns the specific modules to which the package is being open350* or {@code null}, if the package is open all modules which351* have readability to this module.352* @return the specific modules to which the package is being opened353*/354List<? extends ModuleElement> getTargetModules();355}356357/**358* An implementation of a service provided by a module.359* @since 9360*/361interface ProvidesDirective extends Directive {362/**363* {@return the service being provided}364*/365TypeElement getService();366367/**368* {@return the implementations of the service being provided}369*/370List<? extends TypeElement> getImplementations();371}372373/**374* A reference to a service used by a module.375* @since 9376*/377interface UsesDirective extends Directive {378/**379* {@return the service that is used}380*/381TypeElement getService();382}383}384385386