1 // Copyright 2016 The Bazel Authors. All rights reserved. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 package com.google.devtools.build.android.desugar.io; 15 16 import org.objectweb.asm.Opcodes; 17 18 /** Convenience method for working with {@code int} bitwise flags. */ 19 public class BitFlags { 20 21 /** 22 * Returns {@code true} iff <b>all</b> bits in {@code bitmask} are set in {@code flags}. Trivially 23 * returns {@code true} if {@code bitmask} is 0. 24 */ isSet(int flags, int bitmask)25 public static boolean isSet(int flags, int bitmask) { 26 return (flags & bitmask) == bitmask; 27 } 28 29 /** 30 * Returns {@code true} iff <b>none</b> of the bits in {@code bitmask} are set in {@code flags}. 31 * Trivially returns {@code true} if {@code bitmask} is 0. 32 */ noneSet(int flags, int bitmask)33 public static boolean noneSet(int flags, int bitmask) { 34 return (flags & bitmask) == 0; 35 } 36 isInterface(int access)37 public static boolean isInterface(int access) { 38 return isSet(access, Opcodes.ACC_INTERFACE); 39 } 40 isStatic(int access)41 public static boolean isStatic(int access) { 42 return isSet(access, Opcodes.ACC_STATIC); 43 } 44 isSynthetic(int access)45 public static boolean isSynthetic(int access) { 46 return isSet(access, Opcodes.ACC_SYNTHETIC); 47 } 48 49 // Static methods only BitFlags()50 private BitFlags() {} 51 } 52