Skip to content

Commit

Permalink
expose a method_locations hash which lets you look up a line number b…
Browse files Browse the repository at this point in the history
…y method name
  • Loading branch information
Marty Andrews committed Dec 8, 2009
1 parent 685fbb3 commit d726513
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions lib/flog.rb
Expand Up @@ -69,7 +69,7 @@ class Flog < SexpProcessor
@@no_method = :none

attr_accessor :multiplier
attr_reader :calls, :options, :class_stack, :method_stack, :mass
attr_reader :calls, :options, :class_stack, :method_stack, :mass, :method_locations

def self.default_options
{
Expand Down Expand Up @@ -199,8 +199,9 @@ def in_klass name
##
# Adds name to the list of methods, for the duration of the block

def in_method name
def in_method(name, line)
@method_stack.unshift name
@method_locations["#{klass_name}##{name}"] = line
yield
@method_stack.shift
end
Expand All @@ -215,6 +216,7 @@ def initialize options = {}
@options = options
@class_stack = []
@method_stack = []
@method_locations = {}
@mass = {}
@parser = RubyParser.new
self.auto_shift_type = true
Expand Down Expand Up @@ -486,15 +488,15 @@ def process_dasgn_curr(exp)
alias :process_lasgn :process_dasgn_curr

def process_defn(exp)
in_method exp.shift do
in_method(exp.shift, exp.line) do
analyze_list exp
end
s()
end

def process_defs(exp)
process exp.shift
in_method exp.shift do
in_method(exp.shift, exp.line) do
analyze_list exp
end
s()
Expand Down Expand Up @@ -529,8 +531,8 @@ def process_iter(exp)
[:lit, :str].include? recv.arglist[1][0]) then
msg = recv[2]
submsg = recv.arglist[1][1]
in_method submsg do
in_klass msg do
in_klass msg do
in_method(submsg, exp.line) do
analyze_list exp
end
end
Expand Down

2 comments on commit d726513

@zenspider
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just tried to merge this in, had every patch fail, and then figured out that I did this years ago :P

@martinjandrews
Copy link
Owner

@martinjandrews martinjandrews commented on d726513 Jul 1, 2011 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.