Class: Guff::JavaSource::Printer

Inherits:
Object
  • Object
show all
Defined in:
lib/guff/java_source.rb

Instance Method Summary collapse

Constructor Details

#initializePrinter

Returns a new instance of Printer.



594
595
596
597
598
# File 'lib/guff/java_source.rb', line 594

def initialize
    @text=""
    @indent=0
    @current_line = nil
end

Instance Method Details

#append(s) ⇒ Object



605
606
607
608
609
610
611
# File 'lib/guff/java_source.rb', line 605

def append(s)
    if (@current_line.nil?)
        @current_line = indent_text
    end
    @current_line << s.to_s
    self
end

#append_all(writers, joiner) ⇒ Object



613
614
615
616
617
# File 'lib/guff/java_source.rb', line 613

def append_all(writers, joiner)
    writers.each_joined(joiner) {|w|
        w.write_to(self)
    }
end

#close_braceObject



698
699
700
701
# File 'lib/guff/java_source.rb', line 698

def close_brace
    outdent
    line("}")
end

#contentsObject



703
704
705
# File 'lib/guff/java_source.rb', line 703

def contents
    @text
end

#ensure_member_separation_lineObject



640
641
642
643
644
# File 'lib/guff/java_source.rb', line 640

def ensure_member_separation_line
    if (!@text.ends_with?("\n\n"))
        new_line
    end
end

#indentObject



683
684
685
686
# File 'lib/guff/java_source.rb', line 683

def indent
    @indent += 1
    self
end

#indent_textObject



667
668
669
670
671
672
673
# File 'lib/guff/java_source.rb', line 667

def indent_text
    result = ""
    @indent.times {
        result << "    "
    }
    result
end

#line(s = "") ⇒ Object



600
601
602
603
# File 'lib/guff/java_source.rb', line 600

def line(s="")
    append(s)
    new_line
end

#list_with_prefix(prefix, list, joiner = ',') ⇒ Object



633
634
635
636
637
638
# File 'lib/guff/java_source.rb', line 633

def list_with_prefix(prefix, list, joiner=',')
    if (list.nil? == false && list.size > 0)
        word(prefix).word(list.join(joiner))
    end
    self
end

#new_lineObject



676
677
678
679
680
681
# File 'lib/guff/java_source.rb', line 676

def new_line
    @text << @current_line unless @current_line.nil?
    @text << "\n"
    @current_line=nil
    self
end

#open_braceObject



693
694
695
696
# File 'lib/guff/java_source.rb', line 693

def open_brace
    line("{")
    indent
end

#outdentObject



688
689
690
691
# File 'lib/guff/java_source.rb', line 688

def outdent
    @indent -= 1
    self
end

#semi_colonObject



663
664
665
# File 'lib/guff/java_source.rb', line 663

def semi_colon
    append(';')
end

#word(w) ⇒ Object



646
647
648
649
650
651
652
653
654
# File 'lib/guff/java_source.rb', line 646

def word(w)
    if (w.to_s.size > 0)
        if (!@current_line.nil? && !@text.ends_with?(' '))
            w = " #{w}"
        end
        append(w)
    end
    self
end

#word_with_prefix(prefix, w) ⇒ Object



619
620
621
622
623
624
# File 'lib/guff/java_source.rb', line 619

def word_with_prefix(prefix, w)
    if (w.to_s.size>0)
        word(prefix).word(w)
    end
    self
end

#words(ww) ⇒ Object



656
657
658
659
660
661
# File 'lib/guff/java_source.rb', line 656

def words(ww)
    ww.each {|w|
        word(w)
    }
    self
end

#words_with_prefix(prefix, ww) ⇒ Object



626
627
628
629
630
631
# File 'lib/guff/java_source.rb', line 626

def words_with_prefix(prefix, ww)
    if (ww.nil? == false && ww.size > 0)
        word(prefix).words(ww)
    end
    self
end