swift-tools 3.0.1 → 3.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/objc_2_swift.rb +39 -23
- data/lib/swift_tools.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e7f9e144b048f84e06b725d3a6e60db0da26ad82
|
4
|
+
data.tar.gz: d4216fb46541e4915e26063362ad633ce9d99a50
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c3935cc68966effbe14953e10ac713a9ad40a987807eb065b6748de21477a9f7115310b9e541b1c3438c218daa777e5e5994295e45f6d89e754f9b521a0fa2b4
|
7
|
+
data.tar.gz: fa158c838246921bef06caf63f5e1129ef7ba64bc9ec9e5d10e4cbc58472a80f24936c5173c317d9d169c4e919a7651ca112d45e648a3e4b90e79bcfe8ea8cc9
|
data/lib/objc_2_swift.rb
CHANGED
@@ -120,7 +120,7 @@ module SwiftTools
|
|
120
120
|
interface_data[:properties].each {|prop_name, prop_data|
|
121
121
|
line = INDENT
|
122
122
|
if prop_data[:readonly]
|
123
|
-
line += "private(set)
|
123
|
+
line += "private(set) "
|
124
124
|
elsif prop_data[:visibility] == :private
|
125
125
|
line += 'private '
|
126
126
|
end
|
@@ -166,6 +166,10 @@ module SwiftTools
|
|
166
166
|
line += 'private '
|
167
167
|
end
|
168
168
|
|
169
|
+
if interface_data[:base]
|
170
|
+
line += 'override '
|
171
|
+
end
|
172
|
+
|
169
173
|
line += "init() {"
|
170
174
|
|
171
175
|
if init_data[:body].length > 0
|
@@ -206,6 +210,7 @@ module SwiftTools
|
|
206
210
|
fix_null(body)
|
207
211
|
fix_at_string(body)
|
208
212
|
fix_broken_else(body)
|
213
|
+
fix_alloc_init(body)
|
209
214
|
line += body + INDENT + "}\n"
|
210
215
|
end
|
211
216
|
|
@@ -227,19 +232,37 @@ module SwiftTools
|
|
227
232
|
def capture_imports(h_filename, content)
|
228
233
|
r1 = ''
|
229
234
|
r2 = ''
|
230
|
-
content.scan
|
231
|
-
s = m.strip
|
235
|
+
content.to_enum(:scan, /[@#]import *"?([\.a-zA-Z0-9_]+)"? *;? *\n?/m).map { Regexp.last_match }.each {|m|
|
236
|
+
s = m[0].strip
|
232
237
|
if s.start_with?("#")
|
233
238
|
if s.index(h_filename).nil?
|
234
239
|
r2 += "// TODO: Add '#{s}' to bridging header\n"
|
235
240
|
end
|
236
241
|
else
|
237
|
-
r1 +=
|
242
|
+
r1 += "import #{m[1]}\n"
|
238
243
|
end
|
239
244
|
}
|
240
245
|
{:at_imports => r1, :hash_imports => r2}
|
241
246
|
end
|
242
247
|
|
248
|
+
def capture_statics(content)
|
249
|
+
statics = ''
|
250
|
+
content.scan(/static *(.*?);/m) {|m|
|
251
|
+
decl = m[0]
|
252
|
+
decl.gsub!('const', '')
|
253
|
+
decl.gsub!('*', '')
|
254
|
+
decl.gsub!('@"', '"')
|
255
|
+
decl.scan(/([a-zA-Z0-9_\*]+) +([a-zA-Z0-9_\*]+)(?: *= *(.*))?/m) {|mm|
|
256
|
+
statics += "// TODO: Add 'static let #{mm[1]}: #{map_type(mm[0])}"
|
257
|
+
if mm[2]
|
258
|
+
statics += " = #{mm[2]}"
|
259
|
+
end
|
260
|
+
statics += "' to one of your classes'\n"
|
261
|
+
}
|
262
|
+
}
|
263
|
+
statics
|
264
|
+
end
|
265
|
+
|
243
266
|
def capture_interfaces(content, in_hdr)
|
244
267
|
interfaces = {}
|
245
268
|
content.scan(/^\s*@interface\s*([a-zA-Z0-9_]+)(?:\s*:\s*([a-zA-Z0-9_]+)\s*)?(?:\s*\(([a-zA-Z0-9_, ]*)\))?(?:\s*<(.+)>)?((?:.|\n)*?)@end *\n$/m).each {|m|
|
@@ -315,24 +338,6 @@ module SwiftTools
|
|
315
338
|
implementations
|
316
339
|
end
|
317
340
|
|
318
|
-
def capture_statics(content)
|
319
|
-
statics = ''
|
320
|
-
content.scan(/static *(.*?);/m) {|m|
|
321
|
-
decl = m[0]
|
322
|
-
decl.gsub!('const', '')
|
323
|
-
decl.gsub!('*', '')
|
324
|
-
decl.gsub!('@"', '"')
|
325
|
-
decl.scan(/([a-zA-Z0-9_\*]+) +([a-zA-Z0-9_\*]+)(?: *= *(.*))?/m) {|mm|
|
326
|
-
statics += "@objc let #{mm[1]}: #{map_type(mm[0])}"
|
327
|
-
if mm[2]
|
328
|
-
statics += " = #{mm[2]}"
|
329
|
-
end
|
330
|
-
statics += "\n"
|
331
|
-
}
|
332
|
-
}
|
333
|
-
statics
|
334
|
-
end
|
335
|
-
|
336
341
|
def convert_to_dot_syntax(content)
|
337
342
|
# Repeatedly find a [] syntax method call that does not have a nested [] call
|
338
343
|
# and convert it until done.
|
@@ -360,7 +365,7 @@ module SwiftTools
|
|
360
365
|
arg = { :name => label_match[1]}
|
361
366
|
|
362
367
|
if block_match = body.match(/ *(?:\(.*?\))?(?: |\n)\{/, label_match.offset(0)[1])
|
363
|
-
end_of_param = find_close_char_offset(body, block_match.offset(0)[1], '{', '}')
|
368
|
+
end_of_param = find_close_char_offset(body, block_match.offset(0)[1], '{', '}') + 1
|
364
369
|
else
|
365
370
|
# Find the next arg label or the end of the string
|
366
371
|
next_label_match = body.match(param_label_re, label_match.offset(0)[1])
|
@@ -430,6 +435,15 @@ module SwiftTools
|
|
430
435
|
'(' + params + ')'
|
431
436
|
end
|
432
437
|
|
438
|
+
def fix_alloc_init(content)
|
439
|
+
content.gsub!(/([a-zA-Z0-9_]+)\.alloc\(\)\.init(?:With([a-zA-Z0-9_]+))?\(/) { |m|
|
440
|
+
r = "#{$1}("
|
441
|
+
if $2
|
442
|
+
r += $2[0].downcase + $2[1..-1] + ': '
|
443
|
+
end
|
444
|
+
}
|
445
|
+
end
|
446
|
+
|
433
447
|
def fix_if_statements(content)
|
434
448
|
content.gsub!(/if *\((.+?)\)(?: |\n)*{/m) {|m|
|
435
449
|
"if #{$1} {"
|
@@ -509,6 +523,8 @@ module SwiftTools
|
|
509
523
|
'Long'
|
510
524
|
when 'void'
|
511
525
|
'Void'
|
526
|
+
when 'NSString'
|
527
|
+
'String'
|
512
528
|
when /(.*)\*/
|
513
529
|
$1
|
514
530
|
else
|
data/lib/swift_tools.rb
CHANGED