AccessFlags xref

View Javadoc

    1   /*
    2    * Copyright  2000-2004 The Apache Software Foundation
    3    *
    4    *  Licensed under the Apache License, Version 2.0 (the "License");
    5    *  you may not use this file except in compliance with the License.
    6    *  You may obtain a copy of the License at
    7    *
    8    *      http://www.apache.org/licenses/LICENSE-2.0
    9    *
    10   *  Unless required by applicable law or agreed to in writing, software
    11   *  distributed under the License is distributed on an "AS IS" BASIS,
    12   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   *  See the License for the specific language governing permissions and
    14   *  limitations under the License.
    15   *
    16   */
    17  package org.apache.bcel.classfile;
    18
    19  import org.apache.bcel.Constants;
    20
    21  /***
    22   * Super class for all objects that have modifiers like private, final, ...
    23   * I.e. classes, fields, and methods.
    24   *
    25   * @version $Id: AccessFlags.java 386056 2006-03-15 11:31:56Z tcurdt $
    26   * @author  <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
    27   */
    28  public abstract class AccessFlags implements java.io.Serializable {
    29
    30      protected int access_flags;
    31
    32
    33      public AccessFlags() {
    34      }
    35
    36
    37      /***
    38       * @param a inital access flags
    39       */
    40      public AccessFlags(int a) {
    41          access_flags = a;
    42      }
    43
    44
    45      /***
    46       * @return Access flags of the object aka. "modifiers".
    47       */
    48      public final int getAccessFlags() {
    49          return access_flags;
    50      }
    51
    52
    53      /***
    54       * @return Access flags of the object aka. "modifiers".
    55       */
    56      public final int getModifiers() {
    57          return access_flags;
    58      }
    59
    60
    61      /*** Set access flags aka "modifiers".
    62       * @param access_flags Access flags of the object.
    63       */
    64      public final void setAccessFlags( int access_flags ) {
    65          this.access_flags = access_flags;
    66      }
    67
    68
    69      /*** Set access flags aka "modifiers".
    70       * @param access_flags Access flags of the object.
    71       */
    72      public final void setModifiers( int access_flags ) {
    73          setAccessFlags(access_flags);
    74      }
    75
    76
    77      private final void setFlag( int flag, boolean set ) {
    78          if ((access_flags & flag) != 0) { // Flag is set already
    79              if (!set) {
    80                  access_flags ^= flag;
    81              }
    82          } else { // Flag not set
    83              if (set) {
    84                  access_flags |= flag;
    85              }
    86          }
    87      }
    88
    89
    90      public final void isPublic( boolean flag ) {
    91          setFlag(Constants.ACC_PUBLIC, flag);
    92      }
    93
    94
    95      public final boolean isPublic() {
    96          return (access_flags & Constants.ACC_PUBLIC) != 0;
    97      }
    98
    99
    100     public final void isPrivate( boolean flag ) {
    101         setFlag(Constants.ACC_PRIVATE, flag);
    102     }
    103
    104
    105     public final boolean isPrivate() {
    106         return (access_flags & Constants.ACC_PRIVATE) != 0;
    107     }
    108
    109
    110     public final void isProtected( boolean flag ) {
    111         setFlag(Constants.ACC_PROTECTED, flag);
    112     }
    113
    114
    115     public final boolean isProtected() {
    116         return (access_flags & Constants.ACC_PROTECTED) != 0;
    117     }
    118
    119
    120     public final void isStatic( boolean flag ) {
    121         setFlag(Constants.ACC_STATIC, flag);
    122     }
    123
    124
    125     public final boolean isStatic() {
    126         return (access_flags & Constants.ACC_STATIC) != 0;
    127     }
    128
    129
    130     public final void isFinal( boolean flag ) {
    131         setFlag(Constants.ACC_FINAL, flag);
    132     }
    133
    134
    135     public final boolean isFinal() {
    136         return (access_flags & Constants.ACC_FINAL) != 0;
    137     }
    138
    139
    140     public final void isSynchronized( boolean flag ) {
    141         setFlag(Constants.ACC_SYNCHRONIZED, flag);
    142     }
    143
    144
    145     public final boolean isSynchronized() {
    146         return (access_flags & Constants.ACC_SYNCHRONIZED) != 0;
    147     }
    148
    149
    150     public final void isVolatile( boolean flag ) {
    151         setFlag(Constants.ACC_VOLATILE, flag);
    152     }
    153
    154
    155     public final boolean isVolatile() {
    156         return (access_flags & Constants.ACC_VOLATILE) != 0;
    157     }
    158
    159
    160     public final void isTransient( boolean flag ) {
    161         setFlag(Constants.ACC_TRANSIENT, flag);
    162     }
    163
    164
    165     public final boolean isTransient() {
    166         return (access_flags & Constants.ACC_TRANSIENT) != 0;
    167     }
    168
    169
    170     public final void isNative( boolean flag ) {
    171         setFlag(Constants.ACC_NATIVE, flag);
    172     }
    173
    174
    175     public final boolean isNative() {
    176         return (access_flags & Constants.ACC_NATIVE) != 0;
    177     }
    178
    179
    180     public final void isInterface( boolean flag ) {
    181         setFlag(Constants.ACC_INTERFACE, flag);
    182     }
    183
    184
    185     public final boolean isInterface() {
    186         return (access_flags & Constants.ACC_INTERFACE) != 0;
    187     }
    188
    189
    190     public final void isAbstract( boolean flag ) {
    191         setFlag(Constants.ACC_ABSTRACT, flag);
    192     }
    193
    194
    195     public final boolean isAbstract() {
    196         return (access_flags & Constants.ACC_ABSTRACT) != 0;
    197     }
    198
    199
    200     public final void isStrictfp( boolean flag ) {
    201         setFlag(Constants.ACC_STRICT, flag);
    202     }
    203
    204
    205     public final boolean isStrictfp() {
    206         return (access_flags & Constants.ACC_STRICT) != 0;
    207     }
    208
    209
    210     public final void isSynthetic( boolean flag ) {
    211         setFlag(Constants.ACC_SYNTHETIC, flag);
    212     }
    213
    214
    215     public final boolean isSynthetic() {
    216         return (access_flags & Constants.ACC_SYNTHETIC) != 0;
    217     }
    218
    219
    220     public final void isAnnotation( boolean flag ) {
    221         setFlag(Constants.ACC_ANNOTATION, flag);
    222     }
    223
    224
    225     public final boolean isAnnotation() {
    226         return (access_flags & Constants.ACC_ANNOTATION) != 0;
    227     }
    228
    229
    230     public final void isEnum( boolean flag ) {
    231         setFlag(Constants.ACC_ENUM, flag);
    232     }
    233
    234
    235     public final boolean isEnum() {
    236         return (access_flags & Constants.ACC_ENUM) != 0;
    237     }
    238 }