Skip to content

Commit 4470380

Browse files
author
Sheen
committed
STRFRAMEWORK-1674: Code review fix
1 parent b683286 commit 4470380

1 file changed

Lines changed: 27 additions & 36 deletions

File tree

Plist2swift/Plist2swift.swift

Lines changed: 27 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ private func usage() {
3030
exit(1)
3131
}
3232

33-
private func tabs(intendBy: Int = 0) -> String {
33+
private func tabs(indentBy: Int = 0) -> String {
3434
var tabsString = ""
3535

36-
intend(by: intendBy)
36+
indent(by: indentBy)
3737

3838
for _ in 0..<countOfTabs {
3939
tabsString += "\t"
@@ -42,7 +42,7 @@ private func tabs(intendBy: Int = 0) -> String {
4242
return tabsString
4343
}
4444

45-
private func intend(by indentationLevel: Int = 1) {
45+
private func indent(by indentationLevel: Int = 1) {
4646
countOfTabs += indentationLevel
4747
}
4848

@@ -83,9 +83,6 @@ private func generateHeader() {
8383
""")
8484
}
8585

86-
/**
87-
Checking the key is present in the Optional Dictionary
88-
*/
8986
private func isKeyPresentInOptionalDictionary(keyToSearch: String, tupleKey: String, optionalDictionary: [String: [String: String]]) -> Bool {
9087
guard let optionalKeysAndTypes = optionalDictionary[keyToSearch] else {
9188
return false
@@ -95,9 +92,6 @@ private func isKeyPresentInOptionalDictionary(keyToSearch: String, tupleKey: Str
9592
return optionalArray.contains(tupleKey)
9693
}
9794

98-
/**
99-
Checking the key is present in all the plists
100-
*/
10195
private func isKeyAvailableInAllPlists(keyToSearch: String, tupleKey: String, tuplesForPlists: [String: KeyValueTuples]) -> Bool {
10296
for plistPath in tuplesForPlists.keys {
10397

@@ -115,17 +109,14 @@ private func isKeyAvailableInAllPlists(keyToSearch: String, tupleKey: String, tu
115109
return true
116110
}
117111

118-
/**
119-
Generate Protocol for the Tuples and return the optional dictionary
120-
*/
121112
private func generateProtocol(tuplesForPlists: [String: KeyValueTuples], allKeyValueTuples: [String: KeyValueTuples]) -> [String: [String: String]] {
122-
var optionalDictionary = [String: [String: String]]()
113+
var dictionaryWithOptionalValues = [String: [String: String]]()
123114
for (tupleKey, tuples) in allKeyValueTuples {
124115

125116
let name = tupleKey.uppercaseFirst()
126117
let protocolName = name.appending("Protocol")
127118
print("protocol \(protocolName) {")
128-
intend()
119+
indent()
129120

130121
var optionalKeysAndTypes = [String: String]()
131122
for tuple in tuples.tuples {
@@ -139,11 +130,11 @@ private func generateProtocol(tuplesForPlists: [String: KeyValueTuples], allKeyV
139130
print("\(tabs())var \(tuple.key.lowercaseFirst()): \(type) { get }")
140131
}
141132

142-
optionalDictionary[tupleKey] = optionalKeysAndTypes
143-
print("\(tabs(intendBy: -1))}\n")
133+
dictionaryWithOptionalValues[tupleKey] = optionalKeysAndTypes
134+
print("\(tabs(indentBy: -1))}\n")
144135
}
145136

146-
return optionalDictionary
137+
return dictionaryWithOptionalValues
147138
}
148139

149140
/**
@@ -158,14 +149,14 @@ private func generateProtocol(name: String, tuples: KeyValueTuples) -> String {
158149

159150
let protocolName = name.appending("Protocol")
160151
print("protocol \(protocolName) {")
161-
intend()
152+
indent()
162153

163154
for tuple in tuples.tuples {
164155
let type = typeForValue(tuple.value as Any)
165156
print("\(tabs())var \(tuple.key.lowercaseFirst()): \(type) { get }")
166157
}
167158

168-
print("\(tabs(intendBy: -1))}\n")
159+
print("\(tabs(indentBy: -1))}\n")
169160
return protocolName
170161
}
171162

@@ -180,7 +171,7 @@ Generate the general protocol with class properties.
180171
*/
181172
private func generateProtocol(name: String, commonKeys: [String], oddKeys: [String], keysAndTypes: [String:String]) {
182173
print("\(tabs())protocol \(name) {")
183-
intend()
174+
indent()
184175
print("\(tabs())// Common Keys")
185176

186177
for commonKey in commonKeys {
@@ -206,7 +197,7 @@ private func generateProtocol(name: String, commonKeys: [String], oddKeys: [Stri
206197
}
207198
}
208199

209-
print("\(tabs(intendBy: -1))}\n")
200+
print("\(tabs(indentBy: -1))}\n")
210201
}
211202

212203
/**
@@ -268,7 +259,7 @@ private func generateStructs(name key: String? = nil, tuples: KeyValueTuples, ke
268259
}
269260

270261
print("\n\(tabs())internal struct \(structName)\(conformingToProtocol) {")
271-
intend()
262+
indent()
272263

273264
var availableKeys = [String]()
274265
for tuple in tuples.tuples {
@@ -336,7 +327,7 @@ private func generateStructs(name key: String? = nil, tuples: KeyValueTuples, ke
336327
guard
337328
let key = key,
338329
let optionalKeysAndTypes = optionalDictionary[key] else {
339-
print("\(tabs(intendBy: -1))}\n")
330+
print("\(tabs(indentBy: -1))}\n")
340331
return
341332
}
342333

@@ -348,7 +339,7 @@ private func generateStructs(name key: String? = nil, tuples: KeyValueTuples, ke
348339
print("\(tabs())internal var \(key.lowercaseFirst()): \(type) = nil")
349340
}
350341

351-
print("\(tabs(intendBy: -1))}\n")
342+
print("\(tabs(indentBy: -1))}\n")
352343
}
353344

354345
/**
@@ -372,7 +363,7 @@ private func generateExtensions(enumName: String, protocolName: String, allTuple
372363
let structName = caseName.uppercaseFirst()
373364

374365
print("\(tabs())extension \(enumName).\(structName): \(protocolName) {")
375-
intend()
366+
indent()
376367

377368
for oddKey in oddKeys {
378369

@@ -390,8 +381,8 @@ private func generateExtensions(enumName: String, protocolName: String, allTuple
390381
} else if (type.contains("Protocol")){
391382
guard tuples[oddKey] != nil else {
392383
print("\(tabs())var \(oddKey.lowercaseFirst()): \(type)? {")
393-
print("\(tabs(intendBy: 1))return nil")
394-
print("\(tabs(intendBy: -1))}")
384+
print("\(tabs(indentBy: 1))return nil")
385+
print("\(tabs(indentBy: -1))}")
395386
continue
396387
}
397388

@@ -402,17 +393,17 @@ private func generateExtensions(enumName: String, protocolName: String, allTuple
402393

403394
generateStructs(name: oddKey, tuples: KeyValueTuples(tuples: sortedDictionary ?? []), oddKeys: oddKeys, protocolName: type, optionalDictionary: optionalDictionary)
404395
print("\(tabs())var \(oddKey.lowercaseFirst()): \(type)? {")
405-
print("\(tabs(intendBy: 1))return \(oddKey.uppercaseFirst())()")
406-
print("\(tabs(intendBy: -1))}")
396+
print("\(tabs(indentBy: 1))return \(oddKey.uppercaseFirst())()")
397+
print("\(tabs(indentBy: -1))}")
407398
} else { // String
408399
print("\(tabs())var \(oddKey.lowercaseFirst()): \(type)? {")
409-
intend()
400+
indent()
410401
let returnValue = tuples[oddKey] as? String
411402
returnValue != nil ? print("\(tabs())return \"\(returnValue!)\"") : print("\(tabs())return nil")
412-
print("\(tabs(intendBy: -1))}")
403+
print("\(tabs(indentBy: -1))}")
413404
}
414405
}
415-
print("\(tabs(intendBy: -1))}\n")
406+
print("\(tabs(indentBy: -1))}\n")
416407
}
417408
}
418409

@@ -434,7 +425,7 @@ private func generateEnum(name enumName: String, protocolName: String, allTuples
434425
}
435426

436427
print("\(tabs())internal enum \(enumName) {")
437-
intend()
428+
indent()
438429

439430
for caseName in cases {
440431
print("\(tabs())case \(caseName.lowercaseFirst())")
@@ -447,7 +438,7 @@ private func generateEnum(name enumName: String, protocolName: String, allTuples
447438
print("""
448439
\(tabs())var configuration: \(protocolName) {
449440
450-
\(tabs(intendBy: 1))switch self {
441+
\(tabs(indentBy: 1))switch self {
451442
""")
452443

453444
for caseName in cases {
@@ -457,8 +448,8 @@ private func generateEnum(name enumName: String, protocolName: String, allTuples
457448
}
458449

459450
print("\(tabs())}")
460-
print("\(tabs(intendBy: -1))}")
461-
print("\(tabs(intendBy: -1))}\n")
451+
print("\(tabs(indentBy: -1))}")
452+
print("\(tabs(indentBy: -1))}\n")
462453
generateExtensions(enumName: enumName, protocolName: protocolName, allTuples: allTuples, keysAndTypes: keysAndTypes, oddKeys: oddKeys, optionalDictionary: optionalDictionary)
463454
}
464455

0 commit comments

Comments
 (0)