Fix formatting in Engine and templates
This commit is contained in:
committed by
Andrey Breslav
parent
f14ca2cf89
commit
89c1260627
@@ -5,12 +5,12 @@ import templates.Family.*
|
||||
import templates.*
|
||||
import templates.PrimitiveType.*
|
||||
|
||||
fun generateCollectionsAPI(outDir : File) {
|
||||
fun generateCollectionsAPI(outDir: File) {
|
||||
elements().writeTo(File(outDir, "_Elements.kt")) { build() }
|
||||
filtering().writeTo(File(outDir, "_Filtering.kt")) { build() }
|
||||
ordering().writeTo(File(outDir, "_Ordering.kt")) { build() }
|
||||
arrays().writeTo(File(outDir, "_Arrays.kt")) { build() }
|
||||
snapshots().writeTo(File(outDir, "_Snapshots.kt")) { build() }
|
||||
snapshots().writeTo(File(outDir, "_Snapshots.kt")) { build() }
|
||||
mapping().writeTo(File(outDir, "_Mapping.kt")) { build() }
|
||||
aggregates().writeTo(File(outDir, "_Aggregates.kt")) { build() }
|
||||
guards().writeTo(File(outDir, "_Guards.kt")) { build() }
|
||||
@@ -22,11 +22,11 @@ fun generateCollectionsAPI(outDir : File) {
|
||||
numeric().writeTo(File(outDir, "_Numeric.kt")) {
|
||||
val builder = StringBuilder()
|
||||
// TODO: decide if sum for byte and short is needed and how to make it work
|
||||
for(numeric in listOf(Int, Long, /*Byte, Short, */ Double, Float)) {
|
||||
for (numeric in listOf(Int, Long, /*Byte, Short, */ Double, Float)) {
|
||||
build(builder, Iterables, numeric)
|
||||
}
|
||||
|
||||
for(numeric in listOf(Int, Long, Byte, Short, Double, Float)) {
|
||||
for (numeric in listOf(Int, Long, Byte, Short, Double, Float)) {
|
||||
build(builder, ArraysOfObjects, numeric)
|
||||
build(builder, ArraysOfPrimitives, numeric)
|
||||
}
|
||||
|
||||
@@ -104,7 +104,7 @@ fun aggregates(): List<GenericFunction> {
|
||||
doc { "Returns the smallest element or null if there are no elements" }
|
||||
returns("T?")
|
||||
exclude(PrimitiveType.Boolean)
|
||||
typeParam("T: Comparable<T>")
|
||||
typeParam("T : Comparable<T>")
|
||||
body {
|
||||
"""
|
||||
val iterator = iterator()
|
||||
@@ -135,8 +135,8 @@ fun aggregates(): List<GenericFunction> {
|
||||
inline(true)
|
||||
|
||||
doc { "Returns the first element yielding the smallest value of the given function or null if there are no elements" }
|
||||
typeParam("R: Comparable<R>")
|
||||
typeParam("T: Any")
|
||||
typeParam("R : Comparable<R>")
|
||||
typeParam("T : Any")
|
||||
returns("T?")
|
||||
body {
|
||||
"""
|
||||
@@ -149,8 +149,8 @@ fun aggregates(): List<GenericFunction> {
|
||||
val e = iterator.next()
|
||||
val v = f(e)
|
||||
if (minValue > v) {
|
||||
minElem = e
|
||||
minValue = v
|
||||
minElem = e
|
||||
minValue = v
|
||||
}
|
||||
}
|
||||
return minElem
|
||||
@@ -166,8 +166,8 @@ fun aggregates(): List<GenericFunction> {
|
||||
val e = this[i]
|
||||
val v = f(e)
|
||||
if (minValue > v) {
|
||||
minElem = e
|
||||
minValue = v
|
||||
minElem = e
|
||||
minValue = v
|
||||
}
|
||||
}
|
||||
return minElem
|
||||
@@ -180,7 +180,7 @@ fun aggregates(): List<GenericFunction> {
|
||||
|
||||
only(Maps)
|
||||
doc { "Returns the first element yielding the smallest value of the given function or null if there are no elements" }
|
||||
typeParam("R: Comparable<R>")
|
||||
typeParam("R : Comparable<R>")
|
||||
returns("T?")
|
||||
body {
|
||||
"""
|
||||
@@ -193,8 +193,8 @@ fun aggregates(): List<GenericFunction> {
|
||||
val e = iterator.next()
|
||||
val v = f(e)
|
||||
if (minValue > v) {
|
||||
minElem = e
|
||||
minValue = v
|
||||
minElem = e
|
||||
minValue = v
|
||||
}
|
||||
}
|
||||
return minElem
|
||||
@@ -206,7 +206,7 @@ fun aggregates(): List<GenericFunction> {
|
||||
doc { "Returns the largest element or null if there are no elements" }
|
||||
returns("T?")
|
||||
exclude(PrimitiveType.Boolean)
|
||||
typeParam("T: Comparable<T>")
|
||||
typeParam("T : Comparable<T>")
|
||||
body {
|
||||
"""
|
||||
val iterator = iterator()
|
||||
@@ -239,8 +239,8 @@ fun aggregates(): List<GenericFunction> {
|
||||
inline(true)
|
||||
|
||||
doc { "Returns the first element yielding the largest value of the given function or null if there are no elements" }
|
||||
typeParam("R: Comparable<R>")
|
||||
typeParam("T: Any")
|
||||
typeParam("R : Comparable<R>")
|
||||
typeParam("T : Any")
|
||||
returns("T?")
|
||||
body {
|
||||
"""
|
||||
@@ -253,8 +253,8 @@ fun aggregates(): List<GenericFunction> {
|
||||
val e = iterator.next()
|
||||
val v = f(e)
|
||||
if (maxValue < v) {
|
||||
maxElem = e
|
||||
maxValue = v
|
||||
maxElem = e
|
||||
maxValue = v
|
||||
}
|
||||
}
|
||||
return maxElem
|
||||
@@ -270,8 +270,8 @@ fun aggregates(): List<GenericFunction> {
|
||||
val e = this[i]
|
||||
val v = f(e)
|
||||
if (maxValue < v) {
|
||||
maxElem = e
|
||||
maxValue = v
|
||||
maxElem = e
|
||||
maxValue = v
|
||||
}
|
||||
}
|
||||
return maxElem
|
||||
@@ -284,7 +284,7 @@ fun aggregates(): List<GenericFunction> {
|
||||
|
||||
only(Maps)
|
||||
doc { "Returns the first element yielding the largest value of the given function or null if there are no elements" }
|
||||
typeParam("R: Comparable<R>")
|
||||
typeParam("R : Comparable<R>")
|
||||
returns("T?")
|
||||
body {
|
||||
"""
|
||||
@@ -297,8 +297,8 @@ fun aggregates(): List<GenericFunction> {
|
||||
val e = iterator.next()
|
||||
val v = f(e)
|
||||
if (maxValue < v) {
|
||||
maxElem = e
|
||||
maxValue = v
|
||||
maxElem = e
|
||||
maxValue = v
|
||||
}
|
||||
}
|
||||
return maxElem
|
||||
|
||||
@@ -116,7 +116,7 @@ fun elements(): List<GenericFunction> {
|
||||
}
|
||||
}
|
||||
|
||||
templates add f("elementAt(index : Int)") {
|
||||
templates add f("elementAt(index: Int)") {
|
||||
doc { "Returns element at given *index*" }
|
||||
returns("T")
|
||||
body {
|
||||
@@ -241,10 +241,12 @@ fun elements(): List<GenericFunction> {
|
||||
body {
|
||||
"""
|
||||
when (this) {
|
||||
is List<*> -> if (size == 0)
|
||||
is List<*> -> {
|
||||
if (size == 0)
|
||||
throw IllegalArgumentException("Collection is empty")
|
||||
else
|
||||
return this[size - 1] as T
|
||||
}
|
||||
else -> {
|
||||
val iterator = iterator()
|
||||
if (!iterator.hasNext())
|
||||
|
||||
@@ -91,7 +91,7 @@ class GenericFunction(val signature: String) : Comparable<GenericFunction> {
|
||||
typeParams.add(t)
|
||||
}
|
||||
|
||||
fun inline(value : Boolean, vararg families: Family) {
|
||||
fun inline(value: Boolean, vararg families: Family) {
|
||||
if (families.isEmpty())
|
||||
defaultInline = value
|
||||
else
|
||||
@@ -148,7 +148,7 @@ class GenericFunction(val signature: String) : Comparable<GenericFunction> {
|
||||
Iterables -> "Iterable<T>"
|
||||
Collections -> "Collection<T>"
|
||||
Lists -> "List<T>"
|
||||
Maps -> "Map<K,V>"
|
||||
Maps -> "Map<K, V>"
|
||||
Streams -> "Stream<T>"
|
||||
ArraysOfObjects -> "Array<T>"
|
||||
Strings -> "String"
|
||||
@@ -186,7 +186,7 @@ class GenericFunction(val signature: String) : Comparable<GenericFunction> {
|
||||
"T" -> {
|
||||
when (f) {
|
||||
Strings -> "Char"
|
||||
Maps -> "Map.Entry<K,V>"
|
||||
Maps -> "Map.Entry<K, V>"
|
||||
else -> primitive?.name() ?: token
|
||||
}
|
||||
}
|
||||
@@ -200,7 +200,7 @@ class GenericFunction(val signature: String) : Comparable<GenericFunction> {
|
||||
fun effectiveTypeParams(): List<String> {
|
||||
val types = ArrayList(typeParams)
|
||||
if (primitive == null && f != Strings) {
|
||||
val implicitTypeParameters = receiver.dropWhile { it != '<' }.drop(1).takeWhile { it != '>' }.split(",")
|
||||
val implicitTypeParameters = receiver.dropWhile { it != '<' }.drop(1).filterNot { it == ' ' }.takeWhile { it != '>' }.split(",")
|
||||
for (implicit in implicitTypeParameters.reverse()) {
|
||||
if (!types.any { it.startsWith(implicit) }) {
|
||||
types.add(0, implicit)
|
||||
@@ -249,18 +249,21 @@ class GenericFunction(val signature: String) : Comparable<GenericFunction> {
|
||||
|
||||
|
||||
builder.append(receiverType)
|
||||
builder.append(".${signature.renderType()} : ${returnType.renderType()} {")
|
||||
builder.append(".${signature.renderType()}: ${returnType.renderType()} {")
|
||||
|
||||
val body = (bodies[f] ?: defaultBody).trim("\n")
|
||||
val prefix: Int = body.takeWhile { it == ' ' }.length
|
||||
val indent: Int = body.takeWhile { it == ' ' }.length
|
||||
|
||||
builder.append('\n')
|
||||
StringReader(body).forEachLine {
|
||||
builder.append('\n')
|
||||
var count = prefix
|
||||
builder.append(" ").append(it.dropWhile { count-- > 0 && it == ' ' } .renderType())
|
||||
var count = indent
|
||||
val line = it.dropWhile { count-- > 0 && it == ' ' } .renderType()
|
||||
if (line.isNotEmpty()) {
|
||||
builder.append(" ").append(line)
|
||||
builder.append("\n")
|
||||
}
|
||||
}
|
||||
|
||||
builder.append("\n}\n\n")
|
||||
builder.append("}\n\n")
|
||||
}
|
||||
|
||||
public override fun compareTo(other: GenericFunction): Int = this.signature.compareTo(other.signature)
|
||||
|
||||
@@ -29,7 +29,7 @@ fun filtering(): List<GenericFunction> {
|
||||
}
|
||||
|
||||
body(Strings) { "return substring(Math.min(n, size))" }
|
||||
returns(Strings) { "String"}
|
||||
returns(Strings) { "String" }
|
||||
|
||||
body(Collections, ArraysOfObjects, ArraysOfPrimitives) {
|
||||
"""
|
||||
@@ -63,7 +63,7 @@ fun filtering(): List<GenericFunction> {
|
||||
}
|
||||
|
||||
body(Strings) { "return substring(0, Math.min(n, size))" }
|
||||
returns(Strings) { "String"}
|
||||
returns(Strings) { "String" }
|
||||
|
||||
doc(Streams) { "Returns a stream containing first *n* elements" }
|
||||
returns(Streams) { "Stream<T>" }
|
||||
@@ -90,7 +90,7 @@ fun filtering(): List<GenericFunction> {
|
||||
}
|
||||
}
|
||||
|
||||
templates add f("dropWhile(predicate: (T)->Boolean)") {
|
||||
templates add f("dropWhile(predicate: (T) -> Boolean)") {
|
||||
inline(true)
|
||||
|
||||
doc { "Returns a list containing all elements except first elements that satisfy the given *predicate*" }
|
||||
@@ -102,7 +102,7 @@ fun filtering(): List<GenericFunction> {
|
||||
for (item in this)
|
||||
if (yielding)
|
||||
list.add(item)
|
||||
else if(!predicate(item)) {
|
||||
else if (!predicate(item)) {
|
||||
list.add(item)
|
||||
yielding = true
|
||||
}
|
||||
@@ -110,7 +110,7 @@ fun filtering(): List<GenericFunction> {
|
||||
"""
|
||||
}
|
||||
|
||||
returns(Strings) { "String"}
|
||||
returns(Strings) { "String" }
|
||||
body(Strings) {
|
||||
"""
|
||||
for (index in 0..length)
|
||||
@@ -128,20 +128,20 @@ fun filtering(): List<GenericFunction> {
|
||||
"""
|
||||
var yielding = false
|
||||
return FilteringStream(this) {
|
||||
if (yielding)
|
||||
true
|
||||
else if (!predicate(it)) {
|
||||
yielding = true
|
||||
true
|
||||
} else
|
||||
false
|
||||
}
|
||||
if (yielding)
|
||||
true
|
||||
else if (!predicate(it)) {
|
||||
yielding = true
|
||||
true
|
||||
} else
|
||||
false
|
||||
}
|
||||
"""
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
templates add f("takeWhile(predicate: (T)->Boolean)") {
|
||||
templates add f("takeWhile(predicate: (T) -> Boolean)") {
|
||||
inline(true)
|
||||
|
||||
doc { "Returns a list containing first elements satisfying the given *predicate*" }
|
||||
@@ -150,15 +150,15 @@ fun filtering(): List<GenericFunction> {
|
||||
"""
|
||||
val list = ArrayList<T>()
|
||||
for (item in this) {
|
||||
if(!predicate(item))
|
||||
if (!predicate(item))
|
||||
break;
|
||||
list.add(item)
|
||||
list.add(item)
|
||||
}
|
||||
return list
|
||||
"""
|
||||
}
|
||||
|
||||
returns(Strings) { "String"}
|
||||
returns(Strings) { "String" }
|
||||
body(Strings) {
|
||||
"""
|
||||
for (index in 0..length)
|
||||
@@ -179,7 +179,7 @@ fun filtering(): List<GenericFunction> {
|
||||
}
|
||||
}
|
||||
|
||||
templates add f("filter(predicate: (T)->Boolean)") {
|
||||
templates add f("filter(predicate: (T) -> Boolean)") {
|
||||
inline(true)
|
||||
|
||||
doc { "Returns a list containing all elements matching the given *predicate*" }
|
||||
@@ -190,7 +190,7 @@ fun filtering(): List<GenericFunction> {
|
||||
"""
|
||||
}
|
||||
|
||||
returns(Strings) { "String"}
|
||||
returns(Strings) { "String" }
|
||||
body(Strings) {
|
||||
"""
|
||||
return filterTo(StringBuilder(), predicate).toString()
|
||||
@@ -212,7 +212,7 @@ fun filtering(): List<GenericFunction> {
|
||||
inline(true)
|
||||
|
||||
doc { "Appends all elements matching the given *predicate* into the given *collection*" }
|
||||
typeParam("C: TCollection")
|
||||
typeParam("C : TCollection")
|
||||
returns("C")
|
||||
|
||||
body {
|
||||
@@ -236,7 +236,7 @@ fun filtering(): List<GenericFunction> {
|
||||
include(Maps)
|
||||
}
|
||||
|
||||
templates add f("filterNot(predicate: (T)->Boolean)") {
|
||||
templates add f("filterNot(predicate: (T) -> Boolean)") {
|
||||
inline(true)
|
||||
|
||||
doc { "Returns a list containing all elements not matching the given *predicate*" }
|
||||
@@ -247,7 +247,7 @@ fun filtering(): List<GenericFunction> {
|
||||
"""
|
||||
}
|
||||
|
||||
returns(Strings) { "String"}
|
||||
returns(Strings) { "String" }
|
||||
body(Strings) {
|
||||
"""
|
||||
return filterNotTo(StringBuilder(), predicate).toString()
|
||||
@@ -269,7 +269,7 @@ fun filtering(): List<GenericFunction> {
|
||||
inline(true)
|
||||
|
||||
doc { "Appends all elements not matching the given *predicate* to the given *collection*" }
|
||||
typeParam("C: TCollection")
|
||||
typeParam("C : TCollection")
|
||||
returns("C")
|
||||
|
||||
body {
|
||||
@@ -292,7 +292,7 @@ fun filtering(): List<GenericFunction> {
|
||||
templates add f("filterNotNull()") {
|
||||
exclude(ArraysOfPrimitives, Strings)
|
||||
doc { "Returns a list containing all elements that are not null" }
|
||||
typeParam("T: Any")
|
||||
typeParam("T : Any")
|
||||
returns("List<T>")
|
||||
toNullableT = true
|
||||
body {
|
||||
@@ -314,8 +314,8 @@ fun filtering(): List<GenericFunction> {
|
||||
exclude(ArraysOfPrimitives, Strings)
|
||||
doc { "Appends all elements that are not null to the given *collection*" }
|
||||
returns("C")
|
||||
typeParam("C: TCollection")
|
||||
typeParam("T: Any")
|
||||
typeParam("C : TCollection")
|
||||
typeParam("T : Any")
|
||||
toNullableT = true
|
||||
body {
|
||||
"""
|
||||
|
||||
@@ -11,9 +11,9 @@ fun generators(): List<GenericFunction> {
|
||||
returns("List<T>")
|
||||
body {
|
||||
"""
|
||||
val answer = toArrayList()
|
||||
answer.add(element)
|
||||
return answer
|
||||
val answer = toArrayList()
|
||||
answer.add(element)
|
||||
return answer
|
||||
"""
|
||||
}
|
||||
|
||||
@@ -32,9 +32,9 @@ fun generators(): List<GenericFunction> {
|
||||
returns("List<T>")
|
||||
body {
|
||||
"""
|
||||
val answer = toArrayList()
|
||||
answer.addAll(collection)
|
||||
return answer
|
||||
val answer = toArrayList()
|
||||
answer.addAll(collection)
|
||||
return answer
|
||||
"""
|
||||
}
|
||||
}
|
||||
@@ -45,9 +45,9 @@ fun generators(): List<GenericFunction> {
|
||||
returns("List<T>")
|
||||
body {
|
||||
"""
|
||||
val answer = toArrayList()
|
||||
answer.addAll(array)
|
||||
return answer
|
||||
val answer = toArrayList()
|
||||
answer.addAll(array)
|
||||
return answer
|
||||
"""
|
||||
}
|
||||
}
|
||||
@@ -88,32 +88,32 @@ fun generators(): List<GenericFunction> {
|
||||
returns("Pair<List<T>, List<T>>")
|
||||
body {
|
||||
"""
|
||||
val first = ArrayList<T>()
|
||||
val second = ArrayList<T>()
|
||||
for (element in this) {
|
||||
if (predicate(element)) {
|
||||
first.add(element)
|
||||
} else {
|
||||
second.add(element)
|
||||
}
|
||||
val first = ArrayList<T>()
|
||||
val second = ArrayList<T>()
|
||||
for (element in this) {
|
||||
if (predicate(element)) {
|
||||
first.add(element)
|
||||
} else {
|
||||
second.add(element)
|
||||
}
|
||||
return Pair(first, second)
|
||||
}
|
||||
return Pair(first, second)
|
||||
"""
|
||||
}
|
||||
|
||||
returns(Strings) { "Pair<String, String>" }
|
||||
body(Strings) {
|
||||
"""
|
||||
val first = StringBuilder()
|
||||
val second = StringBuilder()
|
||||
for (element in this) {
|
||||
if (predicate(element)) {
|
||||
first.append(element)
|
||||
} else {
|
||||
second.append(element)
|
||||
}
|
||||
val first = StringBuilder()
|
||||
val second = StringBuilder()
|
||||
for (element in this) {
|
||||
if (predicate(element)) {
|
||||
first.append(element)
|
||||
} else {
|
||||
second.append(element)
|
||||
}
|
||||
return Pair(first.toString(), second.toString())
|
||||
}
|
||||
return Pair(first.toString(), second.toString())
|
||||
"""
|
||||
}
|
||||
}
|
||||
@@ -126,37 +126,37 @@ fun generators(): List<GenericFunction> {
|
||||
"""
|
||||
}
|
||||
typeParam("R")
|
||||
returns("List<Pair<T,R>>")
|
||||
returns("List<Pair<T, R>>")
|
||||
body {
|
||||
"""
|
||||
val first = iterator()
|
||||
val second = other.iterator()
|
||||
val list = ArrayList<Pair<T,R>>()
|
||||
while (first.hasNext() && second.hasNext()) {
|
||||
list.add(first.next() to second.next())
|
||||
}
|
||||
return list
|
||||
val first = iterator()
|
||||
val second = other.iterator()
|
||||
val list = ArrayList<Pair<T, R>>()
|
||||
while (first.hasNext() && second.hasNext()) {
|
||||
list.add(first.next() to second.next())
|
||||
}
|
||||
return list
|
||||
"""
|
||||
}
|
||||
}
|
||||
|
||||
templates add f("zip(other : String)") {
|
||||
templates add f("zip(other: String)") {
|
||||
only(Strings)
|
||||
doc {
|
||||
"""
|
||||
Returns a list of pairs built from characters of both strings with same indexes. List has length of shortest collection.
|
||||
"""
|
||||
}
|
||||
returns("List<Pair<Char,Char>>")
|
||||
returns("List<Pair<Char, Char>>")
|
||||
body {
|
||||
"""
|
||||
val first = iterator()
|
||||
val second = other.iterator()
|
||||
val list = ArrayList<Pair<Char,Char>>()
|
||||
while (first.hasNext() && second.hasNext()) {
|
||||
list.add(first.next() to second.next())
|
||||
}
|
||||
return list
|
||||
val first = iterator()
|
||||
val second = other.iterator()
|
||||
val list = ArrayList<Pair<Char, Char>>()
|
||||
while (first.hasNext() && second.hasNext()) {
|
||||
list.add(first.next() to second.next())
|
||||
}
|
||||
return list
|
||||
"""
|
||||
}
|
||||
}
|
||||
@@ -169,16 +169,16 @@ fun generators(): List<GenericFunction> {
|
||||
"""
|
||||
}
|
||||
typeParam("R")
|
||||
returns("List<Pair<T,R>>")
|
||||
returns("List<Pair<T, R>>")
|
||||
body {
|
||||
"""
|
||||
val first = iterator()
|
||||
val second = array.iterator()
|
||||
val list = ArrayList<Pair<T,R>>()
|
||||
while (first.hasNext() && second.hasNext()) {
|
||||
list.add(first.next() to second.next())
|
||||
}
|
||||
return list
|
||||
val first = iterator()
|
||||
val second = array.iterator()
|
||||
val list = ArrayList<Pair<T, R>>()
|
||||
while (first.hasNext() && second.hasNext()) {
|
||||
list.add(first.next() to second.next())
|
||||
}
|
||||
return list
|
||||
"""
|
||||
}
|
||||
}
|
||||
@@ -191,10 +191,10 @@ fun generators(): List<GenericFunction> {
|
||||
"""
|
||||
}
|
||||
typeParam("R")
|
||||
returns("Stream<Pair<T,R>>")
|
||||
returns("Stream<Pair<T, R>>")
|
||||
body {
|
||||
"""
|
||||
return ZippingStream(this, stream)
|
||||
return ZippingStream(this, stream)
|
||||
"""
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ fun guards(): List<GenericFunction> {
|
||||
include(Lists)
|
||||
exclude(Strings, ArraysOfPrimitives)
|
||||
doc { "Returns an original collection containing all the non-*null* elements, throwing an [[IllegalArgumentException]] if there are any null elements" }
|
||||
typeParam("T:Any")
|
||||
typeParam("T : Any")
|
||||
toNullableT = true
|
||||
returns("SELF")
|
||||
body {
|
||||
|
||||
@@ -25,7 +25,7 @@ fun mapping(): List<GenericFunction> {
|
||||
}
|
||||
}
|
||||
|
||||
templates add f("map(transform : (T) -> R)") {
|
||||
templates add f("map(transform: (T) -> R)") {
|
||||
inline(true)
|
||||
|
||||
doc { "Returns a list containing the results of applying the given *transform* function to each element of the original collection" }
|
||||
@@ -39,16 +39,16 @@ fun mapping(): List<GenericFunction> {
|
||||
returns(Streams) { "Stream<R>" }
|
||||
doc(Streams) { "Returns a stream containing the results of applying the given *transform* function to each element of the original stream" }
|
||||
body(Streams) {
|
||||
"return TransformingStream(this, transform) "
|
||||
"return TransformingStream(this, transform)"
|
||||
}
|
||||
include(Maps)
|
||||
}
|
||||
|
||||
templates add f("mapNotNull(transform : (T) -> R)") {
|
||||
templates add f("mapNotNull(transform: (T) -> R)") {
|
||||
inline(true)
|
||||
exclude(Strings, ArraysOfPrimitives)
|
||||
doc { "Returns a list containing the results of applying the given *transform* function to each non-null element of the original collection" }
|
||||
typeParam("T: Any")
|
||||
typeParam("T : Any")
|
||||
typeParam("R")
|
||||
returns("List<R>")
|
||||
toNullableT = true
|
||||
@@ -68,7 +68,7 @@ fun mapping(): List<GenericFunction> {
|
||||
}
|
||||
}
|
||||
|
||||
templates add f("mapTo(collection: C, transform : (T) -> R)") {
|
||||
templates add f("mapTo(collection: C, transform: (T) -> R)") {
|
||||
inline(true)
|
||||
|
||||
doc {
|
||||
@@ -78,7 +78,7 @@ fun mapping(): List<GenericFunction> {
|
||||
"""
|
||||
}
|
||||
typeParam("R")
|
||||
typeParam("C: MutableCollection<in R>")
|
||||
typeParam("C : MutableCollection<in R>")
|
||||
returns("C")
|
||||
|
||||
body {
|
||||
@@ -91,7 +91,7 @@ fun mapping(): List<GenericFunction> {
|
||||
include(Maps)
|
||||
}
|
||||
|
||||
templates add f("mapNotNullTo(collection: C, transform : (T) -> R)") {
|
||||
templates add f("mapNotNullTo(collection: C, transform: (T) -> R)") {
|
||||
inline(true)
|
||||
exclude(Strings, ArraysOfPrimitives)
|
||||
doc {
|
||||
@@ -100,9 +100,9 @@ fun mapping(): List<GenericFunction> {
|
||||
to the given *collection*
|
||||
"""
|
||||
}
|
||||
typeParam("T: Any")
|
||||
typeParam("T : Any")
|
||||
typeParam("R")
|
||||
typeParam("C: MutableCollection<in R>")
|
||||
typeParam("C : MutableCollection<in R>")
|
||||
returns("C")
|
||||
toNullableT = true
|
||||
body {
|
||||
@@ -110,14 +110,14 @@ fun mapping(): List<GenericFunction> {
|
||||
for (element in this) {
|
||||
if (element != null) {
|
||||
collection.add(transform(element))
|
||||
}
|
||||
}
|
||||
}
|
||||
return collection
|
||||
"""
|
||||
}
|
||||
}
|
||||
|
||||
templates add f("flatMap(transform: (T)-> Iterable<R>)") {
|
||||
templates add f("flatMap(transform: (T) -> Iterable<R>)") {
|
||||
inline(true)
|
||||
|
||||
exclude(Streams)
|
||||
@@ -130,7 +130,7 @@ fun mapping(): List<GenericFunction> {
|
||||
include(Maps)
|
||||
}
|
||||
|
||||
templates add f("flatMap(transform: (T)-> Stream<R>)") {
|
||||
templates add f("flatMap(transform: (T) -> Stream<R>)") {
|
||||
only(Streams)
|
||||
doc { "Returns a single stream of all elements streamed from results of *transform* function being invoked on each element of original stream" }
|
||||
typeParam("R")
|
||||
@@ -145,7 +145,7 @@ fun mapping(): List<GenericFunction> {
|
||||
exclude(Streams)
|
||||
doc { "Appends all elements yielded from results of *transform* function being invoked on each element of original collection, to the given *collection*" }
|
||||
typeParam("R")
|
||||
typeParam("C: MutableCollection<in R>")
|
||||
typeParam("C : MutableCollection<in R>")
|
||||
returns("C")
|
||||
body {
|
||||
"""
|
||||
@@ -165,7 +165,7 @@ fun mapping(): List<GenericFunction> {
|
||||
only(Streams)
|
||||
doc { "Appends all elements yielded from results of *transform* function being invoked on each element of original stream, to the given *collection*" }
|
||||
typeParam("R")
|
||||
typeParam("C: MutableCollection<in R>")
|
||||
typeParam("C : MutableCollection<in R>")
|
||||
returns("C")
|
||||
body {
|
||||
"""
|
||||
|
||||
@@ -10,12 +10,12 @@ fun numeric(): List<GenericFunction> {
|
||||
returns("SUM")
|
||||
body {
|
||||
"""
|
||||
val iterator = iterator()
|
||||
var sum : SUM = ZERO
|
||||
while (iterator.hasNext()) {
|
||||
sum += iterator.next()
|
||||
}
|
||||
return sum
|
||||
val iterator = iterator()
|
||||
var sum: SUM = ZERO
|
||||
while (iterator.hasNext()) {
|
||||
sum += iterator.next()
|
||||
}
|
||||
return sum
|
||||
"""
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ fun ordering(): List<GenericFunction> {
|
||||
}
|
||||
|
||||
doc(Strings) { "Returns a string with characters in reversed order" }
|
||||
returns(Strings) { "String"}
|
||||
returns(Strings) { "String" }
|
||||
body(Strings) {
|
||||
// TODO: Replace with StringBuilder(this) when JS can handle it
|
||||
"""
|
||||
@@ -35,7 +35,7 @@ fun ordering(): List<GenericFunction> {
|
||||
"""
|
||||
}
|
||||
returns("List<T>")
|
||||
typeParam("T: Comparable<T>")
|
||||
typeParam("T : Comparable<T>")
|
||||
body {
|
||||
"""
|
||||
val sortedList = toArrayList()
|
||||
@@ -57,11 +57,11 @@ fun ordering(): List<GenericFunction> {
|
||||
"""
|
||||
}
|
||||
returns("List<T>")
|
||||
typeParam("T: Comparable<T>")
|
||||
typeParam("T : Comparable<T>")
|
||||
body {
|
||||
"""
|
||||
val sortedList = toArrayList()
|
||||
val sortBy: Comparator<T> = comparator<T> {(x: T, y: T) -> -x.compareTo(y)}
|
||||
val sortBy: Comparator<T> = comparator<T> {(x: T, y: T) -> -x.compareTo(y) }
|
||||
java.util.Collections.sort(sortedList, sortBy)
|
||||
return sortedList
|
||||
"""
|
||||
@@ -82,11 +82,11 @@ fun ordering(): List<GenericFunction> {
|
||||
"""
|
||||
}
|
||||
returns("List<T>")
|
||||
typeParam("R: Comparable<R>")
|
||||
typeParam("R : Comparable<R>")
|
||||
body {
|
||||
"""
|
||||
val sortedList = toArrayList()
|
||||
val sortBy: Comparator<T> = comparator<T> {(x: T, y: T) -> order(x).compareTo(order(y))}
|
||||
val sortBy: Comparator<T> = comparator<T> {(x: T, y: T) -> order(x).compareTo(order(y)) }
|
||||
java.util.Collections.sort(sortedList, sortBy)
|
||||
return sortedList
|
||||
"""
|
||||
@@ -106,11 +106,11 @@ fun ordering(): List<GenericFunction> {
|
||||
"""
|
||||
}
|
||||
returns("List<T>")
|
||||
typeParam("R: Comparable<R>")
|
||||
typeParam("R : Comparable<R>")
|
||||
body {
|
||||
"""
|
||||
val sortedList = toArrayList()
|
||||
val sortBy: Comparator<T> = comparator<T> {(x: T, y: T) -> -order(x).compareTo(order(y))}
|
||||
val sortBy: Comparator<T> = comparator<T> {(x: T, y: T) -> -order(x).compareTo(order(y)) }
|
||||
java.util.Collections.sort(sortedList, sortBy)
|
||||
return sortedList
|
||||
"""
|
||||
@@ -121,7 +121,7 @@ fun ordering(): List<GenericFunction> {
|
||||
exclude(Strings)
|
||||
}
|
||||
|
||||
templates add f("sortBy(comparator : Comparator<T>)") {
|
||||
templates add f("sortBy(comparator: Comparator<T>)") {
|
||||
doc {
|
||||
"""
|
||||
Returns a list of all elements, sorted by the specified *comparator*
|
||||
|
||||
@@ -5,7 +5,7 @@ import templates.Family.*
|
||||
fun snapshots(): List<GenericFunction> {
|
||||
val templates = arrayListOf<GenericFunction>()
|
||||
|
||||
templates add f("toCollection(collection : C)") {
|
||||
templates add f("toCollection(collection: C)") {
|
||||
doc { "Appends all elements to the given *collection*" }
|
||||
returns("C")
|
||||
typeParam("C : MutableCollection<in T>")
|
||||
@@ -94,7 +94,7 @@ fun snapshots(): List<GenericFunction> {
|
||||
|
||||
templates add f("toSortedList()") {
|
||||
doc { "Returns a sorted list of all elements" }
|
||||
typeParam("T: Comparable<T>")
|
||||
typeParam("T : Comparable<T>")
|
||||
returns("List<T>")
|
||||
body { "return toArrayList().sort()" }
|
||||
body(Iterables) { "return sort()" }
|
||||
|
||||
@@ -63,7 +63,7 @@ fun specialJVM(): List<GenericFunction> {
|
||||
}
|
||||
}
|
||||
|
||||
templates add f("sort(fromIndex : Int = 0, toIndex : Int = size - 1)") {
|
||||
templates add f("sort(fromIndex: Int = 0, toIndex: Int = size - 1)") {
|
||||
only(ArraysOfObjects, ArraysOfPrimitives)
|
||||
exclude(PrimitiveType.Boolean)
|
||||
doc { "Sorts array or range in array inplace" }
|
||||
@@ -75,8 +75,8 @@ fun specialJVM(): List<GenericFunction> {
|
||||
|
||||
templates add f("filterIsInstanceTo(collection: C, klass: Class<R>)") {
|
||||
doc { "Appends all elements that are instances of specified class into the given *collection*" }
|
||||
typeParam("C: MutableCollection<in R>")
|
||||
typeParam("R: T")
|
||||
typeParam("C : MutableCollection<in R>")
|
||||
typeParam("R : T")
|
||||
returns("C")
|
||||
exclude(ArraysOfPrimitives)
|
||||
body {
|
||||
@@ -89,7 +89,7 @@ fun specialJVM(): List<GenericFunction> {
|
||||
|
||||
templates add f("filterIsInstance(klass: Class<R>)") {
|
||||
doc { "Returns a list containing all elements that are instances of specified class" }
|
||||
typeParam("R: T")
|
||||
typeParam("R : T")
|
||||
returns("List<R>")
|
||||
body {
|
||||
"""
|
||||
|
||||
@@ -10,7 +10,11 @@ fun streams(): List<GenericFunction> {
|
||||
returns("Stream<T>")
|
||||
body {
|
||||
"""
|
||||
return object : Stream<T> { override fun iterator() : Iterator<T> { return this@stream.iterator() } }
|
||||
return object : Stream<T> {
|
||||
override fun iterator(): Iterator<T> {
|
||||
return this@stream.iterator()
|
||||
}
|
||||
}
|
||||
"""
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ import templates.Family.*
|
||||
fun strings(): List<GenericFunction> {
|
||||
val templates = arrayListOf<GenericFunction>()
|
||||
|
||||
templates add f("appendString(buffer: Appendable, separator: String = \", \", prefix: String =\"\", postfix: String = \"\", limit: Int = -1, truncated: String = \"...\")") {
|
||||
templates add f("appendString(buffer: Appendable, separator: String = \", \", prefix: String = \"\", postfix: String = \"\", limit: Int = -1, truncated: String = \"...\")") {
|
||||
doc {
|
||||
"""
|
||||
Appends the string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied
|
||||
|
||||
Reference in New Issue
Block a user