< prev index next >

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

Print this page

        

*** 22,31 **** --- 22,33 ---- * 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,67 **** --- 60,70 ---- * * @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,83 **** --- 77,87 ---- * @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,102 **** --- 97,107 ---- * @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,136 **** --- 132,142 ---- * @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,161 **** --- 158,168 ---- * * @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,181 **** --- 179,189 ---- * @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,205 **** --- 204,214 ---- * @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,225 **** --- 225,235 ---- * @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,267 **** --- 268,278 ---- * 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,321 **** --- 323,333 ---- * 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 >