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(constant) ⇒ 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.
- #pop_last_added ⇒ Object
-
#resolve_inheritance(_constant = nil) ⇒ Object
rubocop:disable Metrics/AbcSize rubocop:disable Metrics/MethodLength.
- #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(constant) ⇒ 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(constant) return if @nesting.constants.find_first(constant) root = @nesting.constants.root_namespace_for(constant) (root.nil? ? @nesting.constants : root.constants) << constant @last_added = constant end |
#pop_last_added ⇒ Object
42 43 44 45 46 |
# File 'lib/xumlidot/parsers/stack.rb', line 42 def pop_last_added return if @last_added.nil? @last_added = @nesting.constants.root_namespace_for(@last_added) end |
#resolve_inheritance(_constant = nil) ⇒ Object
rubocop:disable Metrics/AbcSize rubocop:disable Metrics/MethodLength
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 93 94 95 96 97 98 |
# File 'lib/xumlidot/parsers/stack.rb', line 60 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) warn "SETTING SUPERKLASS REFERENCE FOR #{klass} to #{other_klass}" if ::Xumlidot::Options.debug == true 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 |