Class: JavaClass::ClassFile::Constants::Base

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

Overview

Superclass of all constant values in the constant pool. Every constant has a name, a tag and a size in bytes.

Author

Peter Kofler

Direct Known Subclasses

SingleReference, Value

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name = nil) ⇒ Base

Set default constants.



20
21
22
23
24
25
26
27
28
# File 'lib/javaclass/classfile/constants/base.rb', line 20

def initialize(name=nil)
  if name
    @name = name
  else 
    @name = self.class.to_s[/::[^:]+$/][10..-1] # skip modules (::) and "Constant"
  end
  @size = 3
  @slots = 1
end

Instance Attribute Details

#nameObject (readonly)

ZenTest FULL to find method name



14
15
16
# File 'lib/javaclass/classfile/constants/base.rb', line 14

def name
  @name
end

#sizeObject (readonly)

Returns the value of attribute size.



16
17
18
# File 'lib/javaclass/classfile/constants/base.rb', line 16

def size
  @size
end

#slotsObject (readonly)

Returns the value of attribute slots.



17
18
19
# File 'lib/javaclass/classfile/constants/base.rb', line 17

def slots
  @slots
end

#tagObject (readonly)

Returns the value of attribute tag.



15
16
17
# File 'lib/javaclass/classfile/constants/base.rb', line 15

def tag
  @tag
end

Instance Method Details

#const_class?Boolean

Return false for sanity check if it’s a class. Subclasses should overwrite.

Returns:

  • (Boolean)


36
37
38
# File 'lib/javaclass/classfile/constants/base.rb', line 36

def const_class?
  false
end

#const_field?Boolean

Return false for sanity check if it’s a field. Subclasses should overwrite.

Returns:

  • (Boolean)


41
42
43
# File 'lib/javaclass/classfile/constants/base.rb', line 41

def const_field?
  false
end

#const_method?Boolean

Return false for sanity check if it’s a method. Subclasses should overwrite.

Returns:

  • (Boolean)


46
47
48
# File 'lib/javaclass/classfile/constants/base.rb', line 46

def const_method?
  false
end

#dumpObject

Return part of debug output.



31
32
33
# File 'lib/javaclass/classfile/constants/base.rb', line 31

def dump
  "#{@name}\t" # #{@tag}
end