class Astrapi::ClassDiagramPrinter

Constants

DECL_FOR_INSTRINSICS

Public Instance Methods

is_instrinsic(type) click to toggle source
# File lib/class_diagram_printer.rb, line 73
def is_instrinsic type
  if type.respond_to? :type
    str=type.type.name.to_s
    return str==str.upcase
  else
    str=type.name.to_s
    return str==str.upcase
  end
end
print(ast) click to toggle source
visitKlass(klass,args=nil) click to toggle source
# File lib/class_diagram_printer.rb, line 51
def visitKlass klass,args=nil
  indent "visitKlass"
  code = Code.new
  klass.attrs.each do |attr|
    case type=attr.type
    when ArrayOf
      sink=type.type.name.to_s
      head="label=\"*\""
    when Type
      sink=type.name.to_s
      head="label=1"
      code << DECL_FOR_INSTRINSICS[sink.to_sym] if is_instrinsic(type)
    end
    code << "#{klass.name} -> #{sink}[#{head},arrowtail=diamond]"
  end
  if klass.inheritance
    code << "#{klass.inheritance} -> #{klass.name}"
  end
  dedent
  code
end
visitModule(modul,args=nil) click to toggle source
# File lib/class_diagram_printer.rb, line 24
def visitModule modul,args=nil
  indent "visitModule"

  decl=Code.new # declarations of nodes
  modul.classes.collect do |k|
    attrs_str=k.attrs.collect{|attr| "+ #{attr.name}\\n"}
    decl << "#{k.name}[label = \"{#{k.name}|#{attrs_str.join()}|...}\"]"
  end
  cnx=Code.new  #connexions
  modul.classes.each{|k| cnx << k.accept(self)}
  #................................................................
  code=Code.new
  code << "digraph hierarchy {"
  code << " size=\"5,5\""
  #code << " splines=ortho"
  code << " node[shape=record,style=filled,fillcolor=gray95]"
  code << " edge[dir=back, arrowtail=empty]"
  code.newline
  code.indent=2
  code << decl
  code << cnx
  code.indent=0
  code << "}"
  dedent
  return code
end