8308753: Class-File API transition to Preview

Reviewed-by: ihse, mchung, vromero
This commit is contained in:
Adam Sotona 2023-12-04 07:07:57 +00:00
parent b9df827adc
commit 2b00ac0d02
681 changed files with 7518 additions and 6502 deletions

View file

@ -0,0 +1,46 @@
/*
* 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 java.lang.classfile.constantpool;
import java.lang.constant.ConstantDesc;
import jdk.internal.javac.PreviewFeature;
/**
* A constant pool entry that may be used as an annotation constant,
* which includes the four kinds of primitive constants, and UTF8 constants.
*
* @sealedGraph
* @since 22
*/
@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API)
public sealed interface AnnotationConstantValueEntry extends PoolEntry
permits DoubleEntry, FloatEntry, IntegerEntry, LongEntry, Utf8Entry {
/**
* {@return the constant value} The constant value will be an {@link Integer},
* {@link Long}, {@link Float}, {@link Double}, or {@link String}.
*/
ConstantDesc constantValue();
}

View file

@ -0,0 +1,63 @@
/*
* 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 java.lang.classfile.constantpool;
import java.lang.constant.ClassDesc;
import java.lang.constant.ConstantDesc;
import jdk.internal.classfile.impl.AbstractPoolEntry;
import jdk.internal.javac.PreviewFeature;
/**
* Models a {@code CONSTANT_Class_info} constant in the constant pool of a
* classfile.
* @jvms 4.4.1 The CONSTANT_Class_info Structure
*
* @since 22
*/
@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API)
public sealed interface ClassEntry
extends LoadableConstantEntry
permits AbstractPoolEntry.ClassEntryImpl {
@Override
default ConstantDesc constantValue() {
return asSymbol();
}
/**
* {@return the UTF8 constant pool entry for the class name}
*/
Utf8Entry name();
/**
* {@return the class name, as an internal binary name}
*/
String asInternalName();
/**
* {@return the class name, as a symbolic descriptor}
*/
ClassDesc asSymbol();
}

View file

@ -0,0 +1,80 @@
/*
* 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 java.lang.classfile.constantpool;
import java.lang.classfile.TypeKind;
import jdk.internal.classfile.impl.Util;
import java.lang.constant.ClassDesc;
import java.lang.constant.ConstantDesc;
import java.lang.constant.DynamicConstantDesc;
import jdk.internal.classfile.impl.AbstractPoolEntry;
import jdk.internal.javac.PreviewFeature;
/**
* Models a {@code CONSTANT_Dynamic_info} constant in the constant pool of a
* classfile.
* @jvms 4.4.10 The CONSTANT_Dynamic_info and CONSTANT_InvokeDynamic_info Structures
*
* @since 22
*/
@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API)
public sealed interface ConstantDynamicEntry
extends DynamicConstantPoolEntry, LoadableConstantEntry
permits AbstractPoolEntry.ConstantDynamicEntryImpl {
/**
* {@return a symbolic descriptor for the dynamic constant's type}
*/
default ClassDesc typeSymbol() {
return Util.fieldTypeSymbol(nameAndType());
}
@Override
default ConstantDesc constantValue() {
return asSymbol();
}
/**
* {@return the symbolic descriptor for the {@code invokedynamic} constant}
*/
default DynamicConstantDesc<?> asSymbol() {
return DynamicConstantDesc.ofNamed(bootstrap().bootstrapMethod().asSymbol(),
name().stringValue(),
typeSymbol(),
bootstrap().arguments().stream()
.map(LoadableConstantEntry::constantValue)
.toArray(ConstantDesc[]::new));
}
/**
* {@return the type of the constant}
*/
@Override
default TypeKind typeKind() {
return TypeKind.fromDescriptor(type().stringValue());
}
}

View file

@ -0,0 +1,99 @@
/*
* 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 java.lang.classfile.constantpool;
import java.util.Iterator;
import java.util.NoSuchElementException;
import java.lang.classfile.BootstrapMethodEntry;
import java.lang.classfile.ClassReader;
import jdk.internal.javac.PreviewFeature;
/**
* Provides read access to the constant pool and bootstrap method table of a
* classfile.
* @jvms 4.4 The Constant Pool
*
* @sealedGraph
* @since 22
*/
@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API)
public sealed interface ConstantPool extends Iterable<PoolEntry>
permits ClassReader, ConstantPoolBuilder {
/**
* {@return the entry at the specified index}
*
* @param index the index within the pool of the desired entry
* @throws ConstantPoolException if the index is out of range of the
* constant pool, or is considered unusable
*/
PoolEntry entryByIndex(int index);
/**
* {@return the size of the constant pool}
*/
int size();
/**
* {@return an iterator over pool entries}
*/
@Override
default Iterator<PoolEntry> iterator() {
return new Iterator<>() {
int index = 1;
@Override
public boolean hasNext() {
return index < size();
}
@Override
public PoolEntry next() {
if (!hasNext()) throw new NoSuchElementException();
var e = entryByIndex(index);
index += e.width();
return e;
}
};
}
/**
* {@return the {@link BootstrapMethodEntry} at the specified index within
* the bootstrap method table}
*
* @param index the index within the bootstrap method table of the desired
* entry
* @throws ConstantPoolException if the index is out of range of the
* bootstrap methods
*/
BootstrapMethodEntry bootstrapMethodEntry(int index);
/**
* {@return the number of entries in the bootstrap method table}
*/
int bootstrapMethodCount();
}

View file

@ -0,0 +1,564 @@
/*
* 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 java.lang.classfile.constantpool;
import java.lang.constant.ClassDesc;
import java.lang.constant.ConstantDesc;
import java.lang.constant.DirectMethodHandleDesc;
import java.lang.constant.DynamicCallSiteDesc;
import java.lang.constant.DynamicConstantDesc;
import java.lang.constant.MethodTypeDesc;
import java.util.List;
import java.lang.classfile.BootstrapMethodEntry;
import java.lang.classfile.BufWriter;
import java.lang.classfile.ClassBuilder;
import java.lang.classfile.ClassModel;
import jdk.internal.classfile.impl.ClassReaderImpl;
import java.lang.constant.ModuleDesc;
import java.lang.constant.PackageDesc;
import java.lang.classfile.WritableElement;
import jdk.internal.classfile.impl.AbstractPoolEntry.ClassEntryImpl;
import jdk.internal.classfile.impl.AbstractPoolEntry.NameAndTypeEntryImpl;
import jdk.internal.classfile.impl.SplitConstantPool;
import jdk.internal.classfile.impl.TemporaryConstantPool;
import jdk.internal.classfile.impl.Util;
import jdk.internal.javac.PreviewFeature;
import static java.util.Objects.requireNonNull;
/**
* Builder for the constant pool of a classfile. Provides read and write access
* to the constant pool that is being built. Writing is append-only and idempotent
* (entry-bearing methods will return an existing entry if there is one).
*
* A {@linkplain ConstantPoolBuilder} is associated with a {@link ClassBuilder}.
* The {@linkplain ConstantPoolBuilder} also provides access to some of the
* state of the {@linkplain ClassBuilder}, such as classfile processing options.
*
* @since 22
*/
@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API)
public sealed interface ConstantPoolBuilder
extends ConstantPool, WritableElement<ConstantPool>
permits SplitConstantPool, TemporaryConstantPool {
/**
* {@return a new constant pool builder} The new constant pool builder will
* be pre-populated with the contents of the constant pool associated with
* the class reader.
*
* @param classModel the class to copy from
*/
static ConstantPoolBuilder of(ClassModel classModel) {
return new SplitConstantPool((ClassReaderImpl) classModel.constantPool());
}
/**
* {@return a new constant pool builder} The new constant pool builder
* will be empty.
*/
static ConstantPoolBuilder of() {
return new SplitConstantPool();
}
/**
* {@return whether the provided constant pool is index-compatible with this
* one} This may be because they are the same constant pool, or because this
* constant pool was copied from the other.
*
* @param constantPool the other constant pool
*/
boolean canWriteDirect(ConstantPool constantPool);
/**
* Writes associated bootstrap method entries to the specified writer
*
* @param buf the writer
* @return false when no bootstrap method entry has been written
*/
boolean writeBootstrapMethods(BufWriter buf);
/**
* {@return A {@link Utf8Entry} describing the provided {@linkplain String}}
* If a UTF8 entry in the pool already describes this string, it is returned;
* otherwise, a new entry is added and the new entry is returned.
*
* @param s the string
*/
Utf8Entry utf8Entry(String s);
/**
* {@return A {@link Utf8Entry} describing the field descriptor of the provided
* {@linkplain ClassDesc}}
* If a UTF8 entry in the pool already describes this field descriptor, it is returned;
* otherwise, a new entry is added and the new entry is returned.
*
* @param desc the symbolic descriptor for the class
*/
default Utf8Entry utf8Entry(ClassDesc desc) {
return utf8Entry(desc.descriptorString());
}
/**
* {@return A {@link Utf8Entry} describing the method descriptor of the provided
* {@linkplain MethodTypeDesc}}
* If a UTF8 entry in the pool already describes this field descriptor, it is returned;
* otherwise, a new entry is added and the new entry is returned.
*
* @param desc the symbolic descriptor for the method type
*/
default Utf8Entry utf8Entry(MethodTypeDesc desc) {
return utf8Entry(desc.descriptorString());
}
/**
* {@return A {@link ClassEntry} describing the class whose internal name
* is encoded in the provided {@linkplain Utf8Entry}}
* If a Class entry in the pool already describes this class,
* it is returned; otherwise, a new entry is added and the new entry is
* returned.
*
* @param ne the constant pool entry describing the internal name of the class
*/
ClassEntry classEntry(Utf8Entry ne);
/**
* {@return A {@link ClassEntry} describing the class described by
* provided {@linkplain ClassDesc}}
* If a Class entry in the pool already describes this class,
* it is returned; otherwise, a new entry is added and the new entry is
* returned.
*
* @param classDesc the symbolic descriptor for the class
* @throws IllegalArgumentException if {@code classDesc} represents a primitive type
*/
default ClassEntry classEntry(ClassDesc classDesc) {
if (requireNonNull(classDesc).isPrimitive()) {
throw new IllegalArgumentException("Cannot be encoded as ClassEntry: " + classDesc.displayName());
}
ClassEntryImpl ret = (ClassEntryImpl)classEntry(utf8Entry(classDesc.isArray() ? classDesc.descriptorString() : Util.toInternalName(classDesc)));
ret.sym = classDesc;
return ret;
}
/**
* {@return A {@link PackageEntry} describing the class whose internal name
* is encoded in the provided {@linkplain Utf8Entry}}
* If a Package entry in the pool already describes this class,
* it is returned; otherwise, a new entry is added and the new entry is
* returned.
*
* @param nameEntry the constant pool entry describing the internal name of
* the package
*/
PackageEntry packageEntry(Utf8Entry nameEntry);
/**
* {@return A {@link PackageEntry} describing the class described by
* provided {@linkplain PackageDesc}}
* If a Package entry in the pool already describes this class,
* it is returned; otherwise, a new entry is added and the new entry is
* returned.
*
* @param packageDesc the symbolic descriptor for the class
*/
default PackageEntry packageEntry(PackageDesc packageDesc) {
return packageEntry(utf8Entry(packageDesc.internalName()));
}
/**
* {@return A {@link ModuleEntry} describing the module whose name
* is encoded in the provided {@linkplain Utf8Entry}}
* If a module entry in the pool already describes this class,
* it is returned; otherwise, a new entry is added and the new entry is
* returned.
*
* @param moduleName the constant pool entry describing the module name
*/
ModuleEntry moduleEntry(Utf8Entry moduleName);
/**
* {@return A {@link ModuleEntry} describing the module described by
* provided {@linkplain ModuleDesc}}
* If a module entry in the pool already describes this class,
* it is returned; otherwise, a new entry is added and the new entry is
* returned.
*
* @param moduleDesc the symbolic descriptor for the class
*/
default ModuleEntry moduleEntry(ModuleDesc moduleDesc) {
return moduleEntry(utf8Entry(moduleDesc.name()));
}
/**
* {@return A {@link NameAndTypeEntry} describing the provided name and type}
* If a NameAndType entry in the pool already describes this name and type,
* it is returned; otherwise, a new entry is added and the new entry is
* returned.
*
* @param nameEntry the member name
* @param typeEntry the member field or method descriptor
*/
NameAndTypeEntry nameAndTypeEntry(Utf8Entry nameEntry, Utf8Entry typeEntry);
/**
* {@return A {@link NameAndTypeEntry} describing the provided name and type}
* If a NameAndType entry in the pool already describes this name and type,
* it is returned; otherwise, a new entry is added and the new entry is
* returned.
*
* @param name the member name
* @param type the symbolic descriptor for a field type
*/
default NameAndTypeEntry nameAndTypeEntry(String name, ClassDesc type) {
var ret = (NameAndTypeEntryImpl)nameAndTypeEntry(utf8Entry(name), utf8Entry(type.descriptorString()));
ret.typeSym = type;
return ret;
}
/**
* {@return A {@link NameAndTypeEntry} describing the provided name and type}
* If a NameAndType entry in the pool already describes this name and type,
* it is returned; otherwise, a new entry is added and the new entry is
* returned.
*
* @param name the member name
* @param type the symbolic descriptor for a method type
*/
default NameAndTypeEntry nameAndTypeEntry(String name, MethodTypeDesc type) {
var ret = (NameAndTypeEntryImpl)nameAndTypeEntry(utf8Entry(name), utf8Entry(type.descriptorString()));
ret.typeSym = type;
return ret;
}
/**
* {@return A {@link FieldRefEntry} describing a field of a class}
* If a FieldRef entry in the pool already describes this field,
* it is returned; otherwise, a new entry is added and the new entry is
* returned.
*
* @param owner the class the field is a member of
* @param nameAndType the name and type of the field
*/
FieldRefEntry fieldRefEntry(ClassEntry owner, NameAndTypeEntry nameAndType);
/**
* {@return A {@link FieldRefEntry} describing a field of a class}
* If a FieldRef entry in the pool already describes this field,
* it is returned; otherwise, a new entry is added and the new entry is
* returned.
*
* @param owner the class the field is a member of
* @param name the name of the field
* @param type the type of the field
* @throws IllegalArgumentException if {@code owner} represents a primitive type
*/
default FieldRefEntry fieldRefEntry(ClassDesc owner, String name, ClassDesc type) {
return fieldRefEntry(classEntry(owner), nameAndTypeEntry(name, type));
}
/**
* {@return A {@link MethodRefEntry} describing a method of a class}
* If a MethodRefEntry entry in the pool already describes this method,
* it is returned; otherwise, a new entry is added and the new entry is
* returned.
*
* @param owner the class the method is a member of
* @param nameAndType the name and type of the method
*/
MethodRefEntry methodRefEntry(ClassEntry owner, NameAndTypeEntry nameAndType);
/**
* {@return A {@link MethodRefEntry} describing a method of a class}
* If a MethodRefEntry entry in the pool already describes this method,
* it is returned; otherwise, a new entry is added and the new entry is
* returned.
*
* @param owner the class the method is a member of
* @param name the name of the method
* @param type the type of the method
* @throws IllegalArgumentException if {@code owner} represents a primitive type
*/
default MethodRefEntry methodRefEntry(ClassDesc owner, String name, MethodTypeDesc type) {
return methodRefEntry(classEntry(owner), nameAndTypeEntry(name, type));
}
/**
* {@return A {@link InterfaceMethodRefEntry} describing a method of a class}
* If a InterfaceMethodRefEntry entry in the pool already describes this method,
* it is returned; otherwise, a new entry is added and the new entry is
* returned.
*
* @param owner the class the method is a member of
* @param nameAndType the name and type of the method
*/
InterfaceMethodRefEntry interfaceMethodRefEntry(ClassEntry owner, NameAndTypeEntry nameAndType);
/**
* {@return A {@link InterfaceMethodRefEntry} describing a method of a class}
* If a InterfaceMethodRefEntry entry in the pool already describes this method,
* it is returned; otherwise, a new entry is added and the new entry is
* returned.
*
* @param owner the class the method is a member of
* @param name the name of the method
* @param type the type of the method
* @throws IllegalArgumentException if {@code owner} represents a primitive type
*/
default InterfaceMethodRefEntry interfaceMethodRefEntry(ClassDesc owner, String name, MethodTypeDesc type) {
return interfaceMethodRefEntry(classEntry(owner), nameAndTypeEntry(name, type));
}
/**
* {@return A {@link MethodTypeEntry} describing a method type}
* If a MethodType entry in the pool already describes this method type,
* it is returned; otherwise, a new entry is added and the new entry is
* returned.
*
* @param descriptor the symbolic descriptor of the method type
*/
MethodTypeEntry methodTypeEntry(MethodTypeDesc descriptor);
/**
* {@return A {@link MethodTypeEntry} describing a method type}
* If a MethodType entry in the pool already describes this method type,
* it is returned; otherwise, a new entry is added and the new entry is
* returned.
*
* @param descriptor the constant pool entry for the method type descriptor
*/
MethodTypeEntry methodTypeEntry(Utf8Entry descriptor);
/**
* {@return A {@link MethodHandleEntry} describing a direct method handle}
* If a MethodHandle entry in the pool already describes this method handle,
* it is returned; otherwise, a new entry is added and the new entry is
* returned.
*
* @param descriptor the symbolic descriptor of the method handle
*/
default MethodHandleEntry methodHandleEntry(DirectMethodHandleDesc descriptor) {
var owner = classEntry(descriptor.owner());
var nat = nameAndTypeEntry(utf8Entry(descriptor.methodName()), utf8Entry(descriptor.lookupDescriptor()));
return methodHandleEntry(descriptor.refKind(), switch (descriptor.kind()) {
case GETTER, SETTER, STATIC_GETTER, STATIC_SETTER -> fieldRefEntry(owner, nat);
case INTERFACE_STATIC, INTERFACE_VIRTUAL, INTERFACE_SPECIAL -> interfaceMethodRefEntry(owner, nat);
case STATIC, VIRTUAL, SPECIAL, CONSTRUCTOR -> methodRefEntry(owner, nat);
});
}
/**
* {@return A {@link MethodHandleEntry} describing a field accessor or method}
* If a MethodHandle entry in the pool already describes this method handle,
* it is returned; otherwise, a new entry is added and the new entry is
* returned.
*
* @param refKind the reference kind of the method handle {@jvms 4.4.8}
* @param reference the constant pool entry describing the field or method
*/
MethodHandleEntry methodHandleEntry(int refKind, MemberRefEntry reference);
/**
* {@return An {@link InvokeDynamicEntry} describing a dynamic call site}
* If an InvokeDynamic entry in the pool already describes this site,
* it is returned; otherwise, a new entry is added and the new entry is
* returned.
*
* @param dcsd the symbolic descriptor of the method handle
*/
default InvokeDynamicEntry invokeDynamicEntry(DynamicCallSiteDesc dcsd) {
return invokeDynamicEntry(bsmEntry((DirectMethodHandleDesc)dcsd.bootstrapMethod(), List.of(dcsd.bootstrapArgs())), nameAndTypeEntry(dcsd.invocationName(), dcsd.invocationType()));
}
/**
* {@return An {@link InvokeDynamicEntry} describing a dynamic call site}
* If an InvokeDynamic entry in the pool already describes this site,
* it is returned; otherwise, a new entry is added and the new entry is
* returned.
*
* @param bootstrapMethodEntry the entry in the bootstrap method table
* @param nameAndType the invocation name and type
*/
InvokeDynamicEntry invokeDynamicEntry(BootstrapMethodEntry bootstrapMethodEntry,
NameAndTypeEntry nameAndType);
/**
* {@return A {@link ConstantDynamicEntry} describing a dynamic constant}
* If a ConstantDynamic entry in the pool already describes this site,
* it is returned; otherwise, a new entry is added and the new entry is
* returned.
*
* @param dcd the symbolic descriptor of the constant
*/
default ConstantDynamicEntry constantDynamicEntry(DynamicConstantDesc<?> dcd) {
return constantDynamicEntry(bsmEntry(dcd.bootstrapMethod(), List.of(dcd.bootstrapArgs())), nameAndTypeEntry(dcd.constantName(), dcd.constantType()));
}
/**
* {@return A {@link ConstantDynamicEntry} describing a dynamic constant}
* If a ConstantDynamic entry in the pool already describes this site,
* it is returned; otherwise, a new entry is added and the new entry is
* returned.
*
* @param bootstrapMethodEntry the entry in the bootstrap method table
* @param nameAndType the invocation name and type
*/
ConstantDynamicEntry constantDynamicEntry(BootstrapMethodEntry bootstrapMethodEntry, NameAndTypeEntry nameAndType);
/**
* {@return An {@link IntegerEntry} describing the provided value}
* If an integer entry in the pool already describes this value, it is returned;
* otherwise, a new entry is added and the new entry is returned.
*
* @param value the value
*/
IntegerEntry intEntry(int value);
/**
* {@return A {@link FloatEntry} describing the provided value}
* If a float entry in the pool already describes this value, it is returned;
* otherwise, a new entry is added and the new entry is returned.
*
* @param value the value
*/
FloatEntry floatEntry(float value);
/**
* {@return A {@link LongEntry} describing the provided value}
* If a long entry in the pool already describes this value, it is returned;
* otherwise, a new entry is added and the new entry is returned.
*
* @param value the value
*/
LongEntry longEntry(long value);
/**
* {@return A {@link DoubleEntry} describing the provided value}
* If a double entry in the pool already describes this value, it is returned;
* otherwise, a new entry is added and the new entry is returned.
*
* @param value the value
*/
DoubleEntry doubleEntry(double value);
/**
* {@return A {@link StringEntry} referencing the provided UTF8 entry}
* If a String entry in the pool already describes this value, it is returned;
* otherwise, a new entry is added and the new entry is returned.
*
* @param utf8 the UTF8 entry describing the string
*/
StringEntry stringEntry(Utf8Entry utf8);
/**
* {@return A {@link StringEntry} describing the provided value}
* If a string entry in the pool already describes this value, it is returned;
* otherwise, a new entry is added and the new entry is returned.
*
* @param value the value
*/
default StringEntry stringEntry(String value) {
return stringEntry(utf8Entry(value));
}
/**
* {@return A {@link ConstantValueEntry} descripbing the provided
* Integer, Long, Float, Double, or String constant}
*
* @param c the constant
*/
default ConstantValueEntry constantValueEntry(ConstantDesc c) {
if (c instanceof Integer i) return intEntry(i);
if (c instanceof String s) return stringEntry(s);
if (c instanceof Long l) return longEntry(l);
if (c instanceof Float f) return floatEntry(f);
if (c instanceof Double d) return doubleEntry(d);
throw new IllegalArgumentException("Illegal type: " + (c == null ? null : c.getClass()));
}
/**
* {@return A {@link LoadableConstantEntry} describing the provided
* constant} The constant should be an Integer, String, Long, Float,
* Double, ClassDesc (for a Class constant), MethodTypeDesc (for a MethodType
* constant), DirectMethodHandleDesc (for a MethodHandle constant), or
* a DynamicConstantDesc (for a dynamic constant.)
*
* @param c the constant
*/
default LoadableConstantEntry loadableConstantEntry(ConstantDesc c) {
if (c instanceof Integer i) return intEntry(i);
if (c instanceof String s) return stringEntry(s);
if (c instanceof Long l) return longEntry(l);
if (c instanceof Float f) return floatEntry(f);
if (c instanceof Double d) return doubleEntry(d);
if (c instanceof ClassDesc cd && !cd.isPrimitive()) return classEntry(cd);
if (c instanceof MethodTypeDesc mtd) return methodTypeEntry(mtd);
if (c instanceof DirectMethodHandleDesc dmhd) return methodHandleEntry(dmhd);
if (c instanceof DynamicConstantDesc<?> dcd) return constantDynamicEntry(dcd);
throw new IllegalArgumentException("Illegal type: " + (c == null ? null : c.getClass()));
}
/**
* {@return An {@link AnnotationConstantValueEntry} describing the provided
* constant} The constant should be an Integer, String, Long, Float,
* Double, ClassDesc (for a Class constant), or MethodTypeDesc (for a MethodType
* constant.)
*
* @param c the constant
*/
default AnnotationConstantValueEntry annotationConstantValueEntry(ConstantDesc c) {
if (c instanceof Integer i) return intEntry(i);
if (c instanceof String s) return utf8Entry(s);
if (c instanceof Long l) return longEntry(l);
if (c instanceof Float f) return floatEntry(f);
if (c instanceof Double d) return doubleEntry(d);
if (c instanceof ClassDesc cd) return utf8Entry(cd);
if (c instanceof MethodTypeDesc mtd) return utf8Entry(mtd);
throw new IllegalArgumentException("Illegal type: " + (c == null ? null : c.getClass()));
}
/**
* {@return a {@link BootstrapMethodEntry} describing the provided
* bootstrap method and static arguments}
*
* @param methodReference the bootstrap method
* @param arguments the bootstrap arguments
*/
default BootstrapMethodEntry bsmEntry(DirectMethodHandleDesc methodReference,
List<ConstantDesc> arguments) {
return bsmEntry(methodHandleEntry(methodReference),
arguments.stream().map(this::loadableConstantEntry).toList());
}
/**
* {@return a {@link BootstrapMethodEntry} describing the provided
* bootstrap method and static arguments}
*
* @param methodReference the bootstrap method
* @param arguments the bootstrap arguments
*/
BootstrapMethodEntry bsmEntry(MethodHandleEntry methodReference,
List<LoadableConstantEntry> arguments);
}

View file

@ -0,0 +1,84 @@
/*
* Copyright (c) 2023, 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 java.lang.classfile.constantpool;
import jdk.internal.javac.PreviewFeature;
/**
* Thrown to indicate that requested entry cannot be obtained from the constant
* pool.
*
* @since 22
*/
@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API)
public class ConstantPoolException extends IllegalArgumentException {
@java.io.Serial
private static final long serialVersionUID = 7245472922409094120L;
/**
* Constructs a {@code ConstantPoolException} with no detail message.
*/
public ConstantPoolException() {
super();
}
/**
* Constructs a {@code ConstantPoolException} with the specified detail
* message.
*
* @param message the detail message.
*/
public ConstantPoolException(String message) {
super(message);
}
/**
* Constructs a {@code ConstantPoolException} with the specified cause and
* a detail message of {@code (cause==null ? null : cause.toString())}.
* @param cause the cause (which is saved for later retrieval by the
* {@link Throwable#getCause()} method). (A {@code null} value is
* permitted, and indicates that the cause is nonexistent or
* unknown.)
*/
public ConstantPoolException(Throwable cause) {
super(cause);
}
/**
* Constructs a {@code ConstantPoolException} with the specified detail
* message and cause.
*
* @param message the detail message (which is saved for later retrieval
* by the {@link Throwable#getMessage()} method).
* @param cause the cause (which is saved for later retrieval by the
* {@link Throwable#getCause()} method). (A {@code null} value
* is permitted, and indicates that the cause is nonexistent or
* unknown.)
*/
public ConstantPoolException(String message, Throwable cause) {
super(message, cause);
}
}

View file

@ -0,0 +1,48 @@
/*
* 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 java.lang.classfile.constantpool;
import java.lang.constant.ConstantDesc;
import jdk.internal.javac.PreviewFeature;
/**
* Models a constant pool entry that can be used as the constant in a
* {@code ConstantValue} attribute; this includes the four primitive constant
* types and {@linkplain String} constants.
*
* @sealedGraph
* @since 22
*/
@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API)
public sealed interface ConstantValueEntry extends LoadableConstantEntry
permits DoubleEntry, FloatEntry, IntegerEntry, LongEntry, StringEntry {
/**
* {@return the constant value} The constant value will be an {@link Integer},
* {@link Long}, {@link Float}, {@link Double}, or {@link String}.
*/
@Override
ConstantDesc constantValue();
}

View file

@ -0,0 +1,55 @@
/*
* 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 java.lang.classfile.constantpool;
import java.lang.classfile.TypeKind;
import jdk.internal.classfile.impl.AbstractPoolEntry;
import jdk.internal.javac.PreviewFeature;
/**
* Models a {@code CONSTANT_Double_info} constant in the constant pool of a
* classfile.
* @jvms 4.4.5 The CONSTANT_Long_info and CONSTANT_Double_info Structures
*
* @since 22
*/
@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API)
public sealed interface DoubleEntry
extends AnnotationConstantValueEntry, ConstantValueEntry
permits AbstractPoolEntry.DoubleEntryImpl {
/**
* {@return the double value}
*/
double doubleValue();
/**
* {@return the type of the constant}
*/
@Override
default TypeKind typeKind() {
return TypeKind.DoubleType;
}
}

View file

@ -0,0 +1,70 @@
/*
* 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 java.lang.classfile.constantpool;
import java.lang.classfile.BootstrapMethodEntry;
import jdk.internal.javac.PreviewFeature;
/**
* Models a dynamic constant pool entry, which is either {@link ConstantDynamicEntry}
* or {@link InvokeDynamicEntry}.
* @jvms 4.4.10 The CONSTANT_Dynamic_info and CONSTANT_InvokeDynamic_info Structures
*
* @sealedGraph
* @since 22
*/
@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API)
public sealed interface DynamicConstantPoolEntry extends PoolEntry
permits ConstantDynamicEntry, InvokeDynamicEntry {
/**
* {@return the entry in the bootstrap method table for this constant}
*/
BootstrapMethodEntry bootstrap();
/**
* {@return index of the entry in the bootstrap method table for this constant}
*/
int bootstrapMethodIndex();
/**
* {@return the invocation name and type}
*/
NameAndTypeEntry nameAndType();
/**
* {@return the invocation name}
*/
default Utf8Entry name() {
return nameAndType().name();
}
/**
* {@return the invocation type}
*/
default Utf8Entry type() {
return nameAndType().type();
}
}

View file

@ -0,0 +1,49 @@
/*
* 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 java.lang.classfile.constantpool;
import jdk.internal.classfile.impl.AbstractPoolEntry;
import jdk.internal.classfile.impl.Util;
import jdk.internal.javac.PreviewFeature;
import java.lang.constant.ClassDesc;
/**
* Models a {@code CONSTANT_Fieldref_info} constant in the constant pool of a
* classfile.
* @jvms 4.4.2 The CONSTANT_Fieldref_info, CONSTANT_Methodref_info, and CONSTANT_InterfaceMethodref_info Structures
*
* @since 22
*/
@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API)
public sealed interface FieldRefEntry extends MemberRefEntry
permits AbstractPoolEntry.FieldRefEntryImpl {
/**
* {@return a symbolic descriptor for the field's type}
*/
default ClassDesc typeSymbol() {
return Util.fieldTypeSymbol(nameAndType());
}
}

View file

@ -0,0 +1,56 @@
/*
* 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 java.lang.classfile.constantpool;
import java.lang.classfile.TypeKind;
import jdk.internal.classfile.impl.AbstractPoolEntry;
import jdk.internal.javac.PreviewFeature;
/**
* Models a {@code CONSTANT_Float_info} constant in the constant pool of a
* classfile.
* @jvms 4.4.4 The CONSTANT_Integer_info and CONSTANT_Float_info Structures
*
* @since 22
*/
@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API)
public sealed interface FloatEntry
extends AnnotationConstantValueEntry, ConstantValueEntry
permits AbstractPoolEntry.FloatEntryImpl {
/**
* {@return the float value}
*/
float floatValue();
/**
* {@return the type of the constant}
*/
@Override
default TypeKind typeKind() {
return TypeKind.FloatType;
}
}

View file

@ -0,0 +1,55 @@
/*
* 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 java.lang.classfile.constantpool;
import java.lang.classfile.TypeKind;
import jdk.internal.classfile.impl.AbstractPoolEntry;
import jdk.internal.javac.PreviewFeature;
/**
* Models a {@code CONSTANT_Integer_info} constant in the constant pool of a
* classfile.
* @jvms 4.4.4 The CONSTANT_Integer_info and CONSTANT_Float_info Structures
*
* @since 22
*/
@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API)
public sealed interface IntegerEntry
extends AnnotationConstantValueEntry, ConstantValueEntry
permits AbstractPoolEntry.IntegerEntryImpl {
/**
* {@return the integer value}
*/
int intValue();
/**
* {@return the type of the constant}
*/
@Override
default TypeKind typeKind() {
return TypeKind.IntType;
}
}

View file

@ -0,0 +1,50 @@
/*
* 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 java.lang.classfile.constantpool;
import jdk.internal.classfile.impl.AbstractPoolEntry;
import jdk.internal.classfile.impl.Util;
import jdk.internal.javac.PreviewFeature;
import java.lang.constant.MethodTypeDesc;
/**
* Models a {@code CONSTANT_InterfaceMethodRef_info} constant in the constant pool of a
* classfile.
* @jvms 4.4.2 The CONSTANT_Fieldref_info, CONSTANT_Methodref_info, and CONSTANT_InterfaceMethodref_info Structures
*
* @since 22
*/
@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API)
public sealed interface InterfaceMethodRefEntry
extends MemberRefEntry
permits AbstractPoolEntry.InterfaceMethodRefEntryImpl {
/**
* {@return a symbolic descriptor for the interface method's type}
*/
default MethodTypeDesc typeSymbol() {
return Util.methodTypeSymbol(nameAndType());
}
}

View file

@ -0,0 +1,64 @@
/*
* 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 java.lang.classfile.constantpool;
import java.lang.constant.ConstantDesc;
import java.lang.constant.DynamicCallSiteDesc;
import java.lang.constant.MethodTypeDesc;
import jdk.internal.classfile.impl.AbstractPoolEntry;
import jdk.internal.classfile.impl.Util;
import jdk.internal.javac.PreviewFeature;
/**
* Models a constant pool entry for a dynamic call site.
* @jvms 4.4.10 The CONSTANT_Dynamic_info and CONSTANT_InvokeDynamic_info Structures
*
* @since 22
*/
@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API)
public sealed interface InvokeDynamicEntry
extends DynamicConstantPoolEntry
permits AbstractPoolEntry.InvokeDynamicEntryImpl {
/**
* {@return a symbolic descriptor for the call site's invocation type}
*/
default MethodTypeDesc typeSymbol() {
return Util.methodTypeSymbol(nameAndType());
}
/**
* {@return a symbolic descriptor for the dynamic call site}
*/
default DynamicCallSiteDesc asSymbol() {
return DynamicCallSiteDesc.of(bootstrap().bootstrapMethod().asSymbol(),
name().stringValue(),
typeSymbol(),
bootstrap().arguments().stream()
.map(LoadableConstantEntry::constantValue)
.toArray(ConstantDesc[]::new));
}
}

View file

@ -0,0 +1,53 @@
/*
* 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 java.lang.classfile.constantpool;
import java.lang.constant.ConstantDesc;
import java.lang.classfile.TypeKind;
import jdk.internal.javac.PreviewFeature;
/**
* Marker interface for constant pool entries suitable for loading via the
* {@code LDC} instructions.
*
* @sealedGraph
* @since 22
*/
@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API)
public sealed interface LoadableConstantEntry extends PoolEntry
permits ClassEntry, ConstantDynamicEntry, ConstantValueEntry, MethodHandleEntry, MethodTypeEntry {
/**
* {@return the constant described by this entry}
*/
ConstantDesc constantValue();
/**
* {@return the type of the constant}
*/
default TypeKind typeKind() {
return TypeKind.ReferenceType;
}
}

View file

@ -0,0 +1,55 @@
/*
* 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 java.lang.classfile.constantpool;
import java.lang.classfile.TypeKind;
import jdk.internal.classfile.impl.AbstractPoolEntry;
import jdk.internal.javac.PreviewFeature;
/**
* Models a {@code CONSTANT_Long_info} constant in the constant pool of a
* classfile.
* @jvms 4.4.5 The CONSTANT_Long_info and CONSTANT_Double_info Structures
*
* @since 22
*/
@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API)
public sealed interface LongEntry
extends AnnotationConstantValueEntry, ConstantValueEntry
permits AbstractPoolEntry.LongEntryImpl {
/**
* {@return the long value}
*/
long longValue();
/**
* {@return the type of the constant}
*/
@Override
default TypeKind typeKind() {
return TypeKind.LongType;
}
}

View file

@ -0,0 +1,63 @@
/*
* 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 java.lang.classfile.constantpool;
import jdk.internal.classfile.impl.AbstractPoolEntry;
import jdk.internal.javac.PreviewFeature;
/**
* Models a member reference constant in the constant pool of a classfile,
* which includes references to fields, methods, and interface methods.
*
* @sealedGraph
* @since 22
*/
@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API)
public sealed interface MemberRefEntry extends PoolEntry
permits FieldRefEntry, InterfaceMethodRefEntry, MethodRefEntry, AbstractPoolEntry.AbstractMemberRefEntry {
/**
* {@return the class in which this member ref lives}
*/
ClassEntry owner();
/**
* {@return the name and type of the member}
*/
NameAndTypeEntry nameAndType();
/**
* {@return the name of the member}
*/
default Utf8Entry name() {
return nameAndType().name();
}
/**
* {@return the type of the member}
*/
default Utf8Entry type() {
return nameAndType().type();
}
}

View file

@ -0,0 +1,65 @@
/*
* 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 java.lang.classfile.constantpool;
import java.lang.constant.ConstantDesc;
import java.lang.constant.DirectMethodHandleDesc;
import jdk.internal.classfile.impl.AbstractPoolEntry;
import jdk.internal.javac.PreviewFeature;
/**
* Models a {@code CONSTANT_MethodHandle_info} constant in the constant pool of a
* classfile.
* @jvms 4.4.8 The CONSTANT_MethodHandle_info Structure
*
* @since 22
*/
@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API)
public sealed interface MethodHandleEntry
extends LoadableConstantEntry
permits AbstractPoolEntry.MethodHandleEntryImpl {
@Override
default ConstantDesc constantValue() {
return asSymbol();
}
/**
* {@return the reference kind of this method handle {@jvms 4.4.8}}
* @see java.lang.invoke.MethodHandleInfo
*/
int kind();
/**
* {@return the constant pool entry describing the method}
*/
MemberRefEntry reference();
/**
* {@return a symbolic descriptor for this method handle}
*/
DirectMethodHandleDesc asSymbol();
}

View file

@ -0,0 +1,49 @@
/*
* 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 java.lang.classfile.constantpool;
import jdk.internal.classfile.impl.AbstractPoolEntry;
import jdk.internal.classfile.impl.Util;
import jdk.internal.javac.PreviewFeature;
import java.lang.constant.MethodTypeDesc;
/**
* Models a {@code CONSTANT_MethodRef_info} constant in the constant pool of a
* classfile.
* @jvms 4.4.2 The CONSTANT_Fieldref_info, CONSTANT_Methodref_info, and CONSTANT_InterfaceMethodref_info Structures
*
* @since 22
*/
@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API)
public sealed interface MethodRefEntry extends MemberRefEntry
permits AbstractPoolEntry.MethodRefEntryImpl {
/**
* {@return a symbolic descriptor for the method's type}
*/
default MethodTypeDesc typeSymbol() {
return Util.methodTypeSymbol(nameAndType());
}
}

View file

@ -0,0 +1,59 @@
/*
* 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 java.lang.classfile.constantpool;
import java.lang.constant.ConstantDesc;
import java.lang.constant.MethodTypeDesc;
import jdk.internal.classfile.impl.AbstractPoolEntry;
import jdk.internal.javac.PreviewFeature;
/**
* Models a {@code CONSTANT_MethodType_info} constant in the constant pool of a
* classfile.
* @jvms 4.4.9 The CONSTANT_MethodType_info Structure
*
* @since 22
*/
@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API)
public sealed interface MethodTypeEntry
extends LoadableConstantEntry
permits AbstractPoolEntry.MethodTypeEntryImpl {
@Override
default ConstantDesc constantValue() {
return asSymbol();
}
/**
* {@return the constant pool entry describing the method type}
*/
Utf8Entry descriptor();
/**
* {@return a symbolic descriptor for the method type}
*/
MethodTypeDesc asSymbol();
}

View file

@ -0,0 +1,50 @@
/*
* 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 java.lang.classfile.constantpool;
import jdk.internal.classfile.impl.AbstractPoolEntry;
import java.lang.constant.ModuleDesc;
import jdk.internal.javac.PreviewFeature;
/**
* Models a {@code CONSTANT_Module_info} constant in the constant pool of a
* classfile.
* @jvms 4.4.11 The CONSTANT_Module_info Structure
*
* @since 22
*/
@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API)
public sealed interface ModuleEntry extends PoolEntry
permits AbstractPoolEntry.ModuleEntryImpl {
/**
* {@return the name of the module}
*/
Utf8Entry name();
/**
* {@return a symbolic descriptor for the module}
*/
ModuleDesc asSymbol();
}

View file

@ -0,0 +1,50 @@
/*
* 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 java.lang.classfile.constantpool;
import jdk.internal.classfile.impl.AbstractPoolEntry;
import jdk.internal.javac.PreviewFeature;
/**
* Models a {@code CONSTANT_NameAndType_info} constant in the constant pool of a
* classfile.
* @jvms 4.4.6 The CONSTANT_NameAndType_info Structure
*
* @since 22
*/
@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API)
public sealed interface NameAndTypeEntry extends PoolEntry
permits AbstractPoolEntry.NameAndTypeEntryImpl {
/**
* {@return the field or method name}
*/
Utf8Entry name();
/**
* {@return the field or method descriptor}
*/
Utf8Entry type();
}

View file

@ -0,0 +1,50 @@
/*
* 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 java.lang.classfile.constantpool;
import jdk.internal.classfile.impl.AbstractPoolEntry;
import java.lang.constant.PackageDesc;
import jdk.internal.javac.PreviewFeature;
/**
* Models a {@code CONSTANT_Package_info} constant in the constant pool of a
* classfile.
* @jvms 4.4.12 The CONSTANT_Package_info Structure
*
* @since 22
*/
@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API)
public sealed interface PackageEntry extends PoolEntry
permits AbstractPoolEntry.PackageEntryImpl {
/**
* {@return the package name}
*/
Utf8Entry name();
/**
* {@return a symbolic descriptor for the package name}
*/
PackageDesc asSymbol();
}

View file

@ -0,0 +1,61 @@
/*
* 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 java.lang.classfile.constantpool;
import java.lang.classfile.WritableElement;
import jdk.internal.javac.PreviewFeature;
/**
* Models an entry in the constant pool of a classfile.
*
* @sealedGraph
* @since 22
*/
@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API)
public sealed interface PoolEntry extends WritableElement<PoolEntry>
permits AnnotationConstantValueEntry, DynamicConstantPoolEntry,
LoadableConstantEntry, MemberRefEntry, ModuleEntry, NameAndTypeEntry,
PackageEntry {
/**
* {@return the constant pool this entry is from}
*/
ConstantPool constantPool();
/**
* {@return the constant pool tag that describes the type of this entry}
*/
byte tag();
/**
* {@return the index within the constant pool corresponding to this entry}
*/
int index();
/**
* {@return the number of constant pool slots this entry consumes}
*/
int width();
}

View file

@ -0,0 +1,50 @@
/*
* 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 java.lang.classfile.constantpool;
import jdk.internal.classfile.impl.AbstractPoolEntry;
import jdk.internal.javac.PreviewFeature;
/**
* Models a {@code CONSTANT_String_info} constant in the constant pool of a
* classfile.
* @jvms 4.4.3 The CONSTANT_String_info Structure
*
* @since 22
*/
@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API)
public sealed interface StringEntry
extends ConstantValueEntry
permits AbstractPoolEntry.StringEntryImpl {
/**
* {@return the UTF constant pool entry describing the string contents}
*/
Utf8Entry utf8();
/**
* {@return the string value for this entry}
*/
String stringValue();
}

View file

@ -0,0 +1,53 @@
/*
* 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 java.lang.classfile.constantpool;
import jdk.internal.classfile.impl.AbstractPoolEntry;
import jdk.internal.javac.PreviewFeature;
/**
* Models a {@code CONSTANT_UTF8_info} constant in the constant pool of a
* classfile.
* @jvms 4.4.7 The CONSTANT_Utf8_info Structure
*
* @since 22
*/
@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API)
public sealed interface Utf8Entry
extends CharSequence, AnnotationConstantValueEntry
permits AbstractPoolEntry.Utf8EntryImpl {
/**
* {@return the string value for this entry}
*/
String stringValue();
/**
* {@return whether this entry describes the same string as the provided string}
*
* @param s the string to compare to
*/
boolean equalsString(String s);
}

View file

@ -0,0 +1,36 @@
/*
* Copyright (c) 2023, 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.
*/
/**
* <h2>Provides interfaces describing classfile constant pool entries for the {@link java.lang.classfile} library.</h2>
*
* The {@code java.lang.classfile.constantpool} package contains interfaces describing classfile constant pool entries.
*
* @since 22
*/
@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API)
package java.lang.classfile.constantpool;
import jdk.internal.javac.PreviewFeature;