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

Print this page




   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  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     /*


 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 "";
 256     }
 257 
 258     /*
 259      * Access modifier flag constants from tables 4.1, 4.4, 4.5, and 4.7 of
 260      * <cite>The Java&trade; Virtual Machine Specification</cite>
 261      */
 262 
 263     /**
 264      * The {@code int} value representing the {@code public}
 265      * modifier.
 266      */
 267     public static final int PUBLIC           = 0x00000001;
 268 
 269     /**
 270      * The {@code int} value representing the {@code private}
 271      * modifier.
 272      */
 273     public static final int PRIVATE          = 0x00000002;
 274 
 275     /**




   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package java.lang.reflect;
  27 
  28 import java.security.AccessController;
  29 import java.util.StringJoiner;
  30 import sun.reflect.LangReflectAccess;
  31 import sun.reflect.ReflectionFactory;
  32 
  33 /**
  34  * The Modifier class provides {@code static} methods and
  35  * constants to decode class and member access modifiers.  The sets of
  36  * modifiers are represented as integers with distinct bit positions
  37  * representing different modifiers.  The values for the constants
  38  * representing the modifiers are taken from the tables in sections 4.1, 4.4, 4.5, and 4.7 of
  39  * <cite>The Java&trade; Virtual Machine Specification</cite>.
  40  *
  41  * @see Class#getModifiers()
  42  * @see Member#getModifiers()
  43  *
  44  * @author Nakul Saraiya
  45  * @author Kenneth Russell
  46  */
  47 public class Modifier {
  48 
  49     /*


 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         StringJoiner sj = new StringJoiner(" ");

 237 
 238         if ((mod & PUBLIC) != 0)        sj.add("public");
 239         if ((mod & PROTECTED) != 0)     sj.add("protected");
 240         if ((mod & PRIVATE) != 0)       sj.add("private");
 241 
 242         /* Canonical order */
 243         if ((mod & ABSTRACT) != 0)      sj.add("abstract");
 244         if ((mod & STATIC) != 0)        sj.add("static");
 245         if ((mod & FINAL) != 0)         sj.add("final");
 246         if ((mod & TRANSIENT) != 0)     sj.add("transient");
 247         if ((mod & VOLATILE) != 0)      sj.add("volatile");
 248         if ((mod & SYNCHRONIZED) != 0)  sj.add("synchronized");
 249         if ((mod & NATIVE) != 0)        sj.add("native");
 250         if ((mod & STRICT) != 0)        sj.add("strictfp");
 251         if ((mod & INTERFACE) != 0)     sj.add("interface");
 252 
 253         return sj.toString();


 254     }
 255 
 256     /*
 257      * Access modifier flag constants from tables 4.1, 4.4, 4.5, and 4.7 of
 258      * <cite>The Java&trade; Virtual Machine Specification</cite>
 259      */
 260 
 261     /**
 262      * The {@code int} value representing the {@code public}
 263      * modifier.
 264      */
 265     public static final int PUBLIC           = 0x00000001;
 266 
 267     /**
 268      * The {@code int} value representing the {@code private}
 269      * modifier.
 270      */
 271     public static final int PRIVATE          = 0x00000002;
 272 
 273     /**