ModuleElement.java revision 3936:ec4be8a26914
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
26package javax.lang.model.element;
27
28import 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
37public interface ModuleElement extends Element, QualifiedNameable {
38
39    /**
40     * Returns the fully qualified name of this module.  For an
41     * {@linkplain #isUnnamed() unnamed module}, an empty name is returned.
42     *
43     * @return the fully 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 {@linkplain
51     * #isUnnamed() unnamed 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     */
108    enum DirectiveKind {
109        /** A "requires (static|transitive)* module-name" directive. */
110        REQUIRES,
111        /** An "exports package-name [to module-name-list]" directive. */
112        EXPORTS,
113        /** An "opens package-name [to module-name-list]" directive. */
114        OPENS,
115        /** A "uses service-name" directive. */
116        USES,
117        /** A "provides service-name with implementation-name" directive. */
118        PROVIDES
119    };
120
121    /**
122     * Represents a "module statement" within the declaration of this module.
123     *
124     * @since 9
125     *
126     */ // TODO: add jls to Module Statement
127    interface Directive {
128        /**
129         * Returns the {@code kind} of this directive.
130         *
131         * @return the kind of this directive
132         */
133        DirectiveKind getKind();
134    }
135
136    /**
137     * A dependency of a module.
138     * @since 9
139     */
140    interface RequiresDirective extends Directive {
141        /**
142         * Returns whether or not this is a static dependency.
143         * @return whether or not this is a static dependency
144         */
145        boolean isStatic();
146
147        /**
148         * Returns whether or not this is a transitive dependency.
149         * @return whether or not this is a transitive dependency
150         */
151        boolean isTransitive();
152
153        /**
154         * Returns the module that is required
155         * @return the module that is required
156         */
157        ModuleElement getDependency();
158    }
159
160    /**
161     * An exported package of a module.
162     * @since 9
163     */
164    interface ExportsDirective extends Directive {
165
166        /**
167         * Returns the package being exported.
168         * @return the package being exported
169         */
170        PackageElement getPackage();
171
172        /**
173         * Returns the specific modules to which the package is being exported,
174         * or null, if the package is exported to all modules which
175         * have readability to this module.
176         * @return the specific modules to which the package is being exported
177         */
178        List<? extends ModuleElement> getTargetModules();
179    }
180
181    /**
182     * An opened package of a module.
183     * @since 9
184     */
185    interface OpensDirective extends Directive {
186
187        /**
188         * Returns the package being opened.
189         * @return the package being opened
190         */
191        PackageElement getPackage();
192
193        /**
194         * Returns the specific modules to which the package is being open
195         * or null, if the package is open all modules which
196         * have readability to this module.
197         * @return the specific modules to which the package is being opened
198         */
199        List<? extends ModuleElement> getTargetModules();
200    }
201
202    /**
203     * An implementation of a service provided by a module.
204     * @since 9
205     */
206    interface ProvidesDirective extends Directive {
207        /**
208         * Returns the service being provided.
209         * @return the service being provided
210         */
211        TypeElement getService();
212
213        /**
214         * Returns the implementations of the service being provided.
215         * @return the implementations of the service being provided
216         */
217        List<? extends TypeElement> getImplementations();
218    }
219
220    /**
221     * A reference to a service used by a module.
222     * @since 9
223     */
224    interface UsesDirective extends Directive {
225        /**
226         * Returns the service that is used.
227         * @return the service that is used
228         */
229        TypeElement getService();
230    }
231}
232