Stdlib generators DSL: allow to use documentation family extensions inside doc { } without importing them first.

This commit is contained in:
Ilya Gorbunov
2015-11-16 22:52:00 +03:00
parent a426c7879f
commit 16c5289e6c
12 changed files with 12 additions and 30 deletions
@@ -1,8 +1,6 @@
package templates
import templates.Family.*
import templates.DocExtensions.element
import templates.DocExtensions.collection
fun aggregates(): List<GenericFunction> {
val templates = arrayListOf<GenericFunction>()
@@ -1,9 +1,6 @@
package templates
import templates.Family.*
import templates.DocExtensions.element
import templates.DocExtensions.collection
import templates.DocExtensions.prefixWithArticle
fun elements(): List<GenericFunction> {
@@ -1,9 +1,6 @@
package templates
import templates.Family.*
import templates.DocExtensions.collection
import templates.DocExtensions.element
import templates.DocExtensions.mapResult
fun filtering(): List<GenericFunction> {
val templates = arrayListOf<GenericFunction>()
@@ -1,7 +1,6 @@
package templates
import templates.Family.*
import templates.DocExtensions.collection
fun generators(): List<GenericFunction> {
val templates = arrayListOf<GenericFunction>()
@@ -1,12 +1,11 @@
package templates
import java.util.ArrayList
import templates.Family.*
fun guards(): List<GenericFunction> {
val THIS = "\$this"
val templates = ArrayList<GenericFunction>()
val templates = arrayListOf<GenericFunction>()
templates add f("requireNoNulls()") {
include(Lists)
@@ -1,9 +1,6 @@
package templates
import templates.Family.*
import templates.DocExtensions.element
import templates.DocExtensions.collection
import templates.DocExtensions.mapResult
fun mapping(): List<GenericFunction> {
val templates = arrayListOf<GenericFunction>()
@@ -1,7 +1,6 @@
package templates
import templates.Family.*
import templates.DocExtensions.collection
fun numeric(): List<GenericFunction> {
val templates = arrayListOf<GenericFunction>()
@@ -1,13 +1,12 @@
package templates
import templates.Family.*
import templates.DocExtensions.collection
fun ordering(): List<GenericFunction> {
val templates = arrayListOf<GenericFunction>()
templates add f("reverse()") {
doc { f -> "Reverses elements in the ${f.collection} in-place." }
doc { f -> "Reverses ${f.element}s in the ${f.collection} in-place." }
only(Lists, ArraysOfObjects, ArraysOfPrimitives)
customReceiver(Lists) { "MutableList<T>" }
returns { "Unit" }
@@ -1,9 +1,6 @@
package templates
import templates.Family.*
import templates.DocExtensions.element
import templates.DocExtensions.collection
import templates.DocExtensions.mapResult
fun sets(): List<GenericFunction> {
val templates = arrayListOf<GenericFunction>()
@@ -1,8 +1,6 @@
package templates
import templates.Family.*
import templates.DocExtensions.element
import templates.DocExtensions.collection
fun snapshots(): List<GenericFunction> {
val templates = arrayListOf<GenericFunction>()
@@ -276,7 +276,7 @@ fun specialJVM(): List<GenericFunction> {
}
}
templates.forEach { it.jvmOnly(true) }
templates.forEach { it.apply { jvmOnly(true) } }
return templates
}
@@ -77,18 +77,20 @@ class GenericFunction(val signature: String, val keyword: String = "fun") {
}
}
operator fun invoke(vararg keys: TKey, valueBuilder: (TKey) -> TValue) = set(keys.asList(), valueBuilder)
operator fun invoke(value: TValue, vararg keys: TKey) = set(keys.asList(), { value })
protected open fun onKeySet(key: TKey) {}
}
operator fun <TKey: Any, TValue : Any> SpecializedProperty<TKey, TValue>.invoke(vararg keys: TKey, valueBuilder: (TKey) -> TValue) = set(keys.asList(), valueBuilder)
operator fun <TKey: Any, TValue : Any> SpecializedProperty<TKey, TValue>.invoke(value: TValue, vararg keys: TKey) = set(keys.asList(), { value })
open class FamilyProperty<TValue: Any>() : SpecializedProperty<Family, TValue>()
open class PrimitiveProperty<TValue: Any>() : SpecializedProperty<PrimitiveType, TValue>()
class DeprecationProperty() : FamilyProperty<Deprecation>() {
operator fun invoke(value: String, vararg keys: Family) = set(keys.asList(), { Deprecation(value) })
}
class DeprecationProperty() : FamilyProperty<Deprecation>()
operator fun DeprecationProperty.invoke(value: String, vararg keys: Family) = set(keys.asList(), { Deprecation(value) })
class DocProperty() : FamilyProperty<String>()
operator fun DocProperty.invoke(vararg keys: Family, valueBuilder: DocExtensions.(Family) -> String) = set(keys.asList(), { f -> valueBuilder(DocExtensions, f) })
@@ -107,7 +109,7 @@ class GenericFunction(val signature: String, val keyword: String = "fun") {
val customReceiver = FamilyProperty<String>()
val customSignature = FamilyProperty<String>()
val deprecate = DeprecationProperty()
val doc = FamilyProperty<String>()
val doc = DocProperty()
val platformName = PrimitiveProperty<String>()
val inline = FamilyProperty<Boolean>()
val jvmOnly = FamilyProperty<Boolean>()