Skip to content

Commit

Permalink
8265130: Make ConstantDesc class hierarchy sealed
Browse files Browse the repository at this point in the history
Reviewed-by: mchung, jvernee, vromero
  • Loading branch information
Gavin Bierman authored and Vicente Romero committed Jun 2, 2021
1 parent 00c7aee commit 379376f
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 38 deletions.
11 changes: 4 additions & 7 deletions src/java.base/share/classes/java/lang/constant/ClassDesc.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,15 @@
* {@linkplain ClassDesc} for the component type and then call the {@link #arrayType()}
* or {@link #arrayType(int)} methods.
*
* @apiNote In the future, if the Java language permits, {@linkplain ClassDesc}
* may become a {@code sealed} interface, which would prohibit subclassing except
* by explicitly permitted types. Non-platform classes should not implement
* {@linkplain ClassDesc} directly.
*
* @see ConstantDescs
*
* @since 12
*/
public interface ClassDesc
public sealed interface ClassDesc
extends ConstantDesc,
TypeDescriptor.OfField<ClassDesc> {
TypeDescriptor.OfField<ClassDesc>
permits PrimitiveClassDescImpl,
ReferenceClassDescImpl {

/**
* Returns a {@linkplain ClassDesc} for a class or interface type,
Expand Down
20 changes: 10 additions & 10 deletions src/java.base/share/classes/java/lang/constant/ConstantDesc.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,23 +68,23 @@
* {@link Object#equals(Object)} method. There is no guarantee that any
* particular entity will always be represented by the same descriptor instance.
*
* @apiNote In the future, if the Java language permits, {@linkplain ConstantDesc}
* may become a {@code sealed} interface, which would prohibit subclassing except by
* explicitly permitted types. Clients can assume that the following
* set of subtypes is exhaustive: {@link String}, {@link Integer},
* {@link Long}, {@link Float}, {@link Double}, {@link ClassDesc},
* {@link MethodTypeDesc}, {@link MethodHandleDesc}, and
* {@link DynamicConstantDesc}; this list may be extended to reflect future
* changes to the constant pool format as defined in JVMS 4.4.
*
* @see Constable
* @see ConstantDescs
*
* @jvms 4.4 The Constant Pool
*
* @since 12
*/
public interface ConstantDesc {
public sealed interface ConstantDesc
permits ClassDesc,
MethodHandleDesc,
MethodTypeDesc,
Double,
DynamicConstantDesc,
Float,
Integer,
Long,
String {
/**
* Resolves this descriptor reflectively, emulating the resolution behavior
* of JVMS 5.4.3 and the access control behavior of JVMS 5.4.4. The resolution
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,11 @@
* {@link MethodHandle}. A {@linkplain DirectMethodHandleDesc} corresponds to
* a {@code Constant_MethodHandle_info} entry in the constant pool of a classfile.
*
* @apiNote In the future, if the Java language permits, {@linkplain DirectMethodHandleDesc}
* may become a {@code sealed} interface, which would prohibit subclassing except
* by explicitly permitted types. Non-platform classes should not implement
* {@linkplain DirectMethodHandleDesc} directly.
*
* @since 12
*/
public interface DirectMethodHandleDesc extends MethodHandleDesc {
public sealed interface DirectMethodHandleDesc
extends MethodHandleDesc
permits DirectMethodHandleDescImpl {
/**
* Kinds of method handles that can be described with {@linkplain DirectMethodHandleDesc}.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
*
* @since 12
*/
public abstract class DynamicConstantDesc<T>
public abstract non-sealed class DynamicConstantDesc<T>
implements ConstantDesc {

private final DirectMethodHandleDesc bootstrapMethod;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,12 @@
* A <a href="package-summary.html#nominal">nominal descriptor</a> for a
* {@link MethodHandle} constant.
*
* @apiNote In the future, if the Java language permits, {@linkplain MethodHandleDesc}
* may become a {@code sealed} interface, which would prohibit subclassing except
* by explicitly permitted types. Non-platform classes should not implement
* {@linkplain MethodHandleDesc} directly.
*
* @since 12
*/
public interface MethodHandleDesc
extends ConstantDesc {
public sealed interface MethodHandleDesc
extends ConstantDesc
permits AsTypeMethodHandleDesc,
DirectMethodHandleDesc {

/**
* Creates a {@linkplain MethodHandleDesc} corresponding to an invocation of a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,12 @@
* A <a href="package-summary.html#nominal">nominal descriptor</a> for a
* {@linkplain MethodType} constant.
*
* @apiNote In the future, if the Java language permits, {@linkplain MethodTypeDesc}
* may become a {@code sealed} interface, which would prohibit subclassing except
* by explicitly permitted types. Non-platform classes should not implement
* {@linkplain MethodTypeDesc} directly.
*
* @since 12
*/
public interface MethodTypeDesc
public sealed interface MethodTypeDesc
extends ConstantDesc,
TypeDescriptor.OfMethod<ClassDesc, MethodTypeDesc> {
TypeDescriptor.OfMethod<ClassDesc, MethodTypeDesc>
permits MethodTypeDescImpl {
/**
* Creates a {@linkplain MethodTypeDesc} given a method descriptor string.
*
Expand Down

1 comment on commit 379376f

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.