jdk/src/share/classes/java/lang/reflect/Modifier.java
author martin
Mon, 10 Mar 2008 15:07:09 -0700
changeset 51 6fe31bc95bbc
parent 2 90ce3da70b43
child 715 f16baef3a20e
permissions -rw-r--r--
6600143: Remove another 450 unnecessary casts Reviewed-by: alanb, iris, lmalvent, bristor, peterjones, darcy, wetmore
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 1996-2004 Sun Microsystems, Inc.  All Rights Reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package java.lang.reflect;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.security.AccessController;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import sun.reflect.LangReflectAccess;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import sun.reflect.ReflectionFactory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * The Modifier class provides {@code static} methods and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * constants to decode class and member access modifiers.  The sets of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * modifiers are represented as integers with distinct bit positions
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * representing different modifiers.  The values for the constants
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * representing the modifiers are taken from <a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * href="http://java.sun.com/docs/books/vmspec/2nd-edition/html/VMSpecTOC.doc.html"><i>The
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * Java</i><sup><small>TM</small></sup> <i>Virtual Machine Specification, Second
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * edition</i></a> tables
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * <a href="http://java.sun.com/docs/books/vmspec/2nd-edition/html/ClassFile.doc.html#75734">4.1</a>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * <a href="http://java.sun.com/docs/books/vmspec/2nd-edition/html/ClassFile.doc.html#88358">4.4</a>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * <a href="http://java.sun.com/docs/books/vmspec/2nd-edition/html/ClassFile.doc.html#75568">4.5</a>, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * <a href="http://java.sun.com/docs/books/vmspec/2nd-edition/html/ClassFile.doc.html#88478">4.7</a>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * @see Class#getModifiers()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * @see Member#getModifiers()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * @author Nakul Saraiya
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * @author Kenneth Russell
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
public
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
class Modifier {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
     * Bootstrapping protocol between java.lang and java.lang.reflect
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
     *  packages
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        sun.reflect.ReflectionFactory factory =
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
    61
            AccessController.doPrivileged(
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
    62
                new ReflectionFactory.GetReflectionFactoryAction());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        factory.setLangReflectAccess(new java.lang.reflect.ReflectAccess());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     * Return {@code true} if the integer argument includes the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     * {@code public} modifier, {@code false} otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     * @param   mod a set of modifiers
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * @return {@code true} if {@code mod} includes the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     * {@code public} modifier; {@code false} otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    public static boolean isPublic(int mod) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        return (mod & PUBLIC) != 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * Return {@code true} if the integer argument includes the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * {@code private} modifier, {@code false} otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * @param   mod a set of modifiers
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * @return {@code true} if {@code mod} includes the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * {@code private} modifier; {@code false} otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    public static boolean isPrivate(int mod) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        return (mod & PRIVATE) != 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * Return {@code true} if the integer argument includes the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * {@code protected} modifier, {@code false} otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * @param   mod a set of modifiers
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * @return {@code true} if {@code mod} includes the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * {@code protected} modifier; {@code false} otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    public static boolean isProtected(int mod) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        return (mod & PROTECTED) != 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * Return {@code true} if the integer argument includes the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * {@code static} modifier, {@code false} otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * @param   mod a set of modifiers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * @return {@code true} if {@code mod} includes the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * {@code static} modifier; {@code false} otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    public static boolean isStatic(int mod) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        return (mod & STATIC) != 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * Return {@code true} if the integer argument includes the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * {@code final} modifier, {@code false} otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * @param   mod a set of modifiers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * @return {@code true} if {@code mod} includes the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * {@code final} modifier; {@code false} otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    public static boolean isFinal(int mod) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        return (mod & FINAL) != 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * Return {@code true} if the integer argument includes the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * {@code synchronized} modifier, {@code false} otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * @param   mod a set of modifiers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * @return {@code true} if {@code mod} includes the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * {@code synchronized} modifier; {@code false} otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    public static boolean isSynchronized(int mod) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        return (mod & SYNCHRONIZED) != 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * Return {@code true} if the integer argument includes the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * {@code volatile} modifier, {@code false} otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * @param   mod a set of modifiers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * @return {@code true} if {@code mod} includes the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * {@code volatile} modifier; {@code false} otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    public static boolean isVolatile(int mod) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        return (mod & VOLATILE) != 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * Return {@code true} if the integer argument includes the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * {@code transient} modifier, {@code false} otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * @param   mod a set of modifiers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * @return {@code true} if {@code mod} includes the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * {@code transient} modifier; {@code false} otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    public static boolean isTransient(int mod) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        return (mod & TRANSIENT) != 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * Return {@code true} if the integer argument includes the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * {@code native} modifier, {@code false} otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * @param   mod a set of modifiers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * @return {@code true} if {@code mod} includes the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * {@code native} modifier; {@code false} otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    public static boolean isNative(int mod) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        return (mod & NATIVE) != 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * Return {@code true} if the integer argument includes the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * {@code interface} modifier, {@code false} otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * @param   mod a set of modifiers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * @return {@code true} if {@code mod} includes the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * {@code interface} modifier; {@code false} otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    public static boolean isInterface(int mod) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        return (mod & INTERFACE) != 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * Return {@code true} if the integer argument includes the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * {@code abstract} modifier, {@code false} otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * @param   mod a set of modifiers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * @return {@code true} if {@code mod} includes the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * {@code abstract} modifier; {@code false} otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    public static boolean isAbstract(int mod) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        return (mod & ABSTRACT) != 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * Return {@code true} if the integer argument includes the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * {@code strictfp} modifier, {@code false} otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * @param   mod a set of modifiers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * @return {@code true} if {@code mod} includes the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * {@code strictfp} modifier; {@code false} otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    public static boolean isStrict(int mod) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        return (mod & STRICT) != 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * Return a string describing the access modifier flags in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * the specified modifier. For example:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * <blockquote><pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     *    public final synchronized strictfp
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * </pre></blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * The modifier names are returned in an order consistent with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * suggested modifier orderings given in <a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * href="http://java.sun.com/docs/books/jls/second_edition/html/j.title.doc.html"><em>The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * Java Language Specification, Second Edition</em></a> sections
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * <a href="http://java.sun.com/docs/books/jls/second_edition/html/classes.doc.html#21613">&sect;8.1.1</a>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * <a href="http://java.sun.com/docs/books/jls/second_edition/html/classes.doc.html#78091">&sect;8.3.1</a>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * <a href="http://java.sun.com/docs/books/jls/second_edition/html/classes.doc.html#78188">&sect;8.4.3</a>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * <a href="http://java.sun.com/docs/books/jls/second_edition/html/classes.doc.html#42018">&sect;8.8.3</a>, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * <a href="http://java.sun.com/docs/books/jls/second_edition/html/interfaces.doc.html#235947">&sect;9.1.1</a>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * The full modifier ordering used by this method is:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * <blockquote> {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * public protected private abstract static final transient
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * volatile synchronized native strictfp
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * interface } </blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * The {@code interface} modifier discussed in this class is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * not a true modifier in the Java language and it appears after
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * all other modifiers listed by this method.  This method may
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * return a string of modifiers that are not valid modifiers of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * Java entity; in other words, no checking is done on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * possible validity of the combination of modifiers represented
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * by the input.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * @param   mod a set of modifiers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * @return  a string representation of the set of modifiers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * represented by {@code mod}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    public static String toString(int mod) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        StringBuffer sb = new StringBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        int len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        if ((mod & PUBLIC) != 0)        sb.append("public ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        if ((mod & PROTECTED) != 0)     sb.append("protected ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        if ((mod & PRIVATE) != 0)       sb.append("private ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        /* Canonical order */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        if ((mod & ABSTRACT) != 0)      sb.append("abstract ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        if ((mod & STATIC) != 0)        sb.append("static ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        if ((mod & FINAL) != 0)         sb.append("final ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        if ((mod & TRANSIENT) != 0)     sb.append("transient ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        if ((mod & VOLATILE) != 0)      sb.append("volatile ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        if ((mod & SYNCHRONIZED) != 0)  sb.append("synchronized ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        if ((mod & NATIVE) != 0)        sb.append("native ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        if ((mod & STRICT) != 0)        sb.append("strictfp ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        if ((mod & INTERFACE) != 0)     sb.append("interface ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        if ((len = sb.length()) > 0)    /* trim trailing space */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
            return sb.toString().substring(0, len-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        return "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * Access modifier flag constants from <em>The Java Virtual
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * Machine Specification, Second Edition</em>, tables 4.1, 4.4,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * 4.5, and 4.7.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * The {@code int} value representing the {@code public}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * modifier.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    public static final int PUBLIC           = 0x00000001;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     * The {@code int} value representing the {@code private}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * modifier.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    public static final int PRIVATE          = 0x00000002;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     * The {@code int} value representing the {@code protected}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     * modifier.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    public static final int PROTECTED        = 0x00000004;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     * The {@code int} value representing the {@code static}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     * modifier.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    public static final int STATIC           = 0x00000008;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     * The {@code int} value representing the {@code final}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     * modifier.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    public static final int FINAL            = 0x00000010;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     * The {@code int} value representing the {@code synchronized}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     * modifier.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    public static final int SYNCHRONIZED     = 0x00000020;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * The {@code int} value representing the {@code volatile}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     * modifier.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    public static final int VOLATILE         = 0x00000040;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     * The {@code int} value representing the {@code transient}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     * modifier.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
    public static final int TRANSIENT        = 0x00000080;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     * The {@code int} value representing the {@code native}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     * modifier.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
    public static final int NATIVE           = 0x00000100;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     * The {@code int} value representing the {@code interface}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     * modifier.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    public static final int INTERFACE        = 0x00000200;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     * The {@code int} value representing the {@code abstract}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     * modifier.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
    public static final int ABSTRACT         = 0x00000400;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     * The {@code int} value representing the {@code strictfp}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     * modifier.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
    public static final int STRICT           = 0x00000800;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
    // Bits not (yet) exposed in the public API either because they
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    // have different meanings for fields and methods and there is no
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
    // way to distinguish between the two in this class, or because
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
    // they are not Java programming language keywords
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
    static final int BRIDGE    = 0x00000040;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    static final int VARARGS   = 0x00000080;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
    static final int SYNTHETIC = 0x00001000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
    static final int ANNOTATION= 0x00002000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
    static final int ENUM      = 0x00004000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
    static boolean isSynthetic(int mod) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
      return (mod & SYNTHETIC) != 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
}