class Objc2swiftAssistant::ProcessedSourceFile
Attributes
configuration[RW]
file_path[RW]
file_type[RW]
inner_matches[RW]
root_matches[RW]
Public Class Methods
new( file_path, file_type, configuration )
click to toggle source
# 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
Public Instance Methods
dump( indent, tab, errors_only )
click to toggle source
# 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 )
click to toggle source
# 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 )
click to toggle source
# 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()
click to toggle source
# File lib/objc2swift_assistant/file_sets.rb, line 433 def organize_matches @raw_matches.each do |match| end end
recognize_code_fragments( recognizers )
click to toggle source
# 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