src/share/classes/com/sun/tools/javadoc/ModifierFilter.java

Wed, 27 Apr 2016 01:34:52 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:34:52 +0800
changeset 0
959103a6100f
child 2525
2eb010b6cb22
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/langtools/
changeset: 2573:53ca196be1ae
tag: jdk8u25-b17

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation. Oracle designates this
aoqi@0 8 * particular file as subject to the "Classpath" exception as provided
aoqi@0 9 * by Oracle in the LICENSE file that accompanied this code.
aoqi@0 10 *
aoqi@0 11 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 14 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 15 * accompanied this code).
aoqi@0 16 *
aoqi@0 17 * You should have received a copy of the GNU General Public License version
aoqi@0 18 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 20 *
aoqi@0 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 22 * or visit www.oracle.com if you need additional information or have any
aoqi@0 23 * questions.
aoqi@0 24 */
aoqi@0 25
aoqi@0 26 package com.sun.tools.javadoc;
aoqi@0 27
aoqi@0 28 import static com.sun.tools.javac.code.Flags.*;
aoqi@0 29
aoqi@0 30 /**
aoqi@0 31 * A class whose instances are filters over Modifier bits.
aoqi@0 32 * Filtering is done by returning boolean values.
aoqi@0 33 * Classes, methods and fields can be filtered, or filtering
aoqi@0 34 * can be done directly on modifier bits.
aoqi@0 35 *
aoqi@0 36 * <p><b>This is NOT part of any supported API.
aoqi@0 37 * If you write code that depends on this, you do so at your own risk.
aoqi@0 38 * This code and its internal interfaces are subject to change or
aoqi@0 39 * deletion without notice.</b>
aoqi@0 40 *
aoqi@0 41 * @see com.sun.tools.javac.code.Flags
aoqi@0 42 * @author Robert Field
aoqi@0 43 */
aoqi@0 44
aoqi@0 45 public class ModifierFilter {
aoqi@0 46
aoqi@0 47 /**
aoqi@0 48 * Package private access.
aoqi@0 49 * A "pseudo-" modifier bit that can be used in the
aoqi@0 50 * constructors of this class to specify package private
aoqi@0 51 * access. This is needed since there is no Modifier.PACKAGE.
aoqi@0 52 */
aoqi@0 53 public static final long PACKAGE = 0x8000000000000000L;
aoqi@0 54
aoqi@0 55 /**
aoqi@0 56 * All access modifiers.
aoqi@0 57 * A short-hand set of modifier bits that can be used in the
aoqi@0 58 * constructors of this class to specify all access modifiers,
aoqi@0 59 * Same as PRIVATE | PROTECTED | PUBLIC | PACKAGE.
aoqi@0 60 */
aoqi@0 61 public static final long ALL_ACCESS =
aoqi@0 62 PRIVATE | PROTECTED | PUBLIC | PACKAGE;
aoqi@0 63
aoqi@0 64 private long oneOf;
aoqi@0 65 private long must;
aoqi@0 66 private long cannot;
aoqi@0 67
aoqi@0 68 private static final int ACCESS_BITS = PRIVATE | PROTECTED | PUBLIC;
aoqi@0 69
aoqi@0 70 /**
aoqi@0 71 * Constructor - Specify a filter.
aoqi@0 72 *
aoqi@0 73 * @param oneOf If zero, everything passes the filter.
aoqi@0 74 * If non-zero, at least one of the specified
aoqi@0 75 * bits must be on in the modifier bits to
aoqi@0 76 * pass the filter.
aoqi@0 77 */
aoqi@0 78 public ModifierFilter(long oneOf) {
aoqi@0 79 this(oneOf, 0, 0);
aoqi@0 80 }
aoqi@0 81
aoqi@0 82 /**
aoqi@0 83 * Constructor - Specify a filter.
aoqi@0 84 * For example, the filter below will only pass synchronized
aoqi@0 85 * methods that are private or package private access and are
aoqi@0 86 * not native or static.
aoqi@0 87 * <pre>
aoqi@0 88 * ModifierFilter( Modifier.PRIVATE | ModifierFilter.PACKAGE,
aoqi@0 89 * Modifier.SYNCHRONIZED,
aoqi@0 90 * Modifier.NATIVE | Modifier.STATIC)
aoqi@0 91 * </pre><p>
aoqi@0 92 * Each of the three arguments must either be
aoqi@0 93 * zero or the or'ed combination of the bits specified in the
aoqi@0 94 * class Modifier or this class. During filtering, these values
aoqi@0 95 * are compared against the modifier bits as follows:
aoqi@0 96 *
aoqi@0 97 * @param oneOf If zero, ignore this argument.
aoqi@0 98 * If non-zero, at least one of the bits must be on.
aoqi@0 99 * @param must All bits specified must be on.
aoqi@0 100 * @param cannot None of the bits specified can be on.
aoqi@0 101 */
aoqi@0 102 public ModifierFilter(long oneOf, long must, long cannot) {
aoqi@0 103 this.oneOf = oneOf;
aoqi@0 104 this.must = must;
aoqi@0 105 this.cannot = cannot;
aoqi@0 106 }
aoqi@0 107
aoqi@0 108 /**
aoqi@0 109 * Filter on modifier bits.
aoqi@0 110 *
aoqi@0 111 * @param modifierBits Bits as specified in the Modifier class
aoqi@0 112 *
aoqi@0 113 * @return Whether the modifierBits pass this filter.
aoqi@0 114 */
aoqi@0 115 public boolean checkModifier(int modifierBits) {
aoqi@0 116 // Add in the "pseudo-" modifier bit PACKAGE, if needed
aoqi@0 117 long fmod = ((modifierBits & ACCESS_BITS) == 0) ?
aoqi@0 118 modifierBits | PACKAGE :
aoqi@0 119 modifierBits;
aoqi@0 120 return ((oneOf == 0) || ((oneOf & fmod) != 0)) &&
aoqi@0 121 ((must & fmod) == must) &&
aoqi@0 122 ((cannot & fmod) == 0);
aoqi@0 123 }
aoqi@0 124
aoqi@0 125 } // end ModifierFilter

mercurial