< prev index next >

src/java.base/share/classes/java/lang/invoke/MemberName.java

Print this page

 391     }
 392     /** Utility method to query whether this member or its defining class is final. */
 393     public boolean canBeStaticallyBound() {
 394         return Modifier.isFinal(flags | clazz.getModifiers());
 395     }
 396     /** Utility method to query the modifier flags of this member. */
 397     public boolean isVolatile() {
 398         return Modifier.isVolatile(flags);
 399     }
 400     /** Utility method to query the modifier flags of this member. */
 401     public boolean isAbstract() {
 402         return Modifier.isAbstract(flags);
 403     }
 404     /** Utility method to query the modifier flags of this member. */
 405     public boolean isNative() {
 406         return Modifier.isNative(flags);
 407     }
 408     // let the rest (native, volatile, transient, etc.) be tested via Modifier.isFoo
 409 
 410     // unofficial modifier flags, used by HotSpot:
 411     static final int BRIDGE    = 0x00000040;
 412     static final int VARARGS   = 0x00000080;
 413     static final int SYNTHETIC = 0x00001000;
 414     static final int ANNOTATION= 0x00002000;
 415     static final int ENUM      = 0x00004000;

 416     /** Utility method to query the modifier flags of this member; returns false if the member is not a method. */
 417     public boolean isBridge() {
 418         return allFlagsSet(IS_METHOD | BRIDGE);
 419     }
 420     /** Utility method to query the modifier flags of this member; returns false if the member is not a method. */
 421     public boolean isVarargs() {
 422         return allFlagsSet(VARARGS) && isInvocable();
 423     }
 424     /** Utility method to query the modifier flags of this member; returns false if the member is not a method. */
 425     public boolean isSynthetic() {
 426         return allFlagsSet(SYNTHETIC);
 427     }
 428 
 429     static final String CONSTRUCTOR_NAME = "<init>";  // the ever-popular











 430 
 431     // modifiers exported by the JVM:
 432     static final int RECOGNIZED_MODIFIERS = 0xFFFF;
 433 
 434     // private flags, not part of RECOGNIZED_MODIFIERS:
 435     static final int
 436             IS_METHOD        = MN_IS_METHOD,        // method (not constructor)
 437             IS_CONSTRUCTOR   = MN_IS_CONSTRUCTOR,   // constructor
 438             IS_FIELD         = MN_IS_FIELD,         // field
 439             IS_TYPE          = MN_IS_TYPE,          // nested type
 440             CALLER_SENSITIVE = MN_CALLER_SENSITIVE, // @CallerSensitive annotation detected
 441             TRUSTED_FINAL    = MN_TRUSTED_FINAL;    // trusted final field
 442 
 443     static final int ALL_ACCESS = Modifier.PUBLIC | Modifier.PRIVATE | Modifier.PROTECTED;
 444     static final int ALL_KINDS = IS_METHOD | IS_CONSTRUCTOR | IS_FIELD | IS_TYPE;
 445     static final int IS_INVOCABLE = IS_METHOD | IS_CONSTRUCTOR;
 446 
 447     /** Utility method to query whether this member is a method or constructor. */
 448     public boolean isInvocable() {
 449         return anyFlagSet(IS_INVOCABLE);
 450     }
 451     /** Query whether this member is a method. */
 452     public boolean isMethod() {
 453         return allFlagsSet(IS_METHOD);
 454     }
 455     /** Query whether this member is a constructor. */
 456     public boolean isConstructor() {
 457         return allFlagsSet(IS_CONSTRUCTOR);
 458     }
 459     /** Query whether this member is a field. */
 460     public boolean isField() {
 461         return allFlagsSet(IS_FIELD);

 738     }
 739 
 740     // Construction from symbolic parts, for queries:
 741     /** Create a field or type name from the given components:
 742      *  Declaring class, name, type, reference kind.
 743      *  The declaring class may be supplied as null if this is to be a bare name and type.
 744      *  The resulting name will in an unresolved state.
 745      */
 746     public MemberName(Class<?> defClass, String name, Class<?> type, byte refKind) {
 747         init(defClass, name, type, flagsMods(IS_FIELD, 0, refKind));
 748         initResolved(false);
 749     }
 750     /** Create a method or constructor name from the given components:
 751      *  Declaring class, name, type, reference kind.
 752      *  It will be a constructor if and only if the name is {@code "<init>"}.
 753      *  The declaring class may be supplied as null if this is to be a bare name and type.
 754      *  The last argument is optional, a boolean which requests REF_invokeSpecial.
 755      *  The resulting name will in an unresolved state.
 756      */
 757     public MemberName(Class<?> defClass, String name, MethodType type, byte refKind) {
 758         int initFlags = (name != null && name.equals(CONSTRUCTOR_NAME) ? IS_CONSTRUCTOR : IS_METHOD);
 759         init(defClass, name, type, flagsMods(initFlags, 0, refKind));
 760         initResolved(false);
 761     }
 762     /** Create a method, constructor, or field name from the given components:
 763      *  Reference kind, declaring class, name, type.
 764      */
 765     public MemberName(byte refKind, Class<?> defClass, String name, Object type) {
 766         int kindFlags;
 767         if (MethodHandleNatives.refKindIsField(refKind)) {
 768             kindFlags = IS_FIELD;
 769             if (!(type instanceof Class))
 770                 throw newIllegalArgumentException("not a field type");
 771         } else if (MethodHandleNatives.refKindIsMethod(refKind)) {
 772             kindFlags = IS_METHOD;
 773             if (!(type instanceof MethodType))
 774                 throw newIllegalArgumentException("not a method type");
 775         } else if (refKind == REF_newInvokeSpecial) {
 776             kindFlags = IS_CONSTRUCTOR;
 777             if (!(type instanceof MethodType) ||
 778                 !CONSTRUCTOR_NAME.equals(name))

 391     }
 392     /** Utility method to query whether this member or its defining class is final. */
 393     public boolean canBeStaticallyBound() {
 394         return Modifier.isFinal(flags | clazz.getModifiers());
 395     }
 396     /** Utility method to query the modifier flags of this member. */
 397     public boolean isVolatile() {
 398         return Modifier.isVolatile(flags);
 399     }
 400     /** Utility method to query the modifier flags of this member. */
 401     public boolean isAbstract() {
 402         return Modifier.isAbstract(flags);
 403     }
 404     /** Utility method to query the modifier flags of this member. */
 405     public boolean isNative() {
 406         return Modifier.isNative(flags);
 407     }
 408     // let the rest (native, volatile, transient, etc.) be tested via Modifier.isFoo
 409 
 410     // unofficial modifier flags, used by HotSpot:
 411     static final int BRIDGE      = 0x00000040;
 412     static final int VARARGS     = 0x00000080;
 413     static final int SYNTHETIC   = 0x00001000;
 414     static final int ANNOTATION  = 0x00002000;
 415     static final int ENUM        = 0x00004000;
 416 
 417     /** Utility method to query the modifier flags of this member; returns false if the member is not a method. */
 418     public boolean isBridge() {
 419         return allFlagsSet(IS_METHOD | BRIDGE);
 420     }
 421     /** Utility method to query the modifier flags of this member; returns false if the member is not a method. */
 422     public boolean isVarargs() {
 423         return allFlagsSet(VARARGS) && isInvocable();
 424     }
 425     /** Utility method to query the modifier flags of this member; returns false if the member is not a method. */
 426     public boolean isSynthetic() {
 427         return allFlagsSet(SYNTHETIC);
 428     }
 429 
 430     /** Query whether this member is a flat field */
 431     public boolean isFlat() { return getLayout() != 0; }
 432 
 433     /** Query whether this member is a null-restricted field */
 434     public boolean isNullRestricted() { return (flags & MN_NULL_RESTRICTED) == MN_NULL_RESTRICTED; }
 435 
 436     /**
 437      * VM-internal layout code for this field, 0 if this field is not flat.
 438      */
 439     public int getLayout() { return (flags >>> MN_LAYOUT_SHIFT) & MN_LAYOUT_MASK; }
 440 
 441     static final String CONSTRUCTOR_NAME = "<init>";
 442 
 443     // modifiers exported by the JVM:
 444     static final int RECOGNIZED_MODIFIERS = 0xFFFF;
 445 
 446     // private flags, not part of RECOGNIZED_MODIFIERS:
 447     static final int
 448             IS_METHOD             = MN_IS_METHOD,              // method (not constructor)
 449             IS_CONSTRUCTOR        = MN_IS_CONSTRUCTOR,         // constructor
 450             IS_FIELD              = MN_IS_FIELD,               // field
 451             IS_TYPE               = MN_IS_TYPE,                // nested type
 452             CALLER_SENSITIVE      = MN_CALLER_SENSITIVE,       // @CallerSensitive annotation detected
 453             TRUSTED_FINAL         = MN_TRUSTED_FINAL;          // trusted final field
 454 
 455     static final int ALL_ACCESS = Modifier.PUBLIC | Modifier.PRIVATE | Modifier.PROTECTED;
 456     static final int ALL_KINDS = IS_METHOD | IS_CONSTRUCTOR | IS_FIELD | IS_TYPE;
 457     static final int IS_INVOCABLE = IS_METHOD | IS_CONSTRUCTOR;
 458 
 459     /** Utility method to query whether this member is a method or constructor. */
 460     public boolean isInvocable() {
 461         return anyFlagSet(IS_INVOCABLE);
 462     }
 463     /** Query whether this member is a method. */
 464     public boolean isMethod() {
 465         return allFlagsSet(IS_METHOD);
 466     }
 467     /** Query whether this member is a constructor. */
 468     public boolean isConstructor() {
 469         return allFlagsSet(IS_CONSTRUCTOR);
 470     }
 471     /** Query whether this member is a field. */
 472     public boolean isField() {
 473         return allFlagsSet(IS_FIELD);

 750     }
 751 
 752     // Construction from symbolic parts, for queries:
 753     /** Create a field or type name from the given components:
 754      *  Declaring class, name, type, reference kind.
 755      *  The declaring class may be supplied as null if this is to be a bare name and type.
 756      *  The resulting name will in an unresolved state.
 757      */
 758     public MemberName(Class<?> defClass, String name, Class<?> type, byte refKind) {
 759         init(defClass, name, type, flagsMods(IS_FIELD, 0, refKind));
 760         initResolved(false);
 761     }
 762     /** Create a method or constructor name from the given components:
 763      *  Declaring class, name, type, reference kind.
 764      *  It will be a constructor if and only if the name is {@code "<init>"}.
 765      *  The declaring class may be supplied as null if this is to be a bare name and type.
 766      *  The last argument is optional, a boolean which requests REF_invokeSpecial.
 767      *  The resulting name will in an unresolved state.
 768      */
 769     public MemberName(Class<?> defClass, String name, MethodType type, byte refKind) {
 770         int initFlags = CONSTRUCTOR_NAME.equals(name) ? IS_CONSTRUCTOR : IS_METHOD;
 771         init(defClass, name, type, flagsMods(initFlags, 0, refKind));
 772         initResolved(false);
 773     }
 774     /** Create a method, constructor, or field name from the given components:
 775      *  Reference kind, declaring class, name, type.
 776      */
 777     public MemberName(byte refKind, Class<?> defClass, String name, Object type) {
 778         int kindFlags;
 779         if (MethodHandleNatives.refKindIsField(refKind)) {
 780             kindFlags = IS_FIELD;
 781             if (!(type instanceof Class))
 782                 throw newIllegalArgumentException("not a field type");
 783         } else if (MethodHandleNatives.refKindIsMethod(refKind)) {
 784             kindFlags = IS_METHOD;
 785             if (!(type instanceof MethodType))
 786                 throw newIllegalArgumentException("not a method type");
 787         } else if (refKind == REF_newInvokeSpecial) {
 788             kindFlags = IS_CONSTRUCTOR;
 789             if (!(type instanceof MethodType) ||
 790                 !CONSTRUCTOR_NAME.equals(name))
< prev index next >