class SwiftGenerator::SwiftDefinitionSet
The single coordinator object for a set of swift file generations
Attributes
all_class_characteristics[RW]
company_name[RW]
elements_by_name[RW]
generated_root[RW]
generated_test_root[RW]
generated_user_root[RW]
make_more_supporting_elements[RW]
make_unknown_types[RW]
output_files[RW]
test_support_class[RW]
types_by_symbol[RW]
attr_accessor :classes_by_name # Only classes attr_accessor :enums_by_name # Only enums
Public Class Methods
collection_types()
click to toggle source
# File lib/swift_generator/code_generation/swift_class_generation.rb, line 1477 def self.collection_types { list: "list", idList: "idList" } end
mutability_types()
click to toggle source
# File lib/swift_generator/code_generation/swift_class_generation.rb, line 1468 def self.mutability_types { let: MutabilityType.new(:let, 'let', ''), var: MutabilityType.new(:var, 'var', ''), optional: MutabilityType.new(:optional, 'var', '?', must_be_unwrapped: true), unwrapped: MutabilityType.new(:unwrapped, 'var', '!') } end
new( generated_root:nil, generated_user_root:nil, generated_test_root:nil)
click to toggle source
# File lib/swift_generator/code_generation/swift_class_generation.rb, line 1484 def initialize( generated_root:nil, generated_user_root:nil, generated_test_root:nil) @generated_root = File.expand_path(generated_root) @generated_test_root = File.expand_path(generated_test_root) unless generated_test_root.nil? @generated_user_root = File.expand_path(generated_user_root) unless generated_test_root.nil? @make_unknown_types = false @output_files = {} @elements_by_name = {} @make_more_supporting_elements = true @all_class_characteristics = [ :json_serializable, :comparable, :make_test_class, :create_user_class ] @types_by_symbol = {} initial_property_types.each do |propType| @types_by_symbol[propType.swift_type_symbol] = propType end @company_name = "<defined in SwiftDefinitionSet.company_name>" end
Public Instance Methods
add_element(swift_element)
click to toggle source
# File lib/swift_generator/code_generation/swift_class_generation.rb, line 1573 def add_element(swift_element) file_name = swift_element.file_name || swift_element.type_name the_file = file_for_name( file_name, swift_element.is_test_element, swift_element.is_user_editable ) the_file.add_element(swift_element) swift_element.source_file = the_file # if swift_element.is_a? SwiftEnum # @enums_by_name[swift_element.type_name] = swift_element # elsif swift_element.is_a? SwiftClass # @elements_by_name[swift_element.type_name] = swift_element # end @elements_by_name[swift_element.type_name] = swift_element @make_more_supporting_elements = true # # Make a type for this class so that references to this class can be resolved # type_symbol = swift_element.type_name.to_sym # element_property_type = SwiftPropertyType.new( type_symbol, :NSDictionary, swift_kind: :class, test_value:nil ) # @types_by_symbol[type_symbol] = element_property_type (type_symbol, property_type) = swift_element.make_property_type @types_by_symbol[type_symbol] = property_type end
characteristics_are_legal( characteristics )
click to toggle source
General purpose
# File lib/swift_generator/code_generation/swift_class_generation.rb, line 1637 def characteristics_are_legal( characteristics ) unknown_characteristics = (characteristics - @all_class_characteristics) unknown_characteristics.empty? end
file_for_name(name, is_test_element, is_user_editable)
click to toggle source
def add_json_serializable_class(serializable_class)
@json_serializable_classes << serializable_class
end
# File lib/swift_generator/code_generation/swift_class_generation.rb, line 1601 def file_for_name(name, is_test_element, is_user_editable) if( is_test_element ) abort( "User-modifiable test classes are not generated" ) if is_user_editable file_dir = @generated_test_root else if( is_user_editable ) file_dir = @generated_user_root else file_dir = @generated_root end end @output_files[name] ||= SwiftFile.new(name, file_dir, is_user_file:is_user_editable, company_name:@company_name) return @output_files[name] end
make_unknown_type( symbol )
click to toggle source
# File lib/swift_generator/code_generation/swift_class_generation.rb, line 1630 def make_unknown_type( symbol ) property_type = SwiftPropertyType.new( symbol, :NSDictionary ) #TODO: NSDictionary? for unknown type? @types_by_symbol[ symbol ] = property_type property_type end
prepare_for_generation()
click to toggle source
# File lib/swift_generator/code_generation/swift_class_generation.rb, line 1567 def prepare_for_generation @output_files.each do |_, swiftFile| swiftFile.prepare_for_generation end end
prepare_output_paths()
click to toggle source
# File lib/swift_generator/code_generation/swift_class_generation.rb, line 1521 def prepare_output_paths # Create / empty the generated output directories paths = [] paths << @generated_root unless @generated_root.nil? paths << @generated_test_root unless @generated_test_root.nil? paths.each do |path| FileUtils.mkdir_p(path) Dir.foreach(path) do |entry| file_path = File.join(path, entry) if (File::ftype(file_path) == "file") puts "deleting " + file_path File.delete(file_path) end end end end
prepare_supporting_elements()
click to toggle source
Called first during code generation. Note that this method may lead to the creation of new files
# File lib/swift_generator/code_generation/swift_class_generation.rb, line 1539 def prepare_supporting_elements() unless @generated_test_root.nil? @test_support_class = SwiftClass.new(self, 'AutoGeneratedTestSupport', [], characteristics:[], is_test_element: true ) unless while @make_more_supporting_elements do @make_more_supporting_elements = false original_output_files = @output_files.dup original_output_files.each do |_, swiftFile| swiftFile.prepare_supporting_elements end end end end
property_type_for_symbol(symbol)
click to toggle source
# File lib/swift_generator/code_generation/swift_class_generation.rb, line 1617 def property_type_for_symbol(symbol) resolved = @types_by_symbol[symbol] if resolved.nil? if @make_unknown_types resolved = make_unknown_type( symbol ) else puts( "ERROR: Unknown symbol: #{symbol.to_s}") end end resolved end
resolve_inheritance()
click to toggle source
Called during code generation.
# File lib/swift_generator/code_generation/swift_class_generation.rb, line 1555 def resolve_inheritance() @elements_by_name.each do |_, element| element.resolve_inheritance if element.respond_to? :resolve_inheritance end end
resolve_property_types()
click to toggle source
# File lib/swift_generator/code_generation/swift_class_generation.rb, line 1561 def resolve_property_types() @elements_by_name.each do |_, element| element.resolve_property_types if element.respond_to? :resolve_property_types end end
run_generation_sequence()
click to toggle source
# File lib/swift_generator/code_generation/swift_class_generation.rb, line 1511 def run_generation_sequence prepare_output_paths prepare_supporting_elements resolve_property_types resolve_inheritance prepare_for_generation resolve_property_types end