1

I am writing an analyzer for Java class files using ASM. One of the things I want to determine is what the modifiers (public, static, final?) of the fields in a class are. But I am not sure how to do this.

In the documentation i found the opcodes of the modifiers, which seems to correlate with the acces value of the FieldNode class. But I don't see how I derive the modifiers of the field form this value.

Any suggestions?

TheArchitect
  • 129
  • 3
  • 9

1 Answers1

5

The access member variable is a bitfield, each bit position corresponds to a specific access modifier. To check a bit you have to use a binary AND with the constant from Opcodes and check if the result is not zero. For example:

boolean isPublic = (node.access & Opcodes.ACC_PUBLIC) != 0;
boolean isStatic = (node.access & Opcodes.ACC_STATIC) != 0;
Jörn Horstmann
  • 33,639
  • 11
  • 75
  • 118