aoqi@0: /* aoqi@0: * Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. Oracle designates this aoqi@0: * particular file as subject to the "Classpath" exception as provided aoqi@0: * by Oracle in the LICENSE file that accompanied this code. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: */ aoqi@0: aoqi@0: package com.sun.tools.javadoc; aoqi@0: aoqi@0: import static com.sun.tools.javac.code.Flags.*; aoqi@0: aoqi@0: /** aoqi@0: * A class whose instances are filters over Modifier bits. aoqi@0: * Filtering is done by returning boolean values. aoqi@0: * Classes, methods and fields can be filtered, or filtering aoqi@0: * can be done directly on modifier bits. aoqi@0: * aoqi@0: *

This is NOT part of any supported API. aoqi@0: * If you write code that depends on this, you do so at your own risk. aoqi@0: * This code and its internal interfaces are subject to change or aoqi@0: * deletion without notice. aoqi@0: * aoqi@0: * @see com.sun.tools.javac.code.Flags aoqi@0: * @author Robert Field aoqi@0: */ aoqi@0: aoqi@0: public class ModifierFilter { aoqi@0: aoqi@0: /** aoqi@0: * Package private access. aoqi@0: * A "pseudo-" modifier bit that can be used in the aoqi@0: * constructors of this class to specify package private aoqi@0: * access. This is needed since there is no Modifier.PACKAGE. aoqi@0: */ aoqi@0: public static final long PACKAGE = 0x8000000000000000L; aoqi@0: aoqi@0: /** aoqi@0: * All access modifiers. aoqi@0: * A short-hand set of modifier bits that can be used in the aoqi@0: * constructors of this class to specify all access modifiers, aoqi@0: * Same as PRIVATE | PROTECTED | PUBLIC | PACKAGE. aoqi@0: */ aoqi@0: public static final long ALL_ACCESS = aoqi@0: PRIVATE | PROTECTED | PUBLIC | PACKAGE; aoqi@0: aoqi@0: private long oneOf; aoqi@0: private long must; aoqi@0: private long cannot; aoqi@0: aoqi@0: private static final int ACCESS_BITS = PRIVATE | PROTECTED | PUBLIC; aoqi@0: aoqi@0: /** aoqi@0: * Constructor - Specify a filter. aoqi@0: * aoqi@0: * @param oneOf If zero, everything passes the filter. aoqi@0: * If non-zero, at least one of the specified aoqi@0: * bits must be on in the modifier bits to aoqi@0: * pass the filter. aoqi@0: */ aoqi@0: public ModifierFilter(long oneOf) { aoqi@0: this(oneOf, 0, 0); aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Constructor - Specify a filter. aoqi@0: * For example, the filter below will only pass synchronized aoqi@0: * methods that are private or package private access and are aoqi@0: * not native or static. aoqi@0: *

aoqi@0:      * ModifierFilter(  Modifier.PRIVATE | ModifierFilter.PACKAGE,
aoqi@0:      *                  Modifier.SYNCHRONIZED,
aoqi@0:      *                  Modifier.NATIVE | Modifier.STATIC)
aoqi@0:      * 

aoqi@0: * Each of the three arguments must either be aoqi@0: * zero or the or'ed combination of the bits specified in the aoqi@0: * class Modifier or this class. During filtering, these values aoqi@0: * are compared against the modifier bits as follows: aoqi@0: * aoqi@0: * @param oneOf If zero, ignore this argument. aoqi@0: * If non-zero, at least one of the bits must be on. aoqi@0: * @param must All bits specified must be on. aoqi@0: * @param cannot None of the bits specified can be on. aoqi@0: */ aoqi@0: public ModifierFilter(long oneOf, long must, long cannot) { aoqi@0: this.oneOf = oneOf; aoqi@0: this.must = must; aoqi@0: this.cannot = cannot; aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Filter on modifier bits. aoqi@0: * aoqi@0: * @param modifierBits Bits as specified in the Modifier class aoqi@0: * aoqi@0: * @return Whether the modifierBits pass this filter. aoqi@0: */ aoqi@0: public boolean checkModifier(int modifierBits) { aoqi@0: // Add in the "pseudo-" modifier bit PACKAGE, if needed aoqi@0: long fmod = ((modifierBits & ACCESS_BITS) == 0) ? aoqi@0: modifierBits | PACKAGE : aoqi@0: modifierBits; aoqi@0: return ((oneOf == 0) || ((oneOf & fmod) != 0)) && aoqi@0: ((must & fmod) == must) && aoqi@0: ((cannot & fmod) == 0); aoqi@0: } aoqi@0: aoqi@0: } // end ModifierFilter