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, SwiftBlockProperty, SwiftCategory, SwiftClass, SwiftDefinitionSet, SwiftEnum, SwiftEnumCase, SwiftFile, SwiftInitializer, SwiftMethod, SwiftMethodBase, SwiftNonPrimitive, SwiftPersistentProperty, SwiftProperty, SwiftProtocol, SwiftUnitTestClass
Constant Summary
collapse
- VERSION =
"0.3.2"
Class Method Summary
collapse
Class Method Details
.write_category(c) ⇒ Object
.write_class_body(c) ⇒ Object
.write_element(element) ⇒ Object
.write_enum(e) ⇒ Object
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
|
# File 'lib/swift_generator/code_generation/swift_file_template.rb', line 413
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
|
# 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
SwiftGenerator::writeGeneratedFile( f )
end
end
|
.write_methods(methods, for_protocol = false) ⇒ Object
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
|
# File 'lib/swift_generator/code_generation/swift_file_template.rb', line 514
def write_methods( methods, for_protocol=false )
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 + ' '
access_control_modifier_str = m.access_control_modifiers.length > 0 ? m.access_control_modifiers.join( ", " ) + " " : ""
Ribosome.dot(" &{overrideString}&{access_control_modifier_str}&{m.func_fragment + \" \" unless m.func_fragment.length == 0}@{m.name}(&{args})", binding)
if ! (m.returns.nil? || m.returns.length == 0 )
Ribosome.add(" -> @{m.returns}", binding)
end
unless for_protocol
Ribosome.add(" {", binding)
m.bodyLines.each do |line|
Ribosome.dot(" &{line}", binding)
end
Ribosome.dot(" }", binding)
end
end
end
|
.write_property_declarations(properties, property_type_label = nil) ⇒ Object
499
500
501
502
503
504
505
506
507
508
509
|
# File 'lib/swift_generator/code_generation/swift_file_template.rb', line 499
def write_property_declarations( properties, property_type_label=nil )
properties.each_with_index do |prop, i|
if i == 0 && ! property_type_label.nil?
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
|
.write_protocol(p) ⇒ Object
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
|
# File 'lib/swift_generator/code_generation/swift_file_template.rb', line 480
def write_protocol( p )
Ribosome.dot("", binding)
Ribosome.dot("", binding)
Ribosome.dot("&{p.access_control_modifier}protocol @{p.type_name}", binding)
if p.inheritance_list.count > 0
Ribosome.add(" : @{p.inheritance_list.join( \", \" )}", binding)
end
Ribosome.add(" {", binding)
SwiftGenerator::write_property_declarations( p.transient_properties )
SwiftGenerator::write_property_declarations( p.persistent_properties )
SwiftGenerator::write_methods( p.initializers, for_protocol=true )
SwiftGenerator::write_methods( p.methods, for_protocol=true )
Ribosome.dot("}", binding)
end
|
.writeGeneratedFile(f) ⇒ Object
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
405
406
407
408
|
# File 'lib/swift_generator/code_generation/swift_file_template.rb', line 374
def writeGeneratedFile( f )
return if ( f.is_user_file && File.exist?( f.file_path ))
Pathname.new( f.file_path ).parent().mkpath()
Ribosome.output( f.file_path )
Ribosome.dot("//", binding)
Ribosome.dot("// @{ Pathname.new( f.file_name ).basename }", 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
|