Class: Xumlidot::Parsers::MethodSignature

Inherits:
MethodBasedSexpProcessor
  • Object
show all
Defined in:
lib/xumlidot/parsers/method_signature.rb

Overview

Parser for the arguments to a method

e.g. formats def method(a, b = nil)

to a string 'a, b = nil'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(exp, superclass_method: false) ⇒ MethodSignature

Returns a new instance of MethodSignature.



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/xumlidot/parsers/method_signature.rb', line 19

def initialize(exp, superclass_method: false)
  super()

  @definition = ::Xumlidot::Types::MethodSignature.new
  @definition.visibility = Scope.get_visibility
  @definition.args = Args.new(exp.dup[0..2]).definition # only pass the method definition into args
  @definition.superclass_method = superclass_method

  # @assignments = Assignments.new

  process(exp)
end

Instance Attribute Details

#definitionObject (readonly)

class Assignments < Hash end



17
18
19
# File 'lib/xumlidot/parsers/method_signature.rb', line 17

def definition
  @definition
end

Instance Method Details

#process_call(exp) ⇒ Object

CALLS TODO: We need a seperate assignment class to parse these especially assignments so that we can attempt to work out types



63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/xumlidot/parsers/method_signature.rb', line 63

def process_call(exp)
  exp.shift # remove the :call

  _recv = process(exp.shift) # recv
  _name = exp.shift
  _args = process(exp.shift) # args

  exp
rescue StandardError => e
  sdebug('MethodSignature#process_call', e)
  exp
end

#process_defn(exp) ⇒ Object

rubocop:disable Metrics/AbcSize



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/xumlidot/parsers/method_signature.rb', line 37

def process_defn(exp)
  exp.shift unless auto_shift_type # node type
  exp.shift if exp.first.is_a?(Sexp) && exp.first.value == :self # remove :self

  @definition.name = exp.shift
  @definition.file = exp.file
  @definition.line_number = exp.line
  @definition.line_max = exp.line_max

  more = exp.shift
  process(more) if more.is_a?(Sexp) && !more.empty?
  s()
rescue StandardError => e
  warn " ** bug: unable to proces defn #{exp}"

  sdebug('MethodSignature#process_defn', e)
end

#process_defs(exp) ⇒ Object

rubocop:enable Metrics/AbcSize



56
57
58
# File 'lib/xumlidot/parsers/method_signature.rb', line 56

def process_defs(exp)
  process_defn(exp)
end

#process_lasgn(exp) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
# File 'lib/xumlidot/parsers/method_signature.rb', line 76

def process_lasgn(exp)
  exp.shift # remove :lasgn

  _name = exp.shift.to_s
  value = exp.shift

  # @assignments[name] = value

  process(value)
  s()
end

#to_sObject



32
33
34
# File 'lib/xumlidot/parsers/method_signature.rb', line 32

def to_s
  @definition.to_s
end