require "objc2swift_assistant/version" require "objc2swift_assistant/code_recognizer" module Objc2swiftAssistant CATEGORY_DECLARATION_REGEX = /^\s*(@interface)\s*(?\w*)\s*\((?\w*)\)/ CATEGORY_IMPLEMENTATION_REGEX = /^\s*(@implementation)\s*(?\w*)\s*\((?\w*)\)/ class CategoryDeclarationRecognizer < CodeRecognizer def initialize( ) super( CATEGORY_DECLARATION_REGEX, CategoryDeclarationRegion, :implementation, true ) end end class CategoryImplRecognizer < CodeRecognizer def initialize( ) super( CATEGORY_IMPLEMENTATION_REGEX, CategoryImplementationRegion, :implementation, true ) end end class AbstractCategoryRegion < ClassRootRegion attr_accessor :category_name def brief_description() "#{@class_name} (#{(@category_name || "").strip})" end end class CategoryDeclarationRegion < AbstractCategoryRegion def initialize(starting_line_number, is_root_entity ) super(starting_line_number, is_root_entity, CAT_EXT_DECLARARATION_KEY ) end def extract_information( file_slice ) m = CATEGORY_DECLARATION_REGEX.match(file_slice[0]) if m.nil? @configuration.log_warning( "WARNING: Could not match category info in #{file_slice[0]}" ) else @class_name = m[ 'class_name' ] @category_name = m[ 'category_name' ] @region_type = @category_name.nil? || @category_name.length == 0 ? EXTENSION_DECLARARATION_KEY : CATEGORY_DECLARARATION_KEY @configuration.log_verbose( "category_name = #{@category_name} @class_name = #{@class_name}") end end end class CategoryImplementationRegion < AbstractCategoryRegion def initialize(starting_line_number, is_root_entity ) super(starting_line_number, is_root_entity, CATEGORY_IMPLEMENTATION_KEY ) end def extract_information( file_slice ) m = CATEGORY_IMPLEMENTATION_REGEX.match(file_slice[0]) if m.nil? @configuration.log_warning( "Could not match category info in #{file_slice[0]}" ) else @class_name = m[ 'class_name' ] @category_name = m[ 'category_name' ] @configuration.log_verbose( "Matched category = #{@category_name} @class_name = #{@class_name}") end end end end