Skip to content

Commit

Permalink
Move duplicate warnings to separate function
Browse files Browse the repository at this point in the history
  • Loading branch information
tomlokhorst committed Jul 30, 2016
1 parent 5ecc967 commit 719d738
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 102 deletions.
12 changes: 1 addition & 11 deletions R.swift/Generators/ColorGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,7 @@ struct ColorGenerator: Generator {
let name = SwiftIdentifier(name: palette.filename)
let groupedColors = palette.colors.groupBySwiftIdentifiers { $0.0 }

for (sanitizedName, duplicates) in groupedColors.duplicates {
warn("Skipping \(duplicates.count) colors in palette '\(palette.filename)' because symbol '\(sanitizedName)' would be generated for all of these colors: \(duplicates.joinWithSeparator(", "))")
}

let empties = groupedColors.empties
if let empty = empties.first where empties.count == 1 {
warn("Skipping 1 color in palette '\(palette.filename)' because no swift identifier can be generated for image: \(empty)")
}
else if empties.count > 1 {
warn("Skipping \(empties.count) images in palette '\(palette.filename)' because no swift identifier can be generated for all of these images: \(empties.joinWithSeparator(", "))")
}
groupedColors.printWarningsForDuplicatesAndEmpties(source: "color", container: "in palette '\(palette.filename)'", result: "color")

return Struct(
comments: ["This `R.color.\(name)` struct is generated, and contains static references to \(groupedColors.uniques.count) colors."],
Expand Down
12 changes: 1 addition & 11 deletions R.swift/Generators/ImageGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,7 @@ struct ImageGenerator: Generator {
let allFunctions = assetFolderImageNames + imagesNames
let groupedFunctions = allFunctions.groupBySwiftIdentifiers { $0 }

for (sanitizedName, duplicates) in groupedFunctions.duplicates {
warn("Skipping \(duplicates.count) images because symbol '\(sanitizedName)' would be generated for all of these images: \(duplicates.joinWithSeparator(", "))")
}

let empties = groupedFunctions.empties
if let empty = empties.first where empties.count == 1 {
warn("Skipping 1 image because no swift identifier can be generated for image: \(empty)")
}
else if empties.count > 1 {
warn("Skipping \(empties.count) images because no swift identifier can be generated for all of these images: \(empties.joinWithSeparator(", "))")
}
groupedFunctions.printWarningsForDuplicatesAndEmpties(source: "image", result: "image")

let imageLets = groupedFunctions
.uniques
Expand Down
12 changes: 1 addition & 11 deletions R.swift/Generators/NibGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,7 @@ struct NibGenerator: Generator {
init(nibs: [Nib]) {
let groupedNibs = nibs.groupBySwiftIdentifiers { $0.name }

for (name, duplicates) in groupedNibs.duplicates {
warn("Skipping \(duplicates.count) xibs because symbol '\(name)' would be generated for all of these xibs: \(duplicates.joinWithSeparator(", "))")
}

let empties = groupedNibs.empties
if let empty = empties.first where empties.count == 1 {
warn("Skipping 1 xib because no swift identifier can be generated for xib: \(empty)")
}
else if empties.count > 1 {
warn("Skipping \(empties.count) xibs because no swift identifier can be generated for all of these xibs: \(empties.joinWithSeparator(", "))")
}
groupedNibs.printWarningsForDuplicatesAndEmpties(source: "xib", result: "xib")

internalStruct = Struct(
type: Type(module: .Host, name: "nib"),
Expand Down
12 changes: 1 addition & 11 deletions R.swift/Generators/ResourceFileGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,7 @@ struct ResourceFileGenerator: Generator {
init(resourceFiles: [ResourceFile]) {
let groupedResourceFiles = resourceFiles.groupBySwiftIdentifiers { $0.fullname }

for (name, duplicates) in groupedResourceFiles.duplicates {
warn("Skipping \(duplicates.count) resource files because symbol '\(name)' would be generated for all of these files: \(duplicates.joinWithSeparator(", "))")
}

let empties = groupedResourceFiles.empties
if let empty = empties.first where empties.count == 1 {
warn("Skipping 1 resource file because no swift identifier can be generated for file: \(empty)")
}
else if empties.count > 1 {
warn("Skipping \(empties.count) resource files because no swift identifier can be generated for all of these files: \(empties.joinWithSeparator(", "))")
}
groupedResourceFiles.printWarningsForDuplicatesAndEmpties(source: "resource file", result: "file")

let resourceFileProperties: [Property] = groupedResourceFiles
.uniques
Expand Down
12 changes: 1 addition & 11 deletions R.swift/Generators/ReuseIdentifierGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,7 @@ struct ReuseIdentifierGenerator: Generator {

let groupedReusables = deduplicatedReusables.groupBySwiftIdentifiers { $0.identifier }

for (name, duplicates) in groupedReusables.duplicates {
warn("Skipping \(duplicates.count) reuseIdentifiers because symbol '\(name)' would be generated for all of these reuseIdentifiers: \(duplicates.joinWithSeparator(", "))")
}

let empties = groupedReusables.empties
if let empty = empties.first where empties.count == 1 {
warn("Skipping 1 reuseIdentifier because no swift identifier can be generated for reuseIdentifier: \(empty)")
}
else if empties.count > 1 {
warn("Skipping \(empties.count) reuseIdentifiers because no swift identifier can be generated for all of these reuseIdentifiers: \(empties.joinWithSeparator(", "))")
}
groupedReusables.printWarningsForDuplicatesAndEmpties(source: "reuseIdentifier", result: "reuseIdentifier")

let reuseIdentifierProperties = groupedReusables
.uniques
Expand Down
12 changes: 1 addition & 11 deletions R.swift/Generators/SegueGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,7 @@ struct SegueGenerator: Generator {
for (sourceType, seguesBySourceType) in deduplicatedSeguesWithInfo.groupBy({ $0.sourceType }) {
let groupedSeguesWithInfo = seguesBySourceType.groupBySwiftIdentifiers { $0.segue.identifier }

for (name, duplicates) in groupedSeguesWithInfo.duplicates {
warn("Skipping \(duplicates.count) segues for '\(sourceType)' because symbol '\(name)' would be generated for all of these segues, but with a different destination or segue type: \(duplicates.joinWithSeparator(", "))")
}

let empties = groupedSeguesWithInfo.empties
if let empty = empties.first where empties.count == 1 {
warn("Skipping 1 segue for '\(sourceType)' because no swift identifier can be generated for segue: \(empty)")
}
else if empties.count > 1 {
warn("Skipping \(empties.count) segues for '\(sourceType)' because no swift identifier can be generated for all of these segues: \(empties.joinWithSeparator(", "))")
}
groupedSeguesWithInfo.printWarningsForDuplicatesAndEmpties(source: "segue", container: "for '\(sourceType)'", result: "segue")

let sts = groupedSeguesWithInfo
.uniques
Expand Down
12 changes: 1 addition & 11 deletions R.swift/Generators/StoryboardGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,7 @@ struct StoryboardGenerator: Generator {
init(storyboards: [Storyboard]) {
let groupedStoryboards = storyboards.groupBySwiftIdentifiers { $0.name }

for (name, duplicates) in groupedStoryboards.duplicates {
warn("Skipping \(duplicates.count) storyboards because symbol '\(name)' would be generated for all of these storyboards: \(duplicates.joinWithSeparator(", "))")
}

let empties = groupedStoryboards.empties
if let empty = empties.first where empties.count == 1 {
warn("Skipping 1 storyboard because no swift identifier can be generated for storyboard: \(empty)")
}
else if empties.count > 1 {
warn("Skipping \(empties.count) storyboards because no swift identifier can be generated for all of these storyboards: \(empties.joinWithSeparator(", "))")
}
groupedStoryboards.printWarningsForDuplicatesAndEmpties(source: "storyboard", result: "storyboard")

let storyboardStructs = groupedStoryboards
.uniques
Expand Down
24 changes: 2 additions & 22 deletions R.swift/Generators/StringsGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,7 @@ struct StringsGenerator: Generator {
let localized = localizableStrings.groupBy { $0.filename }
let groupedLocalized = localized.groupBySwiftIdentifiers { $0.0 }

for (sanitizedName, duplicates) in groupedLocalized.duplicates {
warn("Skipping \(duplicates.count) strings files because symbol '\(sanitizedName)' would be generated for all of these filenames: \(duplicates.joinWithSeparator(", "))")
}

let empties = groupedLocalized.empties
if let empty = empties.first where empties.count == 1 {
warn("Skipping 1 strings file because no swift identifier can be generated for filename: \(empty)")
}
else if empties.count > 1 {
warn("Skipping \(empties.count) strings files because no swift identifier can be generated for all of these filenames: \(empties.joinWithSeparator(", "))")
}
groupedLocalized.printWarningsForDuplicatesAndEmpties(source: "strings file", result: "file")

externalStruct = Struct(
comments: ["This `R.string` struct is generated, and contains static references to \(groupedLocalized.uniques.count) localization tables."],
Expand Down Expand Up @@ -75,17 +65,7 @@ struct StringsGenerator: Generator {
let filenameLocale = ls.locale.withFilename(filename)
let groupedKeys = ls.dictionary.keys.groupBySwiftIdentifiers { $0 }

for (sanitizedName, duplicates) in groupedKeys.duplicates {
warn("Skipping \(duplicates.count) strings in \(filenameLocale) because symbol '\(sanitizedName)' would be generated for all of these keys: \(duplicates.map { "'\($0)'" }.joinWithSeparator(", "))")
}

let empties = groupedKeys.empties
if let empty = empties.first where empties.count == 1 {
warn("Skipping 1 string in \(filenameLocale) because no swift identifier can be generated for key: \(empty)")
}
else if empties.count > 1 {
warn("Skipping \(empties.count) strings in \(filenameLocale) because no swift identifier can be generated for all of these keys: \(empties.joinWithSeparator(", "))")
}
groupedKeys.printWarningsForDuplicatesAndEmpties(source: "string", container: "in \(filenameLocale)", result: "key")

// Save uniques
for key in groupedKeys.uniques {
Expand Down
20 changes: 20 additions & 0 deletions R.swift/Util/SwiftIdentifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,26 @@ struct SwiftNameGroups<T> {
let uniques: [T]
let duplicates: [(SwiftIdentifier, [String])] // Identifiers that result in duplicate Swift names
let empties: [String] // Identifiers (wrapped in quotes) that result in empty swift names

func printWarningsForDuplicatesAndEmpties(source source: String, container: String? = nil, result: String) {

let sourceSingular = [source, container].flatMap { $0 }.joinWithSeparator(" ")
let sourcePlural = ["\(source)s", container].flatMap { $0 }.joinWithSeparator(" ")

let resultSingular = result
let resultPlural = "\(result)s"

for (sanitizedName, dups) in duplicates {
warn("Skipping \(dups.count) \(sourcePlural) because symbol '\(sanitizedName)' would be generated for all of these \(resultPlural): \(dups.joinWithSeparator(", "))")
}

if let empty = empties.first where empties.count == 1 {
warn("Skipping 1 \(sourceSingular) because no swift identifier can be generated for \(resultSingular): \(empty)")
}
else if empties.count > 1 {
warn("Skipping \(empties.count) \(sourcePlural) because no swift identifier can be generated for all of these \(resultPlural): \(empties.joinWithSeparator(", "))")
}
}
}

extension SequenceType {
Expand Down
6 changes: 3 additions & 3 deletions ResourceApp/ResourceAppTests/ResourceAppTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ class ResourceAppTests: XCTestCase {
"warning: [R.swift] Skipping 2 xibs because symbol 'duplicate' would be generated for all of these xibs: Duplicate, duplicate",
"warning: [R.swift] Skipping 2 storyboards because symbol 'duplicate' would be generated for all of these storyboards: Duplicate, duplicate",
"warning: [R.swift] Skipping 2 reuseIdentifiers because symbol 'duplicateCellView' would be generated for all of these reuseIdentifiers: DuplicateCellView, duplicateCellView",
"warning: [R.swift] Skipping 2 segues for 'SecondViewController' because symbol 'toFirst' would be generated for all of these segues, but with a different destination or segue type: ToFirst, toFirst",
"warning: [R.swift] Skipping 2 segues for 'SecondViewController' because symbol 'toFirst' would be generated for all of these segues: ToFirst, toFirst",
"warning: [R.swift] Skipping 2 images because symbol 'theAppIcon' would be generated for all of these images: The App Icon, TheAppIcon",
"warning: [R.swift] Skipping 2 images because symbol 'second' would be generated for all of these images: Second, second",
"warning: [R.swift] Skipping 2 resource files because symbol 'duplicateJson' would be generated for all of these files: Duplicate.json, duplicateJson",
"warning: [R.swift] Destination view controller with id Zbd-89-K73 for segue toUnknown in FirstViewController not found in storyboard References. Is this storyboard corrupt?",
"warning: [R.swift] Skipping 1 reuseIdentifier because no swift identifier can be generated for reuseIdentifier: ' '",
"warning: [R.swift] Skipping 2 colors in palette 'My R.swift colors' because symbol 'black' would be generated for all of these colors: Black, Black?",

"warning: [R.swift] Skipping 2 strings files because symbol 'duplicate' would be generated for all of these filenames: Duplicate, Duplicate#",
"warning: [R.swift] Skipping 1 strings file because no swift identifier can be generated for filename: '@@'",
"warning: [R.swift] Skipping 2 strings files because symbol 'duplicate' would be generated for all of these files: Duplicate, Duplicate#",
"warning: [R.swift] Skipping 1 strings file because no swift identifier can be generated for file: '@@'",
"warning: [R.swift] Skipping 1 string in 'Generic' because no swift identifier can be generated for key: '#'",
"warning: [R.swift] Strings file 'Localizable' (en) is missing translations for keys: 'japanese only'",
"warning: [R.swift] Strings file 'Localizable' (es) is missing translations for keys: 'japanese only'",
Expand Down

0 comments on commit 719d738

Please sign in to comment.