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