Sha256: 345d0d84f4669944ed7f198db2d8df94fa2ca1b43339011c45c05373ff4b048c

Contents?: true

Size: 1.57 KB

Versions: 13

Compression:

Stored size: 1.57 KB

Contents

module Churn
  
  # Given a ruby file, map the klass and methods to a range of line numbers
  # The klass and method to line numbers mappings, are stored in
  # @klasses_collection and @methods_collection
  class LocationMapping < SexpProcessor
    
    attr_reader :klasses_collection, :methods_collection
    
    def initialize()
      super
      @klasses_collection  = {}
      @methods_collection  = {}
      @parser              = RubyParser.new
      self.auto_shift_type = true
    end
    
    def get_info(file)
      ast = @parser.process(File.read(file), file)
      process ast
    end
    
    def process_class(exp)
      name           = exp.shift
      start_line     = exp.line
      last_line      = exp.last.line
      name           = name if name.is_a?(Symbol)
      name           = name.values.value if name.is_a?(Sexp) #deals with cases like class Test::Unit::TestCase
      @current_class = name
      @klasses_collection[name.to_s] = [] unless @klasses_collection.include?(name)
      @klasses_collection[name.to_s] << (start_line..last_line)
      analyze_list exp
      s()
    end
    
    def analyze_list exp
      process exp.shift until exp.empty?
    end
    
    def process_defn(exp)
      name        = exp.shift
      start_line  = exp.line
      last_line   = exp.last.line
      full_name   = "#{@current_class}##{name}"
      @methods_collection[full_name] = [] unless @methods_collection.include?(full_name)
      @methods_collection[full_name] << (start_line..last_line)
      return s(:defn, name, process(exp.shift), process(exp.shift))
    end

  end

end

Version data entries

13 entries across 13 versions & 2 rubygems

Version Path
churn-0.0.25 lib/churn/location_mapping.rb
churn-0.0.24 lib/churn/location_mapping.rb
churn-0.0.23 lib/churn/location_mapping.rb
churn-0.0.22 lib/churn/location_mapping.rb
churn-0.0.21 lib/churn/location_mapping.rb
churn-0.0.20 lib/churn/location_mapping.rb
churn-0.0.19 lib/churn/location_mapping.rb
rferraz-churn-0.0.19 lib/churn/location_mapping.rb
rferraz-churn-0.0.17 lib/churn/location_mapping.rb
rferraz-churn-0.0.16 lib/churn/location_mapping.rb
churn-0.0.15 lib/churn/location_mapping.rb
churn-0.0.14 lib/churn/location_mapping.rb
churn-0.0.13 lib/churn/location_mapping.rb