class JvmBytecode::Attributes::Attribute

Attributes

attr_name[R]
locations[R]
cp[R]

Public Class Methods

decode_serial(cp, io) click to toggle source
# File lib/jvm_bytecode/attributes/attribute.rb, line 25
def decode_serial(cp, io)
  n = io.read(2).unpack('S>').first
  Array.new(n) do
    name_index = io.read(2).unpack('S>').first
    fetch(cp.constant(name_index).to_s).new(cp).tap { |a| a.decode(io) }
  end
end
define(name: nil, location:) click to toggle source
# File lib/jvm_bytecode/attributes/attribute.rb, line 9
def define(name: nil, location:)
  @attr_name = name || shortname.encode('UTF-8')
  @locations = location

  @@attributes ||= {}
  @@attributes[@attr_name] = self
end
fetch(attr_name) click to toggle source
# File lib/jvm_bytecode/attributes/attribute.rb, line 17
def fetch(attr_name)
  @@attributes[attr_name] || raise(Errors::AttributeError, "#{attr_name} is not implemented")
end
locatable_at(loc) click to toggle source
# File lib/jvm_bytecode/attributes/attribute.rb, line 21
def locatable_at(loc)
  @@attributes.select { |_, v| v.locations.include?(loc) }
end
new(cp) click to toggle source
# File lib/jvm_bytecode/attributes/attribute.rb, line 36
def initialize(cp)
  @cp = cp
end

Public Instance Methods

additional_bytecode() click to toggle source
# File lib/jvm_bytecode/attributes/attribute.rb, line 40
def additional_bytecode
  raise NotImplementedError, "#{self.class}##{__method__} is not implemented!"
end
bytecode() click to toggle source
# File lib/jvm_bytecode/attributes/attribute.rb, line 44
def bytecode
  bc = additional_bytecode
  [cp.utf8(self.class.attr_name), bc.length].pack('S>I>') + bc
end