8307326: Package jdk.internal.classfile.java.lang.constant become obsolete

Reviewed-by: erikj, liach
This commit is contained in:
Adam Sotona 2023-05-17 12:45:19 +00:00
parent c7951cf674
commit 5763be7267
46 changed files with 57 additions and 503 deletions

View file

@ -52,7 +52,7 @@ import jdk.internal.classfile.attribute.CharacterRangeInfo;
import jdk.internal.classfile.attribute.LocalVariableInfo;
import jdk.internal.classfile.attribute.LocalVariableTypeInfo;
import jdk.internal.classfile.instruction.ExceptionCatch;
import jdk.internal.classfile.java.lang.constant.PackageDesc;
import java.lang.constant.PackageDesc;
/**
* Main entry points for parsing, transforming, and generating classfiles.

View file

@ -39,8 +39,8 @@ import java.util.Optional;
import java.util.Set;
import java.util.function.Consumer;
import java.lang.reflect.AccessFlag;
import jdk.internal.classfile.java.lang.constant.ModuleDesc;
import jdk.internal.classfile.java.lang.constant.PackageDesc;
import java.lang.constant.ModuleDesc;
import java.lang.constant.PackageDesc;
import jdk.internal.classfile.impl.ModuleAttributeBuilderImpl;
import jdk.internal.classfile.impl.Util;

View file

@ -30,8 +30,8 @@ import java.util.Set;
import jdk.internal.classfile.constantpool.ModuleEntry;
import jdk.internal.classfile.constantpool.PackageEntry;
import jdk.internal.classfile.java.lang.constant.ModuleDesc;
import jdk.internal.classfile.java.lang.constant.PackageDesc;
import java.lang.constant.ModuleDesc;
import java.lang.constant.PackageDesc;
import java.lang.reflect.AccessFlag;
import jdk.internal.classfile.Classfile;
@ -133,7 +133,7 @@ public sealed interface ModuleExportInfo
*/
static ModuleExportInfo of(PackageDesc exports, int exportFlags,
List<ModuleDesc> exportsTo) {
return of(TemporaryConstantPool.INSTANCE.packageEntry(TemporaryConstantPool.INSTANCE.utf8Entry(exports.packageInternalName())),
return of(TemporaryConstantPool.INSTANCE.packageEntry(TemporaryConstantPool.INSTANCE.utf8Entry(exports.internalName())),
exportFlags,
Util.moduleEntryList(exportsTo));
}

View file

@ -25,7 +25,7 @@
package jdk.internal.classfile.attribute;
import jdk.internal.classfile.constantpool.ModuleEntry;
import jdk.internal.classfile.java.lang.constant.ModuleDesc;
import java.lang.constant.ModuleDesc;
import jdk.internal.classfile.impl.TemporaryConstantPool;
import jdk.internal.classfile.impl.UnboundAttribute;
@ -60,6 +60,6 @@ public sealed interface ModuleHashInfo
* @param hash the hash value
*/
static ModuleHashInfo of(ModuleDesc moduleDesc, byte[] hash) {
return new UnboundAttribute.UnboundModuleHashInfo(TemporaryConstantPool.INSTANCE.moduleEntry(TemporaryConstantPool.INSTANCE.utf8Entry(moduleDesc.moduleName())), hash);
return new UnboundAttribute.UnboundModuleHashInfo(TemporaryConstantPool.INSTANCE.moduleEntry(TemporaryConstantPool.INSTANCE.utf8Entry(moduleDesc.name())), hash);
}
}

View file

@ -30,8 +30,8 @@ import java.util.Set;
import jdk.internal.classfile.constantpool.ModuleEntry;
import jdk.internal.classfile.constantpool.PackageEntry;
import jdk.internal.classfile.java.lang.constant.ModuleDesc;
import jdk.internal.classfile.java.lang.constant.PackageDesc;
import java.lang.constant.ModuleDesc;
import java.lang.constant.PackageDesc;
import java.lang.reflect.AccessFlag;
import jdk.internal.classfile.impl.TemporaryConstantPool;
@ -130,7 +130,7 @@ public sealed interface ModuleOpenInfo
*/
static ModuleOpenInfo of(PackageDesc opens, int opensFlags,
List<ModuleDesc> opensTo) {
return of(TemporaryConstantPool.INSTANCE.packageEntry(TemporaryConstantPool.INSTANCE.utf8Entry(opens.packageInternalName())),
return of(TemporaryConstantPool.INSTANCE.packageEntry(TemporaryConstantPool.INSTANCE.utf8Entry(opens.internalName())),
opensFlags,
Util.moduleEntryList(opensTo));
}

View file

@ -32,7 +32,7 @@ import java.util.Arrays;
import java.util.List;
import jdk.internal.classfile.constantpool.PackageEntry;
import jdk.internal.classfile.java.lang.constant.PackageDesc;
import java.lang.constant.PackageDesc;
import jdk.internal.classfile.impl.TemporaryConstantPool;
import jdk.internal.classfile.impl.UnboundAttribute;
@ -75,7 +75,7 @@ public sealed interface ModulePackagesAttribute
static ModulePackagesAttribute ofNames(List<PackageDesc> packages) {
var p = new PackageEntry[packages.size()];
for (int i = 0; i < packages.size(); i++) {
p[i] = TemporaryConstantPool.INSTANCE.packageEntry(TemporaryConstantPool.INSTANCE.utf8Entry(packages.get(i).packageInternalName()));
p[i] = TemporaryConstantPool.INSTANCE.packageEntry(TemporaryConstantPool.INSTANCE.utf8Entry(packages.get(i).internalName()));
}
return of(p);
}

View file

@ -31,7 +31,7 @@ import java.util.Set;
import jdk.internal.classfile.constantpool.ModuleEntry;
import jdk.internal.classfile.constantpool.Utf8Entry;
import java.lang.reflect.AccessFlag;
import jdk.internal.classfile.java.lang.constant.ModuleDesc;
import java.lang.constant.ModuleDesc;
import jdk.internal.classfile.impl.TemporaryConstantPool;
import jdk.internal.classfile.impl.UnboundAttribute;
import jdk.internal.classfile.impl.Util;
@ -100,7 +100,7 @@ public sealed interface ModuleRequireInfo
* @param requiresVersion the required version
*/
static ModuleRequireInfo of(ModuleDesc requires, int requiresFlags, String requiresVersion) {
return new UnboundAttribute.UnboundModuleRequiresInfo(TemporaryConstantPool.INSTANCE.moduleEntry(TemporaryConstantPool.INSTANCE.utf8Entry(requires.moduleName())), requiresFlags, Optional.ofNullable(requiresVersion).map(s -> TemporaryConstantPool.INSTANCE.utf8Entry(s)));
return new UnboundAttribute.UnboundModuleRequiresInfo(TemporaryConstantPool.INSTANCE.moduleEntry(TemporaryConstantPool.INSTANCE.utf8Entry(requires.name())), requiresFlags, Optional.ofNullable(requiresVersion).map(s -> TemporaryConstantPool.INSTANCE.utf8Entry(s)));
}
/**

View file

@ -40,8 +40,8 @@ import jdk.internal.classfile.ClassModel;
import jdk.internal.classfile.Classfile;
import jdk.internal.classfile.impl.ClassReaderImpl;
import jdk.internal.classfile.impl.Options;
import jdk.internal.classfile.java.lang.constant.ModuleDesc;
import jdk.internal.classfile.java.lang.constant.PackageDesc;
import java.lang.constant.ModuleDesc;
import java.lang.constant.PackageDesc;
import jdk.internal.classfile.WritableElement;
import jdk.internal.classfile.impl.SplitConstantPool;
import jdk.internal.classfile.impl.TemporaryConstantPool;
@ -185,7 +185,7 @@ public sealed interface ConstantPoolBuilder
* @param packageDesc the symbolic descriptor for the class
*/
default PackageEntry packageEntry(PackageDesc packageDesc) {
return packageEntry(utf8Entry(packageDesc.packageInternalName()));
return packageEntry(utf8Entry(packageDesc.internalName()));
}
/**
@ -209,7 +209,7 @@ public sealed interface ConstantPoolBuilder
* @param moduleDesc the symbolic descriptor for the class
*/
default ModuleEntry moduleEntry(ModuleDesc moduleDesc) {
return moduleEntry(utf8Entry(moduleDesc.moduleName()));
return moduleEntry(utf8Entry(moduleDesc.name()));
}
/**

View file

@ -25,7 +25,7 @@
package jdk.internal.classfile.constantpool;
import jdk.internal.classfile.impl.AbstractPoolEntry;
import jdk.internal.classfile.java.lang.constant.ModuleDesc;
import java.lang.constant.ModuleDesc;
/**
* Models a {@code CONSTANT_Module_info} constant in the constant pool of a

View file

@ -25,7 +25,7 @@
package jdk.internal.classfile.constantpool;
import jdk.internal.classfile.impl.AbstractPoolEntry;
import jdk.internal.classfile.java.lang.constant.PackageDesc;
import java.lang.constant.PackageDesc;
/**
* Models a {@code CONSTANT_Package_info} constant in the constant pool of a

View file

@ -51,8 +51,8 @@ import jdk.internal.classfile.constantpool.PackageEntry;
import jdk.internal.classfile.constantpool.PoolEntry;
import jdk.internal.classfile.constantpool.StringEntry;
import jdk.internal.classfile.constantpool.Utf8Entry;
import jdk.internal.classfile.java.lang.constant.ModuleDesc;
import jdk.internal.classfile.java.lang.constant.PackageDesc;
import java.lang.constant.ModuleDesc;
import java.lang.constant.PackageDesc;
public abstract sealed class AbstractPoolEntry {
/*

View file

@ -948,14 +948,14 @@ public final class ClassPrinterImpl {
.map(Utf8Entry::stringValue).orElse(null))))),
new ListNodeImpl(BLOCK, "exports", ma.exports().stream().map(exp ->
new MapNodeImpl(FLOW, "exp").with(
leaf("package", exp.exportedPackage().asSymbol().packageName()),
leaf("package", exp.exportedPackage().asSymbol().name()),
list("flags", "flag", exp.exportsFlags().stream()
.map(AccessFlag::name)),
list("to", "module", exp.exportsTo().stream()
.map(me -> me.name().stringValue()))))),
new ListNodeImpl(BLOCK, "opens", ma.opens().stream().map(opn ->
new MapNodeImpl(FLOW, "opn").with(
leaf("package", opn.openedPackage().asSymbol().packageName()),
leaf("package", opn.openedPackage().asSymbol().name()),
list("flags", "flag", opn.opensFlags().stream()
.map(AccessFlag::name)),
list("to", "module", opn.opensTo().stream()
@ -967,7 +967,7 @@ public final class ClassPrinterImpl {
.map(ce -> ce.name().stringValue())))))));
case ModulePackagesAttribute mopa ->
nodes.add(list("module packages", "subclass", mopa.packages().stream()
.map(mp -> mp.asSymbol().packageName())));
.map(mp -> mp.asSymbol().name())));
case ModuleMainClassAttribute mmca ->
nodes.add(leaf("module main class", mmca.mainClass().name().stringValue()));
case RecordAttribute ra ->

View file

@ -30,8 +30,8 @@ import jdk.internal.classfile.attribute.ModuleAttribute.ModuleAttributeBuilder;
import jdk.internal.classfile.constantpool.ClassEntry;
import jdk.internal.classfile.constantpool.ModuleEntry;
import jdk.internal.classfile.constantpool.Utf8Entry;
import jdk.internal.classfile.java.lang.constant.ModuleDesc;
import jdk.internal.classfile.java.lang.constant.PackageDesc;
import java.lang.constant.ModuleDesc;
import java.lang.constant.PackageDesc;
import java.lang.constant.ClassDesc;
import java.util.*;
@ -55,7 +55,7 @@ public final class ModuleAttributeBuilderImpl
}
public ModuleAttributeBuilderImpl(ModuleDesc moduleName) {
this(TemporaryConstantPool.INSTANCE.moduleEntry(TemporaryConstantPool.INSTANCE.utf8Entry(moduleName.moduleName())));
this(TemporaryConstantPool.INSTANCE.moduleEntry(TemporaryConstantPool.INSTANCE.utf8Entry(moduleName.name())));
}
@Override
@ -67,7 +67,7 @@ public final class ModuleAttributeBuilderImpl
@Override
public ModuleAttributeBuilder moduleName(ModuleDesc moduleName) {
Objects.requireNonNull(moduleName);
moduleEntry = TemporaryConstantPool.INSTANCE.moduleEntry(TemporaryConstantPool.INSTANCE.utf8Entry(moduleName.moduleName()));
moduleEntry = TemporaryConstantPool.INSTANCE.moduleEntry(TemporaryConstantPool.INSTANCE.utf8Entry(moduleName.name()));
return this;
}
@ -86,7 +86,7 @@ public final class ModuleAttributeBuilderImpl
@Override
public ModuleAttributeBuilder requires(ModuleDesc module, int flags, String version) {
Objects.requireNonNull(module);
return requires(ModuleRequireInfo.of(TemporaryConstantPool.INSTANCE.moduleEntry(TemporaryConstantPool.INSTANCE.utf8Entry(module.moduleName())), flags, version == null ? null : TemporaryConstantPool.INSTANCE.utf8Entry(version)));
return requires(ModuleRequireInfo.of(TemporaryConstantPool.INSTANCE.moduleEntry(TemporaryConstantPool.INSTANCE.utf8Entry(module.name())), flags, version == null ? null : TemporaryConstantPool.INSTANCE.utf8Entry(version)));
}
@Override
@ -101,8 +101,8 @@ public final class ModuleAttributeBuilderImpl
Objects.requireNonNull(pkge);
var exportsTo = new ArrayList<ModuleEntry>(exportsToModules.length);
for (var e : exportsToModules)
exportsTo.add(TemporaryConstantPool.INSTANCE.moduleEntry(TemporaryConstantPool.INSTANCE.utf8Entry(e.moduleName())));
return exports(ModuleExportInfo.of(TemporaryConstantPool.INSTANCE.packageEntry(TemporaryConstantPool.INSTANCE.utf8Entry(pkge.packageInternalName())), flags, exportsTo));
exportsTo.add(TemporaryConstantPool.INSTANCE.moduleEntry(TemporaryConstantPool.INSTANCE.utf8Entry(e.name())));
return exports(ModuleExportInfo.of(TemporaryConstantPool.INSTANCE.packageEntry(TemporaryConstantPool.INSTANCE.utf8Entry(pkge.internalName())), flags, exportsTo));
}
@Override
@ -117,8 +117,8 @@ public final class ModuleAttributeBuilderImpl
Objects.requireNonNull(pkge);
var opensTo = new ArrayList<ModuleEntry>(opensToModules.length);
for (var e : opensToModules)
opensTo.add(TemporaryConstantPool.INSTANCE.moduleEntry(TemporaryConstantPool.INSTANCE.utf8Entry(e.moduleName())));
return opens(ModuleOpenInfo.of(TemporaryConstantPool.INSTANCE.packageEntry(TemporaryConstantPool.INSTANCE.utf8Entry(pkge.packageInternalName())), flags, opensTo));
opensTo.add(TemporaryConstantPool.INSTANCE.moduleEntry(TemporaryConstantPool.INSTANCE.utf8Entry(e.name())));
return opens(ModuleOpenInfo.of(TemporaryConstantPool.INSTANCE.packageEntry(TemporaryConstantPool.INSTANCE.utf8Entry(pkge.internalName())), flags, opensTo));
}
@Override

View file

@ -1,50 +0,0 @@
/*
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package jdk.internal.classfile.impl;
import jdk.internal.classfile.java.lang.constant.ModuleDesc;
public record ModuleDescImpl(String moduleName) implements ModuleDesc {
/**
* Validates the correctness of a module name. In particular checks for the presence of
* invalid characters in the name.
*
* {@jvms 4.2.3} Module and Package Names
*
* @param name the module name
* @return the module name passed if valid
* @throws IllegalArgumentException if the module name is invalid
*/
public static String validateModuleName(String name) {
for (int i=name.length() - 1; i >= 0; i--) {
char ch = name.charAt(i);
if ((ch >= '\u0000' && ch <= '\u001F')
|| ((ch == '\\' || ch == ':' || ch =='@') && (i == 0 || name.charAt(--i) != '\\')))
throw new IllegalArgumentException("Invalid module name: " + name);
}
return name;
}
}

View file

@ -1,72 +0,0 @@
/*
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package jdk.internal.classfile.impl;
import jdk.internal.classfile.java.lang.constant.PackageDesc;
public record PackageDescImpl(String packageInternalName) implements PackageDesc {
/**
* Validates the correctness of a binary package name. In particular checks for the presence of
* invalid characters in the name.
*
* @param name the package name
* @return the package name passed if valid
* @throws IllegalArgumentException if the package name is invalid
*/
public static String validateBinaryPackageName(String name) {
for (int i=0; i<name.length(); i++) {
char ch = name.charAt(i);
if (ch == ';' || ch == '[' || ch == '/')
throw new IllegalArgumentException("Invalid package name: " + name);
}
return name;
}
/**
* Validates the correctness of an internal package name.
* In particular checks for the presence of invalid characters in the name.
*
* @param name the package name
* @return the package name passed if valid
* @throws IllegalArgumentException if the package name is invalid
*/
public static String validateInternalPackageName(String name) {
for (int i=0; i<name.length(); i++) {
char ch = name.charAt(i);
if (ch == ';' || ch == '[' || ch == '.')
throw new IllegalArgumentException("Invalid package name: " + name);
}
return name;
}
public static String internalToBinary(String name) {
return name.replace('/', '.');
}
public static String binaryToInternal(String name) {
return name.replace('.', '/');
}
}

View file

@ -35,7 +35,7 @@ import java.util.function.Function;
import jdk.internal.classfile.Opcode;
import jdk.internal.classfile.constantpool.ClassEntry;
import jdk.internal.classfile.constantpool.ModuleEntry;
import jdk.internal.classfile.java.lang.constant.ModuleDesc;
import java.lang.constant.ModuleDesc;
import jdk.internal.classfile.impl.TemporaryConstantPool;
import java.lang.reflect.AccessFlag;
@ -195,7 +195,7 @@ public class Util {
public static List<ModuleEntry> moduleEntryList(List<? extends ModuleDesc> list) {
var result = new Object[list.size()]; // null check
for (int i = 0; i < result.length; i++) {
result[i] = TemporaryConstantPool.INSTANCE.moduleEntry(TemporaryConstantPool.INSTANCE.utf8Entry(list.get(i).moduleName()));
result[i] = TemporaryConstantPool.INSTANCE.moduleEntry(TemporaryConstantPool.INSTANCE.utf8Entry(list.get(i).name()));
}
return SharedSecrets.getJavaUtilCollectionAccess().listFromTrustedArrayNullsAllowed(result);
}

View file

@ -1,85 +0,0 @@
/*
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package jdk.internal.classfile.java.lang.constant;
import static java.util.Objects.requireNonNull;
import jdk.internal.classfile.impl.ModuleDescImpl;
import static jdk.internal.classfile.impl.ModuleDescImpl.*;
/**
* A nominal descriptor for a {@link Module} constant.
*
* <p>To create a {@linkplain ModuleDesc} for a module, use {@link #of}.
*
*/
public sealed interface ModuleDesc
permits ModuleDescImpl {
/**
* Returns a {@linkplain ModuleDesc} for a module,
* given the name of the module.
* <p>
* {@jvms 4.2.3} Module names are not encoded in "internal form" like class and interface names, that is,
* the ASCII periods (.) that separate the identifiers in a module name are not replaced by ASCII forward slashes (/).
* <p>
* Module names may be drawn from the entire Unicode codespace, subject to the following constraints:
* <ul>
* <li>A module name must not contain any code point in the range '&#92;u0000' to '&#92;u001F' inclusive.
* <li>The ASCII backslash (\) is reserved for use as an escape character in module names.
* It must not appear in a module name unless it is followed by an ASCII backslash, an ASCII colon (:), or an ASCII at-sign (@).
* The ASCII character sequence \\ may be used to encode a backslash in a module name.
* <li>The ASCII colon (:) and at-sign (@) are reserved for future use in module names.
* They must not appear in module names unless they are escaped.
* The ASCII character sequences \: and \@ may be used to encode a colon and an at-sign in a module name.
* </ul>
* @param name module name
* @return a {@linkplain ModuleDesc} describing the desired module
* @throws NullPointerException if the argument is {@code null}
* @throws IllegalArgumentException if the name string is not in the
* correct format
*/
static ModuleDesc of(String name) {
validateModuleName(requireNonNull(name));
return new ModuleDescImpl(name);
}
/**
* Returns the module name of this {@linkplain ModuleDesc}.
*
* @return the module name
*/
String moduleName();
/**
* Compare the specified object with this descriptor for equality. Returns
* {@code true} if and only if the specified object is also a
* {@linkplain ModuleDesc} and both describe the same module.
*
* @param o the other object
* @return whether this descriptor is equal to the other object
*/
@Override
boolean equals(Object o);
}

View file

@ -1,106 +0,0 @@
/*
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package jdk.internal.classfile.java.lang.constant;
import static java.util.Objects.requireNonNull;
import jdk.internal.classfile.impl.PackageDescImpl;
import static jdk.internal.classfile.impl.PackageDescImpl.*;
/**
* A nominal descriptor for a {@link Package} constant.
*
* <p>To create a {@linkplain PackageDesc} for a package, use {@link #of} or
* {@link #ofInternalName(String)}.
*
*/
public sealed interface PackageDesc
permits PackageDescImpl {
/**
* Returns a {@linkplain PackageDesc} for a package,
* given the name of the package, such as {@code "java.lang"}.
* <p>
* {@jls 13.1}
*
* @param name the fully qualified (dot-separated) binary package name
* @return a {@linkplain PackageDesc} describing the desired package
* @throws NullPointerException if the argument is {@code null}
* @throws IllegalArgumentException if the name string is not in the
* correct format
*/
static PackageDesc of(String name) {
validateBinaryPackageName(requireNonNull(name));
return new PackageDescImpl(binaryToInternal(name));
}
/**
* Returns a {@linkplain PackageDesc} for a package,
* given the name of the package in internal form,
* such as {@code "java/lang"}.
* <p>
* {@jvms 4.2.1} In this internal form, the ASCII periods (.) that normally separate the identifiers
* which make up the binary name are replaced by ASCII forward slashes (/).
* @param name the fully qualified class name, in internal (slash-separated) form
* @return a {@linkplain PackageDesc} describing the desired package
* @throws NullPointerException if the argument is {@code null}
* @throws IllegalArgumentException if the name string is not in the
* correct format
*/
static PackageDesc ofInternalName(String name) {
validateInternalPackageName(requireNonNull(name));
return new PackageDescImpl(name);
}
/**
* Returns the fully qualified (slash-separated) internal package name
* of this {@linkplain PackageDesc}.
*
* @return the package name, or the empty string for the
* default package
*/
String packageInternalName();
/**
* Returns the fully qualified (dot-separated) binary package name
* of this {@linkplain PackageDesc}.
*
* @return the package name, or the empty string for the
* default package
*/
default String packageName() {
return internalToBinary(packageInternalName());
}
/**
* Compare the specified object with this descriptor for equality. Returns
* {@code true} if and only if the specified object is also a
* {@linkplain PackageDesc} and both describe the same package.
*
* @param o the other object
* @return whether this descriptor is equal to the other object
*/
@Override
boolean equals(Object o);
}

View file

@ -42,8 +42,8 @@ import jdk.internal.classfile.attribute.ModuleMainClassAttribute;
import jdk.internal.classfile.attribute.ModulePackagesAttribute;
import jdk.internal.classfile.attribute.ModuleResolutionAttribute;
import jdk.internal.classfile.attribute.ModuleTargetAttribute;
import jdk.internal.classfile.java.lang.constant.ModuleDesc;
import jdk.internal.classfile.java.lang.constant.PackageDesc;
import java.lang.constant.ModuleDesc;
import java.lang.constant.PackageDesc;
/**