< prev index next >

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

Print this page
@@ -23,10 +23,13 @@
   * questions.
   */
  
  package java.lang.invoke;
  
+ import jdk.internal.value.CheckedType;
+ import jdk.internal.value.NormalCheckedType;
+ import jdk.internal.value.NullRestrictedCheckedType;
  import sun.invoke.util.VerifyAccess;
  
  import java.lang.reflect.Constructor;
  import java.lang.reflect.Field;
  import java.lang.reflect.Member;

@@ -222,10 +225,18 @@
              assert type instanceof Class<?> : "bad field type " + type;
          }
          return (Class<?>) type;
      }
  
+     /**
+      * Return {@code CheckedType} representing the type of this member.
+      */
+     public CheckedType getCheckedFieldType() {
+         return isNullRestricted() ? NullRestrictedCheckedType.of(getFieldType())
+                                   : NormalCheckedType.of(getFieldType());
+     }
+ 
      /** Utility method to produce either the method type or field type of this member. */
      public Object getType() {
          return (isInvocable() ? getMethodType() : getFieldType());
      }
  

@@ -406,15 +417,16 @@
          return Modifier.isNative(flags);
      }
      // let the rest (native, volatile, transient, etc.) be tested via Modifier.isFoo
  
      // unofficial modifier flags, used by HotSpot:
-     static final int BRIDGE    = 0x00000040;
-     static final int VARARGS   = 0x00000080;
-     static final int SYNTHETIC = 0x00001000;
-     static final int ANNOTATION= 0x00002000;
-     static final int ENUM      = 0x00004000;
+     static final int BRIDGE      = 0x00000040;
+     static final int VARARGS     = 0x00000080;
+     static final int SYNTHETIC   = 0x00001000;
+     static final int ANNOTATION  = 0x00002000;
+     static final int ENUM        = 0x00004000;
+ 
      /** Utility method to query the modifier flags of this member; returns false if the member is not a method. */
      public boolean isBridge() {
          return allFlagsSet(IS_METHOD | BRIDGE);
      }
      /** Utility method to query the modifier flags of this member; returns false if the member is not a method. */

@@ -424,23 +436,29 @@
      /** Utility method to query the modifier flags of this member; returns false if the member is not a method. */
      public boolean isSynthetic() {
          return allFlagsSet(SYNTHETIC);
      }
  
-     static final String CONSTRUCTOR_NAME = "<init>";  // the ever-popular
+     /** Query whether this member is a flat field */
+     public boolean isFlat() { return (flags & MN_FLAT_FIELD) == MN_FLAT_FIELD; }
+ 
+     /** Query whether this member is a null-restricted field */
+     public boolean isNullRestricted() { return (flags & MN_NULL_RESTRICTED) == MN_NULL_RESTRICTED; }
+ 
+     static final String CONSTRUCTOR_NAME = "<init>";
  
      // modifiers exported by the JVM:
      static final int RECOGNIZED_MODIFIERS = 0xFFFF;
  
      // private flags, not part of RECOGNIZED_MODIFIERS:
      static final int
-             IS_METHOD        = MN_IS_METHOD,        // method (not constructor)
-             IS_CONSTRUCTOR   = MN_IS_CONSTRUCTOR,   // constructor
-             IS_FIELD         = MN_IS_FIELD,         // field
-             IS_TYPE          = MN_IS_TYPE,          // nested type
-             CALLER_SENSITIVE = MN_CALLER_SENSITIVE, // @CallerSensitive annotation detected
-             TRUSTED_FINAL    = MN_TRUSTED_FINAL;    // trusted final field
+             IS_METHOD             = MN_IS_METHOD,              // method (not constructor)
+             IS_CONSTRUCTOR        = MN_IS_CONSTRUCTOR,         // constructor
+             IS_FIELD              = MN_IS_FIELD,               // field
+             IS_TYPE               = MN_IS_TYPE,                // nested type
+             CALLER_SENSITIVE      = MN_CALLER_SENSITIVE,       // @CallerSensitive annotation detected
+             TRUSTED_FINAL         = MN_TRUSTED_FINAL;          // trusted final field
  
      static final int ALL_ACCESS = Modifier.PUBLIC | Modifier.PRIVATE | Modifier.PROTECTED;
      static final int ALL_KINDS = IS_METHOD | IS_CONSTRUCTOR | IS_FIELD | IS_TYPE;
      static final int IS_INVOCABLE = IS_METHOD | IS_CONSTRUCTOR;
  

@@ -753,11 +771,11 @@
       *  The declaring class may be supplied as null if this is to be a bare name and type.
       *  The last argument is optional, a boolean which requests REF_invokeSpecial.
       *  The resulting name will in an unresolved state.
       */
      public MemberName(Class<?> defClass, String name, MethodType type, byte refKind) {
-         int initFlags = (name != null && name.equals(CONSTRUCTOR_NAME) ? IS_CONSTRUCTOR : IS_METHOD);
+         int initFlags = CONSTRUCTOR_NAME.equals(name) ? IS_CONSTRUCTOR : IS_METHOD;
          init(defClass, name, type, flagsMods(initFlags, 0, refKind));
          initResolved(false);
      }
      /** Create a method, constructor, or field name from the given components:
       *  Reference kind, declaring class, name, type.
< prev index next >