src/java.base/share/classes/java/lang/Package.java
author redestad
Thu, 13 Dec 2018 15:31:05 +0100
changeset 53018 8bf9268df0e2
parent 51412 8f7e3f9ddbc0
child 54952 a978d86ac389
permissions -rw-r--r--
8215281: Use String.isEmpty() when applicable in java.base Reviewed-by: dfuchs, alanb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
51412
8f7e3f9ddbc0 8176425: Add radix indication in NumberFormatException message for Integer.decode
darcy
parents: 47854
diff changeset
     2
 * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3959
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3959
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3959
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3959
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3959
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package java.lang;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    28
import java.lang.annotation.Annotation;
16051
649a03329639 8009267: Restore isAnnotationPresent methods in public AnnotatedElement implementations
darcy
parents: 15659
diff changeset
    29
import java.lang.reflect.AnnotatedElement;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    30
import java.net.MalformedURLException;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    31
import java.net.URI;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.net.URL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.security.AccessController;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.security.PrivilegedAction;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    35
import java.util.Objects;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    37
import jdk.internal.loader.BootLoader;
37363
329dba26ffd2 8137058: Clear out all non-Critical APIs from sun.reflect
chegar
parents: 36511
diff changeset
    38
import jdk.internal.reflect.CallerSensitive;
329dba26ffd2 8137058: Clear out all non-Critical APIs from sun.reflect
chegar
parents: 36511
diff changeset
    39
import jdk.internal.reflect.Reflection;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
/**
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    43
 * Represents metadata about a run-time package associated with a class loader.
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    44
 * Metadata includes annotations, versioning, and sealing.
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    45
 * <p>
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    46
 * Annotations for the run-time package are read from {@code package-info.class}
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    47
 * at the same code source as classes in the run-time package.
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    48
 * <p>
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    49
 * The set of classes that make up the run-time package may implement a
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    50
 * particular specification. The specification title, version, and vendor
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    51
 * (indicating the owner/maintainer of the specification) can be provided
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    52
 * when the {@code Package} is defined. An application can ask if the
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    53
 * {@code Package} is compatible with a particular specification version
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    54
 * by using the {@link #isCompatibleWith Package.isCompatibleWith(String)}
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    55
 * method. In addition, information about the actual classes that make up the
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    56
 * run-time package can be provided when the Package is defined.
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    57
 * This information consists of an implementation title, version, and vendor
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    58
 * (indicating the supplier of the classes).
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    59
 * <p>
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    60
 * A {@code Package} may be explicitly defined with
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    61
 * the {@link ClassLoader#definePackage(String, String, String, String,
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    62
 * String, String, String, URL)} method.
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    63
 * The caller supplies the specification and implementation titles, versions, and
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    64
 * vendors. The caller also indicates whether the package is
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    65
 * {@linkplain java.util.jar.Attributes.Name#SEALED sealed}.
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    66
 * If a {@code Package} is not explicitly defined for a run-time package when
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    67
 * a class in that run-time package is defined, then a {@code Package} is
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    68
 * automatically defined by the class's defining class loader, as follows.
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    69
 * <p>
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    70
 * A {@code Package} automatically defined for classes in a named module has
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    71
 * the following properties:
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    72
 * <ul>
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    73
 * <li>The name of the package is derived from the {@linkplain Class#getName() binary names}
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    74
 *     of the classes. Since classes in a named module must be in a named package,
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    75
 *     the derived name is never empty.</li>
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    76
 * <li>The package is sealed with the {@linkplain java.lang.module.ModuleReference#location()
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    77
 *     module location} as the code source, if known.</li>
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    78
 * <li>The specification and implementation titles, versions, and vendors
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    79
 *     are unspecified.</li>
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    80
 * <li>Any annotations on the package are read from {@code package-info.class}
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    81
 *     as specified above.</li>
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    82
 * </ul>
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    83
 * <p>
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    84
 * A {@code Package} automatically defined for classes in an unnamed module
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    85
 * has the following properties:
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    86
 * <ul>
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    87
 * <li>The name of the package is either {@code ""} (for classes in an unnamed package)
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    88
 *     or derived from the {@linkplain Class#getName() binary names} of the classes
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    89
 *     (for classes in a named package).</li>
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    90
 * <li>The package is not sealed.</li>
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    91
 * <li>The specification and implementation titles, versions, and vendors
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    92
 *     are unspecified.</li>
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    93
 * <li>Any annotations on the package are read from {@code package-info.class}
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    94
 *     as specified above.</li>
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    95
 * </ul>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 *
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    97
 * <p>
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    98
 * A {@code Package} can be obtained with the {@link Package#getPackage
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
    99
 * Package.getPackage(String)} and {@link ClassLoader#getDefinedPackage
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   100
 * ClassLoader.getDefinedPackage(String)} methods.
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   101
 * Every {@code Package} defined by a class loader can be obtained
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   102
 * with the {@link Package#getPackages Package.getPackages()} and
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   103
 * {@link ClassLoader#getDefinedPackages} methods.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
 *
45527
09cded555a99 8181696: Package versioning link does not exist in JAR file specification
mchung
parents: 44545
diff changeset
   105
 * @implNote
09cded555a99 8181696: Package versioning link does not exist in JAR file specification
mchung
parents: 44545
diff changeset
   106
 * The <a href="ClassLoader.html#builtinLoaders">builtin class loaders</a>
09cded555a99 8181696: Package versioning link does not exist in JAR file specification
mchung
parents: 44545
diff changeset
   107
 * do not explicitly define {@code Package} objects for packages in
09cded555a99 8181696: Package versioning link does not exist in JAR file specification
mchung
parents: 44545
diff changeset
   108
 * <em>named modules</em>.  Instead those packages are automatically defined
09cded555a99 8181696: Package versioning link does not exist in JAR file specification
mchung
parents: 44545
diff changeset
   109
 * and have no specification and implementation versioning information.
09cded555a99 8181696: Package versioning link does not exist in JAR file specification
mchung
parents: 44545
diff changeset
   110
 *
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   111
 * @jvms 5.3 Run-time package
47444
b6da56767057 8183901: Fix broken links to "Package Sealing" in the JAR spec
bchristi
parents: 47216
diff changeset
   112
 * @see <a href="{@docRoot}/../specs/jar/jar.html#package-sealing">
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   113
 * The JAR File Specification: Package Sealing</a>
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   114
 * @see ClassLoader#definePackage(String, String, String, String, String, String, String, URL)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
 *
25176
3c2ba9344cbf 8047721: @since should have JDK version
henryjen
parents: 22581
diff changeset
   116
 * @since 1.2
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42338
diff changeset
   117
 * @revised 9
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42338
diff changeset
   118
 * @spec JPMS
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
 */
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   120
public class Package extends NamedPackage implements java.lang.reflect.AnnotatedElement {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * Return the name of this package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     *
9266
121fb370f179 7032960: API files in java.awt need to be updated for references to JVM Spec with editions/hyperlinks
jjh
parents: 8543
diff changeset
   124
     * @return  The fully-qualified name of this package as defined in section 6.5.3 of
121fb370f179 7032960: API files in java.awt need to be updated for references to JVM Spec with editions/hyperlinks
jjh
parents: 8543
diff changeset
   125
     *          <cite>The Java&trade; Language Specification</cite>,
121fb370f179 7032960: API files in java.awt need to be updated for references to JVM Spec with editions/hyperlinks
jjh
parents: 8543
diff changeset
   126
     *          for example, {@code java.lang}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    public String getName() {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   129
        return packageName();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * Return the title of the specification that this package implements.
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   134
     * @return the specification title, {@code null} is returned if it is not known.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    public String getSpecificationTitle() {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   137
        return versionInfo.specTitle;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * Returns the version number of the specification
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * that this package implements.
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   143
     * This version string must be a sequence of non-negative decimal
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * integers separated by "."'s and may have leading zeros.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * When version strings are compared the most significant
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * numbers are compared.
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   147
     *
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   148
     *
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   149
     * <p>Specification version numbers use a syntax that consists of non-negative
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   150
     * decimal integers separated by periods ".", for example "2.0" or
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   151
     * "1.2.3.4.5.6.7".  This allows an extensible number to be used to represent
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   152
     * major, minor, micro, etc. versions.  The version specification is described
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   153
     * by the following formal grammar:
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   154
     * <blockquote>
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   155
     * <dl>
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   156
     * <dt><i>SpecificationVersion:</i>
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   157
     * <dd><i>Digits RefinedVersion<sub>opt</sub></i>
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   158
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   159
     * <dt><i>RefinedVersion:</i>
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   160
     * <dd>{@code .} <i>Digits</i>
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   161
     * <dd>{@code .} <i>Digits RefinedVersion</i>
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   162
     *
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   163
     * <dt><i>Digits:</i>
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   164
     * <dd><i>Digit</i>
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   165
     * <dd><i>Digits</i>
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   166
     *
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   167
     * <dt><i>Digit:</i>
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   168
     * <dd>any character for which {@link Character#isDigit} returns {@code true},
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   169
     * e.g. 0, 1, 2, ...
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   170
     * </dl>
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   171
     * </blockquote>
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   172
     *
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   173
     * @return the specification version, {@code null} is returned if it is not known.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    public String getSpecificationVersion() {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   176
        return versionInfo.specVersion;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * Return the name of the organization, vendor,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * or company that owns and maintains the specification
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * of the classes that implement this package.
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   183
     * @return the specification vendor, {@code null} is returned if it is not known.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    public String getSpecificationVendor() {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   186
        return versionInfo.specVendor;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * Return the title of this package.
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   191
     * @return the title of the implementation, {@code null} is returned if it is not known.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    public String getImplementationTitle() {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   194
        return versionInfo.implTitle;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * Return the version of this implementation. It consists of any string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * assigned by the vendor of this implementation and does
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * not have any particular syntax specified or expected by the Java
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * runtime. It may be compared for equality with other
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * package version strings used for this implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * by this vendor for this package.
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   204
     * @return the version of the implementation, {@code null} is returned if it is not known.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    public String getImplementationVersion() {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   207
        return versionInfo.implVersion;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    /**
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   211
     * Returns the vendor that implemented this package, {@code null}
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   212
     * is returned if it is not known.
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   213
     * @return the vendor that implemented this package, {@code null}
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   214
     * is returned if it is not known.
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42338
diff changeset
   215
     *
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42338
diff changeset
   216
     * @revised 9
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42338
diff changeset
   217
     * @spec JPMS
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    public String getImplementationVendor() {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   220
        return versionInfo.implVendor;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * Returns true if this package is sealed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * @return true if the package is sealed, false otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    public boolean isSealed() {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   229
        return module().isNamed() || versionInfo.sealBase != null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * Returns true if this package is sealed with respect to the specified
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   234
     * code source {@code url}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     *
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   236
     * @param url the code source URL
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   237
     * @return true if this package is sealed with respect to the given {@code url}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    public boolean isSealed(URL url) {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   240
        Objects.requireNonNull(url);
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   241
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   242
        URL sealBase = null;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   243
        if (versionInfo != VersionInfo.NULL_VERSION_INFO) {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   244
            sealBase = versionInfo.sealBase;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   245
        } else {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   246
            try {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   247
                URI uri = location();
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   248
                sealBase = uri != null ? uri.toURL() : null;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   249
            } catch (MalformedURLException e) {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   250
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   251
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        return url.equals(sealBase);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * Compare this package's specification version with a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * desired version. It returns true if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * this packages specification version number is greater than or equal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * to the desired version number. <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * Version numbers are compared by sequentially comparing corresponding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * components of the desired and specification strings.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * Each component is converted as a decimal integer and the values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * compared.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * If the specification value is greater than the desired
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * value true is returned. If the value is less false is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * If the values are equal the period is skipped and the next pair of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * components is compared.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * @param desired the version string of the desired version.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * @return true if this package's version number is greater
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     *          than or equal to the desired version number
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     *
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   274
     * @exception NumberFormatException if the current version is not known or
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   275
     *          the desired or current version is not of the correct dotted form.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    public boolean isCompatibleWith(String desired)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        throws NumberFormatException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   280
        if (versionInfo.specVersion == null || versionInfo.specVersion.length() < 1) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
            throw new NumberFormatException("Empty version string");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   284
        String [] sa = versionInfo.specVersion.split("\\.", -1);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        int [] si = new int[sa.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        for (int i = 0; i < sa.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
            si[i] = Integer.parseInt(sa[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
            if (si[i] < 0)
51412
8f7e3f9ddbc0 8176425: Add radix indication in NumberFormatException message for Integer.decode
darcy
parents: 47854
diff changeset
   289
                throw NumberFormatException.forInputString("" + si[i], 10);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        String [] da = desired.split("\\.", -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        int [] di = new int[da.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        for (int i = 0; i < da.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
            di[i] = Integer.parseInt(da[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
            if (di[i] < 0)
51412
8f7e3f9ddbc0 8176425: Add radix indication in NumberFormatException message for Integer.decode
darcy
parents: 47854
diff changeset
   297
                throw NumberFormatException.forInputString("" + di[i], 10);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        int len = Math.max(di.length, si.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        for (int i = 0; i < len; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
            int d = (i < di.length ? di[i] : 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
            int s = (i < si.length ? si[i] : 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
            if (s < d)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
            if (s > d)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    /**
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   313
     * Finds a package by name in the caller's class loader and its
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   314
     * ancestors.
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   315
     * <p>
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   316
     * If the caller's class loader defines a {@code Package} of the given name,
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   317
     * the {@code Package} is returned. Otherwise, the ancestors of the
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   318
     * caller's class loader are searched recursively (parent by parent)
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   319
     * for a {@code Package} of the given name.
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   320
     * <p>
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   321
     * Calling this method is equivalent to calling {@link ClassLoader#getPackage}
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   322
     * on a {@code ClassLoader} instance which is the caller's class loader.
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   323
     *
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   324
     * @param name A package name, such as "{@code java.lang}".
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   325
     * @return The {@code Package} of the given name defined by the caller's
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   326
     *         class loader or its ancestors, or {@code null} if not found.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     *
40804
aa5e0497d497 8165346: j.l.ClassLoader.getDefinedPackage(String) throws NPE
mchung
parents: 37521
diff changeset
   328
     * @throws NullPointerException
aa5e0497d497 8165346: j.l.ClassLoader.getDefinedPackage(String) throws NPE
mchung
parents: 37521
diff changeset
   329
     *         if {@code name} is {@code null}.
aa5e0497d497 8165346: j.l.ClassLoader.getDefinedPackage(String) throws NPE
mchung
parents: 37521
diff changeset
   330
     *
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   331
     * @deprecated
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   332
     * If multiple class loaders delegate to each other and define classes
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   333
     * with the same package name, and one such loader relies on the lookup
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   334
     * behavior of {@code getPackage} to return a {@code Package} from
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   335
     * a parent loader, then the properties exposed by the {@code Package}
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   336
     * may not be as expected in the rest of the program.
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   337
     * For example, the {@code Package} will only expose annotations from the
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   338
     * {@code package-info.class} file defined by the parent loader, even if
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   339
     * annotations exist in a {@code package-info.class} file defined by
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   340
     * a child loader.  A more robust approach is to use the
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   341
     * {@link ClassLoader#getDefinedPackage} method which returns
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   342
     * a {@code Package} for the specified class loader.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     *
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   344
     * @see ClassLoader#getDefinedPackage
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42338
diff changeset
   345
     *
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42338
diff changeset
   346
     * @revised 9
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42338
diff changeset
   347
     * @spec JPMS
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     */
16906
44dfee24cb71 8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents: 16051
diff changeset
   349
    @CallerSensitive
37521
b6e0f285c998 8145468: update java.lang APIs with new deprecations
smarks
parents: 37363
diff changeset
   350
    @Deprecated(since="9")
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   351
    @SuppressWarnings("deprecation")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
    public static Package getPackage(String name) {
16906
44dfee24cb71 8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents: 16051
diff changeset
   353
        ClassLoader l = ClassLoader.getClassLoader(Reflection.getCallerClass());
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   354
        return l != null ? l.getPackage(name) : BootLoader.getDefinedPackage(name);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
    /**
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   358
     * Returns all of the {@code Package}s defined by the caller's class loader
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   359
     * and its ancestors.  The returned array may contain more than one
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   360
     * {@code Package} object of the same package name, each defined by
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   361
     * a different class loader in the class loader hierarchy.
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   362
     * <p>
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   363
     * Calling this method is equivalent to calling {@link ClassLoader#getPackages}
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   364
     * on a {@code ClassLoader} instance which is the caller's class loader.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     *
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   366
     * @return  The array of {@code Package} objects defined by this
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   367
     *          class loader and its ancestors
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   368
     *
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   369
     * @see ClassLoader#getDefinedPackages
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42338
diff changeset
   370
     *
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42338
diff changeset
   371
     * @revised 9
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42338
diff changeset
   372
     * @spec JPMS
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     */
16906
44dfee24cb71 8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents: 16051
diff changeset
   374
    @CallerSensitive
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    public static Package[] getPackages() {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   376
        ClassLoader cl = ClassLoader.getClassLoader(Reflection.getCallerClass());
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   377
        return cl != null ? cl.getPackages() : BootLoader.packages().toArray(Package[]::new);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
     * Return the hash code computed from the package name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
     * @return the hash code computed from the package name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
     */
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   384
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
    public int hashCode(){
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   386
        return packageName().hashCode();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     * Returns the string representation of this Package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     * Its value is the string "package " and the package name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     * If the package title is defined it is appended.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     * If the package version is defined it is appended.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     * @return the string representation of the package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     */
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   396
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
    public String toString() {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   398
        String spec = versionInfo.specTitle;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   399
        String ver =  versionInfo.specVersion;
53018
8bf9268df0e2 8215281: Use String.isEmpty() when applicable in java.base
redestad
parents: 51412
diff changeset
   400
        if (spec != null && !spec.isEmpty())
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
            spec = ", " + spec;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
            spec = "";
53018
8bf9268df0e2 8215281: Use String.isEmpty() when applicable in java.base
redestad
parents: 51412
diff changeset
   404
        if (ver != null && !ver.isEmpty())
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
            ver = ", version " + ver;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
            ver = "";
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   408
        return "package " + packageName() + spec + ver;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
    private Class<?> getPackageInfo() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        if (packageInfo == null) {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   413
            // find package-info.class defined by loader
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   414
            String cn = packageName() + ".package-info";
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40804
diff changeset
   415
            Module module = module();
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40804
diff changeset
   416
            PrivilegedAction<ClassLoader> pa = module::getClassLoader;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   417
            ClassLoader loader = AccessController.doPrivileged(pa);
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40804
diff changeset
   418
            Class<?> c;
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40804
diff changeset
   419
            if (loader != null) {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40804
diff changeset
   420
                c = loader.loadClass(module, cn);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40804
diff changeset
   421
            } else {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40804
diff changeset
   422
                c = BootLoader.loadClass(module, cn);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40804
diff changeset
   423
            }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40804
diff changeset
   424
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   425
            if (c != null) {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   426
                packageInfo = c;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   427
            } else {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
                // store a proxy for the package info that has no annotations
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
                class PackageInfoProxy {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
                packageInfo = PackageInfoProxy.class;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        return packageInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     * @throws NullPointerException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
    public <A extends Annotation> A getAnnotation(Class<A> annotationClass) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        return getPackageInfo().getAnnotation(annotationClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
    /**
16051
649a03329639 8009267: Restore isAnnotationPresent methods in public AnnotatedElement implementations
darcy
parents: 15659
diff changeset
   445
     * {@inheritDoc}
649a03329639 8009267: Restore isAnnotationPresent methods in public AnnotatedElement implementations
darcy
parents: 15659
diff changeset
   446
     * @throws NullPointerException {@inheritDoc}
649a03329639 8009267: Restore isAnnotationPresent methods in public AnnotatedElement implementations
darcy
parents: 15659
diff changeset
   447
     * @since 1.5
649a03329639 8009267: Restore isAnnotationPresent methods in public AnnotatedElement implementations
darcy
parents: 15659
diff changeset
   448
     */
649a03329639 8009267: Restore isAnnotationPresent methods in public AnnotatedElement implementations
darcy
parents: 15659
diff changeset
   449
    @Override
649a03329639 8009267: Restore isAnnotationPresent methods in public AnnotatedElement implementations
darcy
parents: 15659
diff changeset
   450
    public boolean isAnnotationPresent(Class<? extends Annotation> annotationClass) {
649a03329639 8009267: Restore isAnnotationPresent methods in public AnnotatedElement implementations
darcy
parents: 15659
diff changeset
   451
        return AnnotatedElement.super.isAnnotationPresent(annotationClass);
649a03329639 8009267: Restore isAnnotationPresent methods in public AnnotatedElement implementations
darcy
parents: 15659
diff changeset
   452
    }
649a03329639 8009267: Restore isAnnotationPresent methods in public AnnotatedElement implementations
darcy
parents: 15659
diff changeset
   453
649a03329639 8009267: Restore isAnnotationPresent methods in public AnnotatedElement implementations
darcy
parents: 15659
diff changeset
   454
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
     * @throws NullPointerException {@inheritDoc}
14676
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 14342
diff changeset
   456
     * @since 1.8
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 14342
diff changeset
   457
     */
15659
e575dab44ff5 8007278: Rename j.l.r.AnnotatedElement.getAnnotations(Class) to getAnnotationsByType(Class)
jfranck
parents: 15534
diff changeset
   458
    @Override
e575dab44ff5 8007278: Rename j.l.r.AnnotatedElement.getAnnotations(Class) to getAnnotationsByType(Class)
jfranck
parents: 15534
diff changeset
   459
    public  <A extends Annotation> A[] getAnnotationsByType(Class<A> annotationClass) {
e575dab44ff5 8007278: Rename j.l.r.AnnotatedElement.getAnnotations(Class) to getAnnotationsByType(Class)
jfranck
parents: 15534
diff changeset
   460
        return getPackageInfo().getAnnotationsByType(annotationClass);
14676
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 14342
diff changeset
   461
    }
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 14342
diff changeset
   462
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 14342
diff changeset
   463
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
    public Annotation[] getAnnotations() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
        return getPackageInfo().getAnnotations();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
    /**
14676
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 14342
diff changeset
   471
     * @throws NullPointerException {@inheritDoc}
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 14342
diff changeset
   472
     * @since 1.8
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 14342
diff changeset
   473
     */
15659
e575dab44ff5 8007278: Rename j.l.r.AnnotatedElement.getAnnotations(Class) to getAnnotationsByType(Class)
jfranck
parents: 15534
diff changeset
   474
    @Override
14676
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 14342
diff changeset
   475
    public <A extends Annotation> A getDeclaredAnnotation(Class<A> annotationClass) {
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 14342
diff changeset
   476
        return getPackageInfo().getDeclaredAnnotation(annotationClass);
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 14342
diff changeset
   477
    }
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 14342
diff changeset
   478
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 14342
diff changeset
   479
    /**
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 14342
diff changeset
   480
     * @throws NullPointerException {@inheritDoc}
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 14342
diff changeset
   481
     * @since 1.8
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 14342
diff changeset
   482
     */
15659
e575dab44ff5 8007278: Rename j.l.r.AnnotatedElement.getAnnotations(Class) to getAnnotationsByType(Class)
jfranck
parents: 15534
diff changeset
   483
    @Override
e575dab44ff5 8007278: Rename j.l.r.AnnotatedElement.getAnnotations(Class) to getAnnotationsByType(Class)
jfranck
parents: 15534
diff changeset
   484
    public <A extends Annotation> A[] getDeclaredAnnotationsByType(Class<A> annotationClass) {
e575dab44ff5 8007278: Rename j.l.r.AnnotatedElement.getAnnotations(Class) to getAnnotationsByType(Class)
jfranck
parents: 15534
diff changeset
   485
        return getPackageInfo().getDeclaredAnnotationsByType(annotationClass);
14676
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 14342
diff changeset
   486
    }
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 14342
diff changeset
   487
985410ec95e3 7154390: Add support for repeating annotations in j.l.r.AnnotatedElement
jfranck
parents: 14342
diff changeset
   488
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
    public Annotation[] getDeclaredAnnotations()  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
        return getPackageInfo().getDeclaredAnnotations();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
    /**
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   496
     * Construct a package instance for an unnamed module
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   497
     * with the specified version information.
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   498
     *
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   499
     * @apiNote
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   500
     * This method should not be called to define a Package for named module.
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   501
     *
14014
da3648e13e67 8000269: Cleanup javadoc warnings
alanb
parents: 11117
diff changeset
   502
     * @param name the name of the package
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
     * @param spectitle the title of the specification
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
     * @param specversion the version of the specification
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
     * @param specvendor the organization that maintains the specification
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
     * @param impltitle the title of the implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
     * @param implversion the version of the implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
     * @param implvendor the organization that maintains the implementation
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   509
     * @param sealbase code source where this Package comes from
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   510
     * @param loader defining class loader
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
    Package(String name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
            String spectitle, String specversion, String specvendor,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
            String impltitle, String implversion, String implvendor,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
            URL sealbase, ClassLoader loader)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
    {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   517
        super(Objects.requireNonNull(name),
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   518
              loader != null ? loader.getUnnamedModule()
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   519
                             : BootLoader.getUnnamedModule());
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   520
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   521
        this.versionInfo = VersionInfo.getInstance(spectitle, specversion,
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   522
                                                   specvendor, impltitle,
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   523
                                                   implversion, implvendor,
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   524
                                                   sealbase);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   527
    Package(String name, Module module) {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   528
        super(name, module);
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   529
        this.versionInfo = VersionInfo.NULL_VERSION_INFO;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
    /*
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   533
     * Versioning information.  Only for packages in unnamed modules.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
     */
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   535
    static class VersionInfo {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   536
        static final VersionInfo NULL_VERSION_INFO
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   537
            = new VersionInfo(null, null, null, null, null, null, null);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   539
        private final String specTitle;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   540
        private final String specVersion;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   541
        private final String specVendor;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   542
        private final String implTitle;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   543
        private final String implVersion;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   544
        private final String implVendor;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   545
        private final URL sealBase;
27348
1614e0fd2b9b 8060130: Simplify the synchronization of defining and getting java.lang.Package
redestad
parents: 25859
diff changeset
   546
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   547
        static VersionInfo getInstance(String spectitle, String specversion,
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   548
                                       String specvendor, String impltitle,
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   549
                                       String implversion, String implvendor,
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   550
                                       URL sealbase) {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   551
            if (spectitle == null && specversion == null &&
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   552
                    specvendor == null && impltitle == null &&
47854
09ad9dd26857 8190987: Package.getImplementationVersion returns null even if implementation version is non-null
mchung
parents: 47444
diff changeset
   553
                    implversion == null && implvendor == null &&
09ad9dd26857 8190987: Package.getImplementationVersion returns null even if implementation version is non-null
mchung
parents: 47444
diff changeset
   554
                    sealbase == null) {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   555
                return NULL_VERSION_INFO;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   556
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   557
            return new VersionInfo(spectitle, specversion, specvendor,
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   558
                    impltitle, implversion, implvendor,
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   559
                    sealbase);
27348
1614e0fd2b9b 8060130: Simplify the synchronization of defining and getting java.lang.Package
redestad
parents: 25859
diff changeset
   560
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   562
        private VersionInfo(String spectitle, String specversion,
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   563
                            String specvendor, String impltitle,
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   564
                            String implversion, String implvendor,
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   565
                            URL sealbase)
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   566
        {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   567
            this.implTitle = impltitle;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   568
            this.implVersion = implversion;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   569
            this.implVendor = implvendor;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   570
            this.specTitle = spectitle;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   571
            this.specVersion = specversion;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   572
            this.specVendor = specvendor;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   573
            this.sealBase = sealbase;
27348
1614e0fd2b9b 8060130: Simplify the synchronization of defining and getting java.lang.Package
redestad
parents: 25859
diff changeset
   574
        }
1614e0fd2b9b 8060130: Simplify the synchronization of defining and getting java.lang.Package
redestad
parents: 25859
diff changeset
   575
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   577
    private final VersionInfo versionInfo;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32649
diff changeset
   578
    private Class<?> packageInfo;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
}