class Objc2swiftAssistant::MethodRegion
Attributes
all_lines[RW]
is_class_method[RW]
objc_signature[RW]
ObjC methods do not have “names”
parameters[RW]
raw_parameter_text[RW]
return_nillable_qualifier[RW]
return_pointer_level[RW]
return_type[RW]
takes_arguments[RW]
unmatched_lines[RW]
Public Class Methods
new(starting_line_number, is_root_entity )
click to toggle source
Calls superclass method
Objc2swiftAssistant::MigrationRegion::new
# File lib/objc2swift_assistant/recognizers/method_recognizer.rb, line 28 def initialize(starting_line_number, is_root_entity ) super(starting_line_number, is_root_entity, METHOD_INDETERMINATE_KEY ) @unmatched_lines = [] @all_lines = [] end
Public Instance Methods
brief_description()
click to toggle source
# File lib/objc2swift_assistant/recognizers/method_recognizer.rb, line 179 def brief_description # plus_minus = @is_class_method ? '+' : '-' # pointerText = "" # pointerText = " *****"[1..@pointer_level+1] unless @pointer_level.nil? || @pointer_level == 0 # return "#{plus_minus} (#{@return_type}#{pointerText}) #{@raw_parameter_text}" return @objc_signature end
description()
click to toggle source
# File lib/objc2swift_assistant/recognizers/method_recognizer.rb, line 175 def description() return generic_description( "#{'+' if @is_class_method} return_type:#{@return_type} name:#{@name} #{'declaration' if @is_declaration} #{"body_lines:#{@unmatched_lines.length}" if @unmatched_lines.length > 0}" ) end
extract_information( file_slice )
click to toggle source
# File lib/objc2swift_assistant/recognizers/method_recognizer.rb, line 34 def extract_information( file_slice ) @all_lines = file_slice method_text = file_slice.join( "\n" ) m = method_text.match( /^\s*(?<instance_or_class>[+-])\s*\((?<return_type>\w*)\s*(?<return_pointer>\*+)?\s*(?<nil_return_qualifier>(__nullable|__nonnull))?\s*\)(?<name_and_params>[^\{;]*)\s*(?<declaration_or_implementation>(\{|(;\s*\{)+|;))/m ) if m.nil? @configuration.log_warning( "Could not match method (implemetation or declaration) in #{file_slice[0]}..." ) else @is_class_method = m['instance_or_class'] == '+' @return_nillable_qualifier = m[ 'nil_return_qualifier' ] @return_type = m[ 'return_type' ] @return_pointer_level = m[ 'return_pointer' ].nil? ? 0 : m[ 'return_pointer' ].length @raw_parameter_text = m[ 'name_and_params' ] @parameters, @takes_arguments = parse_parameters( @raw_parameter_text ) @objc_signature = make_signature @unmatched_lines = m.post_match.lines is_declaration = m['declaration_or_implementation'] == ';' @region_type = is_declaration ? METHOD_DECLARATION_KEY : METHOD_IMPLEMENTATION_KEY # log_verbose( description ) end end
make_signature()
click to toggle source
def extract_information
( file_slice )
method_text = file_slice.join( "\n" ) m = method_text.match( /^\s*(?<instance_or_class>[+-])\s*\((?<return_type>\w*)\s*(?<return_pointer>\*+)?\)(?<name_and_params>[^\{;]*)\s*(?<declaration_or_implementation>(\{|(;\s*\{)+|;))/m ) if m.nil? puts( "WARNING: Could not match method (implemetation or declaration) in #{file_slice[0]}..." ) else @is_class_method = m['instance_or_class'] == '+' @return_type = m[ 'return_type' ] @return_pointer_level = m[ 'return_pointer' ].nil? ? 0 : m[ 'return_pointer' ].length @raw_parameter_text = m[ 'name_and_params' ] @parameters, @takes_arguments = parse_parameters( @raw_parameter_text ) @objc_signature = make_signature @unmatched_lines = m.post_match.lines is_declaration = m['declaration_or_implementation'] == ';' @region_type = is_declaration ? METHOD_DECLARATION_KEY : METHOD_IMPLEMENTATION_KEY puts( description ) end
end
def parse_parameters
( parameter_text )
takes_arguments = true parameters = [] matches = [] parameter_text.scan( /(?<label>\w*)\s*:\s*\(\s*(?<null_qualifier>(__nullable|__nonnull))?\s*(?<type>\w*)\s*(?<pointer>\*+)?\s*\)\s*(?<arg>\w*)/ ){ matches << $~ } if matches.length > 0 puts( matches) matches.each do |m| param = MethodParameter.new() param.param_label = m[ 'label' ] param.param_name = m[ 'arg' ] param.param_type = m[ 'type' ] param.null_qualifier = m[ 'null_qualifier' ] param.pointer_level = m[ 'pointer' ].nil? ? 0 : m[ 'pointer' ].length parameters << param takes_arguments = true end else param = MethodParameter.new() param.param_label = parameter_text # No arguments to method: create a parameter with only a label parameters << param takes_arguments = false end return parameters, takes_arguments
end
# File lib/objc2swift_assistant/recognizers/method_recognizer.rb, line 154 def make_signature() signature = '' if @takes_arguments self.parameters.each do |param| signature << "#{param.param_label}:" end else signature = self.parameters[0].param_label end return signature.strip end
params_descr()
click to toggle source
# File lib/objc2swift_assistant/recognizers/method_recognizer.rb, line 171 def params_descr() 'NYI' end
parse_parameters( parameter_text )
click to toggle source
# File lib/objc2swift_assistant/recognizers/method_recognizer.rb, line 55 def parse_parameters( parameter_text ) takes_arguments = true parameters = [] matches = [] # handle single mthod names if parameter_text.include?( ':' ) # Split the arguments including (simple) block arguments parameter_text.scan( /(?<label>\w*)\s*:\s*\((?<is_weak>__weak)?(?<value>[^:]*)\)\s*(?<arg>[^:\s]*)/ ){ matches << $~ } if matches.length > 0 # puts( matches) matches.each do |m| param = ObjCMethodParameter.new() param.param_label = m[ 'label' ].strip param.param_name = m[ 'arg' ].strip unless m[ 'is_weak' ].nil? param.is_weak = true end value = m[ 'value' ].strip if value.include? '^' param.is_block_type = true # Its a block parameter param.param_type = value else param.is_block_type = false m = value.match( /(?<null_qualifier>(__nullable|__nonnull))?\s*(?<type>\w*)\s*(?<pointer>\*+)?/ ) if m.nil? param.match_failure = "Could not match #{value} as a non-blocl parameter" else param.param_type = m[ 'type' ].strip param.null_qualifier = m[ 'null_qualifier' ] param.pointer_level = m[ 'pointer' ].nil? ? 0 : m[ 'pointer' ].length end end if param.param_label.nil? param.param_label = '/* Unknown */' end parameters << param takes_arguments = true end end else param = ObjCMethodParameter.new() param.param_label = parameter_text.strip # No arguments to method: create a parameter with only a label parameters << param takes_arguments = false end return parameters, takes_arguments end