Class: Xumlidot::Parsers::Stack::Constants
- Inherits:
-
Object
- Object
- Xumlidot::Parsers::Stack::Constants
- Defined in:
- lib/xumlidot/parsers/stack.rb
Defined Under Namespace
Classes: ExternalKlassReferences
Instance Attribute Summary collapse
-
#last_added ⇒ Object
readonly
Returns the value of attribute last_added.
Instance Method Summary collapse
-
#add(c) ⇒ Object
when we add a constant we might want to add to the top of the tree e.g.
-
#initialize ⇒ Constants
constructor
A new instance of Constants.
- #resolve_inheritance(constant = nil) ⇒ Object
- #traverse(&block) ⇒ Object
Constructor Details
Instance Attribute Details
#last_added ⇒ Object (readonly)
Returns the value of attribute last_added.
10 11 12 |
# File 'lib/xumlidot/parsers/stack.rb', line 10 def last_added @last_added end |
Instance Method Details
#add(c) ⇒ Object
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)
34 35 36 37 38 39 40 |
# 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) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# 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) ⇒ Object
18 19 20 |
# File 'lib/xumlidot/parsers/stack.rb', line 18 def traverse(&block) @nesting.constants.traverse(&block) end |