Module: JavaClass::Analyse::Dependencies

Included in:
Dsl::ClasspathAnalysers
Defined in:
lib/javaclass/analyse/dependencies.rb

Overview

Analyser to get dependencies of a whole Classpath (to be mixed into Dsl::LoadingClasspath). For an example see how to list all imported types.

Author

Peter Kofler

Instance Method Summary collapse

Instance Method Details

#external_types(&filter) ⇒ Object

Determine all foreign imported types from all classes in this classpath. An additional block is used as filter on class names.



45
46
47
# File 'lib/javaclass/analyse/dependencies.rb', line 45

def external_types(&filter)
  used_types(&filter) - types(&filter)
end

#types(&filter) ⇒ Object

Return all types in this classpath. An additional block is used as filter on class names. Returns a list of JavaQualifiedName. Requires a method names in the base class.



17
18
19
# File 'lib/javaclass/analyse/dependencies.rb', line 17

def types(&filter)
  names(&filter).collect { |c| c.to_classname }.sort
end

#used_types(&filter) ⇒ Object

Determine all imported types from all classes in this classpath. An additional block is used as filter on class names.



39
40
41
# File 'lib/javaclass/analyse/dependencies.rb', line 39

def used_types(&filter)
  used_types_map(&filter).keys.sort
end

#used_types_map(&filter) ⇒ Object

Determine all imported types from all classes in this classpath together with count of imports. An additional block is used as filter on class names. Requires a method values in the base class.



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/javaclass/analyse/dependencies.rb', line 23

def used_types_map(&filter)
  type_map = Hash.new(0) # class_name (JavaQualifiedName) => cnt
  values(&filter).collect { |clazz| clazz.imported_3rd_party_types }.flatten.each do |type|

    # hash keys need to be frozen to keep state
    if !type_map.include?(type)
      type = type.freeze 
    end

    type_map[type] += 1
  end
  type_map
end