class JavaClass::ClassFile::AccessFlags

The general JVM access flags.

Author

Peter Kofler

Attributes

flags[R]

Public Class Methods

new(flags) click to toggle source
# File lib/javaclass/classfile/access_flags.rb, line 14
def initialize(flags)
  @flags = flags
  correct_flags
  assert_flags
end

Public Instance Methods

abstract?() click to toggle source
# File lib/javaclass/classfile/access_flags.rb, line 63
def abstract?
  is? ACC_ABSTRACT
end
accessible?()
Alias for: public?
annotation?() click to toggle source
# File lib/javaclass/classfile/access_flags.rb, line 79
def annotation?
  is? ACC_ANNOTATION
end
enum?() click to toggle source
# File lib/javaclass/classfile/access_flags.rb, line 75
def enum?
  is? ACC_ENUM
end
final?() click to toggle source
# File lib/javaclass/classfile/access_flags.rb, line 59
def final?
  is? ACC_FINAL
end
flags_hex() click to toggle source

Return the hex word of the flag.

# File lib/javaclass/classfile/access_flags.rb, line 88
def flags_hex
  format '%4.4X', @flags
end
interface?() click to toggle source
# File lib/javaclass/classfile/access_flags.rb, line 71
def interface?
  is? ACC_INTERFACE
end
is?(flag) click to toggle source

Return true if the bit flag is set.

# File lib/javaclass/classfile/access_flags.rb, line 37
def is?(flag)
  (@flags & flag) != 0
end
module?() click to toggle source
# File lib/javaclass/classfile/access_flags.rb, line 83
def module?
  is? ACC_MODULE
end
private?() click to toggle source
# File lib/javaclass/classfile/access_flags.rb, line 47
def private?
  is? ACC_PRIVATE
end
protected?() click to toggle source
# File lib/javaclass/classfile/access_flags.rb, line 51
def protected?
  is? ACC_PROTECTED
end
public?() click to toggle source

Return true if the class is public.

# File lib/javaclass/classfile/access_flags.rb, line 42
def public?
  is? ACC_PUBLIC
end
Also aliased as: accessible?
static?() click to toggle source
# File lib/javaclass/classfile/access_flags.rb, line 55
def static?
  is? ACC_STATIC
end
synthetic?() click to toggle source
# File lib/javaclass/classfile/access_flags.rb, line 67
def synthetic?
  is? ACC_SYNTHETIC
end

Private Instance Methods

assert_flags() click to toggle source
# File lib/javaclass/classfile/access_flags.rb, line 28
def assert_flags
  raise ClassFormatError, "inconsistent flags #{flags} (abstract and final)" if abstract? && final?
  raise ClassFormatError, "inconsistent flags #{flags} (interface not abstract)" if interface? && !abstract?
  raise ClassFormatError, "inconsistent flags #{flags} (interface is final)" if interface? && final?
  raise ClassFormatError, "inconsistent flags #{flags} (annotation not interface)" if annotation? && !interface?
end
correct_flags() click to toggle source
# File lib/javaclass/classfile/access_flags.rb, line 20
def correct_flags
  if interface? && !abstract?
    # JDK 1.0 and 1.1 do have non abstract interfaces, fix it
    @flags = @flags | ACC_ABSTRACT
  end
end