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  */  // TODO: add @jls to module section
  37 public interface ModuleElement extends Element, QualifiedNameable {
  38 
  39     /**
  40      * Returns the fully qualified name of this module.
  41      *
  42      * @return the qualified name of this module, or an
  43      * empty name if this is an unnamed module
  44      */
  45     @Override
  46     Name getQualifiedName();
  47 
  48     /**
  49      * Returns the simple name of this module.  For an unnamed
  50      * module, an empty name is returned.
  51      *
  52      * @return the simple name of this module or an empty name if
  53      * this is an unnamed module
  54      */
  55     @Override
  56     Name getSimpleName();
  57 
  58     /**
  59      * Returns the packages within this module.
  60      * @return the packages within this module
  61      */
  62     @Override
  63     List<? extends Element> getEnclosedElements();
  64 
  65     /**
  66      * Returns {@code true} if this is an open module and {@code
  67      * false} otherwise.
  68      *
  69      * @return {@code true} if this is an open module and {@code
  70      * false} otherwise
  71      */ // TODO: add @jls to unnamed module section
  72     boolean isOpen();
  73 
  74     /**
  75      * Returns {@code true} if this is an unnamed module and {@code
  76      * false} otherwise.
  77      *
  78      * @return {@code true} if this is an unnamed module and {@code
  79      * false} otherwise
  80      */ // TODO: add @jls to unnamed module section
  81     boolean isUnnamed();
  82 
  83     /**
  84      * Returns {@code null} since a module is not enclosed by another
  85      * element.
  86      *
  87      * @return {@code null}
  88      */
  89     @Override
  90     Element getEnclosingElement();
  91 
  92     /**
  93      * Returns the directives contained in the declaration of this module.
  94      * @return  the directives in the declaration of this module
  95      */
  96     List<? extends Directive> getDirectives();
  97 
  98     /**
  99      * The {@code kind} of a directive.
 100      *
 101      * <p>Note that it is possible additional directive kinds will be added
 102      * to accommodate new, currently unknown, language structures added to
 103      * future versions of the Java&trade; programming language.
 104      *
 105      * @since 9
 106      */
 107     enum DirectiveKind {
 108         /** A "requires (static|transitive)* module-name" directive. */
 109         REQUIRES,
 110         /** An "exports package-name [to module-name-list]" directive. */
 111         EXPORTS,
 112         /** An "opens package-name [to module-name-list]" directive. */
 113         OPENS,
 114         /** A "uses service-name" directive. */
 115         USES,
 116         /** A "provides service-name with implementation-name" directive. */
 117         PROVIDES
 118     };
 119 
 120     /**
 121      * Represents a "module statement" within the declaration of this module.
 122      *
 123      * @since 9
 124      *
 125      */ // TODO: add jls to Module Statement
 126     interface Directive {
 127         /**
 128          * Returns the {@code kind} of this directive.
 129          *
 130          * @return the kind of this directive
 131          */
 132         DirectiveKind getKind();
 133     }
 134 
 135     /**
 136      * A dependency of a module.
 137      * @since 9
 138      */
 139     interface RequiresDirective extends Directive {
 140         /**
 141          * Returns whether or not this is a static dependency.
 142          * @return whether or not this is a static dependency
 143          */
 144         boolean isStatic();
 145 
 146         /**
 147          * Returns whether or not this is a transitive dependency.
 148          * @return whether or not this is a transitive dependency
 149          */
 150         boolean isTransitive();
 151 
 152         /**
 153          * Returns the module that is required
 154          * @return the module that is required
 155          */
 156         ModuleElement getDependency();
 157     }
 158 
 159     /**
 160      * An exported package of a module.
 161      * @since 9
 162      */
 163     interface ExportsDirective extends Directive {
 164 
 165         /**
 166          * Returns the package being exported.
 167          * @return the package being exported
 168          */
 169         PackageElement getPackage();
 170 
 171         /**
 172          * Returns the specific modules to which the package is being exported,
 173          * or null, if the package is exported to all modules which
 174          * have readability to this module.
 175          * @return the specific modules to which the package is being exported
 176          */
 177         List<? extends ModuleElement> getTargetModules();
 178     }
 179 
 180     /**
 181      * An opened package of a module.
 182      * @since 9
 183      */
 184     interface OpensDirective extends Directive {
 185 
 186         /**
 187          * Returns the package being opened.
 188          * @return the package being opened
 189          */
 190         PackageElement getPackage();
 191 
 192         /**
 193          * Returns the specific modules to which the package is being open
 194          * or null, if the package is open all modules which
 195          * have readability to this module.
 196          * @return the specific modules to which the package is being opened
 197          */
 198         List<? extends ModuleElement> getTargetModules();
 199     }
 200 
 201     /**
 202      * An implementation of a service provided by a module.
 203      * @since 9
 204      */
 205     interface ProvidesDirective extends Directive {
 206         /**
 207          * Returns the service being provided.
 208          * @return the service being provided
 209          */
 210         TypeElement getService();
 211 
 212         /**
 213          * Returns the implementations of the service being provided.
 214          * @return the implementations of the service being provided
 215          */
 216         List<? extends TypeElement> getImplementations();
 217     }
 218 
 219     /**
 220      * A reference to a service used by a module.
 221      * @since 9
 222      */
 223     interface UsesDirective extends Directive {
 224         /**
 225          * Returns the service that is used.
 226          * @return the service that is used
 227          */
 228         TypeElement getService();
 229     }
 230 }