Skip to content

Commit

Permalink
Internal refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
garydgregory committed Jan 7, 2024
1 parent 89b10c4 commit add006f
Showing 1 changed file with 29 additions and 17 deletions.
46 changes: 29 additions & 17 deletions src/main/java/org/apache/bcel/classfile/AccessFlags.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ public abstract class AccessFlags {
@java.lang.Deprecated
protected int access_flags; // TODO not used externally at present

/**
* Constructs a new instance.
*/
public AccessFlags() {
}

Expand Down Expand Up @@ -67,7 +70,7 @@ public final int getModifiers() {
* @return whether the abstract bit is on.
*/
public final boolean isAbstract() {
return (access_flags & Const.ACC_ABSTRACT) != 0;
return test(Const.ACC_ABSTRACT);
}

/**
Expand All @@ -85,7 +88,7 @@ public final void isAbstract(final boolean flag) {
* @return whether the annotation bit is on.
*/
public final boolean isAnnotation() {
return (access_flags & Const.ACC_ANNOTATION) != 0;
return test(Const.ACC_ANNOTATION);
}

/**
Expand All @@ -96,14 +99,13 @@ public final boolean isAnnotation() {
public final void isAnnotation(final boolean flag) {
setFlag(Const.ACC_ANNOTATION, flag);
}

/**
* Tests whether the enum bit is on.
*
* @return whether the enum bit is on.
*/
public final boolean isEnum() {
return (access_flags & Const.ACC_ENUM) != 0;
return test(Const.ACC_ENUM);
}

/**
Expand All @@ -121,7 +123,7 @@ public final void isEnum(final boolean flag) {
* @return whether the final bit is on.
*/
public final boolean isFinal() {
return (access_flags & Const.ACC_FINAL) != 0;
return test(Const.ACC_FINAL);
}

/**
Expand All @@ -139,7 +141,7 @@ public final void isFinal(final boolean flag) {
* @return whether the interface bit is on.
*/
public final boolean isInterface() {
return (access_flags & Const.ACC_INTERFACE) != 0;
return test(Const.ACC_INTERFACE);
}

/**
Expand All @@ -157,7 +159,7 @@ public final void isInterface(final boolean flag) {
* @return whether the native bit is on.
*/
public final boolean isNative() {
return (access_flags & Const.ACC_NATIVE) != 0;
return test(Const.ACC_NATIVE);
}

/**
Expand All @@ -175,7 +177,7 @@ public final void isNative(final boolean flag) {
* @return whether the private bit is on.
*/
public final boolean isPrivate() {
return (access_flags & Const.ACC_PRIVATE) != 0;
return test(Const.ACC_PRIVATE);
}

/**
Expand All @@ -193,7 +195,7 @@ public final void isPrivate(final boolean flag) {
* @return whether the protected bit is on.
*/
public final boolean isProtected() {
return (access_flags & Const.ACC_PROTECTED) != 0;
return test(Const.ACC_PROTECTED);
}

/**
Expand All @@ -211,7 +213,7 @@ public final void isProtected(final boolean flag) {
* @return whether the public bit is on.
*/
public final boolean isPublic() {
return (access_flags & Const.ACC_PUBLIC) != 0;
return test(Const.ACC_PUBLIC);
}

/**
Expand All @@ -229,7 +231,7 @@ public final void isPublic(final boolean flag) {
* @return whether the static bit is on.
*/
public final boolean isStatic() {
return (access_flags & Const.ACC_STATIC) != 0;
return test(Const.ACC_STATIC);
}

/**
Expand All @@ -247,7 +249,7 @@ public final void isStatic(final boolean flag) {
* @return whether the strict bit is on.
*/
public final boolean isStrictfp() {
return (access_flags & Const.ACC_STRICT) != 0;
return test(Const.ACC_STRICT);
}

/**
Expand All @@ -265,7 +267,7 @@ public final void isStrictfp(final boolean flag) {
* @return whether the synchronized bit is on.
*/
public final boolean isSynchronized() {
return (access_flags & Const.ACC_SYNCHRONIZED) != 0;
return test(Const.ACC_SYNCHRONIZED);
}

/**
Expand All @@ -283,7 +285,7 @@ public final void isSynchronized(final boolean flag) {
* @return whether the synthetic bit is on.
*/
public final boolean isSynthetic() {
return (access_flags & Const.ACC_SYNTHETIC) != 0;
return test(Const.ACC_SYNTHETIC);
}

/**
Expand All @@ -301,7 +303,7 @@ public final void isSynthetic(final boolean flag) {
* @return whether the varargs bit is on.
*/
public final boolean isTransient() {
return (access_flags & Const.ACC_TRANSIENT) != 0;
return test(Const.ACC_TRANSIENT);
}

/**
Expand All @@ -319,7 +321,7 @@ public final void isTransient(final boolean flag) {
* @return whether the varargs bit is on.
*/
public final boolean isVarArgs() {
return (access_flags & Const.ACC_VARARGS) != 0;
return test(Const.ACC_VARARGS);
}

/**
Expand All @@ -337,7 +339,7 @@ public final void isVarArgs(final boolean flag) {
* @return whether the volatile bit is on.
*/
public final boolean isVolatile() {
return (access_flags & Const.ACC_VOLATILE) != 0;
return test(Const.ACC_VOLATILE);
}

/**
Expand Down Expand Up @@ -376,4 +378,14 @@ private void setFlag(final int flag, final boolean set) {
public final void setModifiers(final int accessFlags) {
setAccessFlags(accessFlags);
}

/**
* Tests whether the bit is on.
*
* @param test the bit to test.
* @return whether the bit is on.
*/
private boolean test(final short test) {
return (access_flags & test) != 0;
}
}

0 comments on commit add006f

Please sign in to comment.