Class: Objc2swiftAssistant::ObjCFileNode

Inherits:
SourceFileNode show all
Defined in:
lib/objc2swift_assistant/file_sets.rb

Instance Attribute Summary collapse

Attributes inherited from SourceFileNode

#directory_node, #file_set, #should_be_used

Instance Method Summary collapse

Constructor Details

#initialize(directory_node, name_root) ⇒ ObjCFileNode

Returns a new instance of ObjCFileNode.



239
240
241
242
# File 'lib/objc2swift_assistant/file_sets.rb', line 239

def initialize(directory_node, name_root )
  super( directory_node )
  @name_root = name_root
end

Instance Attribute Details

#header_file_pathObject

Returns the value of attribute header_file_path.



231
232
233
# File 'lib/objc2swift_assistant/file_sets.rb', line 231

def header_file_path
  @header_file_path
end

#implementation_file_pathObject

Returns the value of attribute implementation_file_path.



232
233
234
# File 'lib/objc2swift_assistant/file_sets.rb', line 232

def implementation_file_path
  @implementation_file_path
end

#name_rootObject

Returns the value of attribute name_root.



230
231
232
# File 'lib/objc2swift_assistant/file_sets.rb', line 230

def name_root
  @name_root
end

#objc_2_swift_converterObject

Returns the value of attribute objc_2_swift_converter.



237
238
239
# File 'lib/objc2swift_assistant/file_sets.rb', line 237

def objc_2_swift_converter
  @objc_2_swift_converter
end

#processed_header_fileObject

Returns the value of attribute processed_header_file.



234
235
236
# File 'lib/objc2swift_assistant/file_sets.rb', line 234

def processed_header_file
  @processed_header_file
end

#processed_implementation_fileObject

Returns the value of attribute processed_implementation_file.



235
236
237
# File 'lib/objc2swift_assistant/file_sets.rb', line 235

def processed_implementation_file
  @processed_implementation_file
end

#recognized_codeObject

Returns the value of attribute recognized_code.



236
237
238
# File 'lib/objc2swift_assistant/file_sets.rb', line 236

def recognized_code
  @recognized_code
end

Instance Method Details

#cannonical_source_file_pathObject

Utility



319
320
321
322
323
# File 'lib/objc2swift_assistant/file_sets.rb', line 319

def cannonical_source_file_path
  source_path = relative_impl_path
  source_path ||=  relative_header_path
  source_path
end

#create_generated_file_nodes(generated_file_set, generated_directory) ⇒ Object



269
270
271
272
273
274
275
276
277
278
279
# File 'lib/objc2swift_assistant/file_sets.rb', line 269

def create_generated_file_nodes( generated_file_set, generated_directory )
  swift_file_name = @name_root + '.swift'
  generated_file_node = generated_directory.file_nodes_by_name[ swift_file_name ]

  if generated_file_node.nil?
    generated_file_node = GeneratedSwiftFileNode.new( generated_directory, swift_file_name )
    generated_directory.file_nodes_by_name[ swift_file_name ] = generated_file_node
  end

  @objc_2_swift_converter.swift_file_node = generated_file_node
end

#dump(indent, tab, errors_only) ⇒ Object



281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
# File 'lib/objc2swift_assistant/file_sets.rb', line 281

def dump( indent, tab, errors_only )
  # puts( indent + "NameRoot:       #{@name_root}")
  puts( indent + "#{@name_root} :")

  unless @processed_header_file.nil?
    puts( indent+tab + "Header:")
    @processed_header_file.dump( indent+tab+tab, tab, errors_only )
  end

  unless @processed_implementation_file.nil?
    puts( indent+tab + "Implementation:")
    @processed_implementation_file.dump( indent+tab+tab, tab, errors_only )
  end

  unless @objc_2_swift_converter.nil?
    puts( indent+tab + "Swift File Generation:")
    @objc_2_swift_converter.dump( indent+tab+tab, tab, errors_only )
  end
end

#prepare_conversion(configuration) ⇒ Object



257
258
259
260
# File 'lib/objc2swift_assistant/file_sets.rb', line 257

def prepare_conversion( configuration )
  @objc_2_swift_converter = ObjC2SwiftFileConverter.new( self, configuration )
  @objc_2_swift_converter.prepare
end

#prepare_for_useObject



244
245
246
247
248
249
# File 'lib/objc2swift_assistant/file_sets.rb', line 244

def prepare_for_use
  # puts( "prepare_for_use() header: #{@header_file_path}, implementation: #{@implementation_file_path}")
  @recognized_code = []
  @processed_header_file = ProcessedSourceFile.new( @header_file_path, :header, @file_set.configuration ) unless @header_file_path.nil? || @file_set.omit_file( relative_header_path )
  @processed_implementation_file = ProcessedSourceFile.new( @implementation_file_path, :implementation, @file_set.configuration ) unless @implementation_file_path.nil? || @file_set.omit_file( relative_impl_path )
end

#recognize_code_fragments(recognizers) ⇒ Object



251
252
253
254
255
# File 'lib/objc2swift_assistant/file_sets.rb', line 251

def recognize_code_fragments( recognizers )
  @file_set.configuration.log_verbose( "Recognizing code fragments in #{@header_file_path}, #{@implementation_file_path}")
  @processed_header_file.recognize_code_fragments( recognizers ) unless @processed_header_file.nil?
  @processed_implementation_file.recognize_code_fragments( recognizers ) unless @processed_implementation_file.nil?
end

#relative_header_pathObject



301
302
303
304
305
306
307
308
# File 'lib/objc2swift_assistant/file_sets.rb', line 301

def relative_header_path
  if @header_file_path.nil?
    return nil
  else
    return @directory_node.relative_path.join( @header_file_path.basename )
  end

end

#relative_impl_pathObject



310
311
312
313
314
315
316
# File 'lib/objc2swift_assistant/file_sets.rb', line 310

def relative_impl_path
  if @implementation_file_path.nil?
    return nil
  else
    return @directory_node.relative_path.join( @implementation_file_path.basename )
  end
end

#root_matchesObject



262
263
264
265
266
267
# File 'lib/objc2swift_assistant/file_sets.rb', line 262

def root_matches
  root_matches = []
  root_matches.concat( @processed_header_file.root_matches ) unless @processed_header_file.nil?
  root_matches.concat( @processed_implementation_file.root_matches ) unless @processed_implementation_file.nil?
  return root_matches
end