Stdlib generators DSL: allow to use documentation family extensions inside doc { } without importing them first.
This commit is contained in:
@@ -1,8 +1,6 @@
|
|||||||
package templates
|
package templates
|
||||||
|
|
||||||
import templates.Family.*
|
import templates.Family.*
|
||||||
import templates.DocExtensions.element
|
|
||||||
import templates.DocExtensions.collection
|
|
||||||
|
|
||||||
fun aggregates(): List<GenericFunction> {
|
fun aggregates(): List<GenericFunction> {
|
||||||
val templates = arrayListOf<GenericFunction>()
|
val templates = arrayListOf<GenericFunction>()
|
||||||
|
|||||||
@@ -1,9 +1,6 @@
|
|||||||
package templates
|
package templates
|
||||||
|
|
||||||
import templates.Family.*
|
import templates.Family.*
|
||||||
import templates.DocExtensions.element
|
|
||||||
import templates.DocExtensions.collection
|
|
||||||
import templates.DocExtensions.prefixWithArticle
|
|
||||||
|
|
||||||
|
|
||||||
fun elements(): List<GenericFunction> {
|
fun elements(): List<GenericFunction> {
|
||||||
|
|||||||
@@ -1,9 +1,6 @@
|
|||||||
package templates
|
package templates
|
||||||
|
|
||||||
import templates.Family.*
|
import templates.Family.*
|
||||||
import templates.DocExtensions.collection
|
|
||||||
import templates.DocExtensions.element
|
|
||||||
import templates.DocExtensions.mapResult
|
|
||||||
|
|
||||||
fun filtering(): List<GenericFunction> {
|
fun filtering(): List<GenericFunction> {
|
||||||
val templates = arrayListOf<GenericFunction>()
|
val templates = arrayListOf<GenericFunction>()
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package templates
|
package templates
|
||||||
|
|
||||||
import templates.Family.*
|
import templates.Family.*
|
||||||
import templates.DocExtensions.collection
|
|
||||||
|
|
||||||
fun generators(): List<GenericFunction> {
|
fun generators(): List<GenericFunction> {
|
||||||
val templates = arrayListOf<GenericFunction>()
|
val templates = arrayListOf<GenericFunction>()
|
||||||
|
|||||||
@@ -1,12 +1,11 @@
|
|||||||
package templates
|
package templates
|
||||||
|
|
||||||
import java.util.ArrayList
|
|
||||||
import templates.Family.*
|
import templates.Family.*
|
||||||
|
|
||||||
fun guards(): List<GenericFunction> {
|
fun guards(): List<GenericFunction> {
|
||||||
val THIS = "\$this"
|
val THIS = "\$this"
|
||||||
|
|
||||||
val templates = ArrayList<GenericFunction>()
|
val templates = arrayListOf<GenericFunction>()
|
||||||
|
|
||||||
templates add f("requireNoNulls()") {
|
templates add f("requireNoNulls()") {
|
||||||
include(Lists)
|
include(Lists)
|
||||||
|
|||||||
@@ -1,9 +1,6 @@
|
|||||||
package templates
|
package templates
|
||||||
|
|
||||||
import templates.Family.*
|
import templates.Family.*
|
||||||
import templates.DocExtensions.element
|
|
||||||
import templates.DocExtensions.collection
|
|
||||||
import templates.DocExtensions.mapResult
|
|
||||||
|
|
||||||
fun mapping(): List<GenericFunction> {
|
fun mapping(): List<GenericFunction> {
|
||||||
val templates = arrayListOf<GenericFunction>()
|
val templates = arrayListOf<GenericFunction>()
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package templates
|
package templates
|
||||||
|
|
||||||
import templates.Family.*
|
import templates.Family.*
|
||||||
import templates.DocExtensions.collection
|
|
||||||
|
|
||||||
fun numeric(): List<GenericFunction> {
|
fun numeric(): List<GenericFunction> {
|
||||||
val templates = arrayListOf<GenericFunction>()
|
val templates = arrayListOf<GenericFunction>()
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
package templates
|
package templates
|
||||||
|
|
||||||
import templates.Family.*
|
import templates.Family.*
|
||||||
import templates.DocExtensions.collection
|
|
||||||
|
|
||||||
fun ordering(): List<GenericFunction> {
|
fun ordering(): List<GenericFunction> {
|
||||||
val templates = arrayListOf<GenericFunction>()
|
val templates = arrayListOf<GenericFunction>()
|
||||||
|
|
||||||
templates add f("reverse()") {
|
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)
|
only(Lists, ArraysOfObjects, ArraysOfPrimitives)
|
||||||
customReceiver(Lists) { "MutableList<T>" }
|
customReceiver(Lists) { "MutableList<T>" }
|
||||||
returns { "Unit" }
|
returns { "Unit" }
|
||||||
|
|||||||
@@ -1,9 +1,6 @@
|
|||||||
package templates
|
package templates
|
||||||
|
|
||||||
import templates.Family.*
|
import templates.Family.*
|
||||||
import templates.DocExtensions.element
|
|
||||||
import templates.DocExtensions.collection
|
|
||||||
import templates.DocExtensions.mapResult
|
|
||||||
|
|
||||||
fun sets(): List<GenericFunction> {
|
fun sets(): List<GenericFunction> {
|
||||||
val templates = arrayListOf<GenericFunction>()
|
val templates = arrayListOf<GenericFunction>()
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
package templates
|
package templates
|
||||||
|
|
||||||
import templates.Family.*
|
import templates.Family.*
|
||||||
import templates.DocExtensions.element
|
|
||||||
import templates.DocExtensions.collection
|
|
||||||
|
|
||||||
fun snapshots(): List<GenericFunction> {
|
fun snapshots(): List<GenericFunction> {
|
||||||
val templates = arrayListOf<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
|
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) {}
|
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 FamilyProperty<TValue: Any>() : SpecializedProperty<Family, TValue>()
|
||||||
open class PrimitiveProperty<TValue: Any>() : SpecializedProperty<PrimitiveType, TValue>()
|
open class PrimitiveProperty<TValue: Any>() : SpecializedProperty<PrimitiveType, TValue>()
|
||||||
|
|
||||||
class DeprecationProperty() : FamilyProperty<Deprecation>() {
|
class DeprecationProperty() : FamilyProperty<Deprecation>()
|
||||||
operator fun invoke(value: String, vararg keys: Family) = set(keys.asList(), { Deprecation(value) })
|
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 customReceiver = FamilyProperty<String>()
|
||||||
val customSignature = FamilyProperty<String>()
|
val customSignature = FamilyProperty<String>()
|
||||||
val deprecate = DeprecationProperty()
|
val deprecate = DeprecationProperty()
|
||||||
val doc = FamilyProperty<String>()
|
val doc = DocProperty()
|
||||||
val platformName = PrimitiveProperty<String>()
|
val platformName = PrimitiveProperty<String>()
|
||||||
val inline = FamilyProperty<Boolean>()
|
val inline = FamilyProperty<Boolean>()
|
||||||
val jvmOnly = FamilyProperty<Boolean>()
|
val jvmOnly = FamilyProperty<Boolean>()
|
||||||
|
|||||||
Reference in New Issue
Block a user