Class: JavaClass::ClassFile::References

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

Overview

Container class for list of all classes, methods and fields referenced by this class. This information is derived from the constant pool, no analysis.

Author

Peter Kofler

Instance Method Summary collapse

Constructor Details

#initialize(pool, classidx) ⇒ References

Create a references container with the constant pool and skip references to index classidx which is the host class itself.



12
13
14
15
# File 'lib/javaclass/classfile/references.rb', line 12

def initialize(pool, classidx)
  @constant_pool = pool
  @class_idx = classidx
end

Instance Method Details

#referenced_fields(includeown = false) ⇒ Object

Return the constants referring to fields (Constants::ConstantField). If includeown is true then fields of this class are returned also.



19
20
21
22
23
# File 'lib/javaclass/classfile/references.rb', line 19

def referenced_fields(includeown=false)
  @constant_pool.find(ConstantPool::FIELD_TAG).find_all do |field|
    includeown || field.class_index != @class_idx
  end
end

#referenced_methods(includeown = false) ⇒ Object

Return the constants referring to methods (Constants::ConstantMethod) in classes or interfaces. If includeown is true then methods of this class are returned also.



27
28
29
30
31
# File 'lib/javaclass/classfile/references.rb', line 27

def referenced_methods(includeown=false)
  @constant_pool.find(ConstantPool::METHOD_TAG, ConstantPool::INTERFACE_METHOD_TAG).find_all do |method|
    includeown || method.class_index != @class_idx
  end
end

#used_classesObject

Return the list of all constant pool constantss containing class names of all used classes. Returns a list of ConstantClass.



35
36
37
38
39
40
# File 'lib/javaclass/classfile/references.rb', line 35

def used_classes
  my_class_name = @constant_pool[@class_idx].class_name
  @constant_pool.find(ConstantPool::CLASS_TAG).find_all do |cl|
    cl.class_name != my_class_name 
  end
end