Generate JvmMultifileClass annotation on parts.
This commit is contained in:
@@ -21,7 +21,6 @@ fun generateCollectionsAPI(outDir: File) {
|
||||
::sequences,
|
||||
::specialJVM,
|
||||
::ranges,
|
||||
::toPrimitiveArrays,
|
||||
::numeric,
|
||||
::comparables
|
||||
).flatMap { it().sortedBy { it.signature }.asSequence() }
|
||||
|
||||
@@ -52,6 +52,9 @@ fun List<ConcreteFunction>.writeTo(outDir: File, sourceFile: SourceFile) {
|
||||
val its = FileWriter(file)
|
||||
|
||||
its.use {
|
||||
if (sourceFile.multifile) {
|
||||
its.append("@file:kotlin.jvm.JvmMultifileClass\n")
|
||||
}
|
||||
its.append("@file:kotlin.jvm.JvmName(\"${sourceFile.jvmClassName}\")\n\n")
|
||||
its.append("package kotlin\n\n")
|
||||
its.append("$COMMON_AUTOGENERATED_WARNING\n\n")
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package generators
|
||||
|
||||
enum class SourceFile(jvmClassName: String? = null) {
|
||||
enum class SourceFile(jvmClassName: String? = null, val multifile: Boolean = true) {
|
||||
|
||||
Arrays(),
|
||||
Collections(),
|
||||
@@ -9,7 +9,7 @@ enum class SourceFile(jvmClassName: String? = null) {
|
||||
Sequences(),
|
||||
Ranges(),
|
||||
Strings(),
|
||||
Numbers(),
|
||||
Misc(),
|
||||
;
|
||||
|
||||
val name = this.name()
|
||||
|
||||
@@ -54,13 +54,7 @@ fun arrays(): List<GenericFunction> {
|
||||
}
|
||||
}
|
||||
|
||||
return templates
|
||||
}
|
||||
|
||||
|
||||
|
||||
fun toPrimitiveArrays(): List<GenericFunction> =
|
||||
PrimitiveType.values().map { primitive ->
|
||||
templates addAll PrimitiveType.values().map { primitive ->
|
||||
val arrayType = primitive.name + "Array"
|
||||
f("to$arrayType()") {
|
||||
only(ArraysOfObjects, Collections)
|
||||
@@ -88,3 +82,6 @@ fun toPrimitiveArrays(): List<GenericFunction> =
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return templates
|
||||
}
|
||||
@@ -1,11 +1,13 @@
|
||||
package templates
|
||||
|
||||
import generators.SourceFile
|
||||
import templates.Family.*
|
||||
|
||||
fun comparables(): List<GenericFunction> {
|
||||
val templates = arrayListOf<GenericFunction>()
|
||||
|
||||
templates add f("coerceAtLeast(minimumValue: SELF)") {
|
||||
sourceFile(SourceFile.Ranges)
|
||||
only(Primitives, Generic)
|
||||
only(numericPrimitives)
|
||||
returns("SELF")
|
||||
@@ -26,6 +28,7 @@ fun comparables(): List<GenericFunction> {
|
||||
}
|
||||
|
||||
templates add f("coerceAtMost(maximumValue: SELF)") {
|
||||
sourceFile(SourceFile.Ranges)
|
||||
only(Primitives, Generic)
|
||||
only(numericPrimitives)
|
||||
returns("SELF")
|
||||
@@ -45,6 +48,7 @@ fun comparables(): List<GenericFunction> {
|
||||
}
|
||||
|
||||
templates add f("coerceIn(range: Range<T>)") {
|
||||
sourceFile(SourceFile.Ranges)
|
||||
only(Primitives, Generic)
|
||||
only(numericPrimitives)
|
||||
returns("SELF")
|
||||
@@ -65,6 +69,7 @@ fun comparables(): List<GenericFunction> {
|
||||
}
|
||||
|
||||
templates add f("coerceIn(minimumValue: SELF?, maximumValue: SELF?)") {
|
||||
sourceFile(SourceFile.Ranges)
|
||||
only(Primitives, Generic)
|
||||
only(numericPrimitives)
|
||||
returns("SELF")
|
||||
|
||||
@@ -113,6 +113,7 @@ class GenericFunction(val signature: String, val keyword: String = "fun") {
|
||||
}
|
||||
val customPrimitiveBodies = HashMap<Pair<Family, PrimitiveType>, String>()
|
||||
val annotations = FamilyProperty<String>()
|
||||
val sourceFile = FamilyProperty<SourceFile>()
|
||||
|
||||
fun bodyForTypes(family: Family, vararg primitiveTypes: PrimitiveType, b: () -> String) {
|
||||
include(family)
|
||||
@@ -185,17 +186,17 @@ class GenericFunction(val signature: String, val keyword: String = "fun") {
|
||||
}
|
||||
}
|
||||
|
||||
private fun sourceFileFor(f: Family) = getDefaultSourceFile(f)
|
||||
private fun sourceFileFor(f: Family) = sourceFile[f] ?: getDefaultSourceFile(f)
|
||||
|
||||
private fun getDefaultSourceFile(f: Family): SourceFile = when (f) {
|
||||
Iterables, Collections, Lists -> SourceFile.Collections
|
||||
Sequences -> SourceFile.Sequences
|
||||
Sets -> SourceFile.Sets
|
||||
Ranges, RangesOfPrimitives, ProgressionsOfPrimitives -> SourceFile.Ranges
|
||||
ArraysOfObjects, ArraysOfObjectsSubtype, InvariantArraysOfObjects, ArraysOfPrimitives -> SourceFile.Arrays
|
||||
ArraysOfObjects, InvariantArraysOfObjects, ArraysOfPrimitives -> SourceFile.Arrays
|
||||
Maps -> SourceFile.Maps
|
||||
Strings -> SourceFile.Strings
|
||||
Primitives, Generic -> SourceFile.Numbers
|
||||
Primitives, Generic -> SourceFile.Misc
|
||||
}
|
||||
|
||||
fun build(vararg families: Family = Family.values()): String {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package templates
|
||||
|
||||
import generators.SourceFile
|
||||
import templates.Family.*
|
||||
|
||||
fun ranges(): List<GenericFunction> {
|
||||
@@ -47,6 +48,7 @@ fun ranges(): List<GenericFunction> {
|
||||
}
|
||||
|
||||
fun downTo(fromType: PrimitiveType, toType: PrimitiveType) = f("downTo(to: $toType)") {
|
||||
sourceFile(SourceFile.Ranges)
|
||||
only(Primitives)
|
||||
only(fromType)
|
||||
val elementType = PrimitiveType.maxByCapacity(fromType, toType)
|
||||
@@ -79,6 +81,7 @@ fun ranges(): List<GenericFunction> {
|
||||
templates addAll primitivePermutations.map { downTo(it.first, it.second) }
|
||||
|
||||
fun until(fromType: PrimitiveType, toType: PrimitiveType) = f("until(to: $toType)") {
|
||||
sourceFile(SourceFile.Ranges)
|
||||
only(Primitives)
|
||||
only(fromType)
|
||||
val elementType = PrimitiveType.maxByCapacity(fromType, toType)
|
||||
|
||||
Reference in New Issue
Block a user