mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 06:45:07 +02:00
8266670: Better modeling of access flags in core reflection
Reviewed-by: mchung, rriggs, asotona
This commit is contained in:
parent
a5c25d8837
commit
de7467146f
14 changed files with 1480 additions and 16 deletions
|
@ -36,6 +36,7 @@ import java.io.InputStream;
|
|||
import java.io.ObjectStreamField;
|
||||
import java.lang.reflect.AnnotatedElement;
|
||||
import java.lang.reflect.AnnotatedType;
|
||||
import java.lang.reflect.AccessFlag;
|
||||
import java.lang.reflect.Array;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Executable;
|
||||
|
@ -1312,6 +1313,7 @@ public final class Class<T> implements java.io.Serializable,
|
|||
*
|
||||
* @return the {@code int} representing the modifiers for this class
|
||||
* @see java.lang.reflect.Modifier
|
||||
* @see #accessFlags()
|
||||
* @see <a
|
||||
* href="{@docRoot}/java.base/java/lang/reflect/package-summary.html#LanguageJvmModel">Java
|
||||
* programming language and JVM modeling in core reflection</a>
|
||||
|
@ -1322,6 +1324,39 @@ public final class Class<T> implements java.io.Serializable,
|
|||
@IntrinsicCandidate
|
||||
public native int getModifiers();
|
||||
|
||||
/**
|
||||
* {@return an unmodifiable set of the {@linkplain AccessFlag access
|
||||
* flags} for this class, possibly empty}
|
||||
*
|
||||
* <p> If the underlying class is an array class, then its
|
||||
* {@code PUBLIC}, {@code PRIVATE} and {@code PROTECTED}
|
||||
* access flags are the same as those of its component type. If this
|
||||
* {@code Class} object represents a primitive type or void, the
|
||||
* {@code PUBLIC} access flag is present, and the
|
||||
* {@code PROTECTED} and {@code PRIVATE} access flags are always
|
||||
* absent. If this {@code Class} object represents an array class, a
|
||||
* primitive type or void, then the {@code FINAL} access flag is always
|
||||
* present and the interface access flag is always
|
||||
* absent. The values of its other access flags are not determined
|
||||
* by this specification.
|
||||
*
|
||||
* @see #getModifiers()
|
||||
* @jvms 4.1 The ClassFile Structure
|
||||
* @jvms 4.7.6 The InnerClasses Attribute
|
||||
* @since 20
|
||||
*/
|
||||
public Set<AccessFlag> accessFlags() {
|
||||
// This likely needs some refinement. Exploration of hidden
|
||||
// classes, array classes. Location.CLASS allows SUPER and
|
||||
// AccessFlag.MODULE which INNER_CLASS forbids. INNER_CLASS
|
||||
// allows PRIVATE, PROTECTED, and STATIC, which are not
|
||||
// allowed on Location.CLASS.
|
||||
return AccessFlag.maskToAccessFlags(getModifiers(),
|
||||
(isMemberClass() || isLocalClass() ||
|
||||
isAnonymousClass() || isArray()) ?
|
||||
AccessFlag.Location.INNER_CLASS :
|
||||
AccessFlag.Location.CLASS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the signers of this class.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue