Class | JavaClass::Classpath::TrackingClasspath |
In: |
lib/javaclass/classpath/tracking_classpath.rb
|
Parent: | SimpleDelegator |
A delegator classpath that tracks which classes have been accessed. For an example see how to find (un)referenced JARs.
Author: | Peter Kofler |
Create a tracked instance of the classpath .
# File lib/javaclass/classpath/tracking_classpath.rb, line 13 def initialize(classpath) unless classpath.respond_to?(:load_binary) || classpath.respond_to?(:load) raise ArgumentError, "wrong type of delegatee #{classpath.class}" end @classpath = classpath reset_access super(classpath) end
Was the classname accessed then return the count? If classname is nil then check if any class was accessed.
# File lib/javaclass/classpath/tracking_classpath.rb, line 69 def accessed(classname=nil) if classname key = to_key(classname) @accessed[key] else @accessed.values.inject(0) {|s,e| s + e } end end
Return the classnames of all accessed classes. This is a list of frozen JavaClassFileName.
# File lib/javaclass/classpath/tracking_classpath.rb, line 79 def all_accessed @accessed.keys.sort end
Returns the wrapped classpath element (self) of this decorated classpath.
# File lib/javaclass/classpath/tracking_classpath.rb, line 23 def elements if [FolderClasspath, JarClasspath].include?(@classpath.class) # TODO check for any subclass of FileClasspath instead [self] else @classpath.elements end end
Mark the classname as accessed. Return the number of accesses so far.
# File lib/javaclass/classpath/tracking_classpath.rb, line 52 def mark_accessed(classname) key = to_key(classname) if @classpath.includes?(key) # hash keys need to be frozen to keep state if !@accessed.include?(key) key = key.freeze end @accessed[key] += 1 else nil end end