updated the code generator of standard library methods and regenerated it
This commit is contained in:
@@ -55,6 +55,23 @@
|
||||
</execution>
|
||||
</executions>
|
||||
</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>
|
||||
</build>
|
||||
</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 */
|
||||
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 {
|
||||
if (this != null) {
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
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 */
|
||||
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 {
|
||||
if (this != null) {
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
import kotlin.util.*
|
||||
@@ -56,7 +56,19 @@ inline fun <T, C: Collection<in T>> Iterable<T>.filterTo(result: C, predicate: (
|
||||
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 */
|
||||
inline fun <T> Iterable<T>.filterNot(predicate: (T)-> Boolean) : Collection<T> = filterNotTo(ArrayList<T>(), predicate)
|
||||
|
||||
@@ -1,39 +1,35 @@
|
||||
package org.jetbrains.kotlin.tools
|
||||
|
||||
import kotlin.*
|
||||
import kotlin.io.*
|
||||
import kotlin.util.*
|
||||
import java.io.*
|
||||
import java.util.*
|
||||
|
||||
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()
|
||||
val writer = PrintWriter(FileWriter(outFile))
|
||||
try {
|
||||
writer.println("// NOTE this file is auto-generated from $inputFile")
|
||||
writer.println(header)
|
||||
|
||||
val reader = FileReader(inputFile).buffered()
|
||||
outFile.getParentFile()?.mkdirs()
|
||||
val writer = PrintWriter(FileWriter(outFile))
|
||||
try {
|
||||
// TODO ideally we'd use a filterNot() here :)
|
||||
val iter = reader.lineIterator()
|
||||
while (iter.hasNext) {
|
||||
val line = iter.next()
|
||||
writer.println("// NOTE this file is auto-generated from $inputFile")
|
||||
writer.println(header)
|
||||
|
||||
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)
|
||||
writer.println(xform)
|
||||
}
|
||||
if (line.startsWith("package")) continue
|
||||
|
||||
val xform = f(line)
|
||||
writer.println(xform)
|
||||
}
|
||||
} finally {
|
||||
reader.close()
|
||||
reader.close()
|
||||
}
|
||||
} finally {
|
||||
reader.close()
|
||||
reader.close()
|
||||
writer.close()
|
||||
}
|
||||
} finally {
|
||||
writer.close()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -45,39 +41,35 @@ fun generateFile(outFile: File, header: String, inputFile: File, f: (String)-> S
|
||||
* at runtime.
|
||||
*/
|
||||
fun main(args: Array<String>) {
|
||||
var stdlib = File("stdlib")
|
||||
if (!stdlib.exists()) {
|
||||
stdlib = File("../stdlib")
|
||||
if (!stdlib.exists()) {
|
||||
println("Cannot find stdlib!")
|
||||
return
|
||||
var srcDir = File("src")
|
||||
if (!srcDir.exists()) {
|
||||
srcDir = File("stdlib/src")
|
||||
require(srcDir.exists(), "Could not find the src directory!")
|
||||
}
|
||||
}
|
||||
val srcDir = File(stdlib, "ktSrc")
|
||||
val outDir = File(srcDir, "generated")
|
||||
val outDir = File(srcDir, "generated")
|
||||
|
||||
|
||||
// JavaIterables - Generic iterable stuff
|
||||
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")
|
||||
}
|
||||
// JavaIterables - Generic iterable stuff
|
||||
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")
|
||||
}
|
||||
|
||||
generateFile(File(outDir, "StandardFromJavaIterables.kt"), "package kotlin\n\nimport kotlin.util.*", File(srcDir, "JavaIterables.kt")) {
|
||||
it.replaceAll("java.lang.Iterable<T", "Iterable<T")
|
||||
}
|
||||
generateFile(File(outDir, "StandardFromJavaIterables.kt"), "package kotlin\n\nimport kotlin.util.*", File(srcDir, "JavaIterables.kt")) {
|
||||
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")) {
|
||||
it.replaceAll("java.util.Collection<T", "Array<T")
|
||||
}
|
||||
generateFile(File(outDir, "ArraysFromJavaCollections.kt"), "package kotlin", File(srcDir, "JavaCollections.kt")) {
|
||||
it.replaceAll("java.util.Collection<T", "Array<T")
|
||||
}
|
||||
|
||||
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)", "")
|
||||
}
|
||||
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)", "")
|
||||
}
|
||||
|
||||
generateFile(File(outDir, "StandardFromJavaCollections.kt"), "package kotlin", File(srcDir, "JavaCollections.kt")) {
|
||||
it.replaceAll("java.util.Collection<T", "Iterable<T").replaceAll("(this.size)", "")
|
||||
}
|
||||
generateFile(File(outDir, "StandardFromJavaCollections.kt"), "package kotlin", File(srcDir, "JavaCollections.kt")) {
|
||||
it.replaceAll("java.util.Collection<T", "Iterable<T").replaceAll("(this.size)", "")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user