rythm-swift.enum.txt Maven / Gradle / Ivy
@args com.linkedin.pegasus.generator.spec.EnumTemplateSpec enumeration
@import org.coursera.courier.swift.SwiftSyntax
@import org.coursera.courier.swift.SwiftDocEscaping
@import com.linkedin.data.DataMap
@maybePackageAndImports(enumeration)
@{ String className = SwiftSyntax.escapeKeyword(enumeration.getClassName()) }
@classAnnotations(enumeration.getSchema())
public enum @className: Equatable, Hashable {
@{Map symbolDocs = enumeration.getSchema().getSymbolDocs()}
@{Map props = enumeration.getSchema().getProperties()}
@{DataMap deprecatedSymbols = (DataMap)props.get("deprecatedSymbols")}
@for(String symbol: enumeration.getSchema().getSymbols()) {
@{String symbolDoc = symbolDocs.get(symbol)}
@if(symbolDoc != null) {
@SwiftDocEscaping.stringToDocComment(symbolDoc)
}
@if(deprecatedSymbols != null) {
@SwiftDocEscaping.deprecatedToString(deprecatedSymbols.get(symbol))
}
case @SwiftSyntax.escapeKeyword(symbol)
}
case UNKNOWN$(String)
private struct Strings {
@for(String symbol: enumeration.getSchema().getSymbols()) {
static let @(SwiftSyntax.escapeKeyword(symbol)) = "@(SwiftSyntax.escapeKeyword(symbol))"
}
}
public static func read(symbol: String) -> @className {
switch symbol {
@for(String symbol: enumeration.getSchema().getSymbols()) {
case @(className).Strings.@(SwiftSyntax.escapeKeyword(symbol)):
return .@(SwiftSyntax.escapeKeyword(symbol))
}
default:
return .UNKNOWN$(symbol)
}
}
public func write() -> String {
switch self {
@for(String symbol: enumeration.getSchema().getSymbols()) {
case .@(SwiftSyntax.escapeKeyword(symbol)):
return @(className).Strings.@(SwiftSyntax.escapeKeyword(symbol))
}
case .UNKNOWN$(let symbol):
return symbol
}
}
public var hashValue: Int {
return write().hashValue
}
}
public func ==(lhs: @className, rhs: @className) -> Bool {
switch (lhs, rhs) {
@if(enumeration.getSchema().getSymbols().size() > 0) {
case @for(String symbol: enumeration.getSchema().getSymbols()).join(", ") {(.@(SwiftSyntax.escapeKeyword(symbol)), .@(SwiftSyntax.escapeKeyword(symbol)))}:
return true
}
case (let .UNKNOWN$(lhs), let .UNKNOWN$(rhs)):
return lhs == rhs
@if(enumeration.getSchema().getSymbols().size() > 0) {
default:
return false
}
}
}