class SwiftGenerator::SwiftProperty
Attributes
access_control_modifiers[RW]
collection_type[RW]
getter_body[RW]
initialization_value[RW]
is_persistent[RW]
mutability_type[RW]
property_name[RW]
property_qualifiers[RW]
property_type[RW]
property_type_symbol[RW]
protocol_get_set_spec[RW]
required[RW]
rest_omit[RW]
setter_body[RW]
swift_class[RW]
Public Class Methods
new(swift_class, property_name, property_type_symbol, mutability= :let, initialization_value:nil, collection_type: nil, required: true, rest_omit:nil )
click to toggle source
# File lib/swift_generator/code_generation/swift_class_generation.rb, line 900 def initialize(swift_class, property_name, property_type_symbol, mutability= :let, initialization_value:nil, collection_type: nil, required: true, rest_omit:nil ) @swift_class = swift_class @property_name = property_name @property_type_symbol = property_type_symbol @property_type = nil # @property_type = swift_class.definition_set.property_type_for_symbol(property_type) @mutability_type = SwiftDefinitionSet.mutability_types[mutability] @is_persistent = false @collection_type = collection_type @required = required #@access_control_modifier = 'public ' @access_control_modifiers = nil @property_qualifiers = nil @initialization_value = initialization_value @getter_body = nil @setter_body = nil @rest_omit = rest_omit @protocol_get_set_spec = nil swift_class.properties << self end
Public Instance Methods
declaration_lines()
click to toggle source
# File lib/swift_generator/code_generation/swift_class_generation.rb, line 925 def declaration_lines qualifiers = [] qualifiers += [*@access_control_modifiers] unless @access_control_modifiers.nil? qualifiers += [*@property_qualifiers] unless @property_qualifiers.nil? qualifiers << @mutability_type.mutability declaration = "#{qualifiers.join(' ')} #{@property_name} : #{full_type_specifier()}" # Initial Value initial_value = @initialization_value if !initial_value.nil? if( collection_type == :array ) if( @mutability_type.mutability_id == :optional ) # Initialize variable arrays to empty by default initial_value = "[]" end end end declaration += " = #{initial_value}" unless initial_value.nil? declaration += " #{@protocol_get_set_spec}" unless @protocol_get_set_spec.nil? # Must be set if part of a protocol definition # Computed Properties if !( @getter_body.nil? && @setter_body.nil? ) declaration = [declaration + " {"] if !@getter_body.nil? declaration << "\tget {" declaration.concat([*@getter_body].map { |line| "\t\t" + line }) declaration << "\t}" end if !@setter_body.nil? declaration << "" unless @getter_body.nil? declaration << "\tset {" declaration.concat([*@setter_body].map { |line| "\t\t" + line }) declaration << "\t}" end declaration << "}" end return [*declaration] end
full_type_specifier()
click to toggle source
# File lib/swift_generator/code_generation/swift_class_generation.rb, line 973 def full_type_specifier # Apply Collection full_type_name = @property_type.swift_type_name if @collection_type == :array full_type_name = "[#{full_type_name}]" end "#{full_type_name}#{@mutability_type.declaration_wrapping}" end
is_array_of_nsobject()
click to toggle source
Utility
# File lib/swift_generator/code_generation/swift_class_generation.rb, line 1003 def is_array_of_nsobject (@collection_type == :array) && (@property_type.swift_kind == :class) end
is_optional()
click to toggle source
# File lib/swift_generator/code_generation/swift_class_generation.rb, line 1007 def is_optional return @mutability_type.mutability_id == :optional end
make_test_value(index)
click to toggle source
# File lib/swift_generator/code_generation/swift_class_generation.rb, line 990 def make_test_value(index) if @collection_type.nil? return @property_type.make_test_value(index) else return '[]' end end
property_declared_type()
click to toggle source
# File lib/swift_generator/code_generation/swift_class_generation.rb, line 998 def property_declared_type @property_type.swift_type_name + @mutability_type.declaration_wrapping end
resolve_type()
click to toggle source
# File lib/swift_generator/code_generation/swift_class_generation.rb, line 984 def resolve_type() @property_type = @swift_class.definition_set.property_type_for_symbol(@property_type_symbol) abort( "No property type found for #{@property_type_symbol.to_s}") if @property_type.nil? end