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.
112 113 114 115 |
# File 'lib/javaclass/classfile/constant_pool.rb', line 112 def initialize(data, start) @data = data @start = start end |
Instance Attribute Details
#item_count ⇒ Object (readonly)
Returns the value of attribute item_count.
110 111 112 |
# File 'lib/javaclass/classfile/constant_pool.rb', line 110 def item_count @item_count end |
#pool ⇒ Object (readonly)
Returns the value of attribute pool.
110 111 112 |
# File 'lib/javaclass/classfile/constant_pool.rb', line 110 def pool @pool end |
Instance Method Details
#create! ⇒ Object
117 118 119 120 |
# File 'lib/javaclass/classfile/constant_pool.rb', line 117 def create! create_pool fill_pool end |
#create_next_constant ⇒ Object
135 136 137 138 139 140 141 |
# File 'lib/javaclass/classfile/constant_pool.rb', line 135 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
122 123 124 125 126 |
# File 'lib/javaclass/classfile/constant_pool.rb', line 122 def create_pool @pool = {} @item_count = @data.u2(@start) @pos = @start + 2 end |
#determine_constant_type ⇒ Object
143 144 145 146 147 148 149 150 151 |
# File 'lib/javaclass/classfile/constant_pool.rb', line 143 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
128 129 130 131 132 133 |
# File 'lib/javaclass/classfile/constant_pool.rb', line 128 def fill_pool @cnt = 1 while @cnt <= @item_count-1 create_next_constant end end |