Commit d3431961 authored by Lubomir Bulej's avatar Lubomir Bulej

Add Access enum to represent Opcodes.ACC_* flags

parent 31f558ca
package ch.usi.dag.util.asm;
import static java.util.stream.Collectors.joining;
import java.util.Arrays;
import org.objectweb.asm.Opcodes;
/**
* Represents an access flag associated with Java module, class, method, or
* field. Based on and should be kept in synch with ASM {@link Opcodes}
* interface.
*
* @author Lubomir Bulej <bulej@d3s.mff.cuni.cz>
*/
public enum Access {
PUBLIC (Opcodes.ACC_PUBLIC),
PRIVATE (Opcodes.ACC_PRIVATE),
PROTECTED (Opcodes.ACC_PROTECTED),
STATIC (Opcodes.ACC_STATIC),
FINAL (Opcodes.ACC_FINAL),
SUPER (Opcodes.ACC_SUPER),
SYNCHRONIZED (Opcodes.ACC_SYNCHRONIZED),
OPEN (Opcodes.ACC_OPEN),
VOLATILE (Opcodes.ACC_VOLATILE),
BRIDGE (Opcodes.ACC_BRIDGE),
STATIC_PHASE (Opcodes.ACC_STATIC_PHASE),
VARARGS (Opcodes.ACC_VARARGS),
TRANSIENT (Opcodes.ACC_TRANSIENT),
NATIVE (Opcodes.ACC_NATIVE),
INTERFACE (Opcodes.ACC_INTERFACE),
ABSTRACT (Opcodes.ACC_ABSTRACT),
STRICT (Opcodes.ACC_STRICT),
SYNTHETIC (Opcodes.ACC_SYNTHETIC),
ANNOTATION (Opcodes.ACC_ANNOTATION),
ENUM(Opcodes.ACC_ENUM),
MANDATED (Opcodes.ACC_MANDATED),
MODULE (Opcodes.ACC_MODULE),
DEPRECATED (Opcodes.ACC_DEPRECATED);
//
static final Access[] __fieldOrder = {
PUBLIC, PRIVATE, PROTECTED, STATIC, FINAL, VOLATILE, TRANSIENT,
SYNTHETIC, ENUM,
};
static final Access[] __classOrder = {
PUBLIC, PRIVATE, PROTECTED, STATIC, FINAL, SUPER, INTERFACE,
ABSTRACT, SYNTHETIC, ANNOTATION, ENUM, MODULE, DEPRECATED,
};
static final Access[] __methodOrder = {
DEPRECATED, SYNCHRONIZED, NATIVE, BRIDGE, VARARGS, STRICT,
SYNTHETIC, PUBLIC, PRIVATE, PROTECTED, STATIC, FINAL, ABSTRACT,
};
//
private final int __flag;
private String __lowerCaseName;
Access (final int flag) {
__flag = flag;
}
public boolean isSet (final int access) {
return (access & __flag) != 0;
}
public String keyword (final int access) {
if ((access & __flag) == 0) {
return null;
} {
if (__lowerCaseName == null) {
__lowerCaseName = toString().toLowerCase ();
}
return __lowerCaseName;
}
}
//
public static String formatAccess (final int access) {
return __formatAccess (access, values ());
}
public static String formatClassAccess (final int access) {
return __formatAccess (access, __classOrder);
}
public static String formatMethodAccess (final int access) {
return __formatAccess (access, __methodOrder);
}
public static String formatFieldAccess (final int access) {
return __formatAccess (access, __fieldOrder);
}
//
private static String __formatAccess (final int access, final Access[] accesses) {
return Arrays.stream (accesses)
.map (a -> a.keyword (access))
.filter (n -> n != null)
.collect (joining (" "));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment