< prev index next >

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

Print this page

 372     /** Utility method to query the modifier flags of this member. */
 373     public boolean isStatic() {
 374         return Modifier.isStatic(flags);
 375     }
 376     /** Utility method to query the modifier flags of this member. */
 377     public boolean isPublic() {
 378         return Modifier.isPublic(flags);
 379     }
 380     /** Utility method to query the modifier flags of this member. */
 381     public boolean isPrivate() {
 382         return Modifier.isPrivate(flags);
 383     }
 384     /** Utility method to query the modifier flags of this member. */
 385     public boolean isProtected() {
 386         return Modifier.isProtected(flags);
 387     }
 388     /** Utility method to query the modifier flags of this member. */
 389     public boolean isFinal() {
 390         return Modifier.isFinal(flags);
 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))

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

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