8304139: Add <init> and <clinit> method constants to ConstantDescs

Reviewed-by: mchung
This commit is contained in:
Chen Liang 2023-03-21 16:16:08 +00:00 committed by Mandy Chung
parent d6f20e2fbf
commit 019fcd819c
7 changed files with 56 additions and 21 deletions

View file

@ -27,6 +27,7 @@ package java.lang;
import java.lang.annotation.Annotation;
import java.lang.constant.ClassDesc;
import java.lang.constant.ConstantDescs;
import java.lang.invoke.TypeDescriptor;
import java.lang.invoke.MethodHandles;
import java.lang.module.ModuleReader;
@ -1524,9 +1525,9 @@ public final class Class<T> implements java.io.Serializable,
return enclosingClass == null || name == null || descriptor == null;
}
boolean isConstructor() { return !isPartial() && "<init>".equals(name); }
boolean isConstructor() { return !isPartial() && ConstantDescs.INIT_NAME.equals(name); }
boolean isMethod() { return !isPartial() && !isConstructor() && !"<clinit>".equals(name); }
boolean isMethod() { return !isPartial() && !isConstructor() && !ConstantDescs.CLASS_INIT_NAME.equals(name); }
Class<?> getEnclosingClass() { return enclosingClass; }
@ -2040,8 +2041,8 @@ public final class Class<T> implements java.io.Serializable,
* has length 0. (Note that a {@code Class} object which represents a class
* always has public methods, inherited from {@code Object}.)
*
* <p> The returned array never contains methods with names "{@code <init>}"
* or "{@code <clinit>}".
* <p> The returned array never contains methods with names {@value
* ConstantDescs#INIT_NAME} or {@value ConstantDescs#CLASS_INIT_NAME}.
*
* <p> The elements in the returned array are not sorted and are not in any
* particular order.
@ -2234,8 +2235,8 @@ public final class Class<T> implements java.io.Serializable,
* this interface or any of its superinterfaces, then this method does not
* find any method.
*
* <p> This method does not find any method with name "{@code <init>}" or
* "{@code <clinit>}".
* <p> This method does not find any method with name {@value
* ConstantDescs#INIT_NAME} or {@value ConstantDescs#CLASS_INIT_NAME}.
*
* <p> Generally, the method to be reflected is determined by the 4 step
* algorithm that follows.
@ -2293,7 +2294,8 @@ public final class Class<T> implements java.io.Serializable,
* @return the {@code Method} object that matches the specified
* {@code name} and {@code parameterTypes}
* @throws NoSuchMethodException if a matching method is not found
* or if the name is "&lt;init&gt;"or "&lt;clinit&gt;".
* or if the name is {@value ConstantDescs#INIT_NAME} or
* {@value ConstantDescs#CLASS_INIT_NAME}.
* @throws NullPointerException if {@code name} is {@code null}
* @throws SecurityException
* If a security manager, <i>s</i>, is present and
@ -2549,8 +2551,9 @@ public final class Class<T> implements java.io.Serializable,
* object for each such method.
*
* <p> If this {@code Class} object represents a class or interface that
* has a class initialization method {@code <clinit>}, then the returned
* array does <em>not</em> have a corresponding {@code Method} object.
* has a class initialization method {@value ConstantDescs#CLASS_INIT_NAME},
* then the returned array does <em>not</em> have a corresponding {@code
* Method} object.
*
* <p> If this {@code Class} object represents a class or interface with no
* declared methods, then the returned array has length 0.
@ -2721,7 +2724,8 @@ public final class Class<T> implements java.io.Serializable,
* parameter types is declared in a class, and one of these methods has a
* return type that is more specific than any of the others, that method is
* returned; otherwise one of the methods is chosen arbitrarily. If the
* name is "&lt;init&gt;"or "&lt;clinit&gt;" a {@code NoSuchMethodException}
* name is {@value ConstantDescs#INIT_NAME} or {@value
* ConstantDescs#CLASS_INIT_NAME} a {@code NoSuchMethodException}
* is raised.
*
* <p> If this {@code Class} object represents an array type, then this