    001    /* Copyright 2000, 2001, Compaq Computer Corporation */
    002
    003    package javafe.ast;
    004
    005    import javafe.parser.ParseUtil;
    006
    007
    008    /**
    009
    010    <TT>Modifiers</TT> is a class defining the constants used
    011    to identify the different kinds of modifiers, and
    012    static methods to test for modifiers.
    013
    014    */
    015
    016    public class Modifiers {
    017
    018      public static final int NONE                  = 0X000;
    019      public static final int ACC_PUBLIC            = 0X001;
    020      public static final int ACC_PRIVATE           = 0X002;
    021      public static final int ACC_PROTECTED         = 0X004;
    022      public static final int ACC_STATIC            = 0X008;
    023      public static final int ACC_FINAL             = 0X010;
    024      public static final int ACC_SYNCHRONIZED      = 0X020;
    025      public static final int ACC_VOLATILE          = 0X040;
    026      public static final int ACC_TRANSIENT         = 0X080;
    027      public static final int ACC_NATIVE            = 0X100;
    028      public static final int ACC_ABSTRACT          = 0X400;
    029      public static final int ACC_STRICT            = 0X800;
    030
    031      public static final int SIZE_MODIFIER_BITSET  = 16;
    032
    033      public static final int ACCESS_MODIFIERS
    034        = ACC_PUBLIC | ACC_PROTECTED | ACC_PRIVATE;
    035
    036      // ----------------------------------------------------------------------
    037
    038      //@ ensures \result != null;
    039      public static String toString(int modifiers) {
    040        String s = "";
    041
    042        for (int i = 0; i < ParseUtil.modifierKeywords.length; i++) {
    043          if ((modifiers & (1<<i)) != 0) {
    044            s += name(i) + " ";
    045          }
    046        }
    047
    048        return s;
    049      }
    050
    051      /** Takes a modifier index (that is, the index of the bit that
    052        * the "modifiers" field represents) and returns the corresponding
    053        * Java keyword as a String.
    054        */
    055
    056      //@ requires 0 <= modifierIndex;
    057      //@ requires modifierIndex < ParseUtil.modifierKeywords.length;
    058      //@ ensures \result != null;
    059      public static String name(int modifierIndex) {
    060        int tag = ParseUtil.modifierKeywords[modifierIndex];
    061        // Note:  The following "TagConstants" is not the one in this package
    062        // (javafe.ast), but the one in javafe.parser.
    063        return javafe.parser.TagConstants.toString(tag);
    064      }
    065
    066      public static boolean isStrictFP(int modifiers) {
    067        return (modifiers & ACC_STRICT) != 0;
    068      }
    069
    070      public static boolean isAbstract(int modifiers) {
    071        return (modifiers & ACC_ABSTRACT) != 0;
    072      }
    073
    074      public static boolean isNative(int modifiers) {
    075        return (modifiers & ACC_NATIVE) != 0;
    076      }
    077
    078      public static boolean isFinal(int modifiers) {
    079        return (modifiers & ACC_FINAL) != 0;
    080      }
    081
    082      public static boolean isPrivate(int modifiers) {
    083        return (modifiers & ACC_PRIVATE) != 0;
    084      }
    085
    086      public static boolean isProtected(int modifiers) {
    087        return (modifiers & ACC_PROTECTED) != 0;
    088      }
    089
    090      public static boolean isPublic(int modifiers) {
    091        return (modifiers & ACC_PUBLIC) != 0;
    092      }
    093
    094      public static boolean isPackage(int modifiers) {
    095        return (modifiers & (ACC_PRIVATE | ACC_PROTECTED | ACC_PUBLIC)) == 0;
    096      }
    097
    098      public static boolean isVolatile(int modifiers) {
    099        return (modifiers & ACC_VOLATILE) != 0;
    100      }
    101
    102      public static boolean isStatic(int modifiers) {
    103        return (modifiers & ACC_STATIC) != 0;
    104      }
    105
    106      public static boolean isSynchronized(int modifiers) {
    107        return (modifiers & ACC_SYNCHRONIZED) != 0;
    108      }
    109
    110    }