Class: Objc2swiftAssistant::MethodRegion
- Inherits:
-
MigrationRegion
- Object
- FailableProcessingElement
- MigrationRegion
- Objc2swiftAssistant::MethodRegion
- Defined in:
- lib/objc2swift_assistant/recognizers/method_recognizer.rb
Instance Attribute Summary collapse
-
#all_lines ⇒ Object
Returns the value of attribute all_lines.
-
#is_class_method ⇒ Object
Returns the value of attribute is_class_method.
-
#objc_signature ⇒ Object
ObjC methods do not have “names”.
-
#parameters ⇒ Object
Returns the value of attribute parameters.
-
#raw_parameter_text ⇒ Object
Returns the value of attribute raw_parameter_text.
-
#return_nillable_qualifier ⇒ Object
Returns the value of attribute return_nillable_qualifier.
-
#return_pointer_level ⇒ Object
Returns the value of attribute return_pointer_level.
-
#return_type ⇒ Object
Returns the value of attribute return_type.
-
#takes_arguments ⇒ Object
Returns the value of attribute takes_arguments.
-
#unmatched_lines ⇒ Object
Returns the value of attribute unmatched_lines.
Attributes inherited from MigrationRegion
#allowed_parent_region_types, #can_occur_in_class_decl, #configuration, #detection_line, #ending_line_number, #ending_of_root_header, #is_root_entity, #is_single_line, #parent_region, #region_identifier, #region_type, #root_header, #starting_line_number, #sub_regions
Attributes inherited from FailableProcessingElement
Instance Method Summary collapse
- #brief_description ⇒ Object
- #description ⇒ Object
- #extract_information(file_slice) ⇒ Object
-
#initialize(starting_line_number, is_root_entity) ⇒ MethodRegion
constructor
A new instance of MethodRegion.
- #make_signature ⇒ Object
- #params_descr ⇒ Object
- #parse_parameters(parameter_text) ⇒ Object
Methods inherited from MigrationRegion
#add_sub_region, #complete, #contains_line, #dump, #dump_region_info, #generic_description, #has_failed, #resolve_ending_line_number
Methods inherited from FailableProcessingElement
#add_error, #add_warning, #has_errors, #initiailize
Constructor Details
#initialize(starting_line_number, is_root_entity) ⇒ MethodRegion
Returns a new instance of MethodRegion.
28 29 30 31 32 |
# 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 |
Instance Attribute Details
#all_lines ⇒ Object
Returns the value of attribute all_lines.
25 26 27 |
# File 'lib/objc2swift_assistant/recognizers/method_recognizer.rb', line 25 def all_lines @all_lines end |
#is_class_method ⇒ Object
Returns the value of attribute is_class_method.
18 19 20 |
# File 'lib/objc2swift_assistant/recognizers/method_recognizer.rb', line 18 def is_class_method @is_class_method end |
#objc_signature ⇒ Object
ObjC methods do not have “names”
17 18 19 |
# File 'lib/objc2swift_assistant/recognizers/method_recognizer.rb', line 17 def objc_signature @objc_signature end |
#parameters ⇒ Object
Returns the value of attribute parameters.
23 24 25 |
# File 'lib/objc2swift_assistant/recognizers/method_recognizer.rb', line 23 def parameters @parameters end |
#raw_parameter_text ⇒ Object
Returns the value of attribute raw_parameter_text.
22 23 24 |
# File 'lib/objc2swift_assistant/recognizers/method_recognizer.rb', line 22 def raw_parameter_text @raw_parameter_text end |
#return_nillable_qualifier ⇒ Object
Returns the value of attribute return_nillable_qualifier.
21 22 23 |
# File 'lib/objc2swift_assistant/recognizers/method_recognizer.rb', line 21 def return_nillable_qualifier @return_nillable_qualifier end |
#return_pointer_level ⇒ Object
Returns the value of attribute return_pointer_level.
20 21 22 |
# File 'lib/objc2swift_assistant/recognizers/method_recognizer.rb', line 20 def return_pointer_level @return_pointer_level end |
#return_type ⇒ Object
Returns the value of attribute return_type.
19 20 21 |
# File 'lib/objc2swift_assistant/recognizers/method_recognizer.rb', line 19 def return_type @return_type end |
#takes_arguments ⇒ Object
Returns the value of attribute takes_arguments.
24 25 26 |
# File 'lib/objc2swift_assistant/recognizers/method_recognizer.rb', line 24 def takes_arguments @takes_arguments end |
#unmatched_lines ⇒ Object
Returns the value of attribute unmatched_lines.
26 27 28 |
# File 'lib/objc2swift_assistant/recognizers/method_recognizer.rb', line 26 def unmatched_lines @unmatched_lines end |
Instance Method Details
#brief_description ⇒ Object
179 180 181 182 183 184 185 186 |
# 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 ⇒ Object
175 176 177 |
# 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) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# 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 ⇒ Object
154 155 156 157 158 159 160 161 162 163 164 165 |
# 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 ⇒ Object
171 172 173 |
# File 'lib/objc2swift_assistant/recognizers/method_recognizer.rb', line 171 def params_descr() 'NYI' end |
#parse_parameters(parameter_text) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# 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 |