src/share/classes/java/lang/reflect/Modifier.java

Print this page




  26 package java.lang.reflect;
  27 
  28 import java.security.AccessController;
  29 import sun.reflect.LangReflectAccess;
  30 import sun.reflect.ReflectionFactory;
  31 
  32 /**
  33  * The Modifier class provides {@code static} methods and
  34  * constants to decode class and member access modifiers.  The sets of
  35  * modifiers are represented as integers with distinct bit positions
  36  * representing different modifiers.  The values for the constants
  37  * representing the modifiers are taken from the tables in sections 4.1, 4.4, 4.5, and 4.7 of
  38  * <cite>The Java&trade; Virtual Machine Specification</cite>.
  39  *
  40  * @see Class#getModifiers()
  41  * @see Member#getModifiers()
  42  *
  43  * @author Nakul Saraiya
  44  * @author Kenneth Russell
  45  */
  46 public
  47 class Modifier {
  48 
  49     /*
  50      * Bootstrapping protocol between java.lang and java.lang.reflect
  51      *  packages
  52      */
  53     static {
  54         sun.reflect.ReflectionFactory factory =
  55             AccessController.doPrivileged(
  56                 new ReflectionFactory.GetReflectionFactoryAction());
  57         factory.setLangReflectAccess(new java.lang.reflect.ReflectAccess());
  58     }
  59 
  60     /**
  61      * Return {@code true} if the integer argument includes the
  62      * {@code public} modifier, {@code false} otherwise.
  63      *
  64      * @param   mod a set of modifiers
  65      * @return {@code true} if {@code mod} includes the
  66      * {@code public} modifier; {@code false} otherwise.
  67      */


 216      * volatile synchronized native strictfp
 217      * interface } </blockquote>
 218      * The {@code interface} modifier discussed in this class is
 219      * not a true modifier in the Java language and it appears after
 220      * all other modifiers listed by this method.  This method may
 221      * return a string of modifiers that are not valid modifiers of a
 222      * Java entity; in other words, no checking is done on the
 223      * possible validity of the combination of modifiers represented
 224      * by the input.
 225      *
 226      * Note that to perform such checking for a known kind of entity,
 227      * such as a constructor or method, first AND the argument of
 228      * {@code toString} with the appropriate mask from a method like
 229      * {@link #constructorModifiers} or {@link #methodModifiers}.
 230      *
 231      * @param   mod a set of modifiers
 232      * @return  a string representation of the set of modifiers
 233      * represented by {@code mod}
 234      */
 235     public static String toString(int mod) {
 236         StringBuffer sb = new StringBuffer();
 237         int len;
 238 
 239         if ((mod & PUBLIC) != 0)        sb.append("public ");
 240         if ((mod & PROTECTED) != 0)     sb.append("protected ");
 241         if ((mod & PRIVATE) != 0)       sb.append("private ");
 242 
 243         /* Canonical order */
 244         if ((mod & ABSTRACT) != 0)      sb.append("abstract ");
 245         if ((mod & STATIC) != 0)        sb.append("static ");
 246         if ((mod & FINAL) != 0)         sb.append("final ");
 247         if ((mod & TRANSIENT) != 0)     sb.append("transient ");
 248         if ((mod & VOLATILE) != 0)      sb.append("volatile ");
 249         if ((mod & SYNCHRONIZED) != 0)  sb.append("synchronized ");
 250         if ((mod & NATIVE) != 0)        sb.append("native ");
 251         if ((mod & STRICT) != 0)        sb.append("strictfp ");
 252         if ((mod & INTERFACE) != 0)     sb.append("interface ");
 253 
 254         if ((len = sb.length()) > 0)    /* trim trailing space */
 255             return sb.toString().substring(0, len-1);
 256         return "";




  26 package java.lang.reflect;
  27 
  28 import java.security.AccessController;
  29 import sun.reflect.LangReflectAccess;
  30 import sun.reflect.ReflectionFactory;
  31 
  32 /**
  33  * The Modifier class provides {@code static} methods and
  34  * constants to decode class and member access modifiers.  The sets of
  35  * modifiers are represented as integers with distinct bit positions
  36  * representing different modifiers.  The values for the constants
  37  * representing the modifiers are taken from the tables in sections 4.1, 4.4, 4.5, and 4.7 of
  38  * <cite>The Java&trade; Virtual Machine Specification</cite>.
  39  *
  40  * @see Class#getModifiers()
  41  * @see Member#getModifiers()
  42  *
  43  * @author Nakul Saraiya
  44  * @author Kenneth Russell
  45  */
  46 public class Modifier {

  47 
  48     /*
  49      * Bootstrapping protocol between java.lang and java.lang.reflect
  50      *  packages
  51      */
  52     static {
  53         sun.reflect.ReflectionFactory factory =
  54             AccessController.doPrivileged(
  55                 new ReflectionFactory.GetReflectionFactoryAction());
  56         factory.setLangReflectAccess(new java.lang.reflect.ReflectAccess());
  57     }
  58 
  59     /**
  60      * Return {@code true} if the integer argument includes the
  61      * {@code public} modifier, {@code false} otherwise.
  62      *
  63      * @param   mod a set of modifiers
  64      * @return {@code true} if {@code mod} includes the
  65      * {@code public} modifier; {@code false} otherwise.
  66      */


 215      * volatile synchronized native strictfp
 216      * interface } </blockquote>
 217      * The {@code interface} modifier discussed in this class is
 218      * not a true modifier in the Java language and it appears after
 219      * all other modifiers listed by this method.  This method may
 220      * return a string of modifiers that are not valid modifiers of a
 221      * Java entity; in other words, no checking is done on the
 222      * possible validity of the combination of modifiers represented
 223      * by the input.
 224      *
 225      * Note that to perform such checking for a known kind of entity,
 226      * such as a constructor or method, first AND the argument of
 227      * {@code toString} with the appropriate mask from a method like
 228      * {@link #constructorModifiers} or {@link #methodModifiers}.
 229      *
 230      * @param   mod a set of modifiers
 231      * @return  a string representation of the set of modifiers
 232      * represented by {@code mod}
 233      */
 234     public static String toString(int mod) {
 235         StringBuilder sb = new StringBuilder();
 236         int len;
 237 
 238         if ((mod & PUBLIC) != 0)        sb.append("public ");
 239         if ((mod & PROTECTED) != 0)     sb.append("protected ");
 240         if ((mod & PRIVATE) != 0)       sb.append("private ");
 241 
 242         /* Canonical order */
 243         if ((mod & ABSTRACT) != 0)      sb.append("abstract ");
 244         if ((mod & STATIC) != 0)        sb.append("static ");
 245         if ((mod & FINAL) != 0)         sb.append("final ");
 246         if ((mod & TRANSIENT) != 0)     sb.append("transient ");
 247         if ((mod & VOLATILE) != 0)      sb.append("volatile ");
 248         if ((mod & SYNCHRONIZED) != 0)  sb.append("synchronized ");
 249         if ((mod & NATIVE) != 0)        sb.append("native ");
 250         if ((mod & STRICT) != 0)        sb.append("strictfp ");
 251         if ((mod & INTERFACE) != 0)     sb.append("interface ");
 252 
 253         if ((len = sb.length()) > 0)    /* trim trailing space */
 254             return sb.toString().substring(0, len-1);
 255         return "";