Unify componentN templates and add NOTHING_TO_INLINE suppression.

This commit is contained in:
Ilya Gorbunov
2015-07-02 20:56:10 +03:00
parent 9618a3542f
commit f7436064d0
2 changed files with 65 additions and 34 deletions
@@ -704,40 +704,21 @@ fun elements(): List<GenericFunction> {
}
}
templates add f("component1()") {
inline(true)
doc { "Returns 1st *element* from the collection." }
returns("T")
body { "return get(0)" }
only(Lists, ArraysOfObjects, ArraysOfPrimitives)
}
templates add f("component2()") {
inline(true)
doc { "Returns 2nd *element* from the collection." }
returns("T")
body { "return get(1)" }
only(Lists, ArraysOfObjects, ArraysOfPrimitives)
}
templates add f("component3()") {
inline(true)
doc { "Returns 3rd *element* from the collection." }
returns("T")
body { "return get(2)" }
only(Lists, ArraysOfObjects, ArraysOfPrimitives)
}
templates add f("component4()") {
inline(true)
doc { "Returns 4th *element* from the collection." }
returns("T")
body { "return get(3)" }
only(Lists, ArraysOfObjects, ArraysOfPrimitives)
}
templates add f("component5()") {
inline(true)
doc { "Returns 5th *element* from the collection." }
returns("T")
body { "return get(4)" }
only(Lists, ArraysOfObjects, ArraysOfPrimitives)
templates addAll (1..5).map { n ->
f("component$n()") {
inline(true)
annotations("""suppress("NOTHING_TO_INLINE")""")
fun getOrdinal(n: Int) = n.toString() + when (n) {
1 -> "st"
2 -> "nd"
3 -> "rd"
else -> "th"
}
doc { "Returns ${getOrdinal(n)} *element* from the collection." }
returns("T")
body { "return get(${n-1})" }
only(Lists, ArraysOfObjects, ArraysOfPrimitives)
}
}
return templates