Sha256: 32d26b41ac91ae1f2cbd8976951d0d727d9e57c27366b5ce6b3060cd2a86732f
Contents?: true
Size: 1.78 KB
Versions: 5
Compression:
Stored size: 1.78 KB
Contents
require File.join(File.dirname(File.expand_path(__FILE__)), 'code_context') require File.join(File.dirname(File.expand_path(__FILE__)), 'object_refs') module Reek module Core # # The parameters in a method's definition. # module MethodParameters def default_assignments assignments = self[-1] result = [] return result unless is_assignment_block?(assignments) assignments[1..-1].each do |exp| result << exp[1..2] if exp[0] == :lasgn end result end def is_arg?(param) return false if is_assignment_block?(param) return !(param.to_s =~ /^\&/) end def is_assignment_block?(param) Array === param and param[0] == :block end end # # A context wrapper for any method definition found in a syntax tree. # class MethodContext < CodeContext attr_reader :parameters attr_reader :refs attr_reader :num_statements def initialize(outer, exp) super(outer, exp) @parameters = exp[exp[0] == :defn ? 2 : 3] # SMELL: SimulatedPolymorphism @parameters ||= [] @parameters.extend(MethodParameters) @num_statements = 0 @refs = ObjectRefs.new end def count_statements(num) @num_statements += num end def record_call_to(exp) receiver, meth = exp[1..2] receiver ||= [:self] case receiver[0] when :lvar @refs.record_reference_to(receiver) unless meth == :new when :self @refs.record_reference_to(:self) end end def record_use_of_self @refs.record_reference_to(:self) end def envious_receivers return [] if @refs.self_is_max? @refs.max_keys end end end end
Version data entries
5 entries across 5 versions & 1 rubygems