updated the code generator of standard library methods and regenerated it
This commit is contained in:
@@ -55,6 +55,23 @@
|
|||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.codehaus.mojo</groupId>
|
||||||
|
<artifactId>exec-maven-plugin</artifactId>
|
||||||
|
<version>1.2.1</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<goals>
|
||||||
|
<goal>java</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
<configuration>
|
||||||
|
<mainClass>org.jetbrains.kotlin.tools.namespace</mainClass>
|
||||||
|
<classpathScope>test</classpathScope>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
@@ -54,9 +54,9 @@ inline fun <T, C: Collection<in T>> java.lang.Iterable<T>.filterTo(result: C, pr
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Returns a List containing all the non null elements in this collection */
|
/** Returns a List containing all the non null elements in this collection */
|
||||||
inline fun <T> java.lang.Iterable<T?>?.filterNotNull() : Collection<T> = filterNotNullTo(java.util.ArrayList<T>())
|
inline fun <T> java.lang.Iterable<T?>?.filterNotNull() : Collection<T> = filterNotNullTo<T, java.util.ArrayList<T>>(java.util.ArrayList<T>())
|
||||||
|
|
||||||
/** Filters all the null elements in this collection winto the given result collection */
|
/** Filters all the null elements in this collection into the given result collection */
|
||||||
inline fun <T, C: Collection<in T>> java.lang.Iterable<T?>?.filterNotNullTo(result: C) : C {
|
inline fun <T, C: Collection<in T>> java.lang.Iterable<T?>?.filterNotNullTo(result: C) : C {
|
||||||
if (this != null) {
|
if (this != null) {
|
||||||
for (elem in this) {
|
for (elem in this) {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// NOTE this file is auto-generated from stdlib/ktSrc/JavaCollections.kt
|
// NOTE this file is auto-generated from src/JavaCollections.kt
|
||||||
package kotlin
|
package kotlin
|
||||||
|
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// NOTE this file is auto-generated from stdlib/ktSrc/JavaIterables.kt
|
// NOTE this file is auto-generated from src/JavaIterables.kt
|
||||||
package kotlin
|
package kotlin
|
||||||
|
|
||||||
import kotlin.util.*
|
import kotlin.util.*
|
||||||
@@ -57,9 +57,9 @@ inline fun <T, C: Collection<in T>> Array<T>.filterTo(result: C, predicate: (T)-
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Returns a List containing all the non null elements in this collection */
|
/** Returns a List containing all the non null elements in this collection */
|
||||||
inline fun <T> Array<T?>?.filterNotNull() : Collection<T> = filterNotNullTo(java.util.ArrayList<T>())
|
inline fun <T> Array<T?>?.filterNotNull() : Collection<T> = filterNotNullTo<T, java.util.ArrayList<T>>(java.util.ArrayList<T>())
|
||||||
|
|
||||||
/** Filters all the null elements in this collection winto the given result collection */
|
/** Filters all the null elements in this collection into the given result collection */
|
||||||
inline fun <T, C: Collection<in T>> Array<T?>?.filterNotNullTo(result: C) : C {
|
inline fun <T, C: Collection<in T>> Array<T?>?.filterNotNullTo(result: C) : C {
|
||||||
if (this != null) {
|
if (this != null) {
|
||||||
for (elem in this) {
|
for (elem in this) {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// NOTE this file is auto-generated from stdlib/ktSrc/JavaCollections.kt
|
// NOTE this file is auto-generated from src/JavaCollections.kt
|
||||||
package kotlin.util
|
package kotlin.util
|
||||||
|
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// NOTE this file is auto-generated from stdlib/ktSrc/JavaCollections.kt
|
// NOTE this file is auto-generated from src/JavaCollections.kt
|
||||||
package kotlin
|
package kotlin
|
||||||
|
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// NOTE this file is auto-generated from stdlib/ktSrc/JavaIterables.kt
|
// NOTE this file is auto-generated from src/JavaIterables.kt
|
||||||
package kotlin
|
package kotlin
|
||||||
|
|
||||||
import kotlin.util.*
|
import kotlin.util.*
|
||||||
@@ -56,7 +56,19 @@ inline fun <T, C: Collection<in T>> Iterable<T>.filterTo(result: C, predicate: (
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Returns a List containing all the non null elements in this collection */
|
||||||
|
inline fun <T> Iterable<T?>?.filterNotNull() : Collection<T> = filterNotNullTo<T, java.util.ArrayList<T>>(java.util.ArrayList<T>())
|
||||||
|
|
||||||
|
/** Filters all the null elements in this collection into the given result collection */
|
||||||
|
inline fun <T, C: Collection<in T>> Iterable<T?>?.filterNotNullTo(result: C) : C {
|
||||||
|
if (this != null) {
|
||||||
|
for (elem in this) {
|
||||||
|
if (elem != null)
|
||||||
|
result.add(elem)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
/** Returns a new collection containing all elements in this collection which do not match the given predicate */
|
/** Returns a new collection containing all elements in this collection which do not match the given predicate */
|
||||||
inline fun <T> Iterable<T>.filterNot(predicate: (T)-> Boolean) : Collection<T> = filterNotTo(ArrayList<T>(), predicate)
|
inline fun <T> Iterable<T>.filterNot(predicate: (T)-> Boolean) : Collection<T> = filterNotTo(ArrayList<T>(), predicate)
|
||||||
|
|||||||
@@ -1,39 +1,35 @@
|
|||||||
package org.jetbrains.kotlin.tools
|
package org.jetbrains.kotlin.tools
|
||||||
|
|
||||||
import kotlin.*
|
|
||||||
import kotlin.io.*
|
|
||||||
import kotlin.util.*
|
|
||||||
import java.io.*
|
import java.io.*
|
||||||
import java.util.*
|
|
||||||
|
|
||||||
fun generateFile(outFile: File, header: String, inputFile: File, f: (String)-> String) {
|
fun generateFile(outFile: File, header: String, inputFile: File, f: (String)-> String) {
|
||||||
println("Parsing $inputFile and writing $outFile")
|
println("Parsing $inputFile and writing $outFile")
|
||||||
|
|
||||||
outFile.getParentFile()?.mkdirs()
|
outFile.getParentFile()?.mkdirs()
|
||||||
val writer = PrintWriter(FileWriter(outFile))
|
val writer = PrintWriter(FileWriter(outFile))
|
||||||
try {
|
|
||||||
writer.println("// NOTE this file is auto-generated from $inputFile")
|
|
||||||
writer.println(header)
|
|
||||||
|
|
||||||
val reader = FileReader(inputFile).buffered()
|
|
||||||
try {
|
try {
|
||||||
// TODO ideally we'd use a filterNot() here :)
|
writer.println("// NOTE this file is auto-generated from $inputFile")
|
||||||
val iter = reader.lineIterator()
|
writer.println(header)
|
||||||
while (iter.hasNext) {
|
|
||||||
val line = iter.next()
|
|
||||||
|
|
||||||
if (line.startsWith("package")) continue
|
val reader = FileReader(inputFile).buffered()
|
||||||
|
try {
|
||||||
|
// TODO ideally we'd use a filterNot() here :)
|
||||||
|
val iter = reader.lineIterator()
|
||||||
|
while (iter.hasNext) {
|
||||||
|
val line = iter.next()
|
||||||
|
|
||||||
val xform = f(line)
|
if (line.startsWith("package")) continue
|
||||||
writer.println(xform)
|
|
||||||
}
|
val xform = f(line)
|
||||||
|
writer.println(xform)
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
reader.close()
|
||||||
|
reader.close()
|
||||||
|
}
|
||||||
} finally {
|
} finally {
|
||||||
reader.close()
|
writer.close()
|
||||||
reader.close()
|
|
||||||
}
|
}
|
||||||
} finally {
|
|
||||||
writer.close()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -45,39 +41,35 @@ fun generateFile(outFile: File, header: String, inputFile: File, f: (String)-> S
|
|||||||
* at runtime.
|
* at runtime.
|
||||||
*/
|
*/
|
||||||
fun main(args: Array<String>) {
|
fun main(args: Array<String>) {
|
||||||
var stdlib = File("stdlib")
|
var srcDir = File("src")
|
||||||
if (!stdlib.exists()) {
|
if (!srcDir.exists()) {
|
||||||
stdlib = File("../stdlib")
|
srcDir = File("stdlib/src")
|
||||||
if (!stdlib.exists()) {
|
require(srcDir.exists(), "Could not find the src directory!")
|
||||||
println("Cannot find stdlib!")
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
}
|
val outDir = File(srcDir, "generated")
|
||||||
val srcDir = File(stdlib, "ktSrc")
|
|
||||||
val outDir = File(srcDir, "generated")
|
|
||||||
|
|
||||||
|
|
||||||
// JavaIterables - Generic iterable stuff
|
// JavaIterables - Generic iterable stuff
|
||||||
generateFile(File(outDir, "ArraysFromJavaIterables.kt"), "package kotlin\n\nimport kotlin.util.*", File(srcDir, "JavaIterables.kt")) {
|
generateFile(File(outDir, "ArraysFromJavaIterables.kt"), "package kotlin\n\nimport kotlin.util.*", File(srcDir, "JavaIterables.kt")) {
|
||||||
it.replaceAll("java.lang.Iterable<T", "Array<T").replaceAll("java.lang.Iterable<T", "Array<T")
|
it.replaceAll("java.lang.Iterable<T", "Array<T").replaceAll("java.lang.Iterable<T", "Array<T")
|
||||||
}
|
}
|
||||||
|
|
||||||
generateFile(File(outDir, "StandardFromJavaIterables.kt"), "package kotlin\n\nimport kotlin.util.*", File(srcDir, "JavaIterables.kt")) {
|
generateFile(File(outDir, "StandardFromJavaIterables.kt"), "package kotlin\n\nimport kotlin.util.*", File(srcDir, "JavaIterables.kt")) {
|
||||||
it.replaceAll("java.lang.Iterable<T", "Iterable<T")
|
it.replaceAll("java.lang.Iterable<T", "Iterable<T")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// JavaCollections - methods returning a collection of the same input size (if its a collection)
|
// JavaCollections - methods returning a collection of the same input size (if its a collection)
|
||||||
|
|
||||||
generateFile(File(outDir, "ArraysFromJavaCollections.kt"), "package kotlin", File(srcDir, "JavaCollections.kt")) {
|
generateFile(File(outDir, "ArraysFromJavaCollections.kt"), "package kotlin", File(srcDir, "JavaCollections.kt")) {
|
||||||
it.replaceAll("java.util.Collection<T", "Array<T")
|
it.replaceAll("java.util.Collection<T", "Array<T")
|
||||||
}
|
}
|
||||||
|
|
||||||
generateFile(File(outDir, "JavaUtilIterablesFromJavaCollections.kt"), "package kotlin.util", File(srcDir, "JavaCollections.kt")) {
|
generateFile(File(outDir, "JavaUtilIterablesFromJavaCollections.kt"), "package kotlin.util", File(srcDir, "JavaCollections.kt")) {
|
||||||
it.replaceAll("java.util.Collection<T", "java.lang.Iterable<T").replaceAll("(this.size)", "")
|
it.replaceAll("java.util.Collection<T", "java.lang.Iterable<T").replaceAll("(this.size)", "")
|
||||||
}
|
}
|
||||||
|
|
||||||
generateFile(File(outDir, "StandardFromJavaCollections.kt"), "package kotlin", File(srcDir, "JavaCollections.kt")) {
|
generateFile(File(outDir, "StandardFromJavaCollections.kt"), "package kotlin", File(srcDir, "JavaCollections.kt")) {
|
||||||
it.replaceAll("java.util.Collection<T", "Iterable<T").replaceAll("(this.size)", "")
|
it.replaceAll("java.util.Collection<T", "Iterable<T").replaceAll("(this.size)", "")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user