Class: ObjCIvarTemplate

Inherits:
Object
  • Object
show all
Defined in:
lib/mt_tool/short_hand/objc_generate_from_shorthand.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ivar) ⇒ ObjCIvarTemplate

Returns a new instance of ObjCIvarTemplate.



54
55
56
# File 'lib/mt_tool/short_hand/objc_generate_from_shorthand.rb', line 54

def initialize ivar
	@ivar = ivar
end

Instance Attribute Details

#ivarObject (readonly)

Returns the value of attribute ivar.



58
59
60
# File 'lib/mt_tool/short_hand/objc_generate_from_shorthand.rb', line 58

def ivar
  @ivar
end

Instance Method Details

#capitalized_property_nameObject



127
128
129
130
131
# File 'lib/mt_tool/short_hand/objc_generate_from_shorthand.rb', line 127

def capitalized_property_name
	p = property_name.to_s.dup
	p[0,1] = p[0,1].upcase
	p
end

#did_setObject



137
138
139
# File 'lib/mt_tool/short_hand/objc_generate_from_shorthand.rb', line 137

def did_set
	ivar.options.include? :did_set
end

#is_assignObject



153
154
155
156
# File 'lib/mt_tool/short_hand/objc_generate_from_shorthand.rb', line 153

def is_assign
	marker = memory_management_marker
	marker != 'retain' and marker != 'copy'
end

#is_object_typeObject



70
71
72
73
74
75
76
77
# File 'lib/mt_tool/short_hand/objc_generate_from_shorthand.rb', line 70

def is_object_type
	t = ivar.objc_type
	return true if ivar.options.include?(:object)
	return false if (t == :int or t == :uint or t == :bool)
	return true if t.kind_of?(Symbol)
	
	(t =~ /^\s*id\s*(<|$)/) != nil
end

#ivar_nameObject



79
80
81
# File 'lib/mt_tool/short_hand/objc_generate_from_shorthand.rb', line 79

def ivar_name
	"#{ivar.name}_"
end

#ivar_typeObject



60
61
62
63
64
65
66
67
68
# File 'lib/mt_tool/short_hand/objc_generate_from_shorthand.rb', line 60

def ivar_type
	t = ivar.objc_type
	t = "NSString*" if t == :str
	t = "NSInteger" if t == :int
	t = "NSUInteger" if t == :uint
	t = "BOOL" if t == :bool
	t = "#{t}*" if t.kind_of? Symbol and t != :id and t != :Class
	t
end

#memory_management_callObject



158
159
160
# File 'lib/mt_tool/short_hand/objc_generate_from_shorthand.rb', line 158

def memory_management_call
	memory_management_marker
end

#memory_management_markerObject



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/mt_tool/short_hand/objc_generate_from_shorthand.rb', line 87

def memory_management_marker
	if is_object_type
		if ivar.options.include? :retain
			'retain'
		elsif ivar.options.include? :copy
			'copy'
		elsif ivar.options.include? :assign
			'assign'
		elsif ivar.name.to_s == 'delegate' or ivar.name.to_s =~ /Delegate$/ and not ivar.options.include? :ro
			'assign'
		elsif not ivar.options.include? :ro
			'retain'
		end
	end
end

#needs_explicit_getterObject



149
150
151
# File 'lib/mt_tool/short_hand/objc_generate_from_shorthand.rb', line 149

def needs_explicit_getter
	will_get
end

#needs_explicit_setterObject



145
146
147
# File 'lib/mt_tool/short_hand/objc_generate_from_shorthand.rb', line 145

def needs_explicit_setter
	will_set || did_set
end

#outlet_markerObject



83
84
85
# File 'lib/mt_tool/short_hand/objc_generate_from_shorthand.rb', line 83

def outlet_marker
	'IBOutlet' if ivar.options.include? :outlet
end

#property_modifiersObject



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/mt_tool/short_hand/objc_generate_from_shorthand.rb', line 103

def property_modifiers
	s = []
	
	marker = memory_management_marker
	s << marker if marker
	
	s << 'nonatomic' unless ivar.options.include? :atomic
	
	if ivar.options.include? :ro
		s << 'readonly'
	end
	
	getter_name = ivar.options.select { |x| x.kind_of? ObjCIvarGetterNameOption }[0]
	if getter_name
		s << "getter = #{getter_name.name}"
	end
	
	return "(#{s.join ','})"
end

#property_nameObject



123
124
125
# File 'lib/mt_tool/short_hand/objc_generate_from_shorthand.rb', line 123

def property_name
	ivar.name
end

#will_getObject



141
142
143
# File 'lib/mt_tool/short_hand/objc_generate_from_shorthand.rb', line 141

def will_get
	ivar.options.include? :will_get
end

#will_setObject



133
134
135
# File 'lib/mt_tool/short_hand/objc_generate_from_shorthand.rb', line 133

def will_set
	ivar.options.include? :will_set
end