Class: JavaClass::ClassFile::PoolCreator

Inherits:
Object
  • Object
show all
Defined in:
lib/javaclass/classfile/constant_pool.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data, start) ⇒ PoolCreator

Returns a new instance of PoolCreator.



113
114
115
116
# File 'lib/javaclass/classfile/constant_pool.rb', line 113

def initialize(data, start)
  @data = data
  @start = start
end

Instance Attribute Details

#item_countObject (readonly)

Returns the value of attribute item_count.



111
112
113
# File 'lib/javaclass/classfile/constant_pool.rb', line 111

def item_count
  @item_count
end

#poolObject (readonly)

Returns the value of attribute pool.



111
112
113
# File 'lib/javaclass/classfile/constant_pool.rb', line 111

def pool
  @pool
end

Instance Method Details

#create!Object



118
119
120
121
# File 'lib/javaclass/classfile/constant_pool.rb', line 118

def create!
  create_pool
  fill_pool
end

#create_next_constantObject



136
137
138
139
140
141
142
# File 'lib/javaclass/classfile/constant_pool.rb', line 136

def create_next_constant
  type = determine_constant_type
  constant = type.new(@pool, @data, @pos)
  @pool[@cnt] = constant
  @pos += constant.size
  @cnt += constant.slots
end

#create_poolObject



123
124
125
126
127
# File 'lib/javaclass/classfile/constant_pool.rb', line 123

def create_pool
  @pool = {}
  @item_count = @data.u2(@start)
  @pos = @start + 2
end

#determine_constant_typeObject



144
145
146
147
148
149
150
151
152
# File 'lib/javaclass/classfile/constant_pool.rb', line 144

def determine_constant_type
  tag_index = @data.u1(@pos)
  type = ConstantPool::CONSTANT_TYPE_TAGS[tag_index]
  unless type
    raise ClassFormatError, "const ##{@cnt} contains unknown constant pool tag/index #{tag_index} (at pos #{@pos} in class).\n" +
          "allowed are #{ConstantPool::CONSTANT_TYPE_TAGS.keys.sort.join(',')}"
  end
  type
end

#fill_poolObject



129
130
131
132
133
134
# File 'lib/javaclass/classfile/constant_pool.rb', line 129

def fill_pool
  @cnt = 1
  while @cnt <= @item_count-1
    create_next_constant
  end
end