diff options
Diffstat (limited to 'java/com/google/devtools/build/android/desugar/io/BitFlags.java')
-rw-r--r-- | java/com/google/devtools/build/android/desugar/io/BitFlags.java | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/java/com/google/devtools/build/android/desugar/io/BitFlags.java b/java/com/google/devtools/build/android/desugar/io/BitFlags.java new file mode 100644 index 0000000..af6f481 --- /dev/null +++ b/java/com/google/devtools/build/android/desugar/io/BitFlags.java @@ -0,0 +1,51 @@ +// Copyright 2016 The Bazel Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +package com.google.devtools.build.android.desugar.io; + +import org.objectweb.asm.Opcodes; + +/** Convenience method for working with {@code int} bitwise flags. */ +public class BitFlags { + + /** + * Returns {@code true} iff <b>all</b> bits in {@code bitmask} are set in {@code flags}. Trivially + * returns {@code true} if {@code bitmask} is 0. + */ + public static boolean isSet(int flags, int bitmask) { + return (flags & bitmask) == bitmask; + } + + /** + * Returns {@code true} iff <b>none</b> of the bits in {@code bitmask} are set in {@code flags}. + * Trivially returns {@code true} if {@code bitmask} is 0. + */ + public static boolean noneSet(int flags, int bitmask) { + return (flags & bitmask) == 0; + } + + public static boolean isInterface(int access) { + return isSet(access, Opcodes.ACC_INTERFACE); + } + + public static boolean isStatic(int access) { + return isSet(access, Opcodes.ACC_STATIC); + } + + public static boolean isSynthetic(int access) { + return isSet(access, Opcodes.ACC_SYNTHETIC); + } + + // Static methods only + private BitFlags() {} +} |