Rewrite Guards, Numeric, SequenceOps, StringJoinOps in new DSL
This commit is contained in:
@@ -20,12 +20,12 @@ fun main(args: Array<String>) {
|
|||||||
// Mapping,
|
// Mapping,
|
||||||
// SetOps,
|
// SetOps,
|
||||||
Aggregates,
|
Aggregates,
|
||||||
// Guards,
|
Guards,
|
||||||
Generators,
|
Generators,
|
||||||
// StringJoinOps,
|
StringJoinOps,
|
||||||
// SequenceOps,
|
SequenceOps,
|
||||||
// RangeOps,
|
// RangeOps,
|
||||||
// Numeric,
|
Numeric,
|
||||||
// ComparableOps,
|
// ComparableOps,
|
||||||
// CommonArrays,
|
// CommonArrays,
|
||||||
// PlatformSpecialized,
|
// PlatformSpecialized,
|
||||||
|
|||||||
@@ -1,15 +1,30 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2017 JetBrains s.r.o.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
package templates
|
package templates
|
||||||
|
|
||||||
import templates.Family.*
|
import templates.Family.*
|
||||||
import templates.SequenceClass.*
|
import templates.SequenceClass.*
|
||||||
|
|
||||||
fun guards(): List<GenericFunction> {
|
object Guards : TemplateGroupBase() {
|
||||||
val THIS = "\$this"
|
private val THIS = "\$this"
|
||||||
|
|
||||||
val templates = arrayListOf<GenericFunction>()
|
val f_requireNoNulls = fn("requireNoNulls()") {
|
||||||
|
include(Iterables, Sequences, InvariantArraysOfObjects, Lists)
|
||||||
templates add f("requireNoNulls()") {
|
} builder {
|
||||||
only(Iterables, Sequences, InvariantArraysOfObjects, Lists)
|
|
||||||
doc { "Returns an original collection containing all the non-`null` elements, throwing an [IllegalArgumentException] if there are any `null` elements." }
|
doc { "Returns an original collection containing all the non-`null` elements, throwing an [IllegalArgumentException] if there are any `null` elements." }
|
||||||
sequenceClassification(intermediate, stateless)
|
sequenceClassification(intermediate, stateless)
|
||||||
typeParam("T : Any")
|
typeParam("T : Any")
|
||||||
@@ -32,6 +47,4 @@ fun guards(): List<GenericFunction> {
|
|||||||
"""
|
"""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return templates
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,37 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2017 JetBrains s.r.o.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
package templates
|
package templates
|
||||||
|
|
||||||
import templates.Family.*
|
object Numeric : TemplateGroupBase() {
|
||||||
|
|
||||||
fun numeric(): List<GenericFunction> {
|
init {
|
||||||
val templates = arrayListOf<GenericFunction>()
|
defaultBuilder {
|
||||||
|
sequenceClassification(SequenceClass.terminal)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
templates add f("sum()") {
|
// TODO: use just numericPrimitives
|
||||||
exclude(Strings)
|
private val numericPrimitivesDefaultOrder = PrimitiveType.defaultPrimitives intersect PrimitiveType.numericPrimitives
|
||||||
buildFamilies.default!!.forEach { family -> onlyPrimitives(family, numericPrimitives) }
|
|
||||||
doc { f -> "Returns the sum of all elements in the ${f.collection}." }
|
val f_sum = fn("sum()") {
|
||||||
|
Family.defaultFamilies.forEach { family -> include(family, numericPrimitivesDefaultOrder) }
|
||||||
|
} builder {
|
||||||
|
|
||||||
|
doc { "Returns the sum of all elements in the ${f.collection}." }
|
||||||
returns("SUM")
|
returns("SUM")
|
||||||
platformName("sumOf<T>")
|
platformName("sumOf<T>")
|
||||||
body {
|
body {
|
||||||
@@ -22,10 +45,10 @@ fun numeric(): List<GenericFunction> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
templates add f("average()") {
|
val f_average = fn("average()") {
|
||||||
exclude(Strings)
|
Family.defaultFamilies.forEach { family -> include(family, numericPrimitivesDefaultOrder) }
|
||||||
buildFamilies.default!!.forEach { family -> onlyPrimitives(family, numericPrimitives) }
|
} builder {
|
||||||
doc { f -> "Returns an average value of elements in the ${f.collection}."}
|
doc { "Returns an average value of elements in the ${f.collection}."}
|
||||||
returns("Double")
|
returns("Double")
|
||||||
platformName("averageOf<T>")
|
platformName("averageOf<T>")
|
||||||
body {
|
body {
|
||||||
@@ -41,7 +64,4 @@ fun numeric(): List<GenericFunction> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
templates.forEach { it.sequenceClassification(SequenceClass.terminal) }
|
|
||||||
|
|
||||||
return templates
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +1,31 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2017 JetBrains s.r.o.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
package templates
|
package templates
|
||||||
|
|
||||||
import templates.Family.*
|
import templates.Family.*
|
||||||
|
|
||||||
fun sequences(): List<GenericFunction> {
|
object SequenceOps : TemplateGroupBase() {
|
||||||
val templates = arrayListOf<GenericFunction>()
|
|
||||||
|
|
||||||
templates add f("asIterable()") {
|
val f_asIterable = fn("asIterable()") {
|
||||||
only(Iterables, ArraysOfObjects, ArraysOfPrimitives, Sequences, CharSequences, Maps)
|
include(Iterables, ArraysOfObjects, ArraysOfPrimitives, Sequences, CharSequences, Maps)
|
||||||
doc { f -> "Creates an [Iterable] instance that wraps the original ${f.collection} returning its ${f.element.pluralize()} when being iterated." }
|
} builder {
|
||||||
|
doc { "Creates an [Iterable] instance that wraps the original ${f.collection} returning its ${f.element.pluralize()} when being iterated." }
|
||||||
returns("Iterable<T>")
|
returns("Iterable<T>")
|
||||||
body { f ->
|
body {
|
||||||
"""
|
"""
|
||||||
${ when(f) {
|
${ when(f) {
|
||||||
ArraysOfObjects, ArraysOfPrimitives -> "if (isEmpty()) return emptyList()"
|
ArraysOfObjects, ArraysOfPrimitives -> "if (isEmpty()) return emptyList()"
|
||||||
@@ -20,16 +36,20 @@ fun sequences(): List<GenericFunction> {
|
|||||||
"""
|
"""
|
||||||
}
|
}
|
||||||
|
|
||||||
inline(Iterables, Maps) { Inline.Only }
|
specialFor(Iterables, Maps) { inlineOnly() }
|
||||||
|
specialFor(Iterables) {
|
||||||
|
doc { "Returns this collection as an [Iterable]." }
|
||||||
|
body { "return this" }
|
||||||
|
}
|
||||||
|
|
||||||
doc(Iterables) { "Returns this collection as an [Iterable]." }
|
|
||||||
body(Iterables) { "return this" }
|
|
||||||
body(Maps) { "return entries" }
|
body(Maps) { "return entries" }
|
||||||
}
|
}
|
||||||
|
|
||||||
templates add f("asSequence()") {
|
val f_asSequence = fn("asSequence()") {
|
||||||
|
includeDefault()
|
||||||
include(CharSequences, Maps)
|
include(CharSequences, Maps)
|
||||||
doc { f ->
|
} builder {
|
||||||
|
doc {
|
||||||
"""
|
"""
|
||||||
Creates a [Sequence] instance that wraps the original ${f.collection} returning its ${f.element.pluralize()} when being iterated.
|
Creates a [Sequence] instance that wraps the original ${f.collection} returning its ${f.element.pluralize()} when being iterated.
|
||||||
|
|
||||||
@@ -37,7 +57,7 @@ fun sequences(): List<GenericFunction> {
|
|||||||
"""
|
"""
|
||||||
}
|
}
|
||||||
returns("Sequence<T>")
|
returns("Sequence<T>")
|
||||||
body { f ->
|
body {
|
||||||
"""
|
"""
|
||||||
${ when(f) {
|
${ when(f) {
|
||||||
ArraysOfObjects, ArraysOfPrimitives -> "if (isEmpty()) return emptySequence()"
|
ArraysOfObjects, ArraysOfPrimitives -> "if (isEmpty()) return emptySequence()"
|
||||||
@@ -50,11 +70,10 @@ fun sequences(): List<GenericFunction> {
|
|||||||
|
|
||||||
body(Maps) { "return entries.asSequence()" }
|
body(Maps) { "return entries.asSequence()" }
|
||||||
|
|
||||||
doc(Sequences) { "Returns this sequence as a [Sequence]."}
|
specialFor(Sequences) {
|
||||||
inline(Sequences) { Inline.Only }
|
doc { "Returns this sequence as a [Sequence]."}
|
||||||
body(Sequences) { "return this" }
|
inlineOnly()
|
||||||
|
body { "return this" }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return templates
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,29 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2017 JetBrains s.r.o.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
package templates
|
package templates
|
||||||
|
|
||||||
import templates.Family.*
|
import templates.Family.*
|
||||||
import templates.SequenceClass.*
|
import templates.SequenceClass.*
|
||||||
|
|
||||||
fun strings(): List<GenericFunction> {
|
object StringJoinOps : TemplateGroupBase() {
|
||||||
val templates = arrayListOf<GenericFunction>()
|
|
||||||
|
|
||||||
templates add f("joinTo(buffer: A, separator: CharSequence = \", \", prefix: CharSequence = \"\", postfix: CharSequence = \"\", limit: Int = -1, truncated: CharSequence = \"...\", transform: ((T) -> CharSequence)? = null)") {
|
val f_joinTo = fn("joinTo(buffer: A, separator: CharSequence = \", \", prefix: CharSequence = \"\", postfix: CharSequence = \"\", limit: Int = -1, truncated: CharSequence = \"...\", transform: ((T) -> CharSequence)? = null)") {
|
||||||
|
includeDefault()
|
||||||
|
} builder {
|
||||||
doc {
|
doc {
|
||||||
"""
|
"""
|
||||||
Appends the string from all the elements separated using [separator] and using the given [prefix] and [postfix] if supplied.
|
Appends the string from all the elements separated using [separator] and using the given [prefix] and [postfix] if supplied.
|
||||||
@@ -17,7 +34,7 @@ fun strings(): List<GenericFunction> {
|
|||||||
}
|
}
|
||||||
sequenceClassification(terminal)
|
sequenceClassification(terminal)
|
||||||
typeParam("A : Appendable")
|
typeParam("A : Appendable")
|
||||||
returns { "A" }
|
returns("A")
|
||||||
body {
|
body {
|
||||||
"""
|
"""
|
||||||
buffer.append(prefix)
|
buffer.append(prefix)
|
||||||
@@ -33,8 +50,7 @@ fun strings(): List<GenericFunction> {
|
|||||||
return buffer
|
return buffer
|
||||||
"""
|
"""
|
||||||
}
|
}
|
||||||
exclude(Strings)
|
body(ArraysOfPrimitives) {
|
||||||
bodyForTypes(ArraysOfPrimitives, *defaultPrimitives.toTypedArray()) { primitive ->
|
|
||||||
"""
|
"""
|
||||||
buffer.append(prefix)
|
buffer.append(prefix)
|
||||||
var count = 0
|
var count = 0
|
||||||
@@ -54,7 +70,9 @@ fun strings(): List<GenericFunction> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
templates add f("joinToString(separator: CharSequence = \", \", prefix: CharSequence = \"\", postfix: CharSequence = \"\", limit: Int = -1, truncated: CharSequence = \"...\", transform: ((T) -> CharSequence)? = null)") {
|
val f_joinToString = fn("joinToString(separator: CharSequence = \", \", prefix: CharSequence = \"\", postfix: CharSequence = \"\", limit: Int = -1, truncated: CharSequence = \"...\", transform: ((T) -> CharSequence)? = null)") {
|
||||||
|
includeDefault()
|
||||||
|
} builder {
|
||||||
doc {
|
doc {
|
||||||
"""
|
"""
|
||||||
Creates a string from all the elements separated using [separator] and using the given [prefix] and [postfix] if supplied.
|
Creates a string from all the elements separated using [separator] and using the given [prefix] and [postfix] if supplied.
|
||||||
@@ -65,7 +83,6 @@ fun strings(): List<GenericFunction> {
|
|||||||
}
|
}
|
||||||
sequenceClassification(terminal)
|
sequenceClassification(terminal)
|
||||||
|
|
||||||
exclude(Strings)
|
|
||||||
returns("String")
|
returns("String")
|
||||||
body {
|
body {
|
||||||
"""
|
"""
|
||||||
@@ -73,6 +90,4 @@ fun strings(): List<GenericFunction> {
|
|||||||
"""
|
"""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return templates
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user