Class: JavaClass::ClassFile::PoolCreator
- Defined in:
- lib/javaclass/classfile/constant_pool.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#item_count ⇒ Object
readonly
Returns the value of attribute item_count.
-
#pool ⇒ Object
readonly
Returns the value of attribute pool.
Instance Method Summary collapse
- #create! ⇒ Object
- #create_next_constant ⇒ Object
- #create_pool ⇒ Object
- #determine_constant_type ⇒ Object
- #fill_pool ⇒ Object
-
#initialize(data, start) ⇒ PoolCreator
constructor
A new instance of PoolCreator.
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_count ⇒ Object (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 |
#pool ⇒ Object (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_constant ⇒ Object
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_pool ⇒ Object
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_type ⇒ Object
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_pool ⇒ Object
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 |