1 /*
   2  * Copyright (c) 2005, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package javax.lang.model.element;
  27 
  28 import java.util.List;
  29 
  30 /**
  31  * Represents a module program element.  Provides access to information
  32  * about the module and its members.
  33  *
  34  * @see javax.lang.model.util.Elements#getModuleOf
  35  * @since 9
  36  * @spec JPMS
  37  */  // TODO: add @jls to module section
  38 public interface ModuleElement extends Element, QualifiedNameable {
  39 
  40     /**
  41      * Returns the fully qualified name of this module.
  42      *
  43      * @return the qualified name of this module, or an
  44      * empty name if this is an unnamed module
  45      */
  46     @Override
  47     Name getQualifiedName();
  48 
  49     /**
  50      * Returns the simple name of this module.  For an unnamed
  51      * module, an empty name is returned.
  52      *
  53      * @return the simple name of this module or an empty name if
  54      * this is an unnamed module
  55      */
  56     @Override
  57     Name getSimpleName();
  58 
  59     /**
  60      * Returns the packages within this module.
  61      * @return the packages within this module
  62      */
  63     @Override
  64     List<? extends Element> getEnclosedElements();
  65 
  66     /**
  67      * Returns {@code true} if this is an open module and {@code
  68      * false} otherwise.
  69      *
  70      * @return {@code true} if this is an open module and {@code
  71      * false} otherwise
  72      */ // TODO: add @jls to unnamed module section
  73     boolean isOpen();
  74 
  75     /**
  76      * Returns {@code true} if this is an unnamed module and {@code
  77      * false} otherwise.
  78      *
  79      * @return {@code true} if this is an unnamed module and {@code
  80      * false} otherwise
  81      */ // TODO: add @jls to unnamed module section
  82     boolean isUnnamed();
  83 
  84     /**
  85      * Returns {@code null} since a module is not enclosed by another
  86      * element.
  87      *
  88      * @return {@code null}
  89      */
  90     @Override
  91     Element getEnclosingElement();
  92 
  93     /**
  94      * Returns the directives contained in the declaration of this module.
  95      * @return  the directives in the declaration of this module
  96      */
  97     List<? extends Directive> getDirectives();
  98 
  99     /**
 100      * The {@code kind} of a directive.
 101      *
 102      * <p>Note that it is possible additional directive kinds will be added
 103      * to accommodate new, currently unknown, language structures added to
 104      * future versions of the Java&trade; programming language.
 105      *
 106      * @since 9
 107      * @spec JPMS
 108      */
 109     enum DirectiveKind {
 110         /** A "requires (static|transitive)* module-name" directive. */
 111         REQUIRES,
 112         /** An "exports package-name [to module-name-list]" directive. */
 113         EXPORTS,
 114         /** An "opens package-name [to module-name-list]" directive. */
 115         OPENS,
 116         /** A "uses service-name" directive. */
 117         USES,
 118         /** A "provides service-name with implementation-name" directive. */
 119         PROVIDES
 120     };
 121 
 122     /**
 123      * Represents a "module statement" within the declaration of this module.
 124      *
 125      * @since 9
 126      * @spec JPMS
 127      *
 128      */ // TODO: add jls to Module Statement
 129     interface Directive {
 130         /**
 131          * Returns the {@code kind} of this directive.
 132          *
 133          * @return the kind of this directive
 134          */
 135         DirectiveKind getKind();
 136     }
 137 
 138     /**
 139      * A dependency of a module.
 140      * @since 9
 141      * @spec JPMS
 142      */
 143     interface RequiresDirective extends Directive {
 144         /**
 145          * Returns whether or not this is a static dependency.
 146          * @return whether or not this is a static dependency
 147          */
 148         boolean isStatic();
 149 
 150         /**
 151          * Returns whether or not this is a transitive dependency.
 152          * @return whether or not this is a transitive dependency
 153          */
 154         boolean isTransitive();
 155 
 156         /**
 157          * Returns the module that is required
 158          * @return the module that is required
 159          */
 160         ModuleElement getDependency();
 161     }
 162 
 163     /**
 164      * An exported package of a module.
 165      * @since 9
 166      * @spec JPMS
 167      */
 168     interface ExportsDirective extends Directive {
 169 
 170         /**
 171          * Returns the package being exported.
 172          * @return the package being exported
 173          */
 174         PackageElement getPackage();
 175 
 176         /**
 177          * Returns the specific modules to which the package is being exported,
 178          * or null, if the package is exported to all modules which
 179          * have readability to this module.
 180          * @return the specific modules to which the package is being exported
 181          */
 182         List<? extends ModuleElement> getTargetModules();
 183     }
 184 
 185     /**
 186      * An opened package of a module.
 187      * @since 9
 188      * @spec JPMS
 189      */
 190     interface OpensDirective extends Directive {
 191 
 192         /**
 193          * Returns the package being opened.
 194          * @return the package being opened
 195          */
 196         PackageElement getPackage();
 197 
 198         /**
 199          * Returns the specific modules to which the package is being open
 200          * or null, if the package is open all modules which
 201          * have readability to this module.
 202          * @return the specific modules to which the package is being opened
 203          */
 204         List<? extends ModuleElement> getTargetModules();
 205     }
 206 
 207     /**
 208      * An implementation of a service provided by a module.
 209      * @since 9
 210      * @spec JPMS
 211      */
 212     interface ProvidesDirective extends Directive {
 213         /**
 214          * Returns the service being provided.
 215          * @return the service being provided
 216          */
 217         TypeElement getService();
 218 
 219         /**
 220          * Returns the implementations of the service being provided.
 221          * @return the implementations of the service being provided
 222          */
 223         List<? extends TypeElement> getImplementations();
 224     }
 225 
 226     /**
 227      * A reference to a service used by a module.
 228      * @since 9
 229      * @spec JPMS
 230      */
 231     interface UsesDirective extends Directive {
 232         /**
 233          * Returns the service that is used.
 234          * @return the service that is used
 235          */
 236         TypeElement getService();
 237     }
 238 }