class Xumlidot::Parsers::Stack::Constants
Attributes
last_added[R]
Public Class Methods
new()
click to toggle source
# File lib/xumlidot/parsers/stack.rb, line 12 def initialize # This should be main or object @nesting = Xumlidot::Types::Klass.new(nil) @last_added = @nesting end
Public Instance Methods
add(c)
click to toggle source
when we add a constant we might want to add to the top of the tree e.g. Module A Moudle B
or we might want to add onto a given const e,g Module A
Module B
add(Module C, Module B)
# File lib/xumlidot/parsers/stack.rb, line 34 def add(c) return if @nesting.constants.find_first(c) root = @nesting.constants.root_namespace_for(c) (root.nil? ? @nesting.constants : root.constants) << c @last_added = c end
resolve_inheritance(constant = nil)
click to toggle source
# File lib/xumlidot/parsers/stack.rb, line 52 def resolve_inheritance(constant = nil) external_klasses = ExternalKlassReferences.new # The first traversal we are going through finding all # classes with a superklass. The second traversal we are # trying to find the klass which is the superklass of the superklass # found in the first traversal. # # Note Im hacking through this so poor code @nesting.constants.traverse do |klass| next if klass.definition.superklass.empty? # If we reach here we have a superklass @nesting.constants.traverse do |other_klass| if other_klass.definition.superklass_of?(klass.definition.superklass) if ::Xumlidot::Options.debug == true STDERR.puts "SETTING SUPERKLASS REFERENCE FOR #{klass} to #{other_klass}" end klass.superklass.reference = other_klass break end end if klass.superklass.reference.nil? # See if we have added it already to the list of external_klasses found = external_klasses.find do |external_klass| klass.definition == external_klass.definition end if found klass.superklass.reference = found else new_klass = klass.definition.superklass.to_klass klass.superklass.reference = new_klass external_klasses << new_klass add(new_klass) end end end end
traverse(&block)
click to toggle source
# File lib/xumlidot/parsers/stack.rb, line 18 def traverse(&block) @nesting.constants.traverse(&block) end