src/java.base/share/classes/java/lang/module/ModuleDescriptor.java
author alanb
Thu, 04 Jan 2018 15:50:51 +0000
changeset 48431 b2cd597479ea
parent 48261 43edfde828ab
child 49529 c0bdb1b1ab4f
permissions -rw-r--r--
8194644: Typo in ModuleDescriptor.read javadoc Reviewed-by: alanb Contributed-by: christoph.dreis@freenet.de
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     1
/*
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
     2
 * Copyright (c) 2009, 2017, Oracle and/or its affiliates. All rights reserved.
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     4
 *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    10
 *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    15
 * accompanied this code).
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    16
 *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    20
 *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    23
 * questions.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    24
 */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    25
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    26
package java.lang.module;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    27
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    28
import java.io.InputStream;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    29
import java.io.IOException;
37779
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
    30
import java.io.PrintStream;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    31
import java.io.UncheckedIOException;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    32
import java.nio.ByteBuffer;
41817
b90ad1de93ea 8168789: ModuleReader.list and ModuleFinder.of update
alanb
parents: 39050
diff changeset
    33
import java.nio.file.Path;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    34
import java.util.ArrayList;
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
    35
import java.util.Arrays;
37779
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
    36
import java.util.Collection;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    37
import java.util.Collections;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    38
import java.util.EnumSet;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    39
import java.util.HashMap;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    40
import java.util.HashSet;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    41
import java.util.List;
48261
43edfde828ab 8193454: ModuleDescriptor.{Requires,Exports,Open} toString should use toLowerCase(Local.ROOT)
alanb
parents: 47866
diff changeset
    42
import java.util.Locale;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    43
import java.util.Map;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    44
import java.util.Objects;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    45
import java.util.Optional;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    46
import java.util.Set;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    47
import java.util.function.Supplier;
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
    48
import java.util.stream.Collectors;
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
    49
import java.util.stream.Stream;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    50
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    51
import static jdk.internal.module.Checks.*;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    52
import static java.util.Objects.*;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    53
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    54
import jdk.internal.module.Checks;
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
    55
import jdk.internal.module.ModuleInfo;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    56
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    57
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    58
/**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    59
 * A module descriptor.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    60
 *
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
    61
 * <p> A module descriptor describes a named module and defines methods to
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
    62
 * obtain each of its components. The module descriptor for a named module
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
    63
 * in the Java virtual machine is obtained by invoking the {@link
44545
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44359
diff changeset
    64
 * java.lang.Module Module}'s {@link java.lang.Module#getDescriptor
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
    65
 * getDescriptor} method. Module descriptors can also be created using the
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
    66
 * {@link ModuleDescriptor.Builder} class or by reading the binary form of a
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
    67
 * module declaration ({@code module-info.class}) using the {@link
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
    68
 * #read(InputStream,Supplier) read} methods defined here. </p>
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
    69
 *
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
    70
 * <p> A module descriptor describes a <em>normal</em>, open, or automatic
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
    71
 * module. <em>Normal</em> modules and open modules describe their {@link
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
    72
 * #requires() dependences}, {@link #exports() exported-packages}, the services
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
    73
 * that they {@link #uses() use} or {@link #provides() provide}, and other
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
    74
 * components. <em>Normal</em> modules may {@link #opens() open} specific
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
    75
 * packages. The module descriptor for an open modules does not declare any
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
    76
 * open packages (its {@code opens} method returns an empty set) but when
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
    77
 * instantiated in the Java virtual machine then it is treated as if all
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
    78
 * packages are open. The module descriptor for an automatic module does not
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
    79
 * declare any dependences (except for the mandatory dependency on {@code
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
    80
 * java.base}), and does not declare any exported or open packages. Automatic
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
    81
 * module receive special treatment during resolution so that they read all
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
    82
 * other modules in the configuration. When an automatic module is instantiated
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
    83
 * in the Java virtual machine then it reads every unnamed module and is
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
    84
 * treated as if all packages are exported and open. </p>
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    85
 *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    86
 * <p> {@code ModuleDescriptor} objects are immutable and safe for use by
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    87
 * multiple concurrent threads.</p>
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    88
 *
44545
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44359
diff changeset
    89
 * @see java.lang.Module
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    90
 * @since 9
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
    91
 * @spec JPMS
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    92
 */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    93
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    94
public class ModuleDescriptor
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    95
    implements Comparable<ModuleDescriptor>
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    96
{
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    97
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    98
    /**
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
    99
     * A modifier on a module.
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   100
     *
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   101
     * @see ModuleDescriptor#modifiers()
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   102
     * @since 9
45004
ea3137042a61 8178380: Module system implementation refresh (5/2017)
alanb
parents: 44545
diff changeset
   103
     * @spec JPMS
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   104
     */
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   105
    public static enum Modifier {
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   106
        /**
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   107
         * An open module. An open module does not declare any open packages
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   108
         * but the resulting module is treated as if all packages are open.
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   109
         */
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   110
        OPEN,
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   111
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   112
        /**
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   113
         * An automatic module. An automatic module is treated as if it exports
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   114
         * and opens all packages.
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   115
         *
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   116
         * @apiNote This modifier does not correspond to a module flag in the
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   117
         * binary form of a module declaration ({@code module-info.class}).
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   118
         */
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   119
        AUTOMATIC,
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   120
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   121
        /**
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   122
         * The module was not explicitly or implicitly declared.
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   123
         */
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   124
        SYNTHETIC,
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   125
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   126
        /**
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   127
         * The module was implicitly declared.
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   128
         */
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   129
        MANDATED;
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   130
    }
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   131
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   132
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   133
    /**
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   134
     * <p> A dependence upon a module </p>
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   135
     *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   136
     * @see ModuleDescriptor#requires()
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   137
     * @since 9
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   138
     * @spec JPMS
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   139
     */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   140
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   141
    public final static class Requires
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   142
        implements Comparable<Requires>
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   143
    {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   144
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   145
        /**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   146
         * A modifier on a module dependence.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   147
         *
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   148
         * @see Requires#modifiers()
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   149
         * @since 9
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   150
         * @spec JPMS
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   151
         */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   152
        public static enum Modifier {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   153
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   154
            /**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   155
             * The dependence causes any module which depends on the <i>current
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   156
             * module</i> to have an implicitly declared dependence on the module
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   157
             * named by the {@code Requires}.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   158
             */
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   159
            TRANSITIVE,
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   160
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   161
            /**
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   162
             * The dependence is mandatory in the static phase, during compilation,
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   163
             * but is optional in the dynamic phase, during execution.
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   164
             */
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   165
            STATIC,
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   166
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   167
            /**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   168
             * The dependence was not explicitly or implicitly declared in the
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   169
             * source of the module declaration.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   170
             */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   171
            SYNTHETIC,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   172
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   173
            /**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   174
             * The dependence was implicitly declared in the source of the module
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   175
             * declaration.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   176
             */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   177
            MANDATED;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   178
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   179
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   180
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   181
        private final Set<Modifier> mods;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   182
        private final String name;
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   183
        private final Version compiledVersion;
44359
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
   184
        private final String rawCompiledVersion;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   185
44359
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
   186
        private Requires(Set<Modifier> ms, String mn, Version v, String vs) {
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
   187
            assert v == null || vs == null;
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   188
            if (ms.isEmpty()) {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   189
                ms = Collections.emptySet();
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   190
            } else {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   191
                ms = Collections.unmodifiableSet(EnumSet.copyOf(ms));
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   192
            }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   193
            this.mods = ms;
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   194
            this.name = mn;
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   195
            this.compiledVersion = v;
44359
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
   196
            this.rawCompiledVersion = vs;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   197
        }
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   198
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   199
        private Requires(Set<Modifier> ms, String mn, Version v, boolean unused) {
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   200
            this.mods = ms;
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   201
            this.name = mn;
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   202
            this.compiledVersion = v;
44359
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
   203
            this.rawCompiledVersion = null;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   204
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   205
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   206
        /**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   207
         * Returns the set of modifiers.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   208
         *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   209
         * @return A possibly-empty unmodifiable set of modifiers
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   210
         */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   211
        public Set<Modifier> modifiers() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   212
            return mods;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   213
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   214
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   215
        /**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   216
         * Return the module name.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   217
         *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   218
         * @return The module name
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   219
         */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   220
        public String name() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   221
            return name;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   222
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   223
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   224
        /**
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   225
         * Returns the version of the module if recorded at compile-time.
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   226
         *
44359
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
   227
         * @return The version of the module if recorded at compile-time,
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
   228
         *         or an empty {@code Optional} if no version was recorded or
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
   229
         *         the version string recorded is {@linkplain Version#parse(String)
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
   230
         *         unparseable}
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   231
         */
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   232
        public Optional<Version> compiledVersion() {
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   233
            return Optional.ofNullable(compiledVersion);
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   234
        }
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   235
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   236
        /**
44359
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
   237
         * Returns the string with the possibly-unparseable version of the module
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
   238
         * if recorded at compile-time.
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
   239
         *
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
   240
         * @return The string containing the version of the module if recorded
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
   241
         *         at compile-time, or an empty {@code Optional} if no version
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
   242
         *         was recorded
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
   243
         *
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
   244
         * @see #compiledVersion()
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
   245
         */
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
   246
        public Optional<String> rawCompiledVersion() {
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
   247
            if (compiledVersion != null) {
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
   248
                return Optional.of(compiledVersion.toString());
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
   249
            } else {
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
   250
                return Optional.ofNullable(rawCompiledVersion);
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
   251
            }
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
   252
        }
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
   253
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
   254
        /**
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   255
         * Compares this module dependence to another.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   256
         *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   257
         * <p> Two {@code Requires} objects are compared by comparing their
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   258
         * module names lexicographically. Where the module names are equal
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   259
         * then the sets of modifiers are compared in the same way that
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   260
         * module modifiers are compared (see {@link ModuleDescriptor#compareTo
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   261
         * ModuleDescriptor.compareTo}). Where the module names are equal and
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   262
         * the set of modifiers are equal then the version of the modules
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   263
         * recorded at compile-time are compared. When comparing the versions
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   264
         * recorded at compile-time then a dependence that has a recorded
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   265
         * version is considered to succeed a dependence that does not have a
44359
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
   266
         * recorded version. If both recorded versions are {@linkplain
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
   267
         * Version#parse(String) unparseable} then the {@linkplain
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
   268
         * #rawCompiledVersion() raw version strings} are compared
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
   269
         * lexicographically. </p>
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   270
         *
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   271
         * @param  that
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   272
         *         The module dependence to compare
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   273
         *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   274
         * @return A negative integer, zero, or a positive integer if this module
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   275
         *         dependence is less than, equal to, or greater than the given
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   276
         *         module dependence
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   277
         */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   278
        @Override
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   279
        public int compareTo(Requires that) {
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   280
            if (this == that) return 0;
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   281
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   282
            int c = this.name().compareTo(that.name());
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   283
            if (c != 0) return c;
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   284
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   285
            // modifiers
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   286
            long v1 = modsValue(this.modifiers());
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   287
            long v2 = modsValue(that.modifiers());
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   288
            c = Long.compare(v1, v2);
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   289
            if (c != 0) return c;
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   290
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   291
            // compiledVersion
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   292
            c = compare(this.compiledVersion, that.compiledVersion);
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   293
            if (c != 0) return c;
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   294
44359
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
   295
            // rawCompiledVersion
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
   296
            c = compare(this.rawCompiledVersion, that.rawCompiledVersion);
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
   297
            if (c != 0) return c;
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
   298
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   299
            return 0;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   300
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   301
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   302
        /**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   303
         * Tests this module dependence for equality with the given object.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   304
         *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   305
         * <p> If the given object is not a {@code Requires} then this method
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   306
         * returns {@code false}. Two module dependence objects are equal if
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   307
         * the module names are equal, set of modifiers are equal, and the
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   308
         * compiled version of both modules is equal or not recorded for
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   309
         * both modules. </p>
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   310
         *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   311
         * <p> This method satisfies the general contract of the {@link
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   312
         * java.lang.Object#equals(Object) Object.equals} method. </p>
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   313
         *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   314
         * @param   ob
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   315
         *          the object to which this object is to be compared
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   316
         *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   317
         * @return  {@code true} if, and only if, the given object is a module
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   318
         *          dependence that is equal to this module dependence
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   319
         */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   320
        @Override
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   321
        public boolean equals(Object ob) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   322
            if (!(ob instanceof Requires))
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   323
                return false;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   324
            Requires that = (Requires)ob;
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   325
            return name.equals(that.name) && mods.equals(that.mods)
44359
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
   326
                    && Objects.equals(compiledVersion, that.compiledVersion)
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
   327
                    && Objects.equals(rawCompiledVersion, that.rawCompiledVersion);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   328
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   329
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   330
        /**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   331
         * Computes a hash code for this module dependence.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   332
         *
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   333
         * <p> The hash code is based upon the module name, modifiers, and the
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   334
         * module version if recorded at compile time. It satisfies the general
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   335
         * contract of the {@link Object#hashCode Object.hashCode} method. </p>
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   336
         *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   337
         * @return The hash-code value for this module dependence
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   338
         */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   339
        @Override
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   340
        public int hashCode() {
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   341
            int hash = name.hashCode() * 43 + mods.hashCode();
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   342
            if (compiledVersion != null)
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   343
                hash = hash * 43 + compiledVersion.hashCode();
44359
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
   344
            if (rawCompiledVersion != null)
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
   345
                hash = hash * 43 + rawCompiledVersion.hashCode();
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   346
            return hash;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   347
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   348
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   349
        /**
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   350
         * Returns a string describing this module dependence.
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   351
         *
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   352
         * @return A string describing this module dependence
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   353
         */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   354
        @Override
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   355
        public String toString() {
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   356
            String what;
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   357
            if (compiledVersion != null) {
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   358
                what = name() + " (@" + compiledVersion + ")";
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   359
            } else {
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   360
                what = name();
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   361
            }
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   362
            return ModuleDescriptor.toString(mods, what);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   363
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   364
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   365
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   366

9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   367
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   368
    /**
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   369
     * <p> A package exported by a module, may be qualified or unqualified. </p>
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   370
     *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   371
     * @see ModuleDescriptor#exports()
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   372
     * @since 9
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   373
     * @spec JPMS
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   374
     */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   375
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   376
    public final static class Exports
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   377
        implements Comparable<Exports>
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   378
    {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   379
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   380
        /**
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   381
         * A modifier on an exported package.
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   382
         *
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   383
         * @see Exports#modifiers()
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   384
         * @since 9
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   385
         * @spec JPMS
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   386
         */
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   387
        public static enum Modifier {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   388
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   389
            /**
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   390
             * The export was not explicitly or implicitly declared in the
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   391
             * source of the module declaration.
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   392
             */
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   393
            SYNTHETIC,
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   394
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   395
            /**
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   396
             * The export was implicitly declared in the source of the module
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   397
             * declaration.
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   398
             */
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   399
            MANDATED;
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   400
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   401
        }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   402
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   403
        private final Set<Modifier> mods;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   404
        private final String source;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   405
        private final Set<String> targets;  // empty if unqualified export
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   406
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   407
        /**
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   408
         * Constructs an export
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   409
         */
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   410
        private Exports(Set<Modifier> ms, String source, Set<String> targets) {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   411
            if (ms.isEmpty()) {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   412
                ms = Collections.emptySet();
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   413
            } else {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   414
                ms = Collections.unmodifiableSet(EnumSet.copyOf(ms));
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   415
            }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   416
            this.mods = ms;
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   417
            this.source = source;
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   418
            this.targets = emptyOrUnmodifiableSet(targets);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   419
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   420
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   421
        private Exports(Set<Modifier> ms,
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   422
                        String source,
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   423
                        Set<String> targets,
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   424
                        boolean unused) {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   425
            this.mods = ms;
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   426
            this.source = source;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   427
            this.targets = targets;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   428
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   429
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   430
        /**
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   431
         * Returns the set of modifiers.
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   432
         *
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   433
         * @return A possibly-empty unmodifiable set of modifiers
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   434
         */
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   435
        public Set<Modifier> modifiers() {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   436
            return mods;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   437
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   438
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   439
        /**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   440
         * Returns {@code true} if this is a qualified export.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   441
         *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   442
         * @return {@code true} if this is a qualified export
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   443
         */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   444
        public boolean isQualified() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   445
            return !targets.isEmpty();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   446
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   447
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   448
        /**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   449
         * Returns the package name.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   450
         *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   451
         * @return The package name
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   452
         */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   453
        public String source() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   454
            return source;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   455
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   456
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   457
        /**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   458
         * For a qualified export, returns the non-empty and immutable set
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   459
         * of the module names to which the package is exported. For an
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   460
         * unqualified export, returns an empty set.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   461
         *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   462
         * @return The set of target module names or for an unqualified
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   463
         *         export, an empty set
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   464
         */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   465
        public Set<String> targets() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   466
            return targets;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   467
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   468
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   469
        /**
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   470
         * Compares this module export to another.
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   471
         *
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   472
         * <p> Two {@code Exports} objects are compared by comparing the package
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   473
         * names lexicographically. Where the packages names are equal then the
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   474
         * sets of modifiers are compared in the same way that module modifiers
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   475
         * are compared (see {@link ModuleDescriptor#compareTo
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   476
         * ModuleDescriptor.compareTo}). Where the package names are equal and
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   477
         * the set of modifiers are equal then the set of target modules are
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   478
         * compared. This is done by sorting the names of the target modules
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   479
         * in ascending order, and according to their natural ordering, and then
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   480
         * comparing the corresponding elements lexicographically. Where the
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   481
         * sets differ in size, and the larger set contains all elements of the
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   482
         * smaller set, then the larger set is considered to succeed the smaller
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   483
         * set. </p>
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   484
         *
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   485
         * @param  that
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   486
         *         The module export to compare
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   487
         *
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   488
         * @return A negative integer, zero, or a positive integer if this module
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   489
         *         export is less than, equal to, or greater than the given
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   490
         *         export dependence
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   491
         */
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   492
        @Override
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   493
        public int compareTo(Exports that) {
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   494
            if (this == that) return 0;
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   495
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   496
            int c = source.compareTo(that.source);
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   497
            if (c != 0)
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   498
                return c;
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   499
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   500
            // modifiers
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   501
            long v1 = modsValue(this.modifiers());
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   502
            long v2 = modsValue(that.modifiers());
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   503
            c = Long.compare(v1, v2);
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   504
            if (c != 0)
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   505
                return c;
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   506
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   507
            // targets
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   508
            c = compare(targets, that.targets);
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   509
            if (c != 0)
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   510
                return c;
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   511
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   512
            return 0;
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   513
        }
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   514
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   515
        /**
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   516
         * Computes a hash code for this module export.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   517
         *
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   518
         * <p> The hash code is based upon the modifiers, the package name,
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   519
         * and for a qualified export, the set of modules names to which the
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   520
         * package is exported. It satisfies the general contract of the
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   521
         * {@link Object#hashCode Object.hashCode} method.
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   522
         *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   523
         * @return The hash-code value for this module export
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   524
         */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   525
        @Override
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   526
        public int hashCode() {
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   527
            int hash = mods.hashCode();
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   528
            hash = hash * 43 + source.hashCode();
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   529
            return hash * 43 + targets.hashCode();
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   530
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   531
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   532
        /**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   533
         * Tests this module export for equality with the given object.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   534
         *
37880
60ec48925dc6 8156661: Handful of typos in javadoc
igerasim
parents: 37779
diff changeset
   535
         * <p> If the given object is not an {@code Exports} then this method
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   536
         * returns {@code false}. Two module exports objects are equal if their
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   537
         * set of modifiers is equal, the package names are equal and the set
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   538
         * of target module names is equal. </p>
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   539
         *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   540
         * <p> This method satisfies the general contract of the {@link
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   541
         * java.lang.Object#equals(Object) Object.equals} method. </p>
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   542
         *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   543
         * @param   ob
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   544
         *          the object to which this object is to be compared
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   545
         *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   546
         * @return  {@code true} if, and only if, the given object is a module
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   547
         *          dependence that is equal to this module dependence
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   548
         */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   549
        @Override
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   550
        public boolean equals(Object ob) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   551
            if (!(ob instanceof Exports))
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   552
                return false;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   553
            Exports other = (Exports)ob;
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   554
            return Objects.equals(this.mods, other.mods)
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   555
                    && Objects.equals(this.source, other.source)
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   556
                    && Objects.equals(this.targets, other.targets);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   557
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   558
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   559
        /**
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   560
         * Returns a string describing the exported package.
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   561
         *
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   562
         * @return A string describing the exported package
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   563
         */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   564
        @Override
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   565
        public String toString() {
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   566
            String s = ModuleDescriptor.toString(mods, source);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   567
            if (targets.isEmpty())
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   568
                return s;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   569
            else
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   570
                return s + " to " + targets;
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   571
        }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   572
    }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   573
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   574
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   575
    /**
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   576
     * <p> A package opened by a module, may be qualified or unqualified. </p>
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   577
     *
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   578
     * <p> The <em>opens</em> directive in a module declaration declares a
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   579
     * package to be open to allow all types in the package, and all their
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   580
     * members, not just public types and their public members to be reflected
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   581
     * on by APIs that support private access or a way to bypass or suppress
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   582
     * default Java language access control checks. </p>
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   583
     *
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   584
     * @see ModuleDescriptor#opens()
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   585
     * @since 9
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   586
     * @spec JPMS
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   587
     */
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   588
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   589
    public final static class Opens
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   590
        implements Comparable<Opens>
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   591
    {
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   592
        /**
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   593
         * A modifier on an open package.
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   594
         *
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   595
         * @see Opens#modifiers()
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   596
         * @since 9
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   597
         * @spec JPMS
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   598
         */
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   599
        public static enum Modifier {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   600
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   601
            /**
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   602
             * The open package was not explicitly or implicitly declared in
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   603
             * the source of the module declaration.
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   604
             */
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   605
            SYNTHETIC,
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   606
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   607
            /**
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   608
             * The open package was implicitly declared in the source of the
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   609
             * module declaration.
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   610
             */
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   611
            MANDATED;
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   612
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   613
        }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   614
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   615
        private final Set<Modifier> mods;
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   616
        private final String source;
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   617
        private final Set<String> targets;  // empty if unqualified export
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   618
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   619
        /**
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   620
         * Constructs an Opens
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   621
         */
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   622
        private Opens(Set<Modifier> ms, String source, Set<String> targets) {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   623
            if (ms.isEmpty()) {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   624
                ms = Collections.emptySet();
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   625
            } else {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   626
                ms = Collections.unmodifiableSet(EnumSet.copyOf(ms));
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   627
            }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   628
            this.mods = ms;
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   629
            this.source = source;
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   630
            this.targets = emptyOrUnmodifiableSet(targets);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   631
        }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   632
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   633
        private Opens(Set<Modifier> ms,
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   634
                      String source,
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   635
                      Set<String> targets,
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   636
                      boolean unused) {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   637
            this.mods = ms;
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   638
            this.source = source;
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   639
            this.targets = targets;
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   640
        }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   641
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   642
        /**
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   643
         * Returns the set of modifiers.
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   644
         *
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   645
         * @return A possibly-empty unmodifiable set of modifiers
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   646
         */
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   647
        public Set<Modifier> modifiers() {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   648
            return mods;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   649
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   650
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   651
        /**
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   652
         * Returns {@code true} if this is a qualified opens.
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   653
         *
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   654
         * @return {@code true} if this is a qualified opens
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   655
         */
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   656
        public boolean isQualified() {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   657
            return !targets.isEmpty();
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   658
        }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   659
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   660
        /**
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   661
         * Returns the package name.
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   662
         *
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   663
         * @return The package name
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   664
         */
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   665
        public String source() {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   666
            return source;
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   667
        }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   668
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   669
        /**
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   670
         * For a qualified opens, returns the non-empty and immutable set
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   671
         * of the module names to which the package is open. For an
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   672
         * unqualified opens, returns an empty set.
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   673
         *
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   674
         * @return The set of target module names or for an unqualified
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   675
         *         opens, an empty set
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   676
         */
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   677
        public Set<String> targets() {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   678
            return targets;
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   679
        }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   680
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   681
        /**
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   682
         * Compares this module opens to another.
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   683
         *
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   684
         * <p> Two {@code Opens} objects are compared by comparing the package
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   685
         * names lexicographically. Where the packages names are equal then the
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   686
         * sets of modifiers are compared in the same way that module modifiers
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   687
         * are compared (see {@link ModuleDescriptor#compareTo
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   688
         * ModuleDescriptor.compareTo}). Where the package names are equal and
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   689
         * the set of modifiers are equal then the set of target modules are
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   690
         * compared. This is done by sorting the names of the target modules
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   691
         * in ascending order, and according to their natural ordering, and then
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   692
         * comparing the corresponding elements lexicographically. Where the
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   693
         * sets differ in size, and the larger set contains all elements of the
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   694
         * smaller set, then the larger set is considered to succeed the smaller
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   695
         * set. </p>
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   696
         *
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   697
         * @param  that
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   698
         *         The module opens to compare
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   699
         *
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   700
         * @return A negative integer, zero, or a positive integer if this module
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   701
         *         opens is less than, equal to, or greater than the given
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   702
         *         module opens
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   703
         */
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   704
        @Override
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   705
        public int compareTo(Opens that) {
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   706
            if (this == that) return 0;
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   707
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   708
            int c = source.compareTo(that.source);
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   709
            if (c != 0)
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   710
                return c;
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   711
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   712
            // modifiers
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   713
            long v1 = modsValue(this.modifiers());
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   714
            long v2 = modsValue(that.modifiers());
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   715
            c = Long.compare(v1, v2);
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   716
            if (c != 0)
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   717
                return c;
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   718
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   719
            // targets
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   720
            c = compare(targets, that.targets);
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   721
            if (c != 0)
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   722
                return c;
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   723
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   724
            return 0;
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   725
        }
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   726
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   727
        /**
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   728
         * Computes a hash code for this module opens.
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   729
         *
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   730
         * <p> The hash code is based upon the modifiers, the package name,
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   731
         * and for a qualified opens, the set of modules names to which the
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   732
         * package is opened. It satisfies the general contract of the
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   733
         * {@link Object#hashCode Object.hashCode} method.
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   734
         *
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   735
         * @return The hash-code value for this module opens
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   736
         */
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   737
        @Override
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   738
        public int hashCode() {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   739
            int hash = mods.hashCode();
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   740
            hash = hash * 43 + source.hashCode();
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   741
            return hash * 43 + targets.hashCode();
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   742
        }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   743
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   744
        /**
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   745
         * Tests this module opens for equality with the given object.
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   746
         *
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   747
         * <p> If the given object is not an {@code Opens} then this method
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   748
         * returns {@code false}. Two {@code Opens} objects are equal if their
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   749
         * set of modifiers is equal, the package names are equal and the set
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   750
         * of target module names is equal. </p>
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   751
         *
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   752
         * <p> This method satisfies the general contract of the {@link
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   753
         * java.lang.Object#equals(Object) Object.equals} method. </p>
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   754
         *
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   755
         * @param   ob
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   756
         *          the object to which this object is to be compared
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   757
         *
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   758
         * @return  {@code true} if, and only if, the given object is a module
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   759
         *          dependence that is equal to this module dependence
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   760
         */
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   761
        @Override
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   762
        public boolean equals(Object ob) {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   763
            if (!(ob instanceof Opens))
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   764
                return false;
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   765
            Opens other = (Opens)ob;
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   766
            return Objects.equals(this.mods, other.mods)
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   767
                    && Objects.equals(this.source, other.source)
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   768
                    && Objects.equals(this.targets, other.targets);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   769
        }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   770
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   771
        /**
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   772
         * Returns a string describing the open package.
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   773
         *
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   774
         * @return A string describing the open package
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   775
         */
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   776
        @Override
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   777
        public String toString() {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   778
            String s = ModuleDescriptor.toString(mods, source);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   779
            if (targets.isEmpty())
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   780
                return s;
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   781
            else
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   782
                return s + " to " + targets;
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   783
        }
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   784
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   785
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   786
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   787
    /**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   788
     * <p> A service that a module provides one or more implementations of. </p>
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   789
     *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   790
     * @see ModuleDescriptor#provides()
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   791
     * @since 9
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   792
     * @spec JPMS
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   793
     */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   794
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   795
    public final static class Provides
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   796
        implements Comparable<Provides>
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   797
    {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   798
        private final String service;
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   799
        private final List<String> providers;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   800
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   801
        private Provides(String service, List<String> providers) {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   802
            this.service = service;
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   803
            this.providers = Collections.unmodifiableList(providers);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   804
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   805
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   806
        private Provides(String service, List<String> providers, boolean unused) {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   807
            this.service = service;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   808
            this.providers = providers;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   809
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   810
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   811
        /**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   812
         * Returns the fully qualified class name of the service type.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   813
         *
44359
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
   814
         * @return The fully qualified class name of the service type
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   815
         */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   816
        public String service() { return service; }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   817
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   818
        /**
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   819
         * Returns the list of the fully qualified class names of the providers
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   820
         * or provider factories.
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   821
         *
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   822
         * @return A non-empty and unmodifiable list of the fully qualified class
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   823
         *         names of the providers or provider factories
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   824
         */
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   825
        public List<String> providers() { return providers; }
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   826
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   827
        /**
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   828
         * Compares this provides to another.
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   829
         *
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   830
         * <p> Two {@code Provides} objects are compared by comparing the fully
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   831
         * qualified class name of the service type lexicographically. Where the
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   832
         * class names are equal then the list of the provider class names are
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   833
         * compared by comparing the corresponding elements of both lists
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   834
         * lexicographically and in sequence. Where the lists differ in size,
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   835
         * {@code N} is the size of the shorter list, and the first {@code N}
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   836
         * corresponding elements are equal, then the longer list is considered
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   837
         * to succeed the shorter list. </p>
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   838
         *
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   839
         * @param  that
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   840
         *         The {@code Provides} to compare
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   841
         *
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   842
         * @return A negative integer, zero, or a positive integer if this provides
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   843
         *         is less than, equal to, or greater than the given provides
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   844
         */
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   845
        public int compareTo(Provides that) {
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   846
            if (this == that) return 0;
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   847
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   848
            int c = service.compareTo(that.service);
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   849
            if (c != 0) return c;
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   850
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   851
            // compare provider class names in sequence
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   852
            int size1 = this.providers.size();
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   853
            int size2 = that.providers.size();
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   854
            for (int index=0; index<Math.min(size1, size2); index++) {
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   855
                String e1 = this.providers.get(index);
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   856
                String e2 = that.providers.get(index);
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   857
                c = e1.compareTo(e2);
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   858
                if (c != 0) return c;
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   859
            }
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   860
            if (size1 == size2) {
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   861
                return 0;
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   862
            } else {
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   863
                return (size1 > size2) ? 1 : -1;
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   864
            }
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   865
        }
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   866
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   867
        /**
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   868
         * Computes a hash code for this provides.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   869
         *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   870
         * <p> The hash code is based upon the service type and the set of
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   871
         * providers. It satisfies the general contract of the {@link
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   872
         * Object#hashCode Object.hashCode} method. </p>
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   873
         *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   874
         * @return The hash-code value for this module provides
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   875
         */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   876
        @Override
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   877
        public int hashCode() {
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   878
            return service.hashCode() * 43 + providers.hashCode();
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   879
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   880
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   881
        /**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   882
         * Tests this provides for equality with the given object.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   883
         *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   884
         * <p> If the given object is not a {@code Provides} then this method
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   885
         * returns {@code false}. Two {@code Provides} objects are equal if the
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
   886
         * service type is equal and the list of providers is equal. </p>
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   887
         *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   888
         * <p> This method satisfies the general contract of the {@link
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   889
         * java.lang.Object#equals(Object) Object.equals} method. </p>
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   890
         *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   891
         * @param   ob
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   892
         *          the object to which this object is to be compared
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   893
         *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   894
         * @return  {@code true} if, and only if, the given object is a
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   895
         *          {@code Provides} that is equal to this {@code Provides}
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   896
         */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   897
        @Override
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   898
        public boolean equals(Object ob) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   899
            if (!(ob instanceof Provides))
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   900
                return false;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   901
            Provides other = (Provides)ob;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   902
            return Objects.equals(this.service, other.service) &&
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   903
                    Objects.equals(this.providers, other.providers);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   904
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   905
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   906
        /**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   907
         * Returns a string describing this provides.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   908
         *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   909
         * @return A string describing this provides
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   910
         */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   911
        @Override
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   912
        public String toString() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   913
            return service + " with " + providers;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   914
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   915
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   916
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   917
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   918

9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   919
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   920
    /**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   921
     * A module's version string.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   922
     *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   923
     * <p> A version string has three components: The version number itself, an
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   924
     * optional pre-release version, and an optional build version.  Each
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   925
     * component is a sequence of tokens; each token is either a non-negative
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   926
     * integer or a string.  Tokens are separated by the punctuation characters
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   927
     * {@code '.'}, {@code '-'}, or {@code '+'}, or by transitions from a
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   928
     * sequence of digits to a sequence of characters that are neither digits
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   929
     * nor punctuation characters, or vice versa.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   930
     *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   931
     * <ul>
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   932
     *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   933
     *   <li> The <i>version number</i> is a sequence of tokens separated by
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   934
     *   {@code '.'} characters, terminated by the first {@code '-'} or {@code
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   935
     *   '+'} character. </li>
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   936
     *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   937
     *   <li> The <i>pre-release version</i> is a sequence of tokens separated
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   938
     *   by {@code '.'} or {@code '-'} characters, terminated by the first
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   939
     *   {@code '+'} character. </li>
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   940
     *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   941
     *   <li> The <i>build version</i> is a sequence of tokens separated by
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   942
     *   {@code '.'}, {@code '-'}, or {@code '+'} characters.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   943
     *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   944
     * </ul>
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   945
     *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   946
     * <p> When comparing two version strings, the elements of their
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   947
     * corresponding components are compared in pointwise fashion.  If one
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   948
     * component is longer than the other, but otherwise equal to it, then the
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   949
     * first component is considered the greater of the two; otherwise, if two
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   950
     * corresponding elements are integers then they are compared as such;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   951
     * otherwise, at least one of the elements is a string, so the other is
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   952
     * converted into a string if it is an integer and the two are compared
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   953
     * lexicographically.  Trailing integer elements with the value zero are
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   954
     * ignored.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   955
     *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   956
     * <p> Given two version strings, if their version numbers differ then the
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   957
     * result of comparing them is the result of comparing their version
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   958
     * numbers; otherwise, if one of them has a pre-release version but the
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   959
     * other does not then the first is considered to precede the second,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   960
     * otherwise the result of comparing them is the result of comparing their
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   961
     * pre-release versions; otherwise, the result of comparing them is the
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   962
     * result of comparing their build versions.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   963
     *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   964
     * @see ModuleDescriptor#version()
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   965
     * @since 9
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   966
     * @spec JPMS
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   967
     */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   968
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   969
    public final static class Version
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   970
        implements Comparable<Version>
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   971
    {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   972
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   973
        private final String version;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   974
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   975
        // If Java had disjunctive types then we'd write List<Integer|String> here
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   976
        //
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   977
        private final List<Object> sequence;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   978
        private final List<Object> pre;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   979
        private final List<Object> build;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   980
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   981
        // Take a numeric token starting at position i
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   982
        // Append it to the given list
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   983
        // Return the index of the first character not taken
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   984
        // Requires: s.charAt(i) is (decimal) numeric
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   985
        //
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   986
        private static int takeNumber(String s, int i, List<Object> acc) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   987
            char c = s.charAt(i);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   988
            int d = (c - '0');
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   989
            int n = s.length();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   990
            while (++i < n) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   991
                c = s.charAt(i);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   992
                if (c >= '0' && c <= '9') {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   993
                    d = d * 10 + (c - '0');
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   994
                    continue;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   995
                }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   996
                break;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   997
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   998
            acc.add(d);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   999
            return i;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1000
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1001
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1002
        // Take a string token starting at position i
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1003
        // Append it to the given list
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1004
        // Return the index of the first character not taken
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1005
        // Requires: s.charAt(i) is not '.'
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1006
        //
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1007
        private static int takeString(String s, int i, List<Object> acc) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1008
            int b = i;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1009
            int n = s.length();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1010
            while (++i < n) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1011
                char c = s.charAt(i);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1012
                if (c != '.' && c != '-' && c != '+' && !(c >= '0' && c <= '9'))
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1013
                    continue;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1014
                break;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1015
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1016
            acc.add(s.substring(b, i));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1017
            return i;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1018
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1019
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1020
        // Syntax: tok+ ( '-' tok+)? ( '+' tok+)?
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1021
        // First token string is sequence, second is pre, third is build
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1022
        // Tokens are separated by '.' or '-', or by changes between alpha & numeric
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1023
        // Numeric tokens are compared as decimal integers
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1024
        // Non-numeric tokens are compared lexicographically
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1025
        // A version with a non-empty pre is less than a version with same seq but no pre
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1026
        // Tokens in build may contain '-' and '+'
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1027
        //
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1028
        private Version(String v) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1029
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1030
            if (v == null)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1031
                throw new IllegalArgumentException("Null version string");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1032
            int n = v.length();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1033
            if (n == 0)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1034
                throw new IllegalArgumentException("Empty version string");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1035
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1036
            int i = 0;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1037
            char c = v.charAt(i);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1038
            if (!(c >= '0' && c <= '9'))
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1039
                throw new IllegalArgumentException(v
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1040
                                                   + ": Version string does not start"
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1041
                                                   + " with a number");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1042
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1043
            List<Object> sequence = new ArrayList<>(4);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1044
            List<Object> pre = new ArrayList<>(2);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1045
            List<Object> build = new ArrayList<>(2);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1046
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1047
            i = takeNumber(v, i, sequence);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1048
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1049
            while (i < n) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1050
                c = v.charAt(i);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1051
                if (c == '.') {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1052
                    i++;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1053
                    continue;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1054
                }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1055
                if (c == '-' || c == '+') {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1056
                    i++;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1057
                    break;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1058
                }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1059
                if (c >= '0' && c <= '9')
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1060
                    i = takeNumber(v, i, sequence);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1061
                else
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1062
                    i = takeString(v, i, sequence);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1063
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1064
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1065
            if (c == '-' && i >= n)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1066
                throw new IllegalArgumentException(v + ": Empty pre-release");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1067
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1068
            while (i < n) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1069
                c = v.charAt(i);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1070
                if (c >= '0' && c <= '9')
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1071
                    i = takeNumber(v, i, pre);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1072
                else
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1073
                    i = takeString(v, i, pre);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1074
                if (i >= n)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1075
                    break;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1076
                c = v.charAt(i);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1077
                if (c == '.' || c == '-') {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1078
                    i++;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1079
                    continue;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1080
                }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1081
                if (c == '+') {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1082
                    i++;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1083
                    break;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1084
                }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1085
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1086
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1087
            if (c == '+' && i >= n)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1088
                throw new IllegalArgumentException(v + ": Empty pre-release");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1089
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1090
            while (i < n) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1091
                c = v.charAt(i);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1092
                if (c >= '0' && c <= '9')
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1093
                    i = takeNumber(v, i, build);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1094
                else
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1095
                    i = takeString(v, i, build);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1096
                if (i >= n)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1097
                    break;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1098
                c = v.charAt(i);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1099
                if (c == '.' || c == '-' || c == '+') {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1100
                    i++;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1101
                    continue;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1102
                }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1103
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1104
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1105
            this.version = v;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1106
            this.sequence = sequence;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1107
            this.pre = pre;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1108
            this.build = build;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1109
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1110
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1111
        /**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1112
         * Parses the given string as a version string.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1113
         *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1114
         * @param  v
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1115
         *         The string to parse
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1116
         *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1117
         * @return The resulting {@code Version}
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1118
         *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1119
         * @throws IllegalArgumentException
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1120
         *         If {@code v} is {@code null}, an empty string, or cannot be
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1121
         *         parsed as a version string
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1122
         */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1123
        public static Version parse(String v) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1124
            return new Version(v);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1125
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1126
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1127
        @SuppressWarnings("unchecked")
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1128
        private int cmp(Object o1, Object o2) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1129
            return ((Comparable)o1).compareTo(o2);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1130
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1131
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1132
        private int compareTokens(List<Object> ts1, List<Object> ts2) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1133
            int n = Math.min(ts1.size(), ts2.size());
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1134
            for (int i = 0; i < n; i++) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1135
                Object o1 = ts1.get(i);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1136
                Object o2 = ts2.get(i);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1137
                if ((o1 instanceof Integer && o2 instanceof Integer)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1138
                    || (o1 instanceof String && o2 instanceof String))
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1139
                {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1140
                    int c = cmp(o1, o2);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1141
                    if (c == 0)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1142
                        continue;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1143
                    return c;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1144
                }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1145
                // Types differ, so convert number to string form
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1146
                int c = o1.toString().compareTo(o2.toString());
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1147
                if (c == 0)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1148
                    continue;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1149
                return c;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1150
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1151
            List<Object> rest = ts1.size() > ts2.size() ? ts1 : ts2;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1152
            int e = rest.size();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1153
            for (int i = n; i < e; i++) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1154
                Object o = rest.get(i);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1155
                if (o instanceof Integer && ((Integer)o) == 0)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1156
                    continue;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1157
                return ts1.size() - ts2.size();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1158
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1159
            return 0;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1160
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1161
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1162
        /**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1163
         * Compares this module version to another module version. Module
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1164
         * versions are compared as described in the class description.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1165
         *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1166
         * @param that
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1167
         *        The module version to compare
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1168
         *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1169
         * @return A negative integer, zero, or a positive integer as this
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1170
         *         module version is less than, equal to, or greater than the
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1171
         *         given module version
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1172
         */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1173
        @Override
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1174
        public int compareTo(Version that) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1175
            int c = compareTokens(this.sequence, that.sequence);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1176
            if (c != 0) return c;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1177
            if (this.pre.isEmpty()) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1178
                if (!that.pre.isEmpty()) return +1;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1179
            } else {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1180
                if (that.pre.isEmpty()) return -1;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1181
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1182
            c = compareTokens(this.pre, that.pre);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1183
            if (c != 0) return c;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1184
            return compareTokens(this.build, that.build);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1185
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1186
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1187
        /**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1188
         * Tests this module version for equality with the given object.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1189
         *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1190
         * <p> If the given object is not a {@code Version} then this method
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1191
         * returns {@code false}. Two module version are equal if their
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1192
         * corresponding components are equal. </p>
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1193
         *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1194
         * <p> This method satisfies the general contract of the {@link
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1195
         * java.lang.Object#equals(Object) Object.equals} method. </p>
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1196
         *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1197
         * @param   ob
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1198
         *          the object to which this object is to be compared
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1199
         *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1200
         * @return  {@code true} if, and only if, the given object is a module
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1201
         *          reference that is equal to this module reference
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1202
         */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1203
        @Override
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1204
        public boolean equals(Object ob) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1205
            if (!(ob instanceof Version))
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1206
                return false;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1207
            return compareTo((Version)ob) == 0;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1208
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1209
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1210
        /**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1211
         * Computes a hash code for this module version.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1212
         *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1213
         * <p> The hash code is based upon the components of the version and
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1214
         * satisfies the general contract of the {@link Object#hashCode
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1215
         * Object.hashCode} method. </p>
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1216
         *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1217
         * @return The hash-code value for this module version
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1218
         */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1219
        @Override
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1220
        public int hashCode() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1221
            return version.hashCode();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1222
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1223
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1224
        /**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1225
         * Returns the string from which this version was parsed.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1226
         *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1227
         * @return The string from which this version was parsed.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1228
         */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1229
        @Override
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1230
        public String toString() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1231
            return version;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1232
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1233
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1234
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1235
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1236
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1237
    private final String name;
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
  1238
    private final Version version;
44359
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1239
    private final String rawVersionString;
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1240
    private final Set<Modifier> modifiers;
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1241
    private final boolean open;  // true if modifiers contains OPEN
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1242
    private final boolean automatic;  // true if modifiers contains AUTOMATIC
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1243
    private final Set<Requires> requires;
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1244
    private final Set<Exports> exports;
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1245
    private final Set<Opens> opens;
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1246
    private final Set<String> uses;
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1247
    private final Set<Provides> provides;
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
  1248
    private final Set<String> packages;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1249
    private final String mainClass;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1250
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1251
    private ModuleDescriptor(String name,
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
  1252
                             Version version,
44359
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1253
                             String rawVersionString,
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1254
                             Set<Modifier> modifiers,
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1255
                             Set<Requires> requires,
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1256
                             Set<Exports> exports,
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1257
                             Set<Opens> opens,
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1258
                             Set<String> uses,
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1259
                             Set<Provides> provides,
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
  1260
                             Set<String> packages,
44359
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1261
                             String mainClass)
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1262
    {
44359
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1263
        assert version == null || rawVersionString == null;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1264
        this.name = name;
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
  1265
        this.version = version;
44359
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1266
        this.rawVersionString = rawVersionString;
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1267
        this.modifiers = emptyOrUnmodifiableSet(modifiers);
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1268
        this.open = modifiers.contains(Modifier.OPEN);
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1269
        this.automatic = modifiers.contains(Modifier.AUTOMATIC);
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1270
        assert (requires.stream().map(Requires::name).distinct().count()
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1271
                == requires.size());
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1272
        this.requires = emptyOrUnmodifiableSet(requires);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1273
        this.exports = emptyOrUnmodifiableSet(exports);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1274
        this.opens = emptyOrUnmodifiableSet(opens);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1275
        this.uses = emptyOrUnmodifiableSet(uses);
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1276
        this.provides = emptyOrUnmodifiableSet(provides);
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
  1277
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
  1278
        this.packages = emptyOrUnmodifiableSet(packages);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1279
        this.mainClass = mainClass;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1280
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1281
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1282
    /**
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1283
     * Creates a module descriptor from its components.
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1284
     * The arguments are pre-validated and sets are unmodifiable sets.
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1285
     */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1286
    ModuleDescriptor(String name,
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
  1287
                     Version version,
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1288
                     Set<Modifier> modifiers,
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1289
                     Set<Requires> requires,
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1290
                     Set<Exports> exports,
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1291
                     Set<Opens> opens,
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1292
                     Set<String> uses,
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1293
                     Set<Provides> provides,
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
  1294
                     Set<String> packages,
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1295
                     String mainClass,
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1296
                     int hashCode,
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1297
                     boolean unused) {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1298
        this.name = name;
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
  1299
        this.version = version;
44359
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1300
        this.rawVersionString = null;
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1301
        this.modifiers = modifiers;
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1302
        this.open = modifiers.contains(Modifier.OPEN);
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1303
        this.automatic = modifiers.contains(Modifier.AUTOMATIC);
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1304
        this.requires = requires;
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1305
        this.exports = exports;
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1306
        this.opens = opens;
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1307
        this.uses = uses;
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1308
        this.provides = provides;
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1309
        this.packages = packages;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1310
        this.mainClass = mainClass;
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1311
        this.hash = hashCode;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1312
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1313
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1314
    /**
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1315
     * <p> Returns the module name. </p>
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1316
     *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1317
     * @return The module name
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1318
     */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1319
    public String name() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1320
        return name;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1321
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1322
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1323
    /**
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1324
     * <p> Returns the set of module modifiers. </p>
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1325
     *
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1326
     * @return A possibly-empty unmodifiable set of modifiers
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1327
     */
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1328
    public Set<Modifier> modifiers() {
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1329
        return modifiers;
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1330
    }
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1331
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1332
    /**
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1333
     * <p> Returns {@code true} if this is an open module. </p>
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1334
     *
47004
b7e72fc752c9 8186684: Fix broken links in java.base API docs
jjg
parents: 46096
diff changeset
  1335
     * <p> This method is equivalent to testing if the set of {@link #modifiers()
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1336
     * modifiers} contains the {@link Modifier#OPEN OPEN} modifier. </p>
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1337
     *
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1338
     * @return  {@code true} if this is an open module
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1339
     */
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1340
    public boolean isOpen() {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1341
        return open;
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1342
    }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1343
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1344
    /**
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1345
     * <p> Returns {@code true} if this is an automatic module. </p>
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1346
     *
47004
b7e72fc752c9 8186684: Fix broken links in java.base API docs
jjg
parents: 46096
diff changeset
  1347
     * <p> This method is equivalent to testing if the set of {@link #modifiers()
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1348
     * modifiers} contains the {@link Modifier#OPEN AUTOMATIC} modifier. </p>
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1349
     *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1350
     * @return  {@code true} if this is an automatic module
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1351
     */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1352
    public boolean isAutomatic() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1353
        return automatic;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1354
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1355
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1356
    /**
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1357
     * <p> Returns the set of {@code Requires} objects representing the module
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1358
     * dependences. </p>
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1359
     *
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1360
     * <p> The set includes a dependency on "{@code java.base}" when this
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1361
     * module is not named "{@code java.base}". If this module is an automatic
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1362
     * module then it does not have a dependency on any module other than
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1363
     * "{@code java.base}". </p>
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1364
     *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1365
     * @return  A possibly-empty unmodifiable set of {@link Requires} objects
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1366
     */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1367
    public Set<Requires> requires() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1368
        return requires;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1369
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1370
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1371
    /**
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1372
     * <p> Returns the set of {@code Exports} objects representing the exported
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1373
     * packages. </p>
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1374
     *
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1375
     * <p> If this module is an automatic module then the set of exports
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1376
     * is empty. </p>
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1377
     *
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1378
     * @return  A possibly-empty unmodifiable set of exported packages
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1379
     */
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1380
    public Set<Exports> exports() {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1381
        return exports;
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1382
    }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1383
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1384
    /**
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1385
     * <p> Returns the set of {@code Opens} objects representing the open
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1386
     * packages. </p>
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1387
     *
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1388
     * <p> If this module is an open module or an automatic module then the
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1389
     * set of open packages is empty. </p>
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1390
     *
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1391
     * @return  A possibly-empty unmodifiable set of open packages
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1392
     */
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1393
    public Set<Opens> opens() {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1394
        return opens;
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1395
    }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1396
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1397
    /**
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1398
     * <p> Returns the set of service dependences. </p>
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1399
     *
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1400
     * <p> If this module is an automatic module then the set of service
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1401
     * dependences is empty. </p>
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1402
     *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1403
     * @return  A possibly-empty unmodifiable set of the fully qualified class
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1404
     *          names of the service types used
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1405
     */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1406
    public Set<String> uses() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1407
        return uses;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1408
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1409
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1410
    /**
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1411
     * <p> Returns the set of {@code Provides} objects representing the
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1412
     * services that the module provides. </p>
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1413
     *
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1414
     * @return The possibly-empty unmodifiable set of the services that this
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1415
     *         module provides
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1416
     */
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1417
    public Set<Provides> provides() {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1418
        return provides;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1419
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1420
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1421
    /**
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1422
     * <p> Returns the module version. </p>
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1423
     *
44359
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1424
     * @return This module's version, or an empty {@code Optional} if the
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1425
     *         module does not have a version or the version is
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1426
     *         {@linkplain Version#parse(String) unparseable}
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1427
     */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1428
    public Optional<Version> version() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1429
        return Optional.ofNullable(version);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1430
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1431
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1432
    /**
44359
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1433
     * <p> Returns the string with the possibly-unparseable version of the
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1434
     * module </p>
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1435
     *
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1436
     * @return The string containing the version of the module or an empty
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1437
     *         {@code Optional} if the module does not have a version
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1438
     *
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1439
     * @see #version()
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1440
     */
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1441
    public Optional<String> rawVersion() {
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1442
        if (version != null) {
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1443
            return Optional.of(version.toString());
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1444
        } else {
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1445
            return Optional.ofNullable(rawVersionString);
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1446
        }
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1447
    }
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1448
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1449
    /**
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1450
     * <p> Returns a string containing the module name and, if present, its
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1451
     * version. </p>
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1452
     *
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1453
     * @return A string containing the module name and, if present, its
44359
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1454
     *         version
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1455
     */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1456
    public String toNameAndVersion() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1457
        if (version != null) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1458
            return name() + "@" + version;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1459
        } else {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1460
            return name();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1461
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1462
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1463
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1464
    /**
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1465
     * <p> Returns the module main class. </p>
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1466
     *
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1467
     * @return The fully qualified class name of the module's main class
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1468
     */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1469
    public Optional<String> mainClass() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1470
        return Optional.ofNullable(mainClass);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1471
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1472
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1473
    /**
44359
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1474
     * Returns the set of packages in the module.
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1475
     *
44359
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1476
     * <p> The set of packages includes all exported and open packages, as well
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1477
     * as the packages of any service providers, and the package for the main
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1478
     * class. </p>
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1479
     *
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1480
     * @return A possibly-empty unmodifiable set of the packages in the module
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1481
     */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1482
    public Set<String> packages() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1483
        return packages;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1484
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1485
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1486
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1487
    /**
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1488
     * A builder for building {@link ModuleDescriptor} objects.
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1489
     *
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1490
     * <p> {@code ModuleDescriptor} defines the {@link #newModule newModule},
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1491
     * {@link #newOpenModule newOpenModule}, and {@link #newAutomaticModule
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1492
     * newAutomaticModule} methods to create builders for building
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1493
     * <em>normal</em>, open, and automatic modules. </p>
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1494
     *
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1495
     * <p> The set of packages in the module are accumulated by the {@code
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1496
     * Builder} as the {@link ModuleDescriptor.Builder#exports(String) exports},
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1497
     * {@link ModuleDescriptor.Builder#opens(String) opens},
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1498
     * {@link ModuleDescriptor.Builder#packages(Set) packages},
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1499
     * {@link ModuleDescriptor.Builder#provides(String,List) provides}, and
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1500
     * {@link ModuleDescriptor.Builder#mainClass(String) mainClass} methods are
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1501
     * invoked. </p>
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1502
     *
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1503
     * <p> The module names, package names, and class names that are parameters
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1504
     * specified to the builder methods are the module names, package names,
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1505
     * and qualified names of classes (in named packages) as defined in the
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1506
     * <cite>The Java&trade; Language Specification</cite>. </p>
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1507
     *
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1508
     * <p> Example usage: </p>
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1509
     * <pre>{@code    ModuleDescriptor descriptor = ModuleDescriptor.newModule("stats.core")
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1510
     *         .requires("java.base")
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1511
     *         .exports("org.acme.stats.core.clustering")
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1512
     *         .exports("org.acme.stats.core.regression")
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1513
     *         .packages(Set.of("org.acme.stats.core.internal"))
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1514
     *         .build();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1515
     * }</pre>
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1516
     *
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1517
     * @apiNote A {@code Builder} checks the components and invariants as
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1518
     * components are added to the builder. The rationale for this is to detect
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1519
     * errors as early as possible and not defer all validation to the
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1520
     * {@link #build build} method.
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1521
     *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1522
     * @since 9
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1523
     * @spec JPMS
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1524
     */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1525
    public static final class Builder {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1526
        final String name;
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1527
        final boolean strict;
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1528
        final Set<Modifier> modifiers;
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
  1529
        final boolean open;
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1530
        final boolean automatic;
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1531
        final Set<String> packages = new HashSet<>();
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1532
        final Map<String, Requires> requires = new HashMap<>();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1533
        final Map<String, Exports> exports = new HashMap<>();
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1534
        final Map<String, Opens> opens = new HashMap<>();
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1535
        final Set<String> uses = new HashSet<>();
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1536
        final Map<String, Provides> provides = new HashMap<>();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1537
        Version version;
44359
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1538
        String rawVersionString;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1539
        String mainClass;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1540
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1541
        /**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1542
         * Initializes a new builder with the given module name.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1543
         *
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1544
         * If {@code strict} is {@code true} then module, package, and class
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1545
         * names are checked to ensure they are legal names. In addition, the
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1546
         * {@link #build buid} method will add "{@code requires java.base}" if
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1547
         * the dependency is not declared.
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1548
         */
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1549
        Builder(String name, boolean strict, Set<Modifier> modifiers) {
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1550
            this.name = (strict) ? requireModuleName(name) : name;
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
  1551
            this.strict = strict;
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1552
            this.modifiers = modifiers;
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1553
            this.open = modifiers.contains(Modifier.OPEN);
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1554
            this.automatic = modifiers.contains(Modifier.AUTOMATIC);
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1555
            assert !open || !automatic;
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1556
        }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1557
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
  1558
        /**
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1559
         * Returns a snapshot of the packages in the module.
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
  1560
         */
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1561
        /* package */ Set<String> packages() {
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1562
            return Collections.unmodifiableSet(packages);
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1563
        }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1564
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1565
        /**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1566
         * Adds a dependence on a module.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1567
         *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1568
         * @param  req
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1569
         *         The dependence
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1570
         *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1571
         * @return This builder
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1572
         *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1573
         * @throws IllegalArgumentException
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1574
         *         If the dependence is on the module that this builder was
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1575
         *         initialized to build
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1576
         * @throws IllegalStateException
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1577
         *         If the dependence on the module has already been declared
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1578
         *         or this builder is for an automatic module
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1579
         */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1580
        public Builder requires(Requires req) {
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1581
            if (automatic)
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1582
                throw new IllegalStateException("Automatic modules cannot declare"
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1583
                                                + " dependences");
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1584
            String mn = req.name();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1585
            if (name.equals(mn))
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1586
                throw new IllegalArgumentException("Dependence on self");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1587
            if (requires.containsKey(mn))
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1588
                throw new IllegalStateException("Dependence upon " + mn
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1589
                                                + " already declared");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1590
            requires.put(mn, req);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1591
            return this;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1592
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1593
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1594
        /**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1595
         * Adds a dependence on a module with the given (and possibly empty)
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
  1596
         * set of modifiers. The dependence includes the version of the
47866
39db80b32b69 8191632: Typos in comments due to duplicating words
igerasim
parents: 47216
diff changeset
  1597
         * module that was recorded at compile-time.
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
  1598
         *
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
  1599
         * @param  ms
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
  1600
         *         The set of modifiers
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
  1601
         * @param  mn
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
  1602
         *         The module name
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
  1603
         * @param  compiledVersion
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
  1604
         *         The version of the module recorded at compile-time
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
  1605
         *
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
  1606
         * @return This builder
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
  1607
         *
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
  1608
         * @throws IllegalArgumentException
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1609
         *         If the module name is {@code null}, is not a legal module
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1610
         *         name, or is equal to the module name that this builder
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
  1611
         *         was initialized to build
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
  1612
         * @throws IllegalStateException
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
  1613
         *         If the dependence on the module has already been declared
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1614
         *         or this builder is for an automatic module
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
  1615
         */
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
  1616
        public Builder requires(Set<Requires.Modifier> ms,
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
  1617
                                String mn,
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
  1618
                                Version compiledVersion) {
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
  1619
            Objects.requireNonNull(compiledVersion);
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
  1620
            if (strict)
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
  1621
                mn = requireModuleName(mn);
44359
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1622
            return requires(new Requires(ms, mn, compiledVersion, null));
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
  1623
        }
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
  1624
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1625
        /* package */Builder requires(Set<Requires.Modifier> ms,
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1626
                                      String mn,
44359
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1627
                                      String rawCompiledVersion) {
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1628
            Requires r;
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1629
            try {
44359
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1630
                Version v = Version.parse(rawCompiledVersion);
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1631
                r = new Requires(ms, mn, v, null);
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1632
            } catch (IllegalArgumentException e) {
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1633
                if (strict) throw e;
44359
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1634
                r = new Requires(ms, mn, null, rawCompiledVersion);
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1635
            }
44359
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1636
            return requires(r);
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1637
        }
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1638
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
  1639
        /**
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
  1640
         * Adds a dependence on a module with the given (and possibly empty)
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1641
         * set of modifiers.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1642
         *
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1643
         * @param  ms
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1644
         *         The set of modifiers
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1645
         * @param  mn
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1646
         *         The module name
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1647
         *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1648
         * @return This builder
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1649
         *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1650
         * @throws IllegalArgumentException
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1651
         *         If the module name is {@code null}, is not a legal module
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1652
         *         name, or is equal to the module name that this builder
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1653
         *         was initialized to build
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1654
         * @throws IllegalStateException
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1655
         *         If the dependence on the module has already been declared
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1656
         *         or this builder is for an automatic module
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1657
         */
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1658
        public Builder requires(Set<Requires.Modifier> ms, String mn) {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1659
            if (strict)
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1660
                mn = requireModuleName(mn);
44359
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1661
            return requires(new Requires(ms, mn, null, null));
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1662
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1663
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1664
        /**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1665
         * Adds a dependence on a module with an empty set of modifiers.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1666
         *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1667
         * @param  mn
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1668
         *         The module name
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1669
         *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1670
         * @return This builder
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1671
         *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1672
         * @throws IllegalArgumentException
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1673
         *         If the module name is {@code null}, is not a legal module
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1674
         *         name, or is equal to the module name that this builder
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1675
         *         was initialized to build
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1676
         * @throws IllegalStateException
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1677
         *         If the dependence on the module has already been declared
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1678
         *         or this builder is for an automatic module
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1679
         */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1680
        public Builder requires(String mn) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1681
            return requires(EnumSet.noneOf(Requires.Modifier.class), mn);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1682
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1683
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1684
        /**
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1685
         * Adds an exported package.
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1686
         *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1687
         * @param  e
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1688
         *         The export
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1689
         *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1690
         * @return This builder
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1691
         *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1692
         * @throws IllegalStateException
47004
b7e72fc752c9 8186684: Fix broken links in java.base API docs
jjg
parents: 46096
diff changeset
  1693
         *         If the {@link Exports#source() package} is already declared as
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1694
         *         exported or this builder is for an automatic module
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1695
         */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1696
        public Builder exports(Exports e) {
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1697
            if (automatic) {
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1698
                throw new IllegalStateException("Automatic modules cannot declare"
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1699
                                                 + " exported packages");
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1700
            }
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1701
            String source = e.source();
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1702
            if (exports.containsKey(source)) {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1703
                throw new IllegalStateException("Exported package " + source
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1704
                                                 + " already declared");
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1705
            }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1706
            exports.put(source, e);
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1707
            packages.add(source);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1708
            return this;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1709
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1710
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1711
        /**
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1712
         * Adds an exported package with the given (and possibly empty) set of
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1713
         * modifiers. The package is exported to a set of target modules.
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1714
         *
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1715
         * @param  ms
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1716
         *         The set of modifiers
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1717
         * @param  pn
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1718
         *         The package name
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1719
         * @param  targets
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1720
         *         The set of target modules names
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1721
         *
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1722
         * @return This builder
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1723
         *
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1724
         * @throws IllegalArgumentException
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1725
         *         If the package name is {@code null} or is not a legal
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1726
         *         package name, the set of target modules is empty, or the set
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1727
         *         of target modules contains a name that is not a legal module
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1728
         *         name
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1729
         * @throws IllegalStateException
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1730
         *         If the package is already declared as exported
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1731
         *         or this builder is for an automatic module
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1732
         */
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1733
        public Builder exports(Set<Exports.Modifier> ms,
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1734
                               String pn,
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1735
                               Set<String> targets)
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1736
        {
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1737
            Exports e = new Exports(ms, pn, targets);
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1738
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1739
            // check targets
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1740
            targets = e.targets();
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1741
            if (targets.isEmpty())
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1742
                throw new IllegalArgumentException("Empty target set");
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1743
            if (strict) {
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1744
                requirePackageName(e.source());
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1745
                targets.stream().forEach(Checks::requireModuleName);
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1746
            }
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1747
            return exports(e);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1748
        }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1749
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1750
        /**
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1751
         * Adds an exported package with the given (and possibly empty) set of
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1752
         * modifiers. The package is exported to all modules.
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1753
         *
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1754
         * @param  ms
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1755
         *         The set of modifiers
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1756
         * @param  pn
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1757
         *         The package name
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1758
         *
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1759
         * @return This builder
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1760
         *
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1761
         * @throws IllegalArgumentException
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1762
         *         If the package name is {@code null} or is not a legal
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1763
         *         package name
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1764
         * @throws IllegalStateException
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1765
         *         If the package is already declared as exported
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1766
         *         or this builder is for an automatic module
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1767
         */
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1768
        public Builder exports(Set<Exports.Modifier> ms, String pn) {
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1769
            if (strict) {
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1770
                requirePackageName(pn);
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1771
            }
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1772
            Exports e = new Exports(ms, pn, Collections.emptySet());
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1773
            return exports(e);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1774
        }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1775
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1776
        /**
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1777
         * Adds an exported package. The package is exported to a set of target
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1778
         * modules.
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1779
         *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1780
         * @param  pn
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1781
         *         The package name
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1782
         * @param  targets
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1783
         *         The set of target modules names
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1784
         *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1785
         * @return This builder
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1786
         *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1787
         * @throws IllegalArgumentException
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1788
         *         If the package name is {@code null} or is not a legal
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1789
         *         package name, the set of target modules is empty, or the set
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1790
         *         of target modules contains a name that is not a legal module
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1791
         *         name
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1792
         * @throws IllegalStateException
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1793
         *         If the package is already declared as exported
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1794
         *         or this builder is for an automatic module
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1795
         */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1796
        public Builder exports(String pn, Set<String> targets) {
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1797
            return exports(Collections.emptySet(), pn, targets);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1798
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1799
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1800
        /**
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1801
         * Adds an exported package. The package is exported to all modules.
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1802
         *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1803
         * @param  pn
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1804
         *         The package name
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1805
         *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1806
         * @return This builder
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1807
         *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1808
         * @throws IllegalArgumentException
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1809
         *         If the package name is {@code null} or is not a legal
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1810
         *         package name
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1811
         * @throws IllegalStateException
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1812
         *         If the package is already declared as exported
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1813
         *         or this builder is for an automatic module
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1814
         */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1815
        public Builder exports(String pn) {
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1816
            return exports(Collections.emptySet(), pn);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1817
        }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1818
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1819
        /**
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1820
         * Adds an open package.
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1821
         *
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1822
         * @param  obj
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1823
         *         The {@code Opens} object
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1824
         *
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1825
         * @return This builder
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1826
         *
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1827
         * @throws IllegalStateException
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1828
         *         If the package is already declared as open, or this is a
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1829
         *         builder for an open module or automatic module
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1830
         */
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1831
        public Builder opens(Opens obj) {
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1832
            if (open || automatic) {
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1833
                throw new IllegalStateException("Open or automatic modules cannot"
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1834
                                                + " declare open packages");
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1835
            }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1836
            String source = obj.source();
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1837
            if (opens.containsKey(source)) {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1838
                throw new IllegalStateException("Open package " + source
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1839
                                                + " already declared");
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1840
            }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1841
            opens.put(source, obj);
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1842
            packages.add(source);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1843
            return this;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1844
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1845
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1846
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1847
        /**
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1848
         * Adds an open package with the given (and possibly empty) set of
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1849
         * modifiers. The package is open to a set of target modules.
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1850
         *
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1851
         * @param  ms
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1852
         *         The set of modifiers
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1853
         * @param  pn
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1854
         *         The package name
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1855
         * @param  targets
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1856
         *         The set of target modules names
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1857
         *
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1858
         * @return This builder
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1859
         *
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1860
         * @throws IllegalArgumentException
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1861
         *         If the package name is {@code null} or is not a legal
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1862
         *         package name, the set of target modules is empty, or the set
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1863
         *         of target modules contains a name that is not a legal module
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1864
         *         name
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1865
         * @throws IllegalStateException
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1866
         *         If the package is already declared as open, or this is a
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1867
         *         builder for an open module or automatic module
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1868
         */
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1869
        public Builder opens(Set<Opens.Modifier> ms,
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1870
                             String pn,
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1871
                             Set<String> targets)
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1872
        {
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1873
            Opens opens = new Opens(ms, pn, targets);
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1874
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1875
            // check targets
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1876
            targets = opens.targets();
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1877
            if (targets.isEmpty())
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1878
                throw new IllegalArgumentException("Empty target set");
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1879
            if (strict) {
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1880
                requirePackageName(opens.source());
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1881
                targets.stream().forEach(Checks::requireModuleName);
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1882
            }
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1883
            return opens(opens);
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1884
        }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1885
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1886
        /**
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1887
         * Adds an open package with the given (and possibly empty) set of
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1888
         * modifiers. The package is open to all modules.
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1889
         *
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1890
         * @param  ms
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1891
         *         The set of modifiers
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1892
         * @param  pn
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1893
         *         The package name
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1894
         *
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1895
         * @return This builder
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1896
         *
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1897
         * @throws IllegalArgumentException
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1898
         *         If the package name is {@code null} or is not a legal
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1899
         *         package name
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1900
         * @throws IllegalStateException
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1901
         *         If the package is already declared as open, or this is a
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1902
         *         builder for an open module or automatic module
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1903
         */
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1904
        public Builder opens(Set<Opens.Modifier> ms, String pn) {
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1905
            if (strict) {
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1906
                requirePackageName(pn);
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1907
            }
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1908
            Opens e = new Opens(ms, pn, Collections.emptySet());
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1909
            return opens(e);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1910
        }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1911
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1912
        /**
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1913
         * Adds an open package. The package is open to a set of target modules.
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1914
         *
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1915
         * @param  pn
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1916
         *         The package name
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1917
         * @param  targets
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1918
         *         The set of target modules names
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1919
         *
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1920
         * @return This builder
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1921
         *
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1922
         * @throws IllegalArgumentException
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1923
         *         If the package name is {@code null} or is not a legal
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1924
         *         package name, the set of target modules is empty, or the set
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1925
         *         of target modules contains a name that is not a legal module
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1926
         *         name
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1927
         * @throws IllegalStateException
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1928
         *         If the package is already declared as open, or this is a
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1929
         *         builder for an open module or automatic module
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1930
         */
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1931
        public Builder opens(String pn, Set<String> targets) {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1932
            return opens(Collections.emptySet(), pn, targets);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1933
        }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1934
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1935
        /**
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1936
         * Adds an open package. The package is open to all modules.
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1937
         *
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1938
         * @param  pn
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1939
         *         The package name
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1940
         *
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1941
         * @return This builder
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1942
         *
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1943
         * @throws IllegalArgumentException
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1944
         *         If the package name is {@code null} or is not a legal
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1945
         *         package name
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1946
         * @throws IllegalStateException
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1947
         *         If the package is already declared as open, or this is a
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1948
         *         builder for an open module or automatic module
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1949
         */
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1950
        public Builder opens(String pn) {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1951
            return opens(Collections.emptySet(), pn);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1952
        }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1953
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1954
        /**
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1955
         * Adds a service dependence.
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1956
         *
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1957
         * @param  service
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1958
         *         The service type
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1959
         *
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1960
         * @return This builder
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1961
         *
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1962
         * @throws IllegalArgumentException
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1963
         *         If the service type is {@code null} or not a qualified name of
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1964
         *         a class in a named package
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1965
         * @throws IllegalStateException
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1966
         *         If a dependency on the service type has already been declared
44359
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1967
         *         or this is a builder for an automatic module
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1968
         */
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1969
        public Builder uses(String service) {
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1970
            if (automatic)
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1971
                throw new IllegalStateException("Automatic modules can not declare"
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1972
                                                + " service dependences");
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1973
            if (uses.contains(requireServiceTypeName(service)))
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1974
                throw new IllegalStateException("Dependence upon service "
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1975
                                                + service + " already declared");
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1976
            uses.add(service);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  1977
            return this;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1978
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1979
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1980
        /**
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1981
         * Provides a service with one or more implementations. The package for
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1982
         * each {@link Provides#providers provider} (or provider factory) is
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1983
         * added to the module if not already added.
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1984
         *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1985
         * @param  p
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1986
         *         The provides
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1987
         *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1988
         * @return This builder
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1989
         *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1990
         * @throws IllegalStateException
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1991
         *         If the providers for the service type have already been
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1992
         *         declared
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1993
         */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1994
        public Builder provides(Provides p) {
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1995
            String service = p.service();
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1996
            if (provides.containsKey(service))
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1997
                throw new IllegalStateException("Providers of service "
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1998
                                                + service + " already declared");
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1999
            provides.put(service, p);
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2000
            p.providers().forEach(name -> packages.add(packageName(name)));
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2001
            return this;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2002
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2003
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2004
        /**
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2005
         * Provides implementations of a service. The package for each provider
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2006
         * (or provider factory) is added to the module if not already added.
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2007
         *
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2008
         * @param  service
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2009
         *         The service type
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2010
         * @param  providers
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2011
         *         The list of provider or provider factory class names
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2012
         *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2013
         * @return This builder
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2014
         *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2015
         * @throws IllegalArgumentException
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2016
         *         If the service type or any of the provider class names is
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2017
         *         {@code null} or not a qualified name of a class in a named
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2018
         *         package, or the list of provider class names is empty
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2019
         * @throws IllegalStateException
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2020
         *         If the providers for the service type have already been
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2021
         *         declared
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2022
         */
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2023
        public Builder provides(String service, List<String> providers) {
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2024
            Provides p = new Provides(service, providers);
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2025
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2026
            // check providers after the set has been copied.
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2027
            List<String> providerNames = p.providers();
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2028
            if (providerNames.isEmpty())
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2029
                throw new IllegalArgumentException("Empty providers set");
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2030
            if (strict) {
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2031
                requireServiceTypeName(p.service());
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2032
                providerNames.forEach(Checks::requireServiceProviderName);
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2033
            } else {
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2034
                // Disallow service/providers in unnamed package
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2035
                String pn = packageName(service);
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2036
                if (pn.isEmpty()) {
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2037
                    throw new IllegalArgumentException(service
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2038
                                                       + ": unnamed package");
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2039
                }
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2040
                for (String name : providerNames) {
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2041
                    pn = packageName(name);
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2042
                    if (pn.isEmpty()) {
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2043
                        throw new IllegalArgumentException(name
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2044
                                                           + ": unnamed package");
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2045
                    }
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2046
                }
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2047
            }
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2048
            return provides(p);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2049
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2050
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2051
        /**
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2052
         * Adds packages to the module. All packages in the set of package names
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2053
         * that are not in the module are added to module.
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2054
         *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2055
         * @param  pns
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2056
         *         The (possibly empty) set of package names
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2057
         *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2058
         * @return This builder
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2059
         *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2060
         * @throws IllegalArgumentException
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2061
         *         If any of the package names is {@code null} or is not a
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2062
         *         legal package name
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2063
         */
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2064
        public Builder packages(Set<String> pns) {
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2065
            if (strict) {
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2066
                pns = new HashSet<>(pns);
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2067
                pns.forEach(Checks::requirePackageName);
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2068
            }
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2069
            this.packages.addAll(pns);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2070
            return this;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2071
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2072
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2073
        /**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2074
         * Sets the module version.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2075
         *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2076
         * @param  v
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2077
         *         The version
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2078
         *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2079
         * @return This builder
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2080
         */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2081
        public Builder version(Version v) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2082
            version = requireNonNull(v);
44359
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  2083
            rawVersionString = null;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2084
            return this;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2085
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2086
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2087
        /**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2088
         * Sets the module version.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2089
         *
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2090
         * @param  vs
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2091
         *         The version string to parse
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2092
         *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2093
         * @return This builder
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2094
         *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2095
         * @throws IllegalArgumentException
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2096
         *         If {@code vs} is {@code null} or cannot be parsed as a
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2097
         *         version string
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2098
         *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2099
         * @see Version#parse(String)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2100
         */
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2101
        public Builder version(String vs) {
44359
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  2102
            try {
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  2103
                version = Version.parse(vs);
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  2104
                rawVersionString = null;
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  2105
            } catch (IllegalArgumentException e) {
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  2106
                if (strict) throw e;
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  2107
                version = null;
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  2108
                rawVersionString = vs;
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2109
            }
44359
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  2110
            return this;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2111
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2112
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2113
        /**
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2114
         * Sets the module main class. The package for the main class is added
44545
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44359
diff changeset
  2115
         * to the module if not already added. In other words, this method is
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44359
diff changeset
  2116
         * equivalent to first invoking this builder's {@link #packages(Set)
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44359
diff changeset
  2117
         * packages} method to add the package name of the main class.
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2118
         *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2119
         * @param  mc
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2120
         *         The module main class
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2121
         *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2122
         * @return This builder
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2123
         *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2124
         * @throws IllegalArgumentException
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2125
         *         If {@code mainClass} is {@code null} or not a qualified
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2126
         *         name of a class in a named package
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2127
         */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2128
        public Builder mainClass(String mc) {
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2129
            String pn;
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2130
            if (strict) {
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2131
                mc = requireQualifiedClassName("main class name", mc);
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2132
                pn = packageName(mc);
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2133
                assert !pn.isEmpty();
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2134
            } else {
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2135
                // Disallow main class in unnamed package
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2136
                pn = packageName(mc);
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2137
                if (pn.isEmpty()) {
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2138
                    throw new IllegalArgumentException(mc + ": unnamed package");
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2139
                }
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2140
            }
44545
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44359
diff changeset
  2141
            packages.add(pn);
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2142
            mainClass = mc;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2143
            return this;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2144
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2145
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2146
        /**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2147
         * Builds and returns a {@code ModuleDescriptor} from its components.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2148
         *
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2149
         * <p> The module will require "{@code java.base}" even if the dependence
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2150
         * has not been declared (the exception is when building a module named
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2151
         * "{@code java.base}" as it cannot require itself). The dependence on
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2152
         * "{@code java.base}" will have the {@link
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2153
         * java.lang.module.ModuleDescriptor.Requires.Modifier#MANDATED MANDATED}
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2154
         * modifier if the dependence was not declared. </p>
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2155
         *
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2156
         * @return The module descriptor
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2157
         */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2158
        public ModuleDescriptor build() {
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2159
            Set<Requires> requires = new HashSet<>(this.requires.values());
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2160
            Set<Exports> exports = new HashSet<>(this.exports.values());
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2161
            Set<Opens> opens = new HashSet<>(this.opens.values());
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2162
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2163
            // add dependency on java.base
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2164
            if (strict
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2165
                    && !name.equals("java.base")
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2166
                    && !this.requires.containsKey("java.base")) {
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2167
                requires.add(new Requires(Set.of(Requires.Modifier.MANDATED),
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2168
                                          "java.base",
44359
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  2169
                                          null,
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2170
                                          null));
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2171
            }
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2172
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2173
            Set<Provides> provides = new HashSet<>(this.provides.values());
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2174
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2175
            return new ModuleDescriptor(name,
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
  2176
                                        version,
44359
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  2177
                                        rawVersionString,
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2178
                                        modifiers,
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2179
                                        requires,
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2180
                                        exports,
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2181
                                        opens,
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2182
                                        uses,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2183
                                        provides,
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
  2184
                                        packages,
44359
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  2185
                                        mainClass);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2186
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2187
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2188
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2189
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2190
    /**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2191
     * Compares this module descriptor to another.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2192
     *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2193
     * <p> Two {@code ModuleDescriptor} objects are compared by comparing their
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2194
     * module names lexicographically. Where the module names are equal then the
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2195
     * module versions are compared. When comparing the module versions then a
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2196
     * module descriptor with a version is considered to succeed a module
44359
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  2197
     * descriptor that does not have a version. If both versions are {@linkplain
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  2198
     * Version#parse(String) unparseable} then the {@linkplain #rawVersion()
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  2199
     * raw version strings} are compared lexicographically. Where the module names
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  2200
     * are equal and the versions are equal (or not present in both), then the
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  2201
     * set of modifiers are compared. Sets of modifiers are compared by comparing
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2202
     * a <em>binary value</em> computed for each set. If a modifier is present
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2203
     * in the set then the bit at the position of its ordinal is {@code 1}
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2204
     * in the binary value, otherwise {@code 0}. If the two set of modifiers
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2205
     * are also equal then the other components of the module descriptors are
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2206
     * compared in a manner that is consistent with {@code equals}. </p>
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2207
     *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2208
     * @param  that
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2209
     *         The module descriptor to compare
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2210
     *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2211
     * @return A negative integer, zero, or a positive integer if this module
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2212
     *         descriptor is less than, equal to, or greater than the given
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2213
     *         module descriptor
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2214
     */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2215
    @Override
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2216
    public int compareTo(ModuleDescriptor that) {
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2217
        if (this == that) return 0;
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2218
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2219
        int c = this.name().compareTo(that.name());
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2220
        if (c != 0) return c;
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2221
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2222
        c = compare(this.version, that.version);
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2223
        if (c != 0) return c;
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2224
44359
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  2225
        c = compare(this.rawVersionString, that.rawVersionString);
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  2226
        if (c != 0) return c;
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  2227
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2228
        long v1 = modsValue(this.modifiers());
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2229
        long v2 = modsValue(that.modifiers());
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2230
        c = Long.compare(v1, v2);
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2231
        if (c != 0) return c;
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2232
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2233
        c = compare(this.requires, that.requires);
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2234
        if (c != 0) return c;
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2235
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2236
        c = compare(this.packages, that.packages);
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2237
        if (c != 0) return c;
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2238
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2239
        c = compare(this.exports, that.exports);
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2240
        if (c != 0) return c;
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2241
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2242
        c = compare(this.opens, that.opens);
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2243
        if (c != 0) return c;
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2244
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2245
        c = compare(this.uses, that.uses);
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2246
        if (c != 0) return c;
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2247
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2248
        c = compare(this.provides, that.provides);
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2249
        if (c != 0) return c;
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2250
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2251
        c = compare(this.mainClass, that.mainClass);
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2252
        if (c != 0) return c;
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2253
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2254
        return 0;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2255
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2256
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2257
    /**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2258
     * Tests this module descriptor for equality with the given object.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2259
     *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2260
     * <p> If the given object is not a {@code ModuleDescriptor} then this
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2261
     * method returns {@code false}. Two module descriptors are equal if each
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2262
     * of their corresponding components is equal. </p>
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2263
     *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2264
     * <p> This method satisfies the general contract of the {@link
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2265
     * java.lang.Object#equals(Object) Object.equals} method. </p>
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2266
     *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2267
     * @param   ob
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2268
     *          the object to which this object is to be compared
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2269
     *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2270
     * @return  {@code true} if, and only if, the given object is a module
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2271
     *          descriptor that is equal to this module descriptor
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2272
     */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2273
    @Override
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2274
    public boolean equals(Object ob) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2275
        if (ob == this)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2276
            return true;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2277
        if (!(ob instanceof ModuleDescriptor))
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2278
            return false;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2279
        ModuleDescriptor that = (ModuleDescriptor)ob;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2280
        return (name.equals(that.name)
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2281
                && modifiers.equals(that.modifiers)
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2282
                && requires.equals(that.requires)
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2283
                && Objects.equals(packages, that.packages)
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2284
                && exports.equals(that.exports)
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2285
                && opens.equals(that.opens)
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2286
                && uses.equals(that.uses)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2287
                && provides.equals(that.provides)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2288
                && Objects.equals(version, that.version)
44359
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  2289
                && Objects.equals(rawVersionString, that.rawVersionString)
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  2290
                && Objects.equals(mainClass, that.mainClass));
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2291
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2292
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2293
    /**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2294
     * Computes a hash code for this module descriptor.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2295
     *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2296
     * <p> The hash code is based upon the components of the module descriptor,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2297
     * and satisfies the general contract of the {@link Object#hashCode
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2298
     * Object.hashCode} method. </p>
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2299
     *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2300
     * @return The hash-code value for this module descriptor
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2301
     */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2302
    @Override
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2303
    public int hashCode() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2304
        int hc = hash;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2305
        if (hc == 0) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2306
            hc = name.hashCode();
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2307
            hc = hc * 43 + Objects.hashCode(modifiers);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2308
            hc = hc * 43 + requires.hashCode();
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2309
            hc = hc * 43 + Objects.hashCode(packages);
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2310
            hc = hc * 43 + exports.hashCode();
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2311
            hc = hc * 43 + opens.hashCode();
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2312
            hc = hc * 43 + uses.hashCode();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2313
            hc = hc * 43 + provides.hashCode();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2314
            hc = hc * 43 + Objects.hashCode(version);
44359
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  2315
            hc = hc * 43 + Objects.hashCode(rawVersionString);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2316
            hc = hc * 43 + Objects.hashCode(mainClass);
37779
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
  2317
            if (hc == 0)
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
  2318
                hc = -1;
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
  2319
            hash = hc;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2320
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2321
        return hc;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2322
    }
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2323
    private transient int hash;  // cached hash code
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2324
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2325
    /**
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2326
     * <p> Returns a string describing the module. </p>
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2327
     *
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2328
     * @return A string describing the module
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2329
     */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2330
    @Override
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2331
    public String toString() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2332
        StringBuilder sb = new StringBuilder();
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2333
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2334
        if (isOpen())
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2335
            sb.append("open ");
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2336
        sb.append("module { name: ").append(toNameAndVersion());
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2337
        if (!requires.isEmpty())
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2338
            sb.append(", ").append(requires);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2339
        if (!uses.isEmpty())
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
  2340
            sb.append(", uses: ").append(uses);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2341
        if (!exports.isEmpty())
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2342
            sb.append(", exports: ").append(exports);
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2343
        if (!opens.isEmpty())
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2344
            sb.append(", opens: ").append(opens);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2345
        if (!provides.isEmpty()) {
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2346
            sb.append(", provides: ").append(provides);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2347
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2348
        sb.append(" }");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2349
        return sb.toString();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2350
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2351
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2352
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2353
    /**
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2354
     * Instantiates a builder to build a module descriptor.
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2355
     *
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2356
     * @param  name
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2357
     *         The module name
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2358
     * @param  ms
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2359
     *         The set of module modifiers
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2360
     *
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2361
     * @return A new builder
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2362
     *
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2363
     * @throws IllegalArgumentException
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2364
     *         If the module name is {@code null} or is not a legal module
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2365
     *         name, or the set of modifiers contains {@link
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2366
     *         Modifier#AUTOMATIC AUTOMATIC} with other modifiers
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2367
     */
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2368
    public static Builder newModule(String name, Set<Modifier> ms) {
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2369
        Set<Modifier> mods = new HashSet<>(ms);
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2370
        if (mods.contains(Modifier.AUTOMATIC) && mods.size() > 1)
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2371
            throw new IllegalArgumentException("AUTOMATIC cannot be used with"
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2372
                                               + " other modifiers");
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2373
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2374
        return new Builder(name, true, mods);
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2375
    }
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2376
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2377
    /**
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2378
     * Instantiates a builder to build a module descriptor for a <em>normal</em>
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2379
     * module. This method is equivalent to invoking {@link #newModule(String,Set)
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2380
     * newModule} with an empty set of {@link ModuleDescriptor.Modifier modifiers}.
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2381
     *
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2382
     * @param  name
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2383
     *         The module name
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2384
     *
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2385
     * @return A new builder
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2386
     *
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2387
     * @throws IllegalArgumentException
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2388
     *         If the module name is {@code null} or is not a legal module
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2389
     *         name
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2390
     */
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2391
    public static Builder newModule(String name) {
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2392
        return new Builder(name, true, Set.of());
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2393
    }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2394
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2395
    /**
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2396
     * Instantiates a builder to build a module descriptor for an open module.
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2397
     * This method is equivalent to invoking {@link #newModule(String,Set)
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2398
     * newModule} with the {@link ModuleDescriptor.Modifier#OPEN OPEN} modifier.
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2399
     *
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2400
     * <p> The builder for an open module cannot be used to declare any open
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2401
     * packages. </p>
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2402
     *
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2403
     * @param  name
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2404
     *         The module name
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2405
     *
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2406
     * @return A new builder that builds an open module
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2407
     *
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2408
     * @throws IllegalArgumentException
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2409
     *         If the module name is {@code null} or is not a legal module
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2410
     *         name
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2411
     */
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2412
    public static Builder newOpenModule(String name) {
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2413
        return new Builder(name, true, Set.of(Modifier.OPEN));
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2414
    }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2415
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2416
    /**
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2417
     * Instantiates a builder to build a module descriptor for an automatic
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2418
     * module. This method is equivalent to invoking {@link #newModule(String,Set)
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2419
     * newModule} with the {@link ModuleDescriptor.Modifier#AUTOMATIC AUTOMATIC}
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2420
     * modifier.
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2421
     *
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2422
     * <p> The builder for an automatic module cannot be used to declare module
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2423
     * or service dependences. It also cannot be used to declare any exported
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2424
     * or open packages. </p>
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2425
     *
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2426
     * @param  name
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2427
     *         The module name
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2428
     *
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2429
     * @return A new builder that builds an automatic module
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2430
     *
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2431
     * @throws IllegalArgumentException
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2432
     *         If the module name is {@code null} or is not a legal module
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2433
     *         name
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2434
     *
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2435
     * @see ModuleFinder#of(Path[])
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2436
     */
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2437
    public static Builder newAutomaticModule(String name) {
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2438
        return new Builder(name, true, Set.of(Modifier.AUTOMATIC));
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2439
    }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2440
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2441
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2442
    /**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2443
     * Reads the binary form of a module declaration from an input stream
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2444
     * as a module descriptor.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2445
     *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2446
     * <p> If the descriptor encoded in the input stream does not indicate a
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2447
     * set of packages in the module then the {@code packageFinder} will be
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2448
     * invoked. The set of packages that the {@code packageFinder} returns
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2449
     * must include all the packages that the module exports, opens, as well
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2450
     * as the packages of the service implementations that the module provides,
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2451
     * and the package of the main class (if the module has a main class). If
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2452
     * the {@code packageFinder} throws an {@link UncheckedIOException} then
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2453
     * {@link IOException} cause will be re-thrown. </p>
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2454
     *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2455
     * <p> If there are bytes following the module descriptor then it is
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2456
     * implementation specific as to whether those bytes are read, ignored,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2457
     * or reported as an {@code InvalidModuleDescriptorException}. If this
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2458
     * method fails with an {@code InvalidModuleDescriptorException} or {@code
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2459
     * IOException} then it may do so after some, but not all, bytes have
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2460
     * been read from the input stream. It is strongly recommended that the
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2461
     * stream be promptly closed and discarded if an exception occurs. </p>
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2462
     *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2463
     * @apiNote The {@code packageFinder} parameter is for use when reading
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2464
     * module descriptors from legacy module-artifact formats that do not
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2465
     * record the set of packages in the descriptor itself.
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2466
     *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2467
     * @param  in
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2468
     *         The input stream
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2469
     * @param  packageFinder
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2470
     *         A supplier that can produce the set of packages
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2471
     *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2472
     * @return The module descriptor
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2473
     *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2474
     * @throws InvalidModuleDescriptorException
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2475
     *         If an invalid module descriptor is detected or the set of
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2476
     *         packages returned by the {@code packageFinder} does not include
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2477
     *         all of the packages obtained from the module descriptor
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2478
     * @throws IOException
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2479
     *         If an I/O error occurs reading from the input stream or {@code
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2480
     *         UncheckedIOException} is thrown by the package finder
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2481
     */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2482
    public static ModuleDescriptor read(InputStream in,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2483
                                        Supplier<Set<String>> packageFinder)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2484
        throws IOException
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2485
    {
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
  2486
        return ModuleInfo.read(in, requireNonNull(packageFinder)).descriptor();
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2487
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2488
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2489
    /**
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2490
     * Reads the binary form of a module declaration from an input stream as a
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2491
     * module descriptor. This method works exactly as specified by the 2-arg
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2492
     * {@link #read(InputStream,Supplier) read} method with the exception that
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2493
     * a packager finder is not used to find additional packages when the
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2494
     * module descriptor read from the stream does not indicate the set of
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2495
     * packages.
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2496
     *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2497
     * @param  in
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2498
     *         The input stream
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2499
     *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2500
     * @return The module descriptor
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2501
     *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2502
     * @throws InvalidModuleDescriptorException
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2503
     *         If an invalid module descriptor is detected
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2504
     * @throws IOException
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2505
     *         If an I/O error occurs reading from the input stream
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2506
     */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2507
    public static ModuleDescriptor read(InputStream in) throws IOException {
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
  2508
        return ModuleInfo.read(in, null).descriptor();
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2509
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2510
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2511
    /**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2512
     * Reads the binary form of a module declaration from a byte buffer
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2513
     * as a module descriptor.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2514
     *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2515
     * <p> If the descriptor encoded in the byte buffer does not indicate a
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2516
     * set of packages in the module then the {@code packageFinder} will be
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2517
     * invoked. The set of packages that the {@code packageFinder} returns
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2518
     * must include all the packages that the module exports, opens, as well
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2519
     * as the packages of the service implementations that the module provides,
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2520
     * and the package of the main class (if the module has a main class). If
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2521
     * the {@code packageFinder} throws an {@link UncheckedIOException} then
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2522
     * {@link IOException} cause will be re-thrown. </p>
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2523
     *
48431
b2cd597479ea 8194644: Typo in ModuleDescriptor.read javadoc
alanb
parents: 48261
diff changeset
  2524
     * <p> The module descriptor is read from the buffer starting at index
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2525
     * {@code p}, where {@code p} is the buffer's {@link ByteBuffer#position()
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2526
     * position} when this method is invoked. Upon return the buffer's position
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2527
     * will be equal to {@code p + n} where {@code n} is the number of bytes
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2528
     * read from the buffer. </p>
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2529
     *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2530
     * <p> If there are bytes following the module descriptor then it is
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2531
     * implementation specific as to whether those bytes are read, ignored,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2532
     * or reported as an {@code InvalidModuleDescriptorException}. If this
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2533
     * method fails with an {@code InvalidModuleDescriptorException} then it
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2534
     * may do so after some, but not all, bytes have been read. </p>
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2535
     *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2536
     * @apiNote The {@code packageFinder} parameter is for use when reading
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2537
     * module descriptors from legacy module-artifact formats that do not
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2538
     * record the set of packages in the descriptor itself.
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2539
     *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2540
     * @param  bb
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2541
     *         The byte buffer
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2542
     * @param  packageFinder
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2543
     *         A supplier that can produce the set of packages
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2544
     *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2545
     * @return The module descriptor
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2546
     *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2547
     * @throws InvalidModuleDescriptorException
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2548
     *         If an invalid module descriptor is detected or the set of
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2549
     *         packages returned by the {@code packageFinder} does not include
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2550
     *         all of the packages obtained from the module descriptor
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2551
     */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2552
    public static ModuleDescriptor read(ByteBuffer bb,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2553
                                        Supplier<Set<String>> packageFinder)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2554
    {
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
  2555
        return ModuleInfo.read(bb, requireNonNull(packageFinder)).descriptor();
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2556
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2557
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2558
    /**
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2559
     * Reads the binary form of a module declaration from a byte buffer as a
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2560
     * module descriptor. This method works exactly as specified by the 2-arg
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2561
     * {@link #read(ByteBuffer,Supplier) read} method with the exception that a
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2562
     * packager finder is not used to find additional packages when the module
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2563
     * descriptor encoded in the buffer does not indicate the set of packages.
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2564
     *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2565
     * @param  bb
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2566
     *         The byte buffer
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2567
     *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2568
     * @return The module descriptor
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2569
     *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2570
     * @throws InvalidModuleDescriptorException
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2571
     *         If an invalid module descriptor is detected
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2572
     */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2573
    public static ModuleDescriptor read(ByteBuffer bb) {
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
  2574
        return ModuleInfo.read(bb, null).descriptor();
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2575
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2576
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2577
    private static <K,V> Map<K,V> emptyOrUnmodifiableMap(Map<K,V> map) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2578
        if (map.isEmpty()) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2579
            return Collections.emptyMap();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2580
        } else if (map.size() == 1) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2581
            Map.Entry<K, V> entry = map.entrySet().iterator().next();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2582
            return Collections.singletonMap(entry.getKey(), entry.getValue());
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2583
        } else {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2584
            return Collections.unmodifiableMap(map);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2585
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2586
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2587
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2588
    private static <T> Set<T> emptyOrUnmodifiableSet(Set<T> set) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2589
        if (set.isEmpty()) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2590
            return Collections.emptySet();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2591
        } else if (set.size() == 1) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2592
            return Collections.singleton(set.iterator().next());
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2593
        } else {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2594
            return Collections.unmodifiableSet(set);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2595
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2596
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2597
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2598
    private static String packageName(String cn) {
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2599
        int index = cn.lastIndexOf('.');
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2600
        return (index == -1) ? "" : cn.substring(0, index);
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2601
    }
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2602
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2603
    /**
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2604
     * Returns a string containing the given set of modifiers and label.
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2605
     */
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2606
    private static <M> String toString(Set<M> mods, String what) {
48261
43edfde828ab 8193454: ModuleDescriptor.{Requires,Exports,Open} toString should use toLowerCase(Local.ROOT)
alanb
parents: 47866
diff changeset
  2607
        return (Stream.concat(mods.stream().map(e -> e.toString()
43edfde828ab 8193454: ModuleDescriptor.{Requires,Exports,Open} toString should use toLowerCase(Local.ROOT)
alanb
parents: 47866
diff changeset
  2608
                                                      .toLowerCase(Locale.ROOT)),
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2609
                              Stream.of(what)))
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2610
                .collect(Collectors.joining(" "));
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2611
    }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2612
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2613
    private static <T extends Object & Comparable<? super T>>
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2614
    int compare(T obj1, T obj2) {
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2615
        if (obj1 != null) {
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2616
            return (obj2 != null) ? obj1.compareTo(obj2) : 1;
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2617
        } else {
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2618
            return (obj2 == null) ? 0 : -1;
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2619
        }
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2620
    }
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2621
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2622
    /**
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2623
     * Compares two sets of {@code Comparable} objects.
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2624
     */
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2625
    @SuppressWarnings("unchecked")
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2626
    private static <T extends Object & Comparable<? super T>>
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2627
    int compare(Set<T> s1, Set<T> s2) {
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2628
        T[] a1 = (T[]) s1.toArray();
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2629
        T[] a2 = (T[]) s2.toArray();
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2630
        Arrays.sort(a1);
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2631
        Arrays.sort(a2);
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2632
        return Arrays.compare(a1, a2);
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2633
    }
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2634
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2635
    private static <E extends Enum<E>> long modsValue(Set<E> set) {
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2636
        long value = 0;
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2637
        for (Enum<E> e : set) {
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2638
            value += 1 << e.ordinal();
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2639
        }
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2640
        return value;
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2641
    }
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2642
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2643
    static {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2644
        /**
37779
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
  2645
         * Setup the shared secret to allow code in other packages access
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
  2646
         * private package methods in java.lang.module.
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2647
         */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2648
        jdk.internal.misc.SharedSecrets
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2649
            .setJavaLangModuleAccess(new jdk.internal.misc.JavaLangModuleAccess() {
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2650
                @Override
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
  2651
                public Builder newModuleBuilder(String mn,
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
  2652
                                                boolean strict,
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2653
                                                Set<ModuleDescriptor.Modifier> modifiers) {
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2654
                    return new Builder(mn, strict, modifiers);
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2655
                }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2656
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2657
                @Override
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2658
                public Set<String> packages(ModuleDescriptor.Builder builder) {
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2659
                    return builder.packages();
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2660
                }
37779
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
  2661
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2662
                @Override
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2663
                public void requires(ModuleDescriptor.Builder builder,
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2664
                                     Set<Requires.Modifier> ms,
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2665
                                     String mn,
44359
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  2666
                                     String rawCompiledVersion) {
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  2667
                    builder.requires(ms, mn, rawCompiledVersion);
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
  2668
                }
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
  2669
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
  2670
                @Override
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
  2671
                public Requires newRequires(Set<Requires.Modifier> ms, String mn, Version v) {
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
  2672
                    return new Requires(ms, mn, v, true);
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2673
                }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2674
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2675
                @Override
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2676
                public Exports newExports(Set<Exports.Modifier> ms, String source) {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2677
                    return new Exports(ms, source, Collections.emptySet(), true);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2678
                }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2679
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2680
                @Override
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2681
                public Exports newExports(Set<Exports.Modifier> ms,
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2682
                                          String source,
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2683
                                          Set<String> targets) {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2684
                    return new Exports(ms, source, targets, true);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2685
                }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2686
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2687
                @Override
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2688
                public Opens newOpens(Set<Opens.Modifier> ms,
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2689
                                      String source,
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2690
                                      Set<String> targets) {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2691
                    return new Opens(ms, source, targets, true);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2692
                }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2693
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2694
                @Override
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2695
                public Opens newOpens(Set<Opens.Modifier> ms, String source) {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2696
                    return new Opens(ms, source, Collections.emptySet(), true);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2697
                }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2698
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2699
                @Override
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2700
                public Provides newProvides(String service, List<String> providers) {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2701
                    return new Provides(service, providers, true);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2702
                }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2703
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2704
                @Override
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2705
                public ModuleDescriptor newModuleDescriptor(String name,
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
  2706
                                                            Version version,
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2707
                                                            Set<ModuleDescriptor.Modifier> modifiers,
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2708
                                                            Set<Requires> requires,
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2709
                                                            Set<Exports> exports,
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2710
                                                            Set<Opens> opens,
38888
dd584fbea6a2 8159334: ModuleDescriptor retains overlapping sets for all and concealed packages
redestad
parents: 37880
diff changeset
  2711
                                                            Set<String> uses,
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2712
                                                            Set<Provides> provides,
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
  2713
                                                            Set<String> packages,
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2714
                                                            String mainClass,
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2715
                                                            int hashCode) {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2716
                    return new ModuleDescriptor(name,
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
  2717
                                                version,
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2718
                                                modifiers,
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2719
                                                requires,
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2720
                                                exports,
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2721
                                                opens,
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2722
                                                uses,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2723
                                                provides,
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
  2724
                                                packages,
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2725
                                                mainClass,
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2726
                                                hashCode,
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2727
                                                false);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2728
                }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2729
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41817
diff changeset
  2730
                @Override
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2731
                public Configuration resolveAndBind(ModuleFinder finder,
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2732
                                                    Collection<String> roots,
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  2733
                                                    PrintStream traceOutput)
37779
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
  2734
                {
46096
62c77b334012 8185853: Generate readability graph at link time and other startup improvements
alanb
parents: 45004
diff changeset
  2735
                    return Configuration.resolveAndBind(finder, roots, traceOutput);
62c77b334012 8185853: Generate readability graph at link time and other startup improvements
alanb
parents: 45004
diff changeset
  2736
                }
62c77b334012 8185853: Generate readability graph at link time and other startup improvements
alanb
parents: 45004
diff changeset
  2737
62c77b334012 8185853: Generate readability graph at link time and other startup improvements
alanb
parents: 45004
diff changeset
  2738
                @Override
62c77b334012 8185853: Generate readability graph at link time and other startup improvements
alanb
parents: 45004
diff changeset
  2739
                public Configuration newConfiguration(ModuleFinder finder,
62c77b334012 8185853: Generate readability graph at link time and other startup improvements
alanb
parents: 45004
diff changeset
  2740
                                                      Map<String, Set<String>> graph) {
62c77b334012 8185853: Generate readability graph at link time and other startup improvements
alanb
parents: 45004
diff changeset
  2741
                    return new Configuration(finder, graph);
37779
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
  2742
                }
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2743
            });
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2744
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2745
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  2746
}