Class: XDry::Generators::Synthesize

Inherits:
Generator
  • Object
show all
Defined in:
lib/xdry/generators/synthesize.rb

Instance Attribute Summary

Attributes inherited from Generator

#patcher

Instance Method Summary collapse

Methods inherited from Generator

id, inherited, #initialize, #process_class, #verbose?

Constructor Details

This class inherits a constructor from XDry::Generators::Generator

Instance Method Details

#process_attribute(oclass, oattr) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/xdry/generators/synthesize.rb', line 8

def process_attribute oclass, oattr
  if oattr.has_property_def? && !oattr.has_synthesize? && !oclass.has_method_impl?(oattr.getter_selector)
    synthesize = oattr.new_synthesize
    impl = oclass.main_implementation
    new_lines = [synthesize.to_s]
    if impl.synthesizes.empty?
      pos = impl.start_node.pos
      new_lines = [""] + new_lines + [""]
    else
      pos = impl.synthesizes.sort { |a, b| a.pos.line_no <=> b.pos.line_no }.last.pos
    end
    patcher.insert_after pos, new_lines
  end
end