Class: StateMachine::OOStructuredFSM::BasicStructureState
- Inherits:
-
OOStructuredState
- Object
- OOStructuredState
- StateMachine::OOStructuredFSM::BasicStructureState
- Defined in:
- lib/kuniri/state_machine/OO_structured_fsm/basic_structure_state.rb
Overview
Class responsible for handling Basic structures state. Understand basic basic structure by conditional and repetitions.
Direct Known Subclasses
Instance Method Summary collapse
-
#addBasicStructure(pLine, pFlag, pClassIndex, pElementFile) ⇒ Object
protected
Add conditional or repetition.
-
#addToCorrectElement(pElement, pElementFile, pFlag, pClassIndex) ⇒ Object
protected
Add element to correct place, based on the state machine position.
- #aggregation_capture ⇒ Object
- #conditional_capture ⇒ Object
- #constructor_capture ⇒ Object
-
#dynamicallyAdd(pElementFile, pToAdd, pType, pElement) ⇒ Object
protected
Dynamically add based on child class.
-
#dynamicLevelUpdate(pElementFile, pElement) ⇒ Object
protected
Update level of conditional or repetition.
- #execute(pElementFile, pLine) ⇒ Object
- #function_capture ⇒ Object
- #handle_line(pLine) ⇒ Object
-
#initialize(pLanguage) ⇒ BasicStructureState
constructor
A new instance of BasicStructureState.
-
#isNestedStructure?(pType) ⇒ Boolean
protected
If is a structure which can be nested.
- #method_capture ⇒ Object
- #repetition_capture ⇒ Object
-
#updateLevel(pFlag, pElementFile, pClassIndex) ⇒ Object
protected
Update nested level in conditional or repetition.
Methods inherited from OOStructuredState
#attribute_capture, #class_capture, #comment_capture, #idle_capture, #include_capture, #module_capture, #variable_capture
Constructor Details
#initialize(pLanguage) ⇒ BasicStructureState
Returns a new instance of BasicStructureState.
14 15 16 17 18 |
# File 'lib/kuniri/state_machine/OO_structured_fsm/basic_structure_state.rb', line 14 def initialize(pLanguage) @language = pLanguage @language.resetNested @whoAmI = "the fu@!+ nobody" end |
Instance Method Details
#addBasicStructure(pLine, pFlag, pClassIndex, pElementFile) ⇒ Object (protected)
Add conditional or repetition. It is delegate to child class.
90 91 92 |
# File 'lib/kuniri/state_machine/OO_structured_fsm/basic_structure_state.rb', line 90 def addBasicStructure(pLine, pFlag, pClassIndex, pElementFile) raise NotImplementedError end |
#addToCorrectElement(pElement, pElementFile, pFlag, pClassIndex) ⇒ Object (protected)
Add element to correct place, based on the state machine position.
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/kuniri/state_machine/OO_structured_fsm/basic_structure_state.rb', line 115 def addToCorrectElement(pElement, pElementFile, pFlag, pClassIndex) elementType = pElement.type stringToEval = "classes[#{pClassIndex}]." case pFlag when StateMachine::GLOBAL_FUNCTION_STATE dynamicallyAdd(pElementFile, pElement, elementType, "global_functions") when StateMachine::METHOD_STATE dynamicallyAdd(pElementFile, pElement, elementType, stringToEval + "methods") when StateMachine::CONSTRUCTOR_STATE dynamicallyAdd(pElementFile, pElement, elementType, stringToEval + "constructors") end end |
#aggregation_capture ⇒ Object
63 64 65 |
# File 'lib/kuniri/state_machine/OO_structured_fsm/basic_structure_state.rb', line 63 def aggregation_capture @language.set_state(@language.aggregationState) end |
#conditional_capture ⇒ Object
46 47 48 49 |
# File 'lib/kuniri/state_machine/OO_structured_fsm/basic_structure_state.rb', line 46 def conditional_capture @language.moreNested @language.set_state(@language.conditionalState) end |
#constructor_capture ⇒ Object
41 42 43 |
# File 'lib/kuniri/state_machine/OO_structured_fsm/basic_structure_state.rb', line 41 def constructor_capture @language.rewind_state end |
#dynamicallyAdd(pElementFile, pToAdd, pType, pElement) ⇒ Object (protected)
Dynamically add based on child class.
155 156 157 158 159 160 161 162 163 |
# File 'lib/kuniri/state_machine/OO_structured_fsm/basic_structure_state.rb', line 155 def dynamicallyAdd(pElementFile, pToAdd, pType, pElement) classIndex = pElementFile.classes.length - 1 # We want the index index = eval("pElementFile.#{pElement}.length - 1") if (@language.isNested? && isNestedStructure?(pType)) eval("pElementFile.#{pElement}[index]." + "managerCondAndLoop.down_level") end eval("pElementFile.#{pElement}[index].add_#{@whoAmI}(pToAdd)") end |
#dynamicLevelUpdate(pElementFile, pElement) ⇒ Object (protected)
Update level of conditional or repetition
168 169 170 171 172 173 |
# File 'lib/kuniri/state_machine/OO_structured_fsm/basic_structure_state.rb', line 168 def dynamicLevelUpdate(pElementFile, pElement) index = eval("pElementFile.#{pElement}.length - 1") if @language.isNested? eval("pElementFile.#{pElement}[index].managerCondAndLoop.up_level") end end |
#execute(pElementFile, pLine) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/kuniri/state_machine/OO_structured_fsm/basic_structure_state.rb', line 68 def execute(pElementFile, pLine) flag = @language.flagFunctionBehaviour classIndex = pElementFile.classes.length - 1 # We want the index addBasicStructure(pLine, flag, classIndex, pElementFile) #if (@language.endBlockHandler.has_end_of_block?(pLine) || singleLine) if (@language.endBlockHandler.has_end_of_block?(pLine)) updateLevel(flag, pElementFile, classIndex) end return pElementFile end |
#function_capture ⇒ Object
58 59 60 |
# File 'lib/kuniri/state_machine/OO_structured_fsm/basic_structure_state.rb', line 58 def function_capture @language.rewind_state end |
#handle_line(pLine) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/kuniri/state_machine/OO_structured_fsm/basic_structure_state.rb', line 20 def handle_line(pLine) conditional = @language.conditionalHandler.get_conditional(pLine) repetition = @language.repetitionHandler.get_repetition(pLine) if conditional if isNestedStructure?(conditional.type) conditional_capture end elsif repetition if isNestedStructure?(repetition.type) repetition_capture end # aggregation end end |
#isNestedStructure?(pType) ⇒ Boolean (protected)
If is a structure which can be nested. It is delegate.
96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/kuniri/state_machine/OO_structured_fsm/basic_structure_state.rb', line 96 def isNestedStructure?(pType) if pType == Languages::WHILE_LABEL || pType == Languages::FOR_LABEL || pType == Languages::DO_WHILE_LABEL || pType == Languages::UNTIL_LABEL || pType == Languages::IF_LABEL || pType == Languages::CASE_LABEL || pType == Languages::UNLESS_LABEL return true end return false end |
#method_capture ⇒ Object
36 37 38 |
# File 'lib/kuniri/state_machine/OO_structured_fsm/basic_structure_state.rb', line 36 def method_capture @language.rewind_state end |
#repetition_capture ⇒ Object
52 53 54 55 |
# File 'lib/kuniri/state_machine/OO_structured_fsm/basic_structure_state.rb', line 52 def repetition_capture @language.moreNested @language.set_state(@language.repetitionState) end |
#updateLevel(pFlag, pElementFile, pClassIndex) ⇒ Object (protected)
Update nested level in conditional or repetition.
135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/kuniri/state_machine/OO_structured_fsm/basic_structure_state.rb', line 135 def updateLevel(pFlag, pElementFile, pClassIndex) case pFlag when StateMachine::GLOBAL_FUNCTION_STATE dynamicLevelUpdate(pElementFile, "global_functions") when StateMachine::METHOD_STATE stringMethod = "classes[#{pClassIndex}].methods" dynamicLevelUpdate(pElementFile, stringMethod) when StateMachine::CONSTRUCTOR_STATE stringMethod = "classes[#{pClassIndex}].constructors" dynamicLevelUpdate(pElementFile, stringMethod) end @language.rewind_state @language.lessNested end |