Parent

Class/Module Index [+]

Quicksearch

Reek::Core::CodeParser

Traverses a Sexp abstract syntax tree and fires events whenever it encounters specific node types.

Public Class Methods

count_statements(exp) click to toggle source
# File lib/reek/core/code_parser.rb, line 136
def self.count_statements(exp)
  stmts = exp[1..-1]
  ignore = 0
  ignore += 1 if stmts[1] == s(:nil)
  stmts.length - ignore
end
new(sniffer, ctx = StopContext.new) click to toggle source
# File lib/reek/core/code_parser.rb, line 15
def initialize(sniffer, ctx = StopContext.new)
  @sniffer = sniffer
  @element = ctx
end

Public Instance Methods

count_clause(sexp) click to toggle source
# File lib/reek/core/code_parser.rb, line 130
def count_clause(sexp)
  if sexp and !sexp.has_type?(:block)
    @element.count_statements(1)
  end
end
process(exp) click to toggle source
# File lib/reek/core/code_parser.rb, line 20
def process(exp)
  meth = "process_#{exp[0]}"
  meth = :process_default unless self.respond_to?(meth)
  self.send(meth, exp)
  @element
end
process_args(exp) click to toggle source
# File lib/reek/core/code_parser.rb, line 53
def process_args(exp) end
process_attrasgn(exp) click to toggle source
# File lib/reek/core/code_parser.rb, line 69
def process_attrasgn(exp)
  process_call(exp)
end
process_block(exp) click to toggle source
# File lib/reek/core/code_parser.rb, line 59
def process_block(exp)
  @element.count_statements(CodeParser.count_statements(exp))
  process_default(exp)
end
process_call(exp) click to toggle source
# File lib/reek/core/code_parser.rb, line 64
def process_call(exp)
  @element.record_call_to(exp)
  process_default(exp)
end
process_case(exp) click to toggle source
# File lib/reek/core/code_parser.rb, line 107
def process_case(exp)
  process_default(exp)
  @element.count_statements(-1)
end
process_class(exp) click to toggle source
# File lib/reek/core/code_parser.rb, line 41
def process_class(exp)
  process_module(exp)
end
process_default(exp) click to toggle source
# File lib/reek/core/code_parser.rb, line 27
def process_default(exp)
  exp.each { |sub| process(sub) if Array === sub }
end
process_defn(exp) click to toggle source
# File lib/reek/core/code_parser.rb, line 45
def process_defn(exp)
  handle_context(MethodContext, exp[0], exp)
end
process_defs(exp) click to toggle source
# File lib/reek/core/code_parser.rb, line 49
def process_defs(exp)
  handle_context(SingletonMethodContext, exp[0], exp)
end
process_for(exp) click to toggle source
# File lib/reek/core/code_parser.rb, line 93
def process_for(exp)
  count_clause(exp[3])
  process_case(exp)
end
process_iasgn(exp) click to toggle source
# File lib/reek/core/code_parser.rb, line 121
def process_iasgn(exp)
  @element.record_use_of_self
  process_default(exp)
end
process_if(exp) click to toggle source
# File lib/reek/core/code_parser.rb, line 77
def process_if(exp)
  count_clause(exp[2])
  count_clause(exp[3])
  process_default(exp)
  @element.count_statements(-1)
end
process_ivar(exp) click to toggle source
# File lib/reek/core/code_parser.rb, line 117
def process_ivar(exp)
  process_iasgn(exp)
end
process_module(exp) click to toggle source
# File lib/reek/core/code_parser.rb, line 31
def process_module(exp)
  name = Source::SexpFormatter.format(exp[1])
  scope = ModuleContext.new(@element, name, exp)
  push(scope) do
    process_default(exp) unless exp.superclass == [:const, :Struct]
    check_smells(exp[0])
  end
  scope
end
process_op_asgn1(exp) click to toggle source
# File lib/reek/core/code_parser.rb, line 73
def process_op_asgn1(exp)
  process_call(exp)
end
process_resbody(exp) click to toggle source
# File lib/reek/core/code_parser.rb, line 103
def process_resbody(exp)
  process_when(exp)
end
process_rescue(exp) click to toggle source
# File lib/reek/core/code_parser.rb, line 98
def process_rescue(exp)
  count_clause(exp[1])
  process_case(exp)
end
process_self(exp) click to toggle source
# File lib/reek/core/code_parser.rb, line 126
def process_self(exp)
  @element.record_use_of_self
end
process_until(exp) click to toggle source
# File lib/reek/core/code_parser.rb, line 88
def process_until(exp)
  count_clause(exp[2])
  process_case(exp)
end
process_when(exp) click to toggle source
# File lib/reek/core/code_parser.rb, line 112
def process_when(exp)
  count_clause(exp[2])
  process_default(exp)
end
process_while(exp) click to toggle source
# File lib/reek/core/code_parser.rb, line 84
def process_while(exp)
  process_until(exp)
end
process_zsuper(exp) click to toggle source
# File lib/reek/core/code_parser.rb, line 55
def process_zsuper(exp)
  @element.record_use_of_self
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.