class JavaClass::ClassFile::References

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

Public Class Methods

new(pool, classidx) click to toggle source

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

# File lib/javaclass/classfile/references.rb, line 12
def initialize(pool, classidx)
  @constant_pool = pool
  @class_idx = classidx
end

Public Instance Methods

referenced_fields(includeown=false) click to toggle source

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

# 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) click to toggle source

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

# 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_classes() click to toggle source

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

# 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