0N/A/*
2362N/A * Copyright (c) 1996, 2008, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage java.lang.reflect;
0N/A
0N/Aimport java.security.AccessController;
0N/Aimport sun.reflect.LangReflectAccess;
0N/Aimport sun.reflect.ReflectionFactory;
0N/A
0N/A/**
0N/A * The Modifier class provides {@code static} methods and
0N/A * constants to decode class and member access modifiers. The sets of
0N/A * modifiers are represented as integers with distinct bit positions
0N/A * representing different modifiers. The values for the constants
4008N/A * representing the modifiers are taken from the tables in sections 4.1, 4.4, 4.5, and 4.7 of
4008N/A * <cite>The Java&trade; Virtual Machine Specification</cite>.
0N/A *
0N/A * @see Class#getModifiers()
0N/A * @see Member#getModifiers()
0N/A *
0N/A * @author Nakul Saraiya
0N/A * @author Kenneth Russell
0N/A */
0N/Apublic
0N/Aclass Modifier {
0N/A
0N/A /*
0N/A * Bootstrapping protocol between java.lang and java.lang.reflect
0N/A * packages
0N/A */
0N/A static {
0N/A sun.reflect.ReflectionFactory factory =
28N/A AccessController.doPrivileged(
28N/A new ReflectionFactory.GetReflectionFactoryAction());
0N/A factory.setLangReflectAccess(new java.lang.reflect.ReflectAccess());
0N/A }
0N/A
0N/A /**
0N/A * Return {@code true} if the integer argument includes the
0N/A * {@code public} modifier, {@code false} otherwise.
0N/A *
0N/A * @param mod a set of modifiers
0N/A * @return {@code true} if {@code mod} includes the
0N/A * {@code public} modifier; {@code false} otherwise.
0N/A */
0N/A public static boolean isPublic(int mod) {
0N/A return (mod & PUBLIC) != 0;
0N/A }
0N/A
0N/A /**
0N/A * Return {@code true} if the integer argument includes the
0N/A * {@code private} modifier, {@code false} otherwise.
0N/A *
0N/A * @param mod a set of modifiers
0N/A * @return {@code true} if {@code mod} includes the
0N/A * {@code private} modifier; {@code false} otherwise.
0N/A */
0N/A public static boolean isPrivate(int mod) {
0N/A return (mod & PRIVATE) != 0;
0N/A }
0N/A
0N/A /**
0N/A * Return {@code true} if the integer argument includes the
0N/A * {@code protected} modifier, {@code false} otherwise.
0N/A *
0N/A * @param mod a set of modifiers
0N/A * @return {@code true} if {@code mod} includes the
0N/A * {@code protected} modifier; {@code false} otherwise.
0N/A */
0N/A public static boolean isProtected(int mod) {
0N/A return (mod & PROTECTED) != 0;
0N/A }
0N/A
0N/A /**
0N/A * Return {@code true} if the integer argument includes the
0N/A * {@code static} modifier, {@code false} otherwise.
0N/A *
0N/A * @param mod a set of modifiers
0N/A * @return {@code true} if {@code mod} includes the
0N/A * {@code static} modifier; {@code false} otherwise.
0N/A */
0N/A public static boolean isStatic(int mod) {
0N/A return (mod & STATIC) != 0;
0N/A }
0N/A
0N/A /**
0N/A * Return {@code true} if the integer argument includes the
0N/A * {@code final} modifier, {@code false} otherwise.
0N/A *
0N/A * @param mod a set of modifiers
0N/A * @return {@code true} if {@code mod} includes the
0N/A * {@code final} modifier; {@code false} otherwise.
0N/A */
0N/A public static boolean isFinal(int mod) {
0N/A return (mod & FINAL) != 0;
0N/A }
0N/A
0N/A /**
0N/A * Return {@code true} if the integer argument includes the
0N/A * {@code synchronized} modifier, {@code false} otherwise.
0N/A *
0N/A * @param mod a set of modifiers
0N/A * @return {@code true} if {@code mod} includes the
0N/A * {@code synchronized} modifier; {@code false} otherwise.
0N/A */
0N/A public static boolean isSynchronized(int mod) {
0N/A return (mod & SYNCHRONIZED) != 0;
0N/A }
0N/A
0N/A /**
0N/A * Return {@code true} if the integer argument includes the
0N/A * {@code volatile} modifier, {@code false} otherwise.
0N/A *
0N/A * @param mod a set of modifiers
0N/A * @return {@code true} if {@code mod} includes the
0N/A * {@code volatile} modifier; {@code false} otherwise.
0N/A */
0N/A public static boolean isVolatile(int mod) {
0N/A return (mod & VOLATILE) != 0;
0N/A }
0N/A
0N/A /**
0N/A * Return {@code true} if the integer argument includes the
0N/A * {@code transient} modifier, {@code false} otherwise.
0N/A *
0N/A * @param mod a set of modifiers
0N/A * @return {@code true} if {@code mod} includes the
0N/A * {@code transient} modifier; {@code false} otherwise.
0N/A */
0N/A public static boolean isTransient(int mod) {
0N/A return (mod & TRANSIENT) != 0;
0N/A }
0N/A
0N/A /**
0N/A * Return {@code true} if the integer argument includes the
0N/A * {@code native} modifier, {@code false} otherwise.
0N/A *
0N/A * @param mod a set of modifiers
0N/A * @return {@code true} if {@code mod} includes the
0N/A * {@code native} modifier; {@code false} otherwise.
0N/A */
0N/A public static boolean isNative(int mod) {
0N/A return (mod & NATIVE) != 0;
0N/A }
0N/A
0N/A /**
0N/A * Return {@code true} if the integer argument includes the
0N/A * {@code interface} modifier, {@code false} otherwise.
0N/A *
0N/A * @param mod a set of modifiers
0N/A * @return {@code true} if {@code mod} includes the
0N/A * {@code interface} modifier; {@code false} otherwise.
0N/A */
0N/A public static boolean isInterface(int mod) {
0N/A return (mod & INTERFACE) != 0;
0N/A }
0N/A
0N/A /**
0N/A * Return {@code true} if the integer argument includes the
0N/A * {@code abstract} modifier, {@code false} otherwise.
0N/A *
0N/A * @param mod a set of modifiers
0N/A * @return {@code true} if {@code mod} includes the
0N/A * {@code abstract} modifier; {@code false} otherwise.
0N/A */
0N/A public static boolean isAbstract(int mod) {
0N/A return (mod & ABSTRACT) != 0;
0N/A }
0N/A
0N/A /**
0N/A * Return {@code true} if the integer argument includes the
0N/A * {@code strictfp} modifier, {@code false} otherwise.
0N/A *
0N/A * @param mod a set of modifiers
0N/A * @return {@code true} if {@code mod} includes the
0N/A * {@code strictfp} modifier; {@code false} otherwise.
0N/A */
0N/A public static boolean isStrict(int mod) {
0N/A return (mod & STRICT) != 0;
0N/A }
0N/A
0N/A /**
0N/A * Return a string describing the access modifier flags in
0N/A * the specified modifier. For example:
0N/A * <blockquote><pre>
0N/A * public final synchronized strictfp
0N/A * </pre></blockquote>
0N/A * The modifier names are returned in an order consistent with the
4008N/A * suggested modifier orderings given in sections 8.1.1, 8.3.1, 8.4.3, 8.8.3, and 9.1.1 of
4008N/A * <cite>The Java&trade; Language Specification</cite>.
0N/A * The full modifier ordering used by this method is:
0N/A * <blockquote> {@code
0N/A * public protected private abstract static final transient
0N/A * volatile synchronized native strictfp
0N/A * interface } </blockquote>
0N/A * The {@code interface} modifier discussed in this class is
0N/A * not a true modifier in the Java language and it appears after
0N/A * all other modifiers listed by this method. This method may
0N/A * return a string of modifiers that are not valid modifiers of a
0N/A * Java entity; in other words, no checking is done on the
0N/A * possible validity of the combination of modifiers represented
0N/A * by the input.
0N/A *
1600N/A * Note that to perform such checking for a known kind of entity,
1600N/A * such as a constructor or method, first AND the argument of
1600N/A * {@code toString} with the appropriate mask from a method like
1600N/A * {@link #constructorModifiers} or {@link #methodModifiers}.
1600N/A *
0N/A * @param mod a set of modifiers
0N/A * @return a string representation of the set of modifiers
0N/A * represented by {@code mod}
0N/A */
0N/A public static String toString(int mod) {
0N/A StringBuffer sb = new StringBuffer();
0N/A int len;
0N/A
0N/A if ((mod & PUBLIC) != 0) sb.append("public ");
0N/A if ((mod & PROTECTED) != 0) sb.append("protected ");
0N/A if ((mod & PRIVATE) != 0) sb.append("private ");
0N/A
0N/A /* Canonical order */
0N/A if ((mod & ABSTRACT) != 0) sb.append("abstract ");
0N/A if ((mod & STATIC) != 0) sb.append("static ");
0N/A if ((mod & FINAL) != 0) sb.append("final ");
0N/A if ((mod & TRANSIENT) != 0) sb.append("transient ");
0N/A if ((mod & VOLATILE) != 0) sb.append("volatile ");
0N/A if ((mod & SYNCHRONIZED) != 0) sb.append("synchronized ");
0N/A if ((mod & NATIVE) != 0) sb.append("native ");
0N/A if ((mod & STRICT) != 0) sb.append("strictfp ");
0N/A if ((mod & INTERFACE) != 0) sb.append("interface ");
0N/A
0N/A if ((len = sb.length()) > 0) /* trim trailing space */
0N/A return sb.toString().substring(0, len-1);
0N/A return "";
0N/A }
0N/A
0N/A /*
4008N/A * Access modifier flag constants from tables 4.1, 4.4, 4.5, and 4.7 of
4008N/A * <cite>The Java&trade; Virtual Machine Specification</cite>
0N/A */
0N/A
0N/A /**
0N/A * The {@code int} value representing the {@code public}
0N/A * modifier.
0N/A */
0N/A public static final int PUBLIC = 0x00000001;
0N/A
0N/A /**
0N/A * The {@code int} value representing the {@code private}
0N/A * modifier.
0N/A */
0N/A public static final int PRIVATE = 0x00000002;
0N/A
0N/A /**
0N/A * The {@code int} value representing the {@code protected}
0N/A * modifier.
0N/A */
0N/A public static final int PROTECTED = 0x00000004;
0N/A
0N/A /**
0N/A * The {@code int} value representing the {@code static}
0N/A * modifier.
0N/A */
0N/A public static final int STATIC = 0x00000008;
0N/A
0N/A /**
0N/A * The {@code int} value representing the {@code final}
0N/A * modifier.
0N/A */
0N/A public static final int FINAL = 0x00000010;
0N/A
0N/A /**
0N/A * The {@code int} value representing the {@code synchronized}
0N/A * modifier.
0N/A */
0N/A public static final int SYNCHRONIZED = 0x00000020;
0N/A
0N/A /**
0N/A * The {@code int} value representing the {@code volatile}
0N/A * modifier.
0N/A */
0N/A public static final int VOLATILE = 0x00000040;
0N/A
0N/A /**
0N/A * The {@code int} value representing the {@code transient}
0N/A * modifier.
0N/A */
0N/A public static final int TRANSIENT = 0x00000080;
0N/A
0N/A /**
0N/A * The {@code int} value representing the {@code native}
0N/A * modifier.
0N/A */
0N/A public static final int NATIVE = 0x00000100;
0N/A
0N/A /**
0N/A * The {@code int} value representing the {@code interface}
0N/A * modifier.
0N/A */
0N/A public static final int INTERFACE = 0x00000200;
0N/A
0N/A /**
0N/A * The {@code int} value representing the {@code abstract}
0N/A * modifier.
0N/A */
0N/A public static final int ABSTRACT = 0x00000400;
0N/A
0N/A /**
0N/A * The {@code int} value representing the {@code strictfp}
0N/A * modifier.
0N/A */
0N/A public static final int STRICT = 0x00000800;
0N/A
0N/A // Bits not (yet) exposed in the public API either because they
0N/A // have different meanings for fields and methods and there is no
0N/A // way to distinguish between the two in this class, or because
0N/A // they are not Java programming language keywords
0N/A static final int BRIDGE = 0x00000040;
0N/A static final int VARARGS = 0x00000080;
0N/A static final int SYNTHETIC = 0x00001000;
0N/A static final int ANNOTATION= 0x00002000;
0N/A static final int ENUM = 0x00004000;
0N/A static boolean isSynthetic(int mod) {
0N/A return (mod & SYNTHETIC) != 0;
0N/A }
1600N/A
1600N/A /**
1600N/A * See JLSv3 section 8.1.1.
1600N/A */
1600N/A private static final int CLASS_MODIFIERS =
1600N/A Modifier.PUBLIC | Modifier.PROTECTED | Modifier.PRIVATE |
1600N/A Modifier.ABSTRACT | Modifier.STATIC | Modifier.FINAL |
1600N/A Modifier.STRICT;
1600N/A
1600N/A /**
1600N/A * See JLSv3 section 9.1.1.
1600N/A */
1600N/A private static final int INTERFACE_MODIFIERS =
1600N/A Modifier.PUBLIC | Modifier.PROTECTED | Modifier.PRIVATE |
1600N/A Modifier.ABSTRACT | Modifier.STATIC | Modifier.STRICT;
1600N/A
1600N/A
1600N/A /**
1600N/A * See JLSv3 section 8.8.3.
1600N/A */
1600N/A private static final int CONSTRUCTOR_MODIFIERS =
1600N/A Modifier.PUBLIC | Modifier.PROTECTED | Modifier.PRIVATE;
1600N/A
1600N/A /**
1600N/A * See JLSv3 section 8.4.3.
1600N/A */
1600N/A private static final int METHOD_MODIFIERS =
1600N/A Modifier.PUBLIC | Modifier.PROTECTED | Modifier.PRIVATE |
1600N/A Modifier.ABSTRACT | Modifier.STATIC | Modifier.FINAL |
1600N/A Modifier.SYNCHRONIZED | Modifier.NATIVE | Modifier.STRICT;
1600N/A
1600N/A /**
1600N/A * See JLSv3 section 8.3.1.
1600N/A */
1600N/A private static final int FIELD_MODIFIERS =
1600N/A Modifier.PUBLIC | Modifier.PROTECTED | Modifier.PRIVATE |
1600N/A Modifier.STATIC | Modifier.FINAL | Modifier.TRANSIENT |
1600N/A Modifier.VOLATILE;
1600N/A
1600N/A /**
1600N/A * Return an {@code int} value OR-ing together the source language
1600N/A * modifiers that can be applied to a class.
1600N/A * @return an {@code int} value OR-ing together the source language
1600N/A * modifiers that can be applied to a class.
1600N/A *
4008N/A * @jls 8.1.1 Class Modifiers
1600N/A * @since 1.7
1600N/A */
1600N/A public static int classModifiers() {
1600N/A return CLASS_MODIFIERS;
1600N/A }
1600N/A
1600N/A /**
1600N/A * Return an {@code int} value OR-ing together the source language
1600N/A * modifiers that can be applied to an interface.
1600N/A * @return an {@code int} value OR-ing together the source language
1600N/A * modifiers that can be applied to an inteface.
1600N/A *
4008N/A * @jls 9.1.1 Interface Modifiers
1600N/A * @since 1.7
1600N/A */
1600N/A public static int interfaceModifiers() {
1600N/A return INTERFACE_MODIFIERS;
1600N/A }
1600N/A
1600N/A /**
1600N/A * Return an {@code int} value OR-ing together the source language
1600N/A * modifiers that can be applied to a constructor.
1600N/A * @return an {@code int} value OR-ing together the source language
1600N/A * modifiers that can be applied to a constructor.
1600N/A *
4008N/A * @jls 8.8.3 Constructor Modifiers
1600N/A * @since 1.7
1600N/A */
1600N/A public static int constructorModifiers() {
1600N/A return CONSTRUCTOR_MODIFIERS;
1600N/A }
1600N/A
1600N/A /**
1600N/A * Return an {@code int} value OR-ing together the source language
1600N/A * modifiers that can be applied to a method.
1600N/A * @return an {@code int} value OR-ing together the source language
1600N/A * modifiers that can be applied to a method.
1600N/A *
4008N/A * @jls 8.4.3 Method Modifiers
1600N/A * @since 1.7
1600N/A */
1600N/A public static int methodModifiers() {
1600N/A return METHOD_MODIFIERS;
1600N/A }
1600N/A
1600N/A
1600N/A /**
1600N/A * Return an {@code int} value OR-ing together the source language
1600N/A * modifiers that can be applied to a field.
1600N/A * @return an {@code int} value OR-ing together the source language
1600N/A * modifiers that can be applied to a field.
1600N/A *
4008N/A * @jls 8.3.1 Field Modifiers
1600N/A * @since 1.7
1600N/A */
1600N/A public static int fieldModifiers() {
1600N/A return FIELD_MODIFIERS;
1600N/A }
0N/A}