Specify explicitly when to generate platformName annotation.
This commit is contained in:
@@ -48,7 +48,7 @@ class GenericFunction(val signature: String, val keyword: String = "fun") : Comp
|
||||
val inlineFamilies = HashMap<Family, Boolean>()
|
||||
|
||||
val buildFamilies = LinkedHashSet(defaultFamilies.toList())
|
||||
private val buildPrimitives = LinkedHashSet(defaultPrimitives.toList())
|
||||
val buildPrimitives = LinkedHashSet(defaultPrimitives.toList())
|
||||
|
||||
var deprecate: String = ""
|
||||
val deprecates = hashMapOf<Family, String>()
|
||||
@@ -56,6 +56,9 @@ class GenericFunction(val signature: String, val keyword: String = "fun") : Comp
|
||||
var doc: String = ""
|
||||
val docs = HashMap<Family, String>()
|
||||
|
||||
var platformName: String? = null
|
||||
val platformNames = hashMapOf<PrimitiveType, String>()
|
||||
|
||||
var defaultBody: String = ""
|
||||
val bodies = HashMap<Family, String>()
|
||||
val customPrimitiveBodies = HashMap<Pair<Family, PrimitiveType>, String>()
|
||||
@@ -103,6 +106,15 @@ class GenericFunction(val signature: String, val keyword: String = "fun") : Comp
|
||||
}
|
||||
}
|
||||
|
||||
fun platformName(name: String, vararg primitives: PrimitiveType) {
|
||||
if (primitives.isEmpty())
|
||||
platformName = name
|
||||
else
|
||||
for (primitive in primitives) {
|
||||
platformNames[primitive] = name
|
||||
}
|
||||
}
|
||||
|
||||
fun returns(vararg families: Family, b: () -> String) {
|
||||
if (families.isEmpty())
|
||||
defaultReturnType = b()
|
||||
@@ -309,11 +321,6 @@ class GenericFunction(val signature: String, val keyword: String = "fun") : Comp
|
||||
}
|
||||
}
|
||||
|
||||
fun getPlatformName(primitive: PrimitiveType): String {
|
||||
val name = signature.substringBefore('(').trim()
|
||||
return "${name}Of${primitive.name}"
|
||||
}
|
||||
|
||||
val methodDoc = docs[f] ?: doc
|
||||
if (methodDoc != "") {
|
||||
builder.append("/**\n")
|
||||
@@ -330,9 +337,11 @@ class GenericFunction(val signature: String, val keyword: String = "fun") : Comp
|
||||
builder.append("deprecated(\"$deprecated\")\n")
|
||||
}
|
||||
|
||||
// heuristics to define that platform overloads are likely to clash
|
||||
if (!f.isPrimitiveSpecialization && primitive != null && ((returnType == returnType.renderType() && returnType != "T") || returnType == "SUM"))
|
||||
builder.append("platformName(\"${getPlatformName(primitive!!)}\")\n")
|
||||
if (!f.isPrimitiveSpecialization && primitive != null) {
|
||||
val platformName = (platformNames[primitive] ?: platformName) ?.let { it.replace("<T>", primitive.name)}
|
||||
if (platformName != null)
|
||||
builder.append("platformName(\"${platformName}\")\n")
|
||||
}
|
||||
|
||||
builder.append("public ")
|
||||
if (inlineFamilies[f] ?: defaultInline)
|
||||
|
||||
@@ -9,6 +9,7 @@ fun numeric(): List<GenericFunction> {
|
||||
exclude(Strings)
|
||||
doc { "Returns the sum of all elements in the collection." }
|
||||
returns("SUM")
|
||||
platformName("sumOf<T>")
|
||||
body {
|
||||
"""
|
||||
val iterator = iterator()
|
||||
@@ -25,6 +26,7 @@ fun numeric(): List<GenericFunction> {
|
||||
exclude(Strings)
|
||||
doc { "Returns an average value of elements in the collection"}
|
||||
returns("Double")
|
||||
platformName("averageOf<T>")
|
||||
body {
|
||||
"""
|
||||
val iterator = iterator()
|
||||
|
||||
Reference in New Issue
Block a user