< prev index next >

src/java.base/share/classes/java/lang/constant/ClassDesc.java

Print this page

        

@@ -22,10 +22,12 @@
  * or visit www.oracle.com if you need additional information or have any
  * questions.
  */
 package java.lang.constant;
 
+import jdk.internal.lang.annotation.Foldable;
+import java.lang.invoke.MethodHandles;
 import java.lang.invoke.TypeDescriptor;
 import java.util.stream.Stream;
 
 import sun.invoke.util.Wrapper;
 

@@ -58,10 +60,11 @@
  *
  * @since 12
  */
 public interface ClassDesc
         extends ConstantDesc,
+                Constable,
                 TypeDescriptor.OfField<ClassDesc> {
 
     /**
      * Returns a {@linkplain ClassDesc} for a class or interface type,
      * given the name of the class or interface, such as {@code "java.lang.String"}.

@@ -74,10 +77,11 @@
      * @return a {@linkplain ClassDesc} describing the desired class
      * @throws NullPointerException if any argument is {@code null}
      * @throws IllegalArgumentException if the name string is not in the
      * correct format
      */
+    @Foldable
     static ClassDesc of(String name) {
         ConstantUtils.validateBinaryClassName(requireNonNull(name));
         return ClassDesc.ofDescriptor("L" + binaryToInternal(name) + ";");
     }
 

@@ -93,10 +97,11 @@
      * @return a {@linkplain ClassDesc} describing the desired class
      * @throws NullPointerException if any argument is {@code null}
      * @throws IllegalArgumentException if the package name or class name are
      * not in the correct format
      */
+    @Foldable
     static ClassDesc of(String packageName, String className) {
         ConstantUtils.validateBinaryClassName(requireNonNull(packageName));
         if (packageName.isEmpty()) {
             return of(className);
         }

@@ -127,10 +132,11 @@
      * @throws IllegalArgumentException if the name string is not in the
      * correct format
      * @jvms 4.3.2 Field Descriptors
      * @jvms 4.4.1 The CONSTANT_Class_info Structure
      */
+    @Foldable
     static ClassDesc ofDescriptor(String descriptor) {
         requireNonNull(descriptor);
         if (descriptor.isEmpty()) {
             throw new IllegalArgumentException(
                     "not a valid reference type descriptor: " + descriptor);

@@ -152,10 +158,11 @@
      *
      * @return a {@linkplain ClassDesc} describing the array type
      * @throws IllegalStateException if the resulting {@linkplain ClassDesc} would have an array rank of greater than 255
      * @jvms 4.4.1 The CONSTANT_Class_info Structure
      */
+    @Foldable
     default ClassDesc arrayType() {
         int depth = ConstantUtils.arrayDepth(descriptorString());
         if (depth >= ConstantUtils.MAX_ARRAY_TYPE_DESC_DIMENSIONS) {
             throw new IllegalStateException(
                     "Cannot create an array type descriptor with more than " +

@@ -172,10 +179,11 @@
      * @return a {@linkplain ClassDesc} describing the array type
      * @throws IllegalArgumentException if the rank is less than or equal to zero or if the rank of the resulting array type is
      * greater than 255
      * @jvms 4.4.1 The CONSTANT_Class_info Structure
      */
+    @Foldable
     default ClassDesc arrayType(int rank) {
         int currentDepth = ConstantUtils.arrayDepth(descriptorString());
         if (rank <= 0 || currentDepth + rank > ConstantUtils.MAX_ARRAY_TYPE_DESC_DIMENSIONS)
             throw new IllegalArgumentException("rank: " + currentDepth + rank);
         return ClassDesc.ofDescriptor("[".repeat(rank) + descriptorString());

@@ -196,10 +204,11 @@
      * @throws NullPointerException if any argument is {@code null}
      * @throws IllegalStateException if this {@linkplain ClassDesc} does not
      * describe a class or interface type
      * @throws IllegalArgumentException if the nested class name is invalid
      */
+    @Foldable
     default ClassDesc nested(String nestedName) {
         validateMemberName(nestedName, false);
         if (!isClassOrInterface())
             throw new IllegalStateException("Outer class is not a class or interface type");
         return ClassDesc.ofDescriptor(dropLastChar(descriptorString()) + "$" + nestedName + ";");

@@ -216,10 +225,11 @@
      * @throws NullPointerException if any argument is {@code null}
      * @throws IllegalStateException if this {@linkplain ClassDesc} does not
      * describe a class or interface type
      * @throws IllegalArgumentException if the nested class name is invalid
      */
+    @Foldable
     default ClassDesc nested(String firstNestedName, String... moreNestedNames) {
         if (!isClassOrInterface())
             throw new IllegalStateException("Outer class is not a class or interface type");
         return moreNestedNames.length == 0
                ? nested(firstNestedName)

@@ -258,10 +268,11 @@
      * an array type, or {@code null} otherwise.
      *
      * @return a {@linkplain ClassDesc} describing the component type, or {@code null}
      * if this descriptor does not describe an array type
      */
+    @Foldable
     default ClassDesc componentType() {
         return isArray() ? ClassDesc.ofDescriptor(descriptorString().substring(1)) : null;
     }
 
     /**

@@ -312,10 +323,11 @@
      * Returns a field type descriptor string for this type
      *
      * @return the descriptor string
      * @jvms 4.3.2 Field Descriptors
      */
+    @Foldable
     String descriptorString();
 
     /**
      * Compare the specified object with this descriptor for equality.  Returns
      * {@code true} if and only if the specified object is also a
< prev index next >