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