001: /*
002: * Copyright (C) 2007 Júlio Vilmar Gesser.
003: *
004: * This file is part of Java 1.5 parser and Abstract Syntax Tree.
005: *
006: * Java 1.5 parser and Abstract Syntax Tree is free software: you can redistribute it and/or modify
007: * it under the terms of the GNU Lesser General Public License as published by
008: * the Free Software Foundation, either version 3 of the License, or
009: * (at your option) any later version.
010: *
011: * Java 1.5 parser and Abstract Syntax Tree is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: * GNU Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public License
017: * along with Java 1.5 parser and Abstract Syntax Tree. If not, see <http://www.gnu.org/licenses/>.
018: */
019: package japa.parser.ast.body;
020:
021: import japa.parser.ParseException;
022: import japa.parser.Token;
023:
024: /**
025: * Class to hold modifiers.
026: */
027: public final class ModifierSet {
028:
029: private ModifierSet() {
030: }
031:
032: /* Definitions of the bits in the modifiers field. */
033: public static final int PUBLIC = 0x0001;
034:
035: public static final int PROTECTED = 0x0002;
036:
037: public static final int PRIVATE = 0x0004;
038:
039: public static final int ABSTRACT = 0x0008;
040:
041: public static final int STATIC = 0x0010;
042:
043: public static final int FINAL = 0x0020;
044:
045: public static final int SYNCHRONIZED = 0x0040;
046:
047: public static final int NATIVE = 0x0080;
048:
049: public static final int TRANSIENT = 0x0100;
050:
051: public static final int VOLATILE = 0x0200;
052:
053: public static final int STRICTFP = 0x1000;
054:
055: /** A set of accessors that indicate whether the specified modifier
056: is in the set. */
057:
058: public static boolean isPublic(int modifiers) {
059: return (modifiers & PUBLIC) != 0;
060: }
061:
062: public static boolean isProtected(int modifiers) {
063: return (modifiers & PROTECTED) != 0;
064: }
065:
066: public static boolean isPrivate(int modifiers) {
067: return (modifiers & PRIVATE) != 0;
068: }
069:
070: public static boolean isStatic(int modifiers) {
071: return (modifiers & STATIC) != 0;
072: }
073:
074: public static boolean isAbstract(int modifiers) {
075: return (modifiers & ABSTRACT) != 0;
076: }
077:
078: public static boolean isFinal(int modifiers) {
079: return (modifiers & FINAL) != 0;
080: }
081:
082: public static boolean isNative(int modifiers) {
083: return (modifiers & NATIVE) != 0;
084: }
085:
086: public static boolean isStrictfp(int modifiers) {
087: return (modifiers & STRICTFP) != 0;
088: }
089:
090: public static boolean isSynchronized(int modifiers) {
091: return (modifiers & SYNCHRONIZED) != 0;
092: }
093:
094: public static boolean isTransient(int modifiers) {
095: return (modifiers & TRANSIENT) != 0;
096: }
097:
098: public static boolean isVolatile(int modifiers) {
099: return (modifiers & VOLATILE) != 0;
100: }
101:
102: /**
103: * Adds the given modifier.
104: */
105: public static int addModifier(int modifiers, int mod) {
106: return modifiers |= mod;
107: }
108:
109: /**
110: * Removes the given modifier.
111: */
112: public static int removeModifier(int modifiers, int mod) {
113: return modifiers &= ~mod;
114: }
115:
116: /**
117: * Adds the given modifier.
118: */
119: public static int addModifier(int modifiers, int mod, Token token)
120: throws ParseException {
121: if ((modifiers & mod) != 0) {
122: throw new ParseException(token, "Duplicated modifier");
123: }
124: return modifiers |= mod;
125: }
126: }
|