home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 November / Chip_1998-11_cd.bin / tema / Cafe / main.bin / Modifier.java < prev    next >
Text File  |  1997-05-20  |  5KB  |  176 lines

  1. /*
  2.  * @(#)Modifier.java    1.4 96/11/23
  3.  * 
  4.  * Copyright (c) 1995, 1996 Sun Microsystems, Inc. All Rights Reserved.
  5.  * 
  6.  * This software is the confidential and proprietary information of Sun
  7.  * Microsystems, Inc. ("Confidential Information").  You shall not
  8.  * disclose such Confidential Information and shall use it only in
  9.  * accordance with the terms of the license agreement you entered into
  10.  * with Sun.
  11.  * 
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
  13.  * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  14.  * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  15.  * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
  16.  * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
  17.  * THIS SOFTWARE OR ITS DERIVATIVES.
  18.  * 
  19.  * CopyrightVersion 1.1_beta
  20.  * 
  21.  */
  22.  
  23. package java.lang.reflect;
  24.  
  25. /**
  26.  * The Modifier class provides static methods and constants to decode
  27.  * class and member access modifiers.
  28.  *
  29.  * @see Class#getModifiers()
  30.  * @see Member#getModifiers()
  31.  *
  32.  * @author Nakul Saraiya
  33.  */
  34. public
  35. class Modifier {
  36.  
  37.     /**
  38.      * Return true if the specified integer includes the <tt>public</tt>
  39.      * modifier.
  40.      */
  41.     public static boolean isPublic(int mod) {
  42.     return (mod & PUBLIC) != 0;
  43.     }
  44.  
  45.     /**
  46.      * Return true if the specifier integer includes the <tt>private</tt>
  47.      * modifier.
  48.      */
  49.     public static boolean isPrivate(int mod) {
  50.     return (mod & PRIVATE) != 0;
  51.     }
  52.  
  53.     /**
  54.      * Return true if the specifier integer includes the <tt>protected</tt>
  55.      * modifier.
  56.      */
  57.     public static boolean isProtected(int mod) {
  58.     return (mod & PROTECTED) != 0;
  59.     }
  60.  
  61.     /**
  62.      * Return true if the specifier integer includes the <tt>static</tt>
  63.      * modifier.
  64.      */
  65.     public static boolean isStatic(int mod) {
  66.     return (mod & STATIC) != 0;
  67.     }
  68.  
  69.     /**
  70.      * Return true if the specifier integer includes the <tt>final</tt>
  71.      * modifier.
  72.      */
  73.     public static boolean isFinal(int mod) {
  74.     return (mod & FINAL) != 0;
  75.     }
  76.  
  77.     /**
  78.      * Return true if the specifier integer includes the <tt>final</tt>
  79.      * modifier.
  80.      */
  81.     public static boolean isSynchronized(int mod) {
  82.     return (mod & SYNCHRONIZED) != 0;
  83.     }
  84.  
  85.     /**
  86.      * Return true if the specifier integer includes the <tt>volatile</tt>
  87.      * modifier.
  88.      */
  89.     public static boolean isVolatile(int mod) {
  90.     return (mod & VOLATILE) != 0;
  91.     }
  92.  
  93.     /**
  94.      * Return true if the specifier integer includes the <tt>transient</tt>
  95.      * modifier.
  96.      */
  97.     public static boolean isTransient(int mod) {
  98.     return (mod & TRANSIENT) != 0;
  99.     }
  100.  
  101.     /**
  102.      * Return true if the specifier integer includes the <tt>native</tt>
  103.      * modifier.
  104.      */
  105.     public static boolean isNative(int mod) {
  106.     return (mod & NATIVE) != 0;
  107.     }
  108.  
  109.     /**
  110.      * Return true if the specifier integer includes the <tt>interface</tt>
  111.      * modifier.
  112.      */
  113.     public static boolean isInterface(int mod) {
  114.     return (mod & INTERFACE) != 0;
  115.     }
  116.  
  117.     /**
  118.      * Return true if the specifier integer includes the <tt>abstract</tt>
  119.      * modifier.
  120.      */
  121.     public static boolean isAbstract(int mod) {
  122.     return (mod & ABSTRACT) != 0;
  123.     }
  124.  
  125.     /**
  126.      * Return a string describing the access modifier flags in
  127.      * the specified modifier. For example:
  128.      * <pre>
  129.      *    public final synchronized
  130.      *    private transient volatile
  131.      * </pre>
  132.      * The modifier names are return in canonical order, as
  133.      * specified by <em>The Java Language Specification<em>.
  134.      */
  135.     public static String toString(int mod) {
  136.     StringBuffer sb = new StringBuffer();
  137.     int len;
  138.  
  139.     if ((mod & PUBLIC) != 0)    sb.append("public ");
  140.     if ((mod & PRIVATE) != 0)    sb.append("private ");
  141.     if ((mod & PROTECTED) != 0)    sb.append("protected ");
  142.  
  143.     /* Canonical order */
  144.     if ((mod & ABSTRACT) != 0)    sb.append("abstract ");
  145.     if ((mod & STATIC) != 0)    sb.append("static ");
  146.     if ((mod & FINAL) != 0)        sb.append("final ");
  147.     if ((mod & TRANSIENT) != 0)    sb.append("transient ");
  148.     if ((mod & VOLATILE) != 0)    sb.append("volatile ");
  149.     if ((mod & NATIVE) != 0)    sb.append("native ");
  150.     if ((mod & SYNCHRONIZED) != 0)    sb.append("synchronized ");
  151.  
  152.     if ((mod & INTERFACE) != 0)    sb.append("interface ");
  153.  
  154.     if ((len = sb.length()) > 0)    /* trim trailing space */
  155.         return sb.toString().substring(0, len-1);
  156.     return "";
  157.     }
  158.  
  159.     /*
  160.      * Access modifier flag constants from <em>The Java Virtual
  161.      * Machine Specification</em>, Table 4.1.
  162.      */
  163.     public static final int PUBLIC           = 0x00000001;
  164.     public static final int PRIVATE          = 0x00000002;
  165.     public static final int PROTECTED        = 0x00000004;
  166.     public static final int STATIC           = 0x00000008;
  167.     public static final int FINAL            = 0x00000010;
  168.     public static final int SYNCHRONIZED     = 0x00000020;
  169.     public static final int VOLATILE         = 0x00000040;
  170.     public static final int TRANSIENT        = 0x00000080;
  171.     public static final int NATIVE           = 0x00000100;
  172.     public static final int INTERFACE        = 0x00000200;
  173.     public static final int ABSTRACT         = 0x00000400;
  174.  
  175. }
  176.