Sha256: b3c50d3662d3c2c5e644f8d4e7c745c4cfd9747ed4074cae9f3b9a2e22d4194b
Contents?: true
Size: 1.94 KB
Versions: 4
Compression:
Stored size: 1.94 KB
Contents
require 'set' require 'reek/code_context' class Class def is_overriding_method?(name) sym = name.to_sym mine = instance_methods(false) dads = superclass.instance_methods(true) (mine.include?(sym) and dads.include?(sym)) or (mine.include?(name) and dads.include?(name)) end end module Reek class ClassContext < CodeContext def ClassContext.create(outer, exp) res = Name.resolve(exp[1], outer) ClassContext.new(res[0], res[1], exp[2]) end def ClassContext.from_s(src) source = src.to_reek_source sniffer = Sniffer.new(source) CodeParser.new(sniffer).process_class(source.syntax_tree) end attr_reader :conditionals, :parsed_methods # SMELL: inconsistent with other contexts (not linked to the sexp) def initialize(outer, name, superclass = nil) super(outer, nil) @name = name @superclass = superclass @parsed_methods = [] @instance_variables = Set.new @conditionals = [] end def myself @myself ||= @outer.find_module(@name) end def find_module(modname) return nil unless myself @myself.const_or_nil(modname.to_s) end def is_overriding_method?(name) return false unless myself @myself.is_overriding_method?(name.to_s) end def is_struct? @superclass == [:const, :Struct] end def num_methods @parsed_methods.length end def record_instance_variable(sym) @instance_variables << Name.new(sym) end def record_method(meth) @parsed_methods << meth end def outer_name "#{@outer.outer_name}#{@name}#" end def to_s "#{@outer.outer_name}#{@name}" end def variable_names @instance_variables end def record_conditional(exp) @conditionals << exp end def parameterized_methods(min_clump_size) parsed_methods.select {|meth| meth.parameters.length >= min_clump_size } end end end
Version data entries
4 entries across 4 versions & 2 rubygems