< prev index next >
src/java.base/share/classes/java/lang/constant/ClassDesc.java
Print this page
rev 54588 : 8212975: ClassDesc should have a full name method
Reviewed-by: vromero
*** 25,38 ****
package java.lang.constant;
import java.lang.invoke.TypeDescriptor;
import java.util.stream.Stream;
- import sun.invoke.util.Wrapper;
-
import static java.lang.constant.ConstantUtils.binaryToInternal;
import static java.lang.constant.ConstantUtils.dropLastChar;
import static java.lang.constant.ConstantUtils.internalToBinary;
import static java.lang.constant.ConstantUtils.validateMemberName;
import static java.util.Objects.requireNonNull;
import static java.util.stream.Collectors.joining;
--- 25,37 ----
package java.lang.constant;
import java.lang.invoke.TypeDescriptor;
import java.util.stream.Stream;
import static java.lang.constant.ConstantUtils.binaryToInternal;
import static java.lang.constant.ConstantUtils.dropLastChar;
+ import static java.lang.constant.ConstantUtils.getClassDisplayName;
import static java.lang.constant.ConstantUtils.internalToBinary;
import static java.lang.constant.ConstantUtils.validateMemberName;
import static java.util.Objects.requireNonNull;
import static java.util.stream.Collectors.joining;
*** 289,313 ****
* suffixed with the appropriate number of {@code []} pairs for array types.
*
* @return the human-readable name
*/
default String displayName() {
! if (isPrimitive())
! return Wrapper.forBasicType(descriptorString().charAt(0)).primitiveSimpleName();
! else if (isClassOrInterface()) {
! return descriptorString().substring(Math.max(1, descriptorString().lastIndexOf('/') + 1),
! descriptorString().length() - 1);
! }
! else if (isArray()) {
! int depth = ConstantUtils.arrayDepth(descriptorString());
! ClassDesc c = this;
! for (int i=0; i<depth; i++)
! c = c.componentType();
! return c.displayName() + "[]".repeat(depth);
}
! else
! throw new IllegalStateException(descriptorString());
}
/**
* Returns a field type descriptor string for this type
*
--- 288,316 ----
* suffixed with the appropriate number of {@code []} pairs for array types.
*
* @return the human-readable name
*/
default String displayName() {
! return getClassDisplayName(this, false);
}
!
! /**
! * Returns a fully qualified human-readable name for the type described
! * by this descriptor.
! *
! * @implSpec
! * <p>The default implementation returns the name
! * (e.g., {@code int}) for primitive types, the qualified class name
! * for class or interface types (e.g., {@code java.lang.String}),
! * or the name of the component type with the appropriate
! * number of {@code []} pairs for array types
! * (e.g., {@code java.lang.String[]}).
! *
! * @return the fully qualified human-readable name
! */
! default String displayFullName() {
! return getClassDisplayName(this, true);
}
/**
* Returns a field type descriptor string for this type
*
< prev index next >