001: /*
002: * Janino - An embedded Java[TM] compiler
003: *
004: * Copyright (c) 2006, Arno Unkrig
005: * All rights reserved.
006: *
007: * Redistribution and use in source and binary forms, with or without
008: * modification, are permitted provided that the following conditions
009: * are met:
010: *
011: * 1. Redistributions of source code must retain the above copyright
012: * notice, this list of conditions and the following disclaimer.
013: * 2. Redistributions in binary form must reproduce the above
014: * copyright notice, this list of conditions and the following
015: * disclaimer in the documentation and/or other materials
016: * provided with the distribution.
017: * 3. The name of the author may not be used to endorse or promote
018: * products derived from this software without specific prior
019: * written permission.
020: *
021: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
022: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
023: * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
024: * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
025: * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
026: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
027: * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
028: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
029: * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
030: * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
031: * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
032: */
033:
034: package org.codehaus.janino;
035:
036: /**
037: * This class defines constants and convenience methods for the handling of
038: * modifiers as defined by the JVM.
039: */
040: public class Mod {
041: private Mod() {
042: } // Don't instantiate me!
043:
044: public final static short NONE = 0x0000;
045:
046: public final static short PUBLIC = 0x0001;
047: public final static short PRIVATE = 0x0002;
048: public final static short PROTECTED = 0x0004;
049: public final static short PACKAGE = 0x0000;
050: public final static short PPP = 0x0007;
051:
052: public static boolean isPublicAccess(short sh) {
053: return (sh & Mod.PPP) == Mod.PUBLIC;
054: }
055:
056: public static boolean isPrivateAccess(short sh) {
057: return (sh & Mod.PPP) == Mod.PRIVATE;
058: }
059:
060: public static boolean isProtectedAccess(short sh) {
061: return (sh & Mod.PPP) == Mod.PROTECTED;
062: }
063:
064: public static boolean isPackageAccess(short sh) {
065: return (sh & Mod.PPP) == Mod.PACKAGE;
066: }
067:
068: public static short changeAccess(short sh, short newAccess) {
069: return (short) ((sh & ~Mod.PPP) | newAccess);
070: }
071:
072: public final static short STATIC = 0x0008;
073: public final static short FINAL = 0x0010;
074: public final static short SUPER = 0x0020;
075: public final static short SYNCHRONIZED = 0x0020;
076: public final static short VOLATILE = 0x0040;
077: public final static short TRANSIENT = 0x0080;
078: public final static short NATIVE = 0x0100;
079: public final static short INTERFACE = 0x0200;
080: public final static short ABSTRACT = 0x0400;
081: public final static short STRICTFP = 0x0800;
082:
083: // Poorly documented JDK 1.5 modifiers:
084: public final static short SYNTHETIC = 0x1000;
085: public final static short ANNOTATION = 0x2000;
086: public final static short ENUM = 0x4000;
087:
088: public static String shortToString(short sh) {
089: String res = "";
090: for (int i = 0; i < Mod.mappings.length; i += 2) {
091: if ((sh & ((Short) Mod.mappings[i + 1]).shortValue()) == 0)
092: continue;
093: if (res.length() > 0)
094: res += ' ';
095: res += (String) Mod.mappings[i];
096: }
097: return res;
098: }
099:
100: private final static Object[] mappings = { "public",
101: new Short(Mod.PUBLIC), "private", new Short(Mod.PRIVATE),
102: "protected",
103: new Short(Mod.PROTECTED),
104: "static",
105: new Short(Mod.STATIC),
106: "final",
107: new Short(Mod.FINAL),
108: // "super", new Short(Mod.SUPER),
109: "synchronized", new Short(Mod.SYNCHRONIZED), "volatile",
110: new Short(Mod.VOLATILE), "transient",
111: new Short(Mod.TRANSIENT), "native", new Short(Mod.NATIVE),
112: "interface", new Short(Mod.INTERFACE), "abstract",
113: new Short(Mod.ABSTRACT), "strictfp",
114: new Short(Mod.STRICTFP), };
115: }
|