Class: Objc2swiftAssistant::ProcessedSourceFile
- Inherits:
-
Object
- Object
- Objc2swiftAssistant::ProcessedSourceFile
- Defined in:
- lib/objc2swift_assistant/file_sets.rb
Instance Attribute Summary collapse
-
#configuration ⇒ Object
Returns the value of attribute configuration.
-
#file_path ⇒ Object
Returns the value of attribute file_path.
-
#file_type ⇒ Object
Returns the value of attribute file_type.
-
#inner_matches ⇒ Object
Returns the value of attribute inner_matches.
-
#root_matches ⇒ Object
Returns the value of attribute root_matches.
Instance Method Summary collapse
- #dump(indent, tab, errors_only) ⇒ Object
-
#initialize(file_path, file_type, configuration) ⇒ ProcessedSourceFile
constructor
A new instance of ProcessedSourceFile.
- #match_already_exists(new_match, existing_matches) ⇒ Object
- #match_already_found(new_match) ⇒ Object
- #organize_matches ⇒ Object
- #recognize_code_fragments(recognizers) ⇒ Object
Constructor Details
#initialize(file_path, file_type, configuration) ⇒ ProcessedSourceFile
Returns a new instance of ProcessedSourceFile.
334 335 336 337 338 339 340 |
# File 'lib/objc2swift_assistant/file_sets.rb', line 334 def initialize( file_path, file_type, configuration ) @file_path = file_path @file_type = file_type @configuration = configuration @root_matches = [] @inner_matches = [] end |
Instance Attribute Details
#configuration ⇒ Object
Returns the value of attribute configuration.
332 333 334 |
# File 'lib/objc2swift_assistant/file_sets.rb', line 332 def configuration @configuration end |
#file_path ⇒ Object
Returns the value of attribute file_path.
328 329 330 |
# File 'lib/objc2swift_assistant/file_sets.rb', line 328 def file_path @file_path end |
#file_type ⇒ Object
Returns the value of attribute file_type.
329 330 331 |
# File 'lib/objc2swift_assistant/file_sets.rb', line 329 def file_type @file_type end |
#inner_matches ⇒ Object
Returns the value of attribute inner_matches.
331 332 333 |
# File 'lib/objc2swift_assistant/file_sets.rb', line 331 def inner_matches @inner_matches end |
#root_matches ⇒ Object
Returns the value of attribute root_matches.
330 331 332 |
# File 'lib/objc2swift_assistant/file_sets.rb', line 330 def root_matches @root_matches end |
Instance Method Details
#dump(indent, tab, errors_only) ⇒ Object
439 440 441 442 443 444 445 446 447 |
# File 'lib/objc2swift_assistant/file_sets.rb', line 439 def dump( indent, tab, errors_only ) puts( indent + "Path: #{@file_path.to_s}") puts( indent + "Type: #{@file_type.to_s}") puts( indent + 'Matches:') @root_matches.each do |region| region.dump( indent + tab, tab, errors_only ) end end |
#match_already_exists(new_match, existing_matches) ⇒ Object
423 424 425 426 427 428 429 430 431 |
# File 'lib/objc2swift_assistant/file_sets.rb', line 423 def match_already_exists( new_match, existing_matches ) existing_matches.each do | existing_match | if new_match.starting_line_number == existing_match.starting_line_number @configuration.log_verbose( "match : #{new_match.brief_description} found at existing match: #{existing_match.brief_description}") return true end end return false end |
#match_already_found(new_match) ⇒ Object
419 420 421 |
# File 'lib/objc2swift_assistant/file_sets.rb', line 419 def match_already_found( new_match ) return match_already_exists( new_match, @root_matches ) || match_already_exists( new_match, @inner_matches ) end |
#organize_matches ⇒ Object
433 434 435 436 437 |
# File 'lib/objc2swift_assistant/file_sets.rb', line 433 def organize_matches @raw_matches.each do |match| end end |
#recognize_code_fragments(recognizers) ⇒ Object
342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 |
# File 'lib/objc2swift_assistant/file_sets.rb', line 342 def recognize_code_fragments( recognizers ) file_lines = Objc2swiftAssistant::de_comment_lines( @file_path.readlines ) @configuration.log_verbose( "\nRecognizing code fragments in #{@file_path.to_s}" ) recognizers.each do |recognizer| if recognizer.should_scan_file( @file_type ) matches = recognizer.matches( file_lines ) matches.each do |match| unless match_already_found( match ) if match.is_root_entity @root_matches << match else @inner_matches << match unless match_already_found( match ) end end end end end # Sort both sets of matches by the starting line number @root_matches.sort_by!{ |m| m.starting_line_number } @inner_matches.sort_by!{ |m| m.starting_line_number } # Delimit the root matches in the file previous_match = nil @root_matches.each do |match| previous_match.ending_line_number = match.starting_line_number - 1 unless previous_match.nil? previous_match = match end previous_match.ending_line_number = file_lines.count - 1 unless previous_match.nil? # Associate the inner_matches with the root matches that they belong to root_match_fiber = Fiber.new do if @root_matches @root_matches.each do |match| Fiber.yield match end end Fiber.yield nil end # puts( root_match_fiber.resume.region_type_name ) if root_match_fiber.alive? # puts( root_match_fiber.resume.region_type_name ) if root_match_fiber.alive? # puts( root_match_fiber.resume.region_type_name ) if root_match_fiber.alive? # Add inner matches to the containing root match, if possible if @root_matches.length > 0 current_root_match = nil @inner_matches.each do |inner_match| while( current_root_match.nil? || ! current_root_match.contains_line( inner_match.starting_line_number ) ) if root_match_fiber.alive? current_root_match = root_match_fiber.resume # puts(current_root_match) if current_root_match.nil? configuration.log_verbose( "Uncontained inner match: #{inner_match}") end else configuration.log_verbose( "Uncontained inner match: #{inner_match}") current_root_match = nil break end end current_root_match.add_sub_region( inner_match ) unless current_root_match.nil? end end @root_matches.each do |root_match| root_match.complete( file_lines ) configuration.log_verbose( " added match: #{root_match.description} in file: #{@file_path.to_s}") end end |