8307326: Package jdk.internal.classfile.java.lang.constant become obsolete
Reviewed-by: erikj, liach
This commit is contained in:
parent
c7951cf674
commit
5763be7267
@ -602,7 +602,6 @@ define SetupRunMicroTestBody
|
||||
--add-exports java.base/jdk.internal.classfile.attribute=ALL-UNNAMED \
|
||||
--add-exports java.base/jdk.internal.classfile.constantpool=ALL-UNNAMED \
|
||||
--add-exports java.base/jdk.internal.classfile.instruction=ALL-UNNAMED \
|
||||
--add-exports java.base/jdk.internal.classfile.java.lang.constant=ALL-UNNAMED \
|
||||
--add-exports java.base/jdk.internal.classfile.components=ALL-UNNAMED \
|
||||
--add-exports java.base/jdk.internal.classfile.impl=ALL-UNNAMED
|
||||
|
||||
|
@ -100,7 +100,6 @@ $(eval $(call SetupJavaCompilation, BUILD_JDK_MICROBENCHMARK, \
|
||||
--add-exports java.base/jdk.internal.classfile.attribute=ALL-UNNAMED \
|
||||
--add-exports java.base/jdk.internal.classfile.constantpool=ALL-UNNAMED \
|
||||
--add-exports java.base/jdk.internal.classfile.instruction=ALL-UNNAMED \
|
||||
--add-exports java.base/jdk.internal.classfile.java.lang.constant=ALL-UNNAMED \
|
||||
--add-exports java.base/jdk.internal.classfile.components=ALL-UNNAMED \
|
||||
--add-exports java.base/jdk.internal.classfile.impl=ALL-UNNAMED \
|
||||
--add-exports java.base/jdk.internal.org.objectweb.asm=ALL-UNNAMED \
|
||||
|
@ -57,7 +57,6 @@ $(eval $(call SetupJavaCompilation, BUILD_TEST_LIB_JAR, \
|
||||
--add-exports java.base/jdk.internal.classfile=ALL-UNNAMED \
|
||||
--add-exports java.base/jdk.internal.classfile.attribute=ALL-UNNAMED \
|
||||
--add-exports java.base/jdk.internal.classfile.constantpool=ALL-UNNAMED \
|
||||
--add-exports java.base/jdk.internal.classfile.java.lang.constant=ALL-UNNAMED \
|
||||
--add-exports java.base/jdk.internal.module=ALL-UNNAMED \
|
||||
--enable-preview, \
|
||||
))
|
||||
|
@ -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.
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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));
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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));
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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)));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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 {
|
||||
/*
|
||||
|
@ -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 ->
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
@ -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('.', '/');
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
|
@ -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 '\u0000' to '\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);
|
||||
}
|
@ -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);
|
||||
}
|
@ -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;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -38,7 +38,6 @@ import org.testng.annotations.Test;
|
||||
* @modules java.base/jdk.internal.classfile
|
||||
* java.base/jdk.internal.classfile.attribute
|
||||
* java.base/jdk.internal.classfile.constantpool
|
||||
* java.base/jdk.internal.classfile.java.lang.constant
|
||||
* java.base/jdk.internal.misc
|
||||
* java.base/jdk.internal.module
|
||||
* java.compiler
|
||||
|
@ -57,7 +57,6 @@ EXPORTS=--add-exports java.base/jdk.internal.jimage=ALL-UNNAMED \
|
||||
--add-exports java.base/jdk.internal.classfile=ALL-UNNAMED \
|
||||
--add-exports java.base/jdk.internal.classfile.attribute=ALL-UNNAMED \
|
||||
--add-exports java.base/jdk.internal.classfile.constantpool=ALL-UNNAMED \
|
||||
--add-exports java.base/jdk.internal.classfile.java.lang.constant=ALL-UNNAMED \
|
||||
--add-exports java.base/jdk.internal.access=ALL-UNNAMED
|
||||
|
||||
CTW_MAIN_CLASS = sun.hotspot.tools.ctw.CompileTheWorld
|
||||
|
@ -29,7 +29,6 @@
|
||||
* @modules java.base/jdk.internal.classfile
|
||||
* java.base/jdk.internal.classfile.attribute
|
||||
* java.base/jdk.internal.classfile.constantpool
|
||||
* java.base/jdk.internal.classfile.java.lang.constant
|
||||
* java.base/jdk.internal.module
|
||||
* @library /test/lib
|
||||
* @build jdk.test.lib.util.JarUtils
|
||||
|
@ -55,7 +55,6 @@ import static org.testng.Assert.*;
|
||||
* java.base/jdk.internal.classfile
|
||||
* java.base/jdk.internal.classfile.attribute
|
||||
* java.base/jdk.internal.classfile.constantpool
|
||||
* java.base/jdk.internal.classfile.java.lang.constant
|
||||
* java.base/jdk.internal.module
|
||||
* @library /test/lib
|
||||
* @build jdk.test.lib.util.ModuleInfoWriter
|
||||
|
@ -26,7 +26,6 @@
|
||||
* @modules java.base/jdk.internal.classfile
|
||||
* java.base/jdk.internal.classfile.attribute
|
||||
* java.base/jdk.internal.classfile.constantpool
|
||||
* java.base/jdk.internal.classfile.java.lang.constant
|
||||
* java.base/jdk.internal.module
|
||||
* @library /test/lib
|
||||
* @build jdk.test.lib.util.ModuleInfoWriter
|
||||
|
@ -27,7 +27,6 @@
|
||||
* java.base/jdk.internal.classfile
|
||||
* java.base/jdk.internal.classfile.attribute
|
||||
* java.base/jdk.internal.classfile.constantpool
|
||||
* java.base/jdk.internal.classfile.java.lang.constant
|
||||
* java.base/jdk.internal.module
|
||||
* @library /test/lib
|
||||
* @build ConfigurationTest
|
||||
|
@ -28,7 +28,6 @@
|
||||
* java.base/jdk.internal.classfile
|
||||
* java.base/jdk.internal.classfile.attribute
|
||||
* java.base/jdk.internal.classfile.constantpool
|
||||
* java.base/jdk.internal.classfile.java.lang.constant
|
||||
* java.base/jdk.internal.module
|
||||
* @library /test/lib
|
||||
* @build jdk.test.lib.util.ModuleInfoWriter
|
||||
@ -65,8 +64,8 @@ import jdk.internal.access.JavaLangModuleAccess;
|
||||
import jdk.internal.access.SharedSecrets;
|
||||
import jdk.internal.classfile.Classfile;
|
||||
import jdk.internal.classfile.attribute.ModuleAttribute;
|
||||
import jdk.internal.classfile.java.lang.constant.PackageDesc;
|
||||
import jdk.internal.classfile.java.lang.constant.ModuleDesc;
|
||||
import java.lang.constant.PackageDesc;
|
||||
import java.lang.constant.ModuleDesc;
|
||||
import jdk.test.lib.util.ModuleInfoWriter;
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
|
@ -26,7 +26,6 @@
|
||||
* @modules java.base/jdk.internal.classfile
|
||||
* java.base/jdk.internal.classfile.attribute
|
||||
* java.base/jdk.internal.classfile.constantpool
|
||||
* java.base/jdk.internal.classfile.java.lang.constant
|
||||
* java.base/jdk.internal.module
|
||||
* @library /test/lib
|
||||
* @build ModuleFinderTest jdk.test.lib.util.ModuleInfoWriter
|
||||
|
@ -27,7 +27,6 @@
|
||||
* java.base/jdk.internal.classfile
|
||||
* java.base/jdk.internal.classfile.attribute
|
||||
* java.base/jdk.internal.classfile.constantpool
|
||||
* java.base/jdk.internal.classfile.java.lang.constant
|
||||
* java.base/jdk.internal.module
|
||||
* @library /test/lib
|
||||
* @build jdk.test.lib.util.ModuleInfoWriter
|
||||
|
@ -26,7 +26,6 @@
|
||||
* @modules java.base/jdk.internal.classfile
|
||||
* java.base/jdk.internal.classfile.attribute
|
||||
* java.base/jdk.internal.classfile.constantpool
|
||||
* java.base/jdk.internal.classfile.java.lang.constant
|
||||
* java.base/jdk.internal.module
|
||||
* @library /test/lib
|
||||
* @build MultiReleaseJarTest
|
||||
|
@ -50,7 +50,6 @@ import jdk.test.lib.util.ModuleInfoWriter;
|
||||
* @modules java.base/jdk.internal.classfile
|
||||
* java.base/jdk.internal.classfile.attribute
|
||||
* java.base/jdk.internal.classfile.constantpool
|
||||
* java.base/jdk.internal.classfile.java.lang.constant
|
||||
* java.base/jdk.internal.module
|
||||
* @library /test/lib
|
||||
* @build jdk.test.lib.util.JarUtils
|
||||
|
@ -46,7 +46,6 @@ import jdk.test.lib.util.ModuleInfoWriter;
|
||||
* @modules java.base/jdk.internal.classfile
|
||||
* java.base/jdk.internal.classfile.attribute
|
||||
* java.base/jdk.internal.classfile.constantpool
|
||||
* java.base/jdk.internal.classfile.java.lang.constant
|
||||
* java.base/jdk.internal.module
|
||||
* @library /test/lib
|
||||
* @build jdk.test.lib.util.JarUtils jdk.test.lib.util.ModuleInfoWriter
|
||||
|
@ -45,7 +45,6 @@ import jdk.test.lib.util.ModuleInfoWriter;
|
||||
* @modules java.base/jdk.internal.classfile
|
||||
* java.base/jdk.internal.classfile.attribute
|
||||
* java.base/jdk.internal.classfile.constantpool
|
||||
* java.base/jdk.internal.classfile.java.lang.constant
|
||||
* java.base/jdk.internal.module
|
||||
* @library /test/lib
|
||||
* @build jdk.test.lib.util.JarUtils jdk.test.lib.util.ModuleInfoWriter
|
||||
|
@ -61,7 +61,7 @@ import jdk.internal.classfile.instruction.ReturnInstruction;
|
||||
import jdk.internal.classfile.instruction.StoreInstruction;
|
||||
import java.lang.reflect.AccessFlag;
|
||||
import jdk.internal.classfile.components.CodeRelabeler;
|
||||
import jdk.internal.classfile.java.lang.constant.ModuleDesc;
|
||||
import java.lang.constant.ModuleDesc;
|
||||
import jdk.internal.classfile.components.ClassPrinter;
|
||||
import static java.lang.annotation.ElementType.*;
|
||||
import java.lang.annotation.Retention;
|
||||
|
@ -38,8 +38,8 @@ import jdk.internal.classfile.attribute.ModulePackagesAttribute;
|
||||
import jdk.internal.classfile.attribute.ModuleProvideInfo;
|
||||
import jdk.internal.classfile.attribute.ModuleRequireInfo;
|
||||
import jdk.internal.classfile.Attributes;
|
||||
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 org.junit.jupiter.api.Test;
|
||||
|
||||
import java.lang.constant.ClassDesc;
|
||||
@ -104,7 +104,7 @@ class ModuleBuilderTest {
|
||||
var cm = Classfile.parse(modBytes);
|
||||
|
||||
var attr =cm.findAttribute(Attributes.MODULE).get();
|
||||
assertEquals(attr.moduleName().name().stringValue(), modName.moduleName());
|
||||
assertEquals(attr.moduleName().name().stringValue(), modName.name());
|
||||
assertEquals(attr.moduleFlagsMask(), 0);
|
||||
assertEquals(attr.moduleVersion().get().stringValue(), modVsn);
|
||||
}
|
||||
@ -118,12 +118,12 @@ class ModuleBuilderTest {
|
||||
void testVerifyRequires() {
|
||||
assertEquals(attr.requires().size(), 2);
|
||||
ModuleRequireInfo r = attr.requires().get(0);
|
||||
assertEquals(r.requires().name().stringValue(), require1.moduleName());
|
||||
assertEquals(r.requires().name().stringValue(), require1.name());
|
||||
assertEquals(r.requiresVersion().get().stringValue(), vsn1);
|
||||
assertEquals(r.requiresFlagsMask(), 77);
|
||||
|
||||
r = attr.requires().get(1);
|
||||
assertEquals(r.requires().name().stringValue(), require2.moduleName());
|
||||
assertEquals(r.requires().name().stringValue(), require2.name());
|
||||
assertEquals(r.requiresVersion().get().stringValue(), vsn2);
|
||||
assertEquals(r.requiresFlagsMask(), 99);
|
||||
}
|
||||
@ -138,14 +138,14 @@ class ModuleBuilderTest {
|
||||
}
|
||||
assertEquals(exports.get(0).exportsTo().size(), 2);
|
||||
for (int i = 0; i < 2; i++)
|
||||
assertEquals(exports.get(0).exportsTo().get(i).name().stringValue(), et1[i].moduleName());
|
||||
assertEquals(exports.get(0).exportsTo().get(i).name().stringValue(), et1[i].name());
|
||||
|
||||
assertEquals(exports.get(1).exportsTo().size(), 1);
|
||||
assertEquals(exports.get(1).exportsTo().get(0).name().stringValue(), et2[0].moduleName());
|
||||
assertEquals(exports.get(1).exportsTo().get(0).name().stringValue(), et2[0].name());
|
||||
|
||||
assertEquals(exports.get(2).exportsTo().size(), 3);
|
||||
for (int i = 0; i < 3; i++)
|
||||
assertEquals(exports.get(2).exportsTo().get(i).name().stringValue(), et3[i].moduleName());
|
||||
assertEquals(exports.get(2).exportsTo().get(i).name().stringValue(), et3[i].name());
|
||||
|
||||
assertEquals(exports.get(3).exportsTo().size(), 0);
|
||||
assertEquals(exports.get(4).exportsTo().size(), 0);
|
||||
@ -159,7 +159,7 @@ class ModuleBuilderTest {
|
||||
assertEquals(opens.get(1).opensTo().size(), 0);
|
||||
assertEquals(opens.get(2).opensTo().size(), 2);
|
||||
assertEquals(opens.get(2).opensFlagsMask(), 2);
|
||||
assertEquals(opens.get(2).opensTo().get(1).name().stringValue(), ot3[1].moduleName());
|
||||
assertEquals(opens.get(2).opensTo().get(1).name().stringValue(), ot3[1].name());
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -182,7 +182,7 @@ class ModuleBuilderTest {
|
||||
@Test
|
||||
void verifyPackages() {
|
||||
ModulePackagesAttribute a = moduleModel.findAttribute(Attributes.MODULE_PACKAGES).orElseThrow();
|
||||
assertEquals(a.packages().stream().map(pe -> pe.asSymbol().packageName()).toList(), List.of("foo.bar.baz", "quux"));
|
||||
assertEquals(a.packages().stream().map(pe -> pe.asSymbol().name()).toList(), List.of("foo.bar.baz", "quux"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @summary Testing ModuleDesc.
|
||||
* @run junit ModuleDescTest
|
||||
*/
|
||||
import jdk.internal.classfile.java.lang.constant.ModuleDesc;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class ModuleDescTest {
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {"abc\\", "ab\\c", "\u0000", "\u0001", "\u001e", "\u001f"})
|
||||
public void testInvalidModuleNames(String mdl) {
|
||||
assertThrows(IllegalArgumentException.class, () -> ModuleDesc.of(mdl));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {"a\\\\b", "a.b/c", "a\\@b\\: c"})
|
||||
public void testValidModuleNames(String mdl) {
|
||||
assertEquals(ModuleDesc.of(mdl), ModuleDesc.of(mdl));
|
||||
assertEquals(ModuleDesc.of(mdl).moduleName(), mdl);
|
||||
}
|
||||
}
|
@ -1,63 +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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @summary Testing PackageDesc.
|
||||
* @run junit PackageDescTest
|
||||
*/
|
||||
import jdk.internal.classfile.java.lang.constant.PackageDesc;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
class PackageDescTest {
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {"a/b.d", "a[]", "a;"})
|
||||
void testInvalidPackageNames(String pkg) {
|
||||
assertThrows(IllegalArgumentException.class, () -> PackageDesc.of(pkg));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {"a/b.d", "a[]", "a;"})
|
||||
void testInvalidInternalPackageNames(String pkg) {
|
||||
assertThrows(IllegalArgumentException.class, () -> PackageDesc.ofInternalName(pkg));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testValidPackageNames() {
|
||||
assertEquals(PackageDesc.of("a"), PackageDesc.ofInternalName("a"));
|
||||
assertEquals(PackageDesc.of("a.b"), PackageDesc.ofInternalName("a/b"));
|
||||
assertEquals(PackageDesc.of("a.b.c"), PackageDesc.ofInternalName("a/b/c"));
|
||||
assertEquals(PackageDesc.of("a").packageName(), PackageDesc.ofInternalName("a").packageName());
|
||||
assertEquals(PackageDesc.of("a.b").packageName(), PackageDesc.ofInternalName("a/b").packageName());
|
||||
assertEquals(PackageDesc.of("a.b.c").packageName(), PackageDesc.ofInternalName("a/b/c").packageName());
|
||||
assertEquals(PackageDesc.of("a").packageInternalName(), PackageDesc.ofInternalName("a").packageInternalName());
|
||||
assertEquals(PackageDesc.of("a.b").packageInternalName(), PackageDesc.ofInternalName("a/b").packageInternalName());
|
||||
assertEquals(PackageDesc.of("a.b.c").packageInternalName(), PackageDesc.ofInternalName("a/b/c").packageInternalName());
|
||||
}
|
||||
}
|
@ -7,7 +7,6 @@ modules = \
|
||||
java.base/jdk.internal.classfile.instruction \
|
||||
java.base/jdk.internal.classfile.impl \
|
||||
java.base/jdk.internal.classfile.impl.verifier \
|
||||
java.base/jdk.internal.classfile.java.lang.constant \
|
||||
java.base/jdk.internal.classfile.components \
|
||||
java.base/jdk.internal.classfile.util \
|
||||
java.base/jdk.internal.org.objectweb.asm \
|
||||
|
@ -46,8 +46,8 @@ import jdk.internal.classfile.attribute.ModuleMainClassAttribute;
|
||||
import jdk.internal.classfile.attribute.ModulePackagesAttribute;
|
||||
import jdk.internal.classfile.attribute.RuntimeVisibleAnnotationsAttribute;
|
||||
import jdk.internal.classfile.Attributes;
|
||||
import jdk.internal.classfile.java.lang.constant.PackageDesc;
|
||||
import jdk.internal.classfile.java.lang.constant.ModuleDesc;
|
||||
import java.lang.constant.PackageDesc;
|
||||
import java.lang.constant.ModuleDesc;
|
||||
|
||||
public class ModuleExamples {
|
||||
private static final FileSystem JRT = FileSystems.getFileSystem(URI.create("jrt:/"));
|
||||
|
@ -32,8 +32,8 @@ import jdk.internal.classfile.*;
|
||||
import jdk.internal.classfile.attribute.*;
|
||||
import jdk.internal.classfile.constantpool.*;
|
||||
import jdk.internal.classfile.instruction.*;
|
||||
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.components.CodeStackTracker;
|
||||
|
||||
class RebuildingTransformation {
|
||||
|
@ -27,7 +27,6 @@
|
||||
* @modules java.base/jdk.internal.classfile
|
||||
* java.base/jdk.internal.classfile.attribute
|
||||
* java.base/jdk.internal.classfile.constantpool
|
||||
* java.base/jdk.internal.classfile.java.lang.constant
|
||||
* java.base/jdk.internal.module
|
||||
* @library /test/lib
|
||||
* @build ServiceBinding TestBootLayer jdk.test.lib.util.ModuleInfoWriter
|
||||
|
@ -57,7 +57,6 @@ import jdk.test.lib.util.ModuleInfoWriter;
|
||||
* java.base/jdk.internal.classfile
|
||||
* java.base/jdk.internal.classfile.attribute
|
||||
* java.base/jdk.internal.classfile.constantpool
|
||||
* java.base/jdk.internal.classfile.java.lang.constant
|
||||
* java.base/jdk.internal.module
|
||||
* @library /test/lib
|
||||
* @build test.TestProcess
|
||||
|
@ -31,7 +31,6 @@
|
||||
* @modules java.base/jdk.internal.classfile
|
||||
* java.base/jdk.internal.classfile.attribute
|
||||
* java.base/jdk.internal.classfile.constantpool
|
||||
* java.base/jdk.internal.classfile.java.lang.constant
|
||||
* java.base/jdk.internal.jimage
|
||||
* java.base/jdk.internal.module
|
||||
* jdk.jdeps/com.sun.tools.classfile
|
||||
|
@ -31,7 +31,7 @@ import java.lang.reflect.AccessFlag;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.Map;
|
||||
import jdk.internal.classfile.Classfile;
|
||||
import jdk.internal.classfile.java.lang.constant.PackageDesc;
|
||||
import java.lang.constant.PackageDesc;
|
||||
import jdk.internal.classfile.attribute.ModuleAttribute;
|
||||
import jdk.internal.classfile.attribute.ModuleExportInfo;
|
||||
import jdk.internal.classfile.attribute.ModuleMainClassAttribute;
|
||||
|
Loading…
Reference in New Issue
Block a user