Class: Objc2swiftAssistant::MigrationRegion
- Inherits:
-
FailableProcessingElement
- Object
- FailableProcessingElement
- Objc2swiftAssistant::MigrationRegion
- Defined in:
- lib/objc2swift_assistant/code_recognizer.rb
Direct Known Subclasses
AtDirectiveRegion, ClassRootRegion, MethodRegion, PragmaMarkRegion, PropertyDeclarationRegion, ProtocolRegion
Instance Attribute Summary collapse
-
#allowed_parent_region_types ⇒ Object
Returns the value of attribute allowed_parent_region_types.
-
#can_occur_in_class_decl ⇒ Object
Returns the value of attribute can_occur_in_class_decl.
-
#configuration ⇒ Object
Returns the value of attribute configuration.
-
#detection_line ⇒ Object
For diagnostics.
-
#ending_line_number ⇒ Object
actually a zero-based index.
-
#ending_of_root_header ⇒ Object
i.e.
-
#is_root_entity ⇒ Object
Returns the value of attribute is_root_entity.
-
#is_single_line ⇒ Object
Returns the value of attribute is_single_line.
-
#parent_region ⇒ Object
Returns the value of attribute parent_region.
-
#region_identifier ⇒ Object
Returns the value of attribute region_identifier.
-
#region_type ⇒ Object
Returns the value of attribute region_type.
-
#root_header ⇒ Object
The content of the ivar declaration.
-
#starting_line_number ⇒ Object
actually a zero-based index.
-
#sub_regions ⇒ Object
attr_accessor :consumed_line_count.
Attributes inherited from FailableProcessingElement
Instance Method Summary collapse
- #add_sub_region(sub_region) ⇒ Object
- #brief_description ⇒ Object
- #complete(file_lines) ⇒ Object
- #contains_line(line_number) ⇒ Object
-
#dump(indent, tab, errors_only) ⇒ Object
Output.
- #dump_region_info(indent, tab, errors_only) ⇒ Object
- #extract_information(file_lines) ⇒ Object
- #generic_description(detail) ⇒ Object
- #has_failed ⇒ Object
-
#initialize(starting_line_number, is_root_entity, region_type, can_occur_in_class_decl: false) ⇒ MigrationRegion
constructor
A new instance of MigrationRegion.
- #resolve_ending_line_number(region, suggested_line_number) ⇒ Object
Methods inherited from FailableProcessingElement
#add_error, #add_warning, #has_errors, #initiailize
Constructor Details
#initialize(starting_line_number, is_root_entity, region_type, can_occur_in_class_decl: false) ⇒ MigrationRegion
Returns a new instance of MigrationRegion.
119 120 121 122 123 124 125 126 127 128 |
# File 'lib/objc2swift_assistant/code_recognizer.rb', line 119 def initialize( starting_line_number, is_root_entity, region_type, can_occur_in_class_decl:false ) @starting_line_number = starting_line_number @is_root_entity = is_root_entity @region_type = region_type @detection_line = detection_line @can_occur_in_class_decl = can_occur_in_class_decl @sub_regions = [] = [] @is_single_line = false end |
Instance Attribute Details
#allowed_parent_region_types ⇒ Object
Returns the value of attribute allowed_parent_region_types.
101 102 103 |
# File 'lib/objc2swift_assistant/code_recognizer.rb', line 101 def allowed_parent_region_types @allowed_parent_region_types end |
#can_occur_in_class_decl ⇒ Object
Returns the value of attribute can_occur_in_class_decl.
103 104 105 |
# File 'lib/objc2swift_assistant/code_recognizer.rb', line 103 def can_occur_in_class_decl @can_occur_in_class_decl end |
#configuration ⇒ Object
Returns the value of attribute configuration.
117 118 119 |
# File 'lib/objc2swift_assistant/code_recognizer.rb', line 117 def configuration @configuration end |
#detection_line ⇒ Object
For diagnostics
105 106 107 |
# File 'lib/objc2swift_assistant/code_recognizer.rb', line 105 def detection_line @detection_line end |
#ending_line_number ⇒ Object
actually a zero-based index
111 112 113 |
# File 'lib/objc2swift_assistant/code_recognizer.rb', line 111 def ending_line_number @ending_line_number end |
#ending_of_root_header ⇒ Object
i.e. (ideally) The end of the class ivar declaration
112 113 114 |
# File 'lib/objc2swift_assistant/code_recognizer.rb', line 112 def ending_of_root_header @ending_of_root_header end |
#is_root_entity ⇒ Object
Returns the value of attribute is_root_entity.
100 101 102 |
# File 'lib/objc2swift_assistant/code_recognizer.rb', line 100 def is_root_entity @is_root_entity end |
#is_single_line ⇒ Object
Returns the value of attribute is_single_line.
109 110 111 |
# File 'lib/objc2swift_assistant/code_recognizer.rb', line 109 def is_single_line @is_single_line end |
#parent_region ⇒ Object
Returns the value of attribute parent_region.
116 117 118 |
# File 'lib/objc2swift_assistant/code_recognizer.rb', line 116 def parent_region @parent_region end |
#region_identifier ⇒ Object
Returns the value of attribute region_identifier.
107 108 109 |
# File 'lib/objc2swift_assistant/code_recognizer.rb', line 107 def region_identifier @region_identifier end |
#region_type ⇒ Object
Returns the value of attribute region_type.
102 103 104 |
# File 'lib/objc2swift_assistant/code_recognizer.rb', line 102 def region_type @region_type end |
#root_header ⇒ Object
The content of the ivar declaration
113 114 115 |
# File 'lib/objc2swift_assistant/code_recognizer.rb', line 113 def root_header @root_header end |
#starting_line_number ⇒ Object
actually a zero-based index
110 111 112 |
# File 'lib/objc2swift_assistant/code_recognizer.rb', line 110 def starting_line_number @starting_line_number end |
#sub_regions ⇒ Object
attr_accessor :consumed_line_count
115 116 117 |
# File 'lib/objc2swift_assistant/code_recognizer.rb', line 115 def sub_regions @sub_regions end |
Instance Method Details
#add_sub_region(sub_region) ⇒ Object
134 135 136 137 |
# File 'lib/objc2swift_assistant/code_recognizer.rb', line 134 def add_sub_region( sub_region ) @sub_regions << sub_region sub_region.parent_region = self end |
#brief_description ⇒ Object
184 185 186 |
# File 'lib/objc2swift_assistant/code_recognizer.rb', line 184 def brief_description() return "" end |
#complete(file_lines) ⇒ Object
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/objc2swift_assistant/code_recognizer.rb', line 139 def complete( file_lines ) # Delimit sub-regions previous_sub_region = nil @sub_regions.each do |sub_region| resolve_ending_line_number( previous_sub_region, sub_region.starting_line_number - 1) unless previous_sub_region.nil? previous_sub_region = sub_region end resolve_ending_line_number( previous_sub_region, self.ending_line_number ) unless previous_sub_region.nil? self.extract_information( file_lines[ @starting_line_number..@ending_line_number] ) @sub_regions.each do |sub_region| sub_region.complete( file_lines ) end #Find the limits of the unrecognized code in the root migration region @ending_of_root_header = nil @sub_regions.each.with_index(0) do |sub_region, i| if ! sub_region.can_occur_in_class_decl @ending_of_root_header = sub_region.starting_line_number - 1 break end end @ending_of_root_header = @ending_line_number if @ending_of_root_header.nil? @root_header = file_lines[ @starting_line_number..@ending_of_root_header ] # can_occur_in_class_decl end |
#contains_line(line_number) ⇒ Object
130 131 132 |
# File 'lib/objc2swift_assistant/code_recognizer.rb', line 130 def contains_line( line_number ) line_number >= @starting_line_number && line_number <= @ending_line_number end |
#dump(indent, tab, errors_only) ⇒ Object
Output
193 194 195 196 197 198 |
# File 'lib/objc2swift_assistant/code_recognizer.rb', line 193 def dump( indent, tab, errors_only ) dump_region_info( indent, tab, errors_only ) @sub_regions.each do |sub_region| sub_region.dump( indent+tab, tab, errors_only ) end end |
#dump_region_info(indent, tab, errors_only) ⇒ Object
200 201 202 203 204 |
# File 'lib/objc2swift_assistant/code_recognizer.rb', line 200 def dump_region_info( indent, tab, errors_only ) # puts( indent + "#{@region_type} [lines: #{@starting_line_number || '?'}-#{@ending_line_number || '?'}]") printf( "%s%-25s [lines: %3d-%-3d] %s %s\n", indent, @region_type, @starting_line_number+1|| -1, @ending_line_number+1 || -1, brief_description(), .nil? ? '' : 'ERROR: ' + ) end |
#extract_information(file_lines) ⇒ Object
176 177 178 |
# File 'lib/objc2swift_assistant/code_recognizer.rb', line 176 def extract_information( file_lines ) # Do nothing by default end |
#generic_description(detail) ⇒ Object
180 181 182 |
# File 'lib/objc2swift_assistant/code_recognizer.rb', line 180 def generic_description( detail ) return detail end |
#has_failed ⇒ Object
188 189 190 |
# File 'lib/objc2swift_assistant/code_recognizer.rb', line 188 def has_failed ! .length > 0 end |
#resolve_ending_line_number(region, suggested_line_number) ⇒ Object
168 169 170 171 172 173 174 |
# File 'lib/objc2swift_assistant/code_recognizer.rb', line 168 def resolve_ending_line_number( region, suggested_line_number ) if region.is_single_line region.ending_line_number = region.starting_line_number else region.ending_line_number = suggested_line_number end end |