001: /*
002: * Copyright 2000-2003 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025:
026: package com.sun.tools.javadoc;
027:
028: import static com.sun.tools.javac.code.Flags.*;
029:
030: /**
031: * A class whose instances are filters over Modifier bits.
032: * Filtering is done by returning boolean values.
033: * Classes, methods and fields can be filtered, or filtering
034: * can be done directly on modifier bits.
035: * @see com.sun.tools.javac.code.Flags;
036: * @version 07/05/05
037: * @author Robert Field
038: */
039:
040: public class ModifierFilter {
041:
042: /**
043: * Package private access.
044: * A "pseudo-" modifier bit that can be used in the
045: * constructors of this class to specify package private
046: * access. This is needed since there is no Modifier.PACKAGE.
047: */
048: public static final long PACKAGE = 0x8000000000000000L;
049:
050: /**
051: * All access modifiers.
052: * A short-hand set of modifier bits that can be used in the
053: * constructors of this class to specify all access modifiers,
054: * Same as PRIVATE | PROTECTED | PUBLIC | PACKAGE.
055: */
056: public static final long ALL_ACCESS = PRIVATE | PROTECTED | PUBLIC
057: | PACKAGE;
058:
059: private long oneOf;
060: private long must;
061: private long cannot;
062:
063: private static final int ACCESS_BITS = PRIVATE | PROTECTED | PUBLIC;
064:
065: /**
066: * Constructor - Specify a filter.
067: *
068: * @param oneOf If zero, everything passes the filter.
069: * If non-zero, at least one of the specified
070: * bits must be on in the modifier bits to
071: * pass the filter.
072: */
073: public ModifierFilter(long oneOf) {
074: this (oneOf, 0, 0);
075: }
076:
077: /**
078: * Constructor - Specify a filter.
079: * For example, the filter below will only pass synchronized
080: * methods that are private or package private access and are
081: * not native or static.
082: * <pre>
083: * ModifierFilter( Modifier.PRIVATE | ModifierFilter.PACKAGE,
084: * Modifier.SYNCHRONIZED,
085: * Modifier.NATIVE | Modifier.STATIC)
086: * </pre><p>
087: * Each of the three arguments must either be
088: * zero or the or'ed combination of the bits specified in the
089: * class Modifier or this class. During filtering, these values
090: * are compared against the modifier bits as follows:
091: *
092: * @param oneOf If zero, ignore this argument.
093: * If non-zero, at least one of the bits must be on.
094: * @param must All bits specified must be on.
095: * @param cannot None of the bits specified can be on.
096: */
097: public ModifierFilter(long oneOf, long must, long cannot) {
098: this .oneOf = oneOf;
099: this .must = must;
100: this .cannot = cannot;
101: }
102:
103: /**
104: * Filter on modifier bits.
105: *
106: * @param modifierBits Bits as specified in the Modifier class
107: *
108: * @return Whether the modifierBits pass this filter.
109: */
110: public boolean checkModifier(int modifierBits) {
111: // Add in the "pseudo-" modifier bit PACKAGE, if needed
112: long fmod = ((modifierBits & ACCESS_BITS) == 0) ? modifierBits
113: | PACKAGE : modifierBits;
114: return ((oneOf == 0) || ((oneOf & fmod) != 0))
115: && ((must & fmod) == must) && ((cannot & fmod) == 0);
116: }
117:
118: } // end ModifierFilter
|