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