Skip to content

Commit

Permalink
Don't generate empty structs
Browse files Browse the repository at this point in the history
  • Loading branch information
tomlokhorst committed Jun 7, 2017
1 parent 5748879 commit 017907a
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 2 deletions.
4 changes: 3 additions & 1 deletion Sources/RswiftCore/Generators/ColorStructGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ struct ColorStructGenerator: ExternalOnlyStructGenerator {

let structs = assetSubfolders.folders
.map { $0.generatedColorStruct(at: externalAccessLevel, prefix: qualifiedName) }
.filter { !$0.isEmpty }

let colorLets = groupedColors
.uniques
Expand Down Expand Up @@ -104,6 +105,7 @@ private extension NamespacedAssetSubfolder {
let qualifiedName = prefix + structName
let structs = assetSubfolders.folders
.map { $0.generatedColorStruct(at: externalAccessLevel, prefix: qualifiedName) }
.filter { !$0.isEmpty }

let colorLets = groupedFunctions
.uniques
Expand All @@ -119,7 +121,7 @@ private extension NamespacedAssetSubfolder {
}

return Struct(
availables: ["tvOS 11.0, *", "iOS 11.0, *"],
availables: [],
comments: ["This `\(qualifiedName)` struct is generated, and contains static references to \(colorLets.count) colors."],
accessModifier: externalAccessLevel,
type: Type(module: .host, name: structName),
Expand Down
2 changes: 2 additions & 0 deletions Sources/RswiftCore/Generators/ImageStructGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ struct ImageStructGenerator: ExternalOnlyStructGenerator {

let structs = assetSubfolders.folders
.map { $0.generatedImageStruct(at: externalAccessLevel, prefix: qualifiedName) }
.filter { !$0.isEmpty }

let imageLets = groupedFunctions
.uniques
Expand Down Expand Up @@ -115,6 +116,7 @@ private extension NamespacedAssetSubfolder {
let qualifiedName = prefix + structName
let structs = assetSubfolders.folders
.map { $0.generatedImageStruct(at: externalAccessLevel, prefix: qualifiedName) }
.filter { !$0.isEmpty }

let imageLets = groupedFunctions
.uniques
Expand Down
2 changes: 1 addition & 1 deletion Sources/RswiftCore/RswiftCore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public struct RswiftCore {
do {
let colorPaletteGenerator = ColorPaletteStructGenerator(palettes: resources.colors)
let colorPaletteGeneratorStruct = colorPaletteGenerator.generatedStructs(at: callInformation.accessLevel, prefix: "")
if colorPaletteGeneratorStruct.externalStruct.structs.count > 0 {
if !colorPaletteGeneratorStruct.externalStruct.isEmpty {
generators.append(colorPaletteGenerator)
}
}
Expand Down
7 changes: 7 additions & 0 deletions Sources/RswiftCore/SwiftTypes/Struct.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ struct Struct: UsedTypesProvider, SwiftCodeConverible {
var structs: [Struct]
var classes: [Class]

var isEmpty: Bool {
return properties.isEmpty
&& functions.isEmpty
&& (structs.isEmpty || structs.all { $0.isEmpty })
&& classes.isEmpty
}

var usedTypes: [UsedType] {
return [
type.usedTypes,
Expand Down
4 changes: 4 additions & 0 deletions Sources/RswiftCore/Util/UtilExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ extension Sequence {

return groupedBy
}

func all(where predicate: (Self.Element) throws -> Bool) rethrows -> Bool {
return !(try contains(where: { !(try predicate($0)) }))
}
}

extension Sequence where Iterator.Element : Sequence {
Expand Down

0 comments on commit 017907a

Please sign in to comment.