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.



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

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)

Container for values assigned to a variable class Assignments < Hash end



19
20
21
# File 'lib/xumlidot/parsers/method_signature.rb', line 19

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



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/xumlidot/parsers/method_signature.rb', line 66

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

  recv = process(exp.shift) # recv
  name = exp.shift
  args = process(exp.shift) # args

  exp
rescue Exception => e
  if ENV["XUMLIDOT_DEBUG"]
    STDERR.puts "ERROR (MethodSignature#process_call) #{e.message}"
    STDERR.puts e.backtrace.reverse
  end
  exp
end

#process_defn(exp) ⇒ Object



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

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 Exception => e
  STDERR.puts " ** bug: unable to proces defn #{exp}"
  if ENV["XUMLIDOT_DEBUG"]
    STDERR.puts "ERROR (MethodSignature#process_defn) #{e.message}"
    STDERR.puts e.backtrace.reverse
  end
  s()
end

#process_defs(exp) ⇒ Object



59
60
61
# File 'lib/xumlidot/parsers/method_signature.rb', line 59

def process_defs(exp)
  process_defn(exp)
end

#process_lasgn(exp) ⇒ Object



82
83
84
85
86
87
88
89
90
91
92
# File 'lib/xumlidot/parsers/method_signature.rb', line 82

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



34
35
36
# File 'lib/xumlidot/parsers/method_signature.rb', line 34

def to_s
  @definition.to_s
end