jaxp/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/classfile/AccessFlags.java
changeset 46174 5611d2529b49
parent 44797 8b3b3b911b8a
equal deleted inserted replaced
46173:5546b5710844 46174:5611d2529b49
     1 /*
     1 /*
     2  * reserved comment block
     2  * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT REMOVE OR ALTER!
       
     4  */
     3  */
     5 /*
     4 /*
     6  * Licensed to the Apache Software Foundation (ASF) under one or more
     5  * Licensed to the Apache Software Foundation (ASF) under one or more
     7  * contributor license agreements.  See the NOTICE file distributed with
     6  * contributor license agreements.  See the NOTICE file distributed with
     8  * this work for additional information regarding copyright ownership.
     7  * this work for additional information regarding copyright ownership.
    16  * distributed under the License is distributed on an "AS IS" BASIS,
    15  * distributed under the License is distributed on an "AS IS" BASIS,
    17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    18  * See the License for the specific language governing permissions and
    17  * See the License for the specific language governing permissions and
    19  * limitations under the License.
    18  * limitations under the License.
    20  */
    19  */
    21 
       
    22 package com.sun.org.apache.bcel.internal.classfile;
    20 package com.sun.org.apache.bcel.internal.classfile;
    23 
    21 
    24 
    22 import com.sun.org.apache.bcel.internal.Const;
    25 import  com.sun.org.apache.bcel.internal.Constants;
       
    26 
    23 
    27 /**
    24 /**
    28  * Super class for all objects that have modifiers like private, final, ...
    25  * Super class for all objects that have modifiers like private, final, ... I.e.
    29  * I.e. classes, fields, and methods.
    26  * classes, fields, and methods.
    30  *
    27  *
    31  * @author  <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
    28  * @version $Id: AccessFlags.java 1748636 2016-06-15 20:45:17Z dbrosius $
    32  */
    29  */
    33 public abstract class AccessFlags implements java.io.Serializable {
    30 public abstract class AccessFlags {
    34   protected int access_flags;
    31 
    35 
    32     private int access_flags;
    36   public AccessFlags() {}
    33 
    37 
    34     public AccessFlags() {
    38   /**
    35     }
    39    * @param a inital access flags
    36 
    40    */
    37     /**
    41   public AccessFlags(int a) {
    38      * @param a inital access flags
    42     access_flags = a;
    39      */
    43   }
    40     public AccessFlags(final int a) {
    44 
    41         access_flags = a;
    45   /**
    42     }
    46    * @return Access flags of the object aka. "modifiers".
    43 
    47    */
    44     /**
    48   public final int getAccessFlags() { return access_flags; }
    45      * @return Access flags of the object aka. "modifiers".
    49 
    46      */
    50   /**
    47     public final int getAccessFlags() {
    51    * @return Access flags of the object aka. "modifiers".
    48         return access_flags;
    52    */
    49     }
    53   public final int getModifiers() { return access_flags; }
    50 
    54 
    51     /**
    55   /** Set access flags aka "modifiers".
    52      * @return Access flags of the object aka. "modifiers".
    56    * @param access_flags Access flags of the object.
    53      */
    57    */
    54     public final int getModifiers() {
    58   public final void setAccessFlags(int access_flags) {
    55         return access_flags;
    59     this.access_flags = access_flags;
    56     }
    60   }
    57 
    61 
    58     /**
    62   /** Set access flags aka "modifiers".
    59      * Set access flags aka "modifiers".
    63    * @param access_flags Access flags of the object.
    60      *
    64    */
    61      * @param access_flags Access flags of the object.
    65   public final void setModifiers(int access_flags) {
    62      */
    66     setAccessFlags(access_flags);
    63     public final void setAccessFlags(final int access_flags) {
    67   }
    64         this.access_flags = access_flags;
    68 
    65     }
    69   private final void setFlag(int flag, boolean set) {
    66 
    70     if((access_flags & flag) != 0) { // Flag is set already
    67     /**
    71       if(!set) // Delete flag ?
    68      * Set access flags aka "modifiers".
    72         access_flags ^= flag;
    69      *
    73     } else {   // Flag not set
    70      * @param access_flags Access flags of the object.
    74       if(set)  // Set flag ?
    71      */
    75         access_flags |= flag;
    72     public final void setModifiers(final int access_flags) {
    76     }
    73         setAccessFlags(access_flags);
    77   }
    74     }
    78 
    75 
    79   public final void isPublic(boolean flag) { setFlag(Constants.ACC_PUBLIC, flag); }
    76     private void setFlag(final int flag, final boolean set) {
    80   public final boolean isPublic() {
    77         if ((access_flags & flag) != 0) { // Flag is set already
    81     return (access_flags & Constants.ACC_PUBLIC) != 0;
    78             if (!set) {
    82   }
    79                 access_flags ^= flag;
    83 
    80             }
    84   public final void isPrivate(boolean flag) { setFlag(Constants.ACC_PRIVATE, flag); }
    81         } else { // Flag not set
    85   public final boolean isPrivate() {
    82             if (set) {
    86     return (access_flags & Constants.ACC_PRIVATE) != 0;
    83                 access_flags |= flag;
    87   }
    84             }
    88 
    85         }
    89   public final void isProtected(boolean flag) { setFlag(Constants.ACC_PROTECTED, flag); }
    86     }
    90   public final boolean isProtected() {
    87 
    91     return (access_flags & Constants.ACC_PROTECTED) != 0;
    88     public final void isPublic(final boolean flag) {
    92   }
    89         setFlag(Const.ACC_PUBLIC, flag);
    93 
    90     }
    94   public final void isStatic(boolean flag) { setFlag(Constants.ACC_STATIC, flag); }
    91 
    95   public final boolean isStatic() {
    92     public final boolean isPublic() {
    96     return (access_flags & Constants.ACC_STATIC) != 0;
    93         return (access_flags & Const.ACC_PUBLIC) != 0;
    97   }
    94     }
    98 
    95 
    99   public final void isFinal(boolean flag) { setFlag(Constants.ACC_FINAL, flag); }
    96     public final void isPrivate(final boolean flag) {
   100   public final boolean isFinal() {
    97         setFlag(Const.ACC_PRIVATE, flag);
   101     return (access_flags & Constants.ACC_FINAL) != 0;
    98     }
   102   }
    99 
   103 
   100     public final boolean isPrivate() {
   104   public final void isSynchronized(boolean flag) { setFlag(Constants.ACC_SYNCHRONIZED, flag); }
   101         return (access_flags & Const.ACC_PRIVATE) != 0;
   105   public final boolean isSynchronized() {
   102     }
   106     return (access_flags & Constants.ACC_SYNCHRONIZED) != 0;
   103 
   107   }
   104     public final void isProtected(final boolean flag) {
   108 
   105         setFlag(Const.ACC_PROTECTED, flag);
   109   public final void isVolatile(boolean flag) { setFlag(Constants.ACC_VOLATILE, flag); }
   106     }
   110   public final boolean isVolatile() {
   107 
   111     return (access_flags & Constants.ACC_VOLATILE) != 0;
   108     public final boolean isProtected() {
   112   }
   109         return (access_flags & Const.ACC_PROTECTED) != 0;
   113 
   110     }
   114   public final void isTransient(boolean flag) { setFlag(Constants.ACC_TRANSIENT, flag); }
   111 
   115   public final boolean isTransient() {
   112     public final void isStatic(final boolean flag) {
   116     return (access_flags & Constants.ACC_TRANSIENT) != 0;
   113         setFlag(Const.ACC_STATIC, flag);
   117   }
   114     }
   118 
   115 
   119   public final void isNative(boolean flag) { setFlag(Constants.ACC_NATIVE, flag); }
   116     public final boolean isStatic() {
   120   public final boolean isNative() {
   117         return (access_flags & Const.ACC_STATIC) != 0;
   121     return (access_flags & Constants.ACC_NATIVE) != 0;
   118     }
   122   }
   119 
   123 
   120     public final void isFinal(final boolean flag) {
   124   public final void isInterface(boolean flag) { setFlag(Constants.ACC_INTERFACE, flag); }
   121         setFlag(Const.ACC_FINAL, flag);
   125   public final boolean isInterface() {
   122     }
   126     return (access_flags & Constants.ACC_INTERFACE) != 0;
   123 
   127   }
   124     public final boolean isFinal() {
   128 
   125         return (access_flags & Const.ACC_FINAL) != 0;
   129   public final void isAbstract(boolean flag) { setFlag(Constants.ACC_ABSTRACT, flag); }
   126     }
   130   public final boolean isAbstract() {
   127 
   131     return (access_flags & Constants.ACC_ABSTRACT) != 0;
   128     public final void isSynchronized(final boolean flag) {
   132   }
   129         setFlag(Const.ACC_SYNCHRONIZED, flag);
   133 
   130     }
   134   public final void isStrictfp(boolean flag) { setFlag(Constants.ACC_STRICT, flag); }
   131 
   135   public final boolean isStrictfp() {
   132     public final boolean isSynchronized() {
   136     return (access_flags & Constants.ACC_STRICT) != 0;
   133         return (access_flags & Const.ACC_SYNCHRONIZED) != 0;
   137   }
   134     }
       
   135 
       
   136     public final void isVolatile(final boolean flag) {
       
   137         setFlag(Const.ACC_VOLATILE, flag);
       
   138     }
       
   139 
       
   140     public final boolean isVolatile() {
       
   141         return (access_flags & Const.ACC_VOLATILE) != 0;
       
   142     }
       
   143 
       
   144     public final void isTransient(final boolean flag) {
       
   145         setFlag(Const.ACC_TRANSIENT, flag);
       
   146     }
       
   147 
       
   148     public final boolean isTransient() {
       
   149         return (access_flags & Const.ACC_TRANSIENT) != 0;
       
   150     }
       
   151 
       
   152     public final void isNative(final boolean flag) {
       
   153         setFlag(Const.ACC_NATIVE, flag);
       
   154     }
       
   155 
       
   156     public final boolean isNative() {
       
   157         return (access_flags & Const.ACC_NATIVE) != 0;
       
   158     }
       
   159 
       
   160     public final void isInterface(final boolean flag) {
       
   161         setFlag(Const.ACC_INTERFACE, flag);
       
   162     }
       
   163 
       
   164     public final boolean isInterface() {
       
   165         return (access_flags & Const.ACC_INTERFACE) != 0;
       
   166     }
       
   167 
       
   168     public final void isAbstract(final boolean flag) {
       
   169         setFlag(Const.ACC_ABSTRACT, flag);
       
   170     }
       
   171 
       
   172     public final boolean isAbstract() {
       
   173         return (access_flags & Const.ACC_ABSTRACT) != 0;
       
   174     }
       
   175 
       
   176     public final void isStrictfp(final boolean flag) {
       
   177         setFlag(Const.ACC_STRICT, flag);
       
   178     }
       
   179 
       
   180     public final boolean isStrictfp() {
       
   181         return (access_flags & Const.ACC_STRICT) != 0;
       
   182     }
       
   183 
       
   184     public final void isSynthetic(final boolean flag) {
       
   185         setFlag(Const.ACC_SYNTHETIC, flag);
       
   186     }
       
   187 
       
   188     public final boolean isSynthetic() {
       
   189         return (access_flags & Const.ACC_SYNTHETIC) != 0;
       
   190     }
       
   191 
       
   192     public final void isAnnotation(final boolean flag) {
       
   193         setFlag(Const.ACC_ANNOTATION, flag);
       
   194     }
       
   195 
       
   196     public final boolean isAnnotation() {
       
   197         return (access_flags & Const.ACC_ANNOTATION) != 0;
       
   198     }
       
   199 
       
   200     public final void isEnum(final boolean flag) {
       
   201         setFlag(Const.ACC_ENUM, flag);
       
   202     }
       
   203 
       
   204     public final boolean isEnum() {
       
   205         return (access_flags & Const.ACC_ENUM) != 0;
       
   206     }
       
   207 
       
   208     public final void isVarArgs(final boolean flag) {
       
   209         setFlag(Const.ACC_VARARGS, flag);
       
   210     }
       
   211 
       
   212     public final boolean isVarArgs() {
       
   213         return (access_flags & Const.ACC_VARARGS) != 0;
       
   214     }
   138 }
   215 }