Class: SwiftGenerator::SwiftProperty
- Inherits:
-
Object
- Object
- SwiftGenerator::SwiftProperty
- Defined in:
- lib/swift_generator/code_generation/swift_class_generation.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#access_control_modifiers ⇒ Object
Returns the value of attribute access_control_modifiers.
-
#collection_type ⇒ Object
Returns the value of attribute collection_type.
-
#getter_body ⇒ Object
Returns the value of attribute getter_body.
-
#initialization_value ⇒ Object
Returns the value of attribute initialization_value.
-
#is_persistent ⇒ Object
Returns the value of attribute is_persistent.
-
#mutability_type ⇒ Object
Returns the value of attribute mutability_type.
-
#property_name ⇒ Object
Returns the value of attribute property_name.
-
#property_qualifiers ⇒ Object
Returns the value of attribute property_qualifiers.
-
#property_type ⇒ Object
Returns the value of attribute property_type.
-
#property_type_symbol ⇒ Object
Returns the value of attribute property_type_symbol.
-
#protocol_get_set_spec ⇒ Object
for declarations in protocols.
-
#required ⇒ Object
Returns the value of attribute required.
-
#rest_omit ⇒ Object
Returns the value of attribute rest_omit.
-
#setter_body ⇒ Object
Returns the value of attribute setter_body.
-
#swift_class ⇒ Object
Returns the value of attribute swift_class.
Instance Method Summary collapse
- #declaration_lines ⇒ Object
- #full_type_specifier ⇒ Object
-
#initialize(swift_class, property_name, property_type_symbol, mutability = :let, initialization_value: nil, collection_type: nil, required: true, rest_omit: nil) ⇒ SwiftProperty
constructor
A new instance of SwiftProperty.
-
#is_array_of_nsobject ⇒ Object
Utility.
- #is_optional ⇒ Object
- #make_test_value(index) ⇒ Object
- #property_declared_type ⇒ Object
- #resolve_type ⇒ Object
Constructor Details
#initialize(swift_class, property_name, property_type_symbol, mutability = :let, initialization_value: nil, collection_type: nil, required: true, rest_omit: nil) ⇒ SwiftProperty
Returns a new instance of SwiftProperty.
900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 |
# 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 |
Instance Attribute Details
#access_control_modifiers ⇒ Object
Returns the value of attribute access_control_modifiers.
895 896 897 |
# File 'lib/swift_generator/code_generation/swift_class_generation.rb', line 895 def access_control_modifiers @access_control_modifiers end |
#collection_type ⇒ Object
Returns the value of attribute collection_type.
888 889 890 |
# File 'lib/swift_generator/code_generation/swift_class_generation.rb', line 888 def collection_type @collection_type end |
#getter_body ⇒ Object
Returns the value of attribute getter_body.
892 893 894 |
# File 'lib/swift_generator/code_generation/swift_class_generation.rb', line 892 def getter_body @getter_body end |
#initialization_value ⇒ Object
Returns the value of attribute initialization_value.
891 892 893 |
# File 'lib/swift_generator/code_generation/swift_class_generation.rb', line 891 def initialization_value @initialization_value end |
#is_persistent ⇒ Object
Returns the value of attribute is_persistent.
887 888 889 |
# File 'lib/swift_generator/code_generation/swift_class_generation.rb', line 887 def is_persistent @is_persistent end |
#mutability_type ⇒ Object
Returns the value of attribute mutability_type.
885 886 887 |
# File 'lib/swift_generator/code_generation/swift_class_generation.rb', line 885 def mutability_type @mutability_type end |
#property_name ⇒ Object
Returns the value of attribute property_name.
882 883 884 |
# File 'lib/swift_generator/code_generation/swift_class_generation.rb', line 882 def property_name @property_name end |
#property_qualifiers ⇒ Object
Returns the value of attribute property_qualifiers.
886 887 888 |
# File 'lib/swift_generator/code_generation/swift_class_generation.rb', line 886 def property_qualifiers @property_qualifiers end |
#property_type ⇒ Object
Returns the value of attribute property_type.
884 885 886 |
# File 'lib/swift_generator/code_generation/swift_class_generation.rb', line 884 def property_type @property_type end |
#property_type_symbol ⇒ Object
Returns the value of attribute property_type_symbol.
883 884 885 |
# File 'lib/swift_generator/code_generation/swift_class_generation.rb', line 883 def property_type_symbol @property_type_symbol end |
#protocol_get_set_spec ⇒ Object
for declarations in protocols
897 898 899 |
# File 'lib/swift_generator/code_generation/swift_class_generation.rb', line 897 def protocol_get_set_spec @protocol_get_set_spec end |
#required ⇒ Object
Returns the value of attribute required.
889 890 891 |
# File 'lib/swift_generator/code_generation/swift_class_generation.rb', line 889 def required @required end |
#rest_omit ⇒ Object
Returns the value of attribute rest_omit.
894 895 896 |
# File 'lib/swift_generator/code_generation/swift_class_generation.rb', line 894 def rest_omit @rest_omit end |
#setter_body ⇒ Object
Returns the value of attribute setter_body.
893 894 895 |
# File 'lib/swift_generator/code_generation/swift_class_generation.rb', line 893 def setter_body @setter_body end |
#swift_class ⇒ Object
Returns the value of attribute swift_class.
881 882 883 |
# File 'lib/swift_generator/code_generation/swift_class_generation.rb', line 881 def swift_class @swift_class end |
Instance Method Details
#declaration_lines ⇒ Object
925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 |
# 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 ⇒ Object
973 974 975 976 977 978 979 980 981 |
# 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 ⇒ Object
Utility
1003 1004 1005 |
# 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 ⇒ Object
1007 1008 1009 |
# 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) ⇒ Object
990 991 992 993 994 995 996 |
# 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 ⇒ Object
998 999 1000 |
# 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 ⇒ Object
984 985 986 987 |
# 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 |