Module: SwiftGenerator
- Defined in:
- lib/swift_generator/specfile_parser.rb,
lib/swift_generator.rb,
lib/swift_generator/version.rb,
lib/swift_generator/code_generation/swift_file_template.rb,
lib/swift_generator/code_generation/swift_class_generation.rb
Overview
TODO: Use jamesbrooks/hash_validator to check for required and valid values
Defined Under Namespace
Classes: Generator, MutabilityType, SpecfileParser, SwiftClass, SwiftDefinitionSet, SwiftEnum, SwiftEnumCase, SwiftFile, SwiftInitializer, SwiftMethod, SwiftMethodBase, SwiftNonPrimitive, SwiftPersistentProperty, SwiftProperty, SwiftUnitTestClass
Constant Summary
collapse
- VERSION =
"0.1.2"
Class Method Summary
collapse
Class Method Details
.write_class(c) ⇒ Object
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
|
# File 'lib/swift_generator/code_generation/swift_file_template.rb', line 438
def write_class( c )
Ribosome.dot("", binding)
Ribosome.dot("", binding)
Ribosome.dot("&{c.access_control_modifier}class @{c.type_name}", binding)
if c.inheritance_list.count > 0
Ribosome.add(" : @{c.inheritance_list.join( \", \" )}", binding)
end
Ribosome.add(" {", binding)
SwiftGenerator::write_property_declarations( c.transient_properties, "Transient" )
SwiftGenerator::write_property_declarations( c.persistent_properties, "Persistent" )
SwiftGenerator::write_methods( c.initializers )
SwiftGenerator::write_methods( c.methods )
Ribosome.dot("}", binding)
end
|
.write_element(element) ⇒ Object
.write_enum(e) ⇒ Object
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
|
# File 'lib/swift_generator/code_generation/swift_file_template.rb', line 409
def write_enum( e )
Ribosome.dot("", binding)
Ribosome.dot("", binding)
Ribosome.dot("&{e.access_control_modifier}enum @{e.type_name}", binding)
if e.inheritance_list.count > 0
Ribosome.add(" : @{e.inheritance_list.join( \", \" )}", binding)
end
Ribosome.add(" {", binding)
e.enum_cases.each_with_index do |enum_case, _|
enum_case.declaration_lines().each do |declLine|
Ribosome.dot(" &{declLine}", binding)
end
end
e.properties.each_with_index do |prop, i|
Ribosome.dot("", binding)
prop.declaration_lines().each do |declLine|
Ribosome.dot(" &{declLine}", binding)
end
end
SwiftGenerator::write_methods( e.methods )
Ribosome.dot(" }", binding)
end
|
.write_files_for_definition_set(definition_set) ⇒ Object
348
349
350
351
352
353
354
|
# File 'lib/swift_generator/code_generation/swift_file_template.rb', line 348
def write_files_for_definition_set( definition_set )
for _, f in definition_set.output_files
path = Pathname.new( f.file_path )
path.parent.mkpath
SwiftGenerator::writeGeneratedFile( f )
end
end
|
.write_methods(methods) ⇒ Object
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
|
# File 'lib/swift_generator/code_generation/swift_file_template.rb', line 475
def write_methods( methods )
methods.each_with_index do |m, i|
overrideString = m.override ? 'override ' : ''
Ribosome.dot("", binding)
if ! m..nil?
Ribosome.dot(" &{m.comment}", binding)
end
args = m.argStr.nil? || m.argStr.empty? ? m.argStr : ' ' + m.argStr + ' '
Ribosome.dot(" &{overrideString}&{m.access_control_modifier}&{m.func_fragment} @{m.name}(&{args})", binding)
if ! (m.returns.nil? || m.returns.length == 0 )
Ribosome.add(" -> @{m.returns}", binding)
end
Ribosome.add(" {", binding)
m.bodyLines.each do |line|
Ribosome.dot(" &{line}", binding)
end
Ribosome.dot(" }", binding)
end
end
|
.write_property_declarations(properties, property_type_label) ⇒ Object
459
460
461
462
463
464
465
466
467
468
469
470
|
# File 'lib/swift_generator/code_generation/swift_file_template.rb', line 459
def write_property_declarations( properties, property_type_label )
properties.each_with_index do |prop, i|
if i == 0
Ribosome.dot("", binding)
Ribosome.dot(" // MARK: @{property_type_label} Properties", binding)
end
prop.declaration_lines().each do |declLine|
Ribosome.dot(" &{declLine}", binding)
end
end
end
|
.writeGeneratedFile(f) ⇒ Object
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
|
# File 'lib/swift_generator/code_generation/swift_file_template.rb', line 372
def writeGeneratedFile( f )
return if ( f.is_user_file && File.exist?( f.file_path ))
Ribosome.output( f.file_path )
Ribosome.dot("//", binding)
Ribosome.dot("// @{f.file_name}", binding)
Ribosome.dot("// @{f.company_name}", binding)
if $definition_file
Ribosome.dot("//", binding)
Ribosome.dot("// Generated from @{$definition_file} on @{Time.now.strftime(\"%d/%m/%Y %H:%M\")}", binding)
end
if f.include_editing_warnings
if !f.is_user_file
Ribosome.dot("//", binding)
Ribosome.dot("// WARNING: This entire file is generated. DO NOT EDIT.", binding)
else
Ribosome.dot("//", binding)
Ribosome.dot("// This is a user-editable generated file. Delete or rename this file to have a new empty file generated", binding)
end
end
Ribosome.dot("//", binding)
Ribosome.dot("// Copyright (c) @{Time.now.strftime(\"\")} @{f.company_name}, Inc. All rights reserved.", binding)
Ribosome.dot("//", binding)
for import_statement in f.import_statements.sort
Ribosome.dot("&{import_statement}", binding)
end
for element in f.elements
SwiftGenerator::write_element(element)
end
end
|