diff --git a/libraries/pom.xml b/libraries/pom.xml index 545322b176b..6068b15a657 100644 --- a/libraries/pom.xml +++ b/libraries/pom.xml @@ -91,6 +91,8 @@ tools/kdoc-maven-plugin stdlib + stdlib/validator + kunit kotlin-jdbc kotlin-swing diff --git a/libraries/stdlib/src/kotlin/JLangJVM.kt b/libraries/stdlib/src/kotlin/JLangJVM.kt index 0feaa0591aa..5e8e971e88d 100644 --- a/libraries/stdlib/src/kotlin/JLangJVM.kt +++ b/libraries/stdlib/src/kotlin/JLangJVM.kt @@ -19,12 +19,12 @@ import kotlin.InlineOption.ONLY_LOCAL_RETURN * String readFile(String name) throws IOException {...} */ Retention(RetentionPolicy.SOURCE) -public annotation class throws(vararg val exceptionClasses: Class) +public annotation class throws(public vararg val exceptionClasses: Class) [Intrinsic("kotlin.javaClass.property")] public val T.javaClass : Class get() = (this as java.lang.Object).getClass() as Class -[Intrinsic("kotlin.javaClass.function")] fun javaClass() : Class = null as Class +[Intrinsic("kotlin.javaClass.function")] public fun javaClass(): Class = null as Class public inline fun synchronized(lock: Any, [inlineOptions(ONLY_LOCAL_RETURN)] block: () -> R): R { monitorEnter(lock) diff --git a/libraries/stdlib/src/kotlin/Numbers.kt b/libraries/stdlib/src/kotlin/Numbers.kt index baf74f35640..ddc3aa1ef5d 100644 --- a/libraries/stdlib/src/kotlin/Numbers.kt +++ b/libraries/stdlib/src/kotlin/Numbers.kt @@ -4,10 +4,10 @@ package kotlin * Returns {@code true} if the specified number is a * Not-a-Number (NaN) value, {@code false} otherwise. */ -fun Double.isNaN() = this != this +public fun Double.isNaN(): Boolean = this != this /** * Returns {@code true} if the specified number is a * Not-a-Number (NaN) value, {@code false} otherwise. */ -fun Float.isNaN() = this != this \ No newline at end of file +public fun Float.isNaN(): Boolean = this != this \ No newline at end of file diff --git a/libraries/stdlib/src/kotlin/OrderingJVM.kt b/libraries/stdlib/src/kotlin/OrderingJVM.kt index f1908a4a8f7..f923bad70ca 100644 --- a/libraries/stdlib/src/kotlin/OrderingJVM.kt +++ b/libraries/stdlib/src/kotlin/OrderingJVM.kt @@ -6,7 +6,7 @@ import java.util.Comparator * Helper method for implementing [[Comparable]] methods using a list of functions * to calculate the values to compare */ -fun compareBy(a: T?, b: T?, vararg functions: T.() -> Comparable<*>?): Int { +public fun compareBy(a: T?, b: T?, vararg functions: T.() -> Comparable<*>?): Int { require(functions.size > 0) if (a === b) return 0 if (a == null) return - 1 @@ -41,7 +41,7 @@ public fun comparator(vararg functions: T.() -> Comparable<*>?): Comparator< } -private class FunctionComparator(vararg val functions: T.() -> Comparable<*>?): Comparator { +private class FunctionComparator(private vararg val functions: T.() -> Comparable<*>?) : Comparator { public override fun toString(): String { return "FunctionComparator${functions.toList()}" @@ -62,7 +62,8 @@ private class FunctionComparator(vararg val functions: T.() -> Comparable<*>? public fun comparator(fn: (T,T) -> Int): Comparator { return Function2Comparator(fn) } -private class Function2Comparator(val compareFn: (T,T) -> Int): Comparator { + +private class Function2Comparator(private val compareFn: (T, T) -> Int) : Comparator { public override fun toString(): String { return "Function2Comparator${compareFn}" diff --git a/libraries/stdlib/src/kotlin/collections/AbstractIterator.kt b/libraries/stdlib/src/kotlin/collections/AbstractIterator.kt index 193b5e83955..64c286256b0 100644 --- a/libraries/stdlib/src/kotlin/collections/AbstractIterator.kt +++ b/libraries/stdlib/src/kotlin/collections/AbstractIterator.kt @@ -6,7 +6,7 @@ import java.util.NoSuchElementException import java.lang.UnsupportedOperationException // not using an enum for now as JS generation doesn't support it -object State { +private object State { val Ready = 0 val NotReady = 1 val Done = 2 diff --git a/libraries/stdlib/src/kotlin/collections/Exceptions.kt b/libraries/stdlib/src/kotlin/collections/Exceptions.kt index 3acdb6f5725..eac02e90037 100644 --- a/libraries/stdlib/src/kotlin/collections/Exceptions.kt +++ b/libraries/stdlib/src/kotlin/collections/Exceptions.kt @@ -1,5 +1,5 @@ package kotlin -public class EmptyIterableException(val it : Iterable<*>) : RuntimeException("$it is empty") +public class EmptyIterableException(private val it: Iterable<*>) : RuntimeException("$it is empty") public class DuplicateKeyException(message : String = "Duplicate keys detected") : RuntimeException(message) \ No newline at end of file diff --git a/libraries/stdlib/src/kotlin/collections/JUtil.kt b/libraries/stdlib/src/kotlin/collections/JUtil.kt index 05bb42dc830..fffda871414 100644 --- a/libraries/stdlib/src/kotlin/collections/JUtil.kt +++ b/libraries/stdlib/src/kotlin/collections/JUtil.kt @@ -2,11 +2,11 @@ package kotlin import java.util.* -class stdlib_emptyListClass : List by ArrayList() {} +private class stdlib_emptyListClass : List by ArrayList() {} private val stdlib_emptyList : List = ArrayList() // TODO: Change to stdlib_emptyListClass() when KT-5192 is fixed private fun stdlib_emptyList() = stdlib_emptyList as List -class stdlib_emptyMapClass : Map by HashMap() {} +private class stdlib_emptyMapClass : Map by HashMap() {} private val stdlib_emptyMap : Map = HashMap() // TODO: Change to stdlib_emptyMapClass() when KT-5192 is fixed private fun stdlib_emptyMap() = stdlib_emptyMap as Map @@ -71,7 +71,7 @@ public val Int.indices: IntRange public fun Collection.isNotEmpty(): Boolean = !this.isEmpty() /** Returns true if this collection is not empty */ -val Collection<*>.notEmpty: Boolean +public val Collection<*>.notEmpty: Boolean get() = isNotEmpty() /** Returns the Collection if its not null otherwise it returns the empty list */ @@ -105,7 +105,7 @@ answer.sort(comparator) * * @includeFunctionBody ../../test/collections/ListSpecificTest.kt first */ -val List.first: T? +public val List.first: T? get() = this.head @@ -114,7 +114,7 @@ val List.first: T? * * @includeFunctionBody ../../test/collections/ListSpecificTest.kt last */ -val List.last: T? +public val List.last: T? get() { val s = this.size return if (s > 0) this[s - 1] else null @@ -125,7 +125,7 @@ val List.last: T? * * @includeFunctionBody ../../test/collections/ListSpecificTest.kt lastIndex */ -val List.lastIndex: Int +public val List.lastIndex: Int get() = this.size - 1 /** @@ -133,7 +133,7 @@ val List.lastIndex: Int * * @includeFunctionBody ../../test/collections/ListSpecificTest.kt head */ -val List.head: T? +public val List.head: T? get() = if (this.isNotEmpty()) this[0] else null /** @@ -141,7 +141,7 @@ val List.head: T? * * @includeFunctionBody ../../test/collections/ListSpecificTest.kt tail */ -val List.tail: List +public val List.tail: List get() { return this.drop(1) } diff --git a/libraries/stdlib/src/kotlin/collections/JUtilJVM.kt b/libraries/stdlib/src/kotlin/collections/JUtilJVM.kt index a83d1ede0c6..b65e291e6c3 100644 --- a/libraries/stdlib/src/kotlin/collections/JUtilJVM.kt +++ b/libraries/stdlib/src/kotlin/collections/JUtilJVM.kt @@ -46,4 +46,4 @@ public fun Set?.orEmpty(): Set * specified enumeration in the order they are returned by the * enumeration. */ -fun Enumeration.toList(): List = Collections.list(this) +public fun Enumeration.toList(): List = Collections.list(this) diff --git a/libraries/stdlib/src/kotlin/collections/Maps.kt b/libraries/stdlib/src/kotlin/collections/Maps.kt index 48540340d2c..29a374e6880 100644 --- a/libraries/stdlib/src/kotlin/collections/Maps.kt +++ b/libraries/stdlib/src/kotlin/collections/Maps.kt @@ -27,17 +27,17 @@ public val Map.Entry.value: V get() = getValue() /** Returns the key of the entry */ -fun Map.Entry.component1(): K { +public fun Map.Entry.component1(): K { return getKey() } /** Returns the value of the entry */ -fun Map.Entry.component2(): V { +public fun Map.Entry.component2(): V { return getValue() } /** Converts entry to Pair with key being first component and value being second */ -fun Map.Entry.toPair(): Pair { +public fun Map.Entry.toPair(): Pair { return Pair(getKey(), getValue()) } diff --git a/libraries/stdlib/src/kotlin/collections/Stream.kt b/libraries/stdlib/src/kotlin/collections/Stream.kt index 357e78ff1b6..5ce7c097d01 100644 --- a/libraries/stdlib/src/kotlin/collections/Stream.kt +++ b/libraries/stdlib/src/kotlin/collections/Stream.kt @@ -9,7 +9,9 @@ public trait Stream { public fun streamOf(vararg elements: T): Stream = elements.stream() -public class FilteringStream(val stream: Stream, val sendWhen: Boolean = true, val predicate: (T) -> Boolean) : Stream { +public class FilteringStream( + private val stream: Stream, private val sendWhen: Boolean = true, private val predicate: (T) -> Boolean +) : Stream { override fun iterator(): Iterator = object : AbstractIterator() { val iterator = stream.iterator() override fun computeNext() { @@ -25,7 +27,7 @@ public class FilteringStream(val stream: Stream, val sendWhen: Boolean = t } } -public class TransformingStream(val stream: Stream, val transformer: (T) -> R) : Stream { +public class TransformingStream(private val stream: Stream, private val transformer: (T) -> R) : Stream { override fun iterator(): Iterator = object : AbstractIterator() { val iterator = stream.iterator() override fun computeNext() { @@ -38,7 +40,9 @@ public class TransformingStream(val stream: Stream, val transformer: (T } } -public class MergingStream(val stream1: Stream, val stream2: Stream, val transform: (T1, T2) -> V) : Stream { +public class MergingStream( + private val stream1: Stream, private val stream2: Stream, private val transform: (T1, T2) -> V +) : Stream { override fun iterator(): Iterator = object : AbstractIterator() { val iterator1 = stream1.iterator() val iterator2 = stream2.iterator() @@ -52,7 +56,9 @@ public class MergingStream(val stream1: Stream, val stream2: Stre } } -public class FlatteningStream(val stream: Stream, val transformer: (T) -> Stream) : Stream { +public class FlatteningStream( + private val stream: Stream, private val transformer: (T) -> Stream +) : Stream { override fun iterator(): Iterator = object : AbstractIterator() { val iterator = stream.iterator() var itemIterator: Iterator? = null @@ -81,7 +87,7 @@ public class FlatteningStream(val stream: Stream, val transformer: (T) } } -public class Multistream(val streams: Stream>) : Stream { +public class Multistream(private val streams: Stream>) : Stream { override fun iterator(): Iterator = object : AbstractIterator() { val iterator = streams.iterator() var streamIterator: Iterator? = null @@ -110,7 +116,9 @@ public class Multistream(val streams: Stream>) : Stream { } } -public class LimitedStream(val stream: Stream, val stopWhen: Boolean = true, val predicate: (T) -> Boolean) : Stream { +public class LimitedStream( + private val stream: Stream, private val stopWhen: Boolean = true, private val predicate: (T) -> Boolean +) : Stream { override fun iterator(): Iterator = object : AbstractIterator() { val iterator = stream.iterator() override fun computeNext() { @@ -128,7 +136,7 @@ public class LimitedStream(val stream: Stream, val stopWhen: Boolean = tru } } -public class FunctionStream(val producer: () -> T?) : Stream { +public class FunctionStream(private val producer: () -> T?) : Stream { override fun iterator(): Iterator = object : AbstractIterator() { override fun computeNext() { diff --git a/libraries/stdlib/src/kotlin/collections/iterators/Iterators.kt b/libraries/stdlib/src/kotlin/collections/iterators/Iterators.kt index 474d6c8e1e6..c13f229124e 100644 --- a/libraries/stdlib/src/kotlin/collections/iterators/Iterators.kt +++ b/libraries/stdlib/src/kotlin/collections/iterators/Iterators.kt @@ -33,7 +33,8 @@ deprecated("Replace Iterator with Stream by using stream() function instea public fun Iterator.skip(n: Int): Iterator = SkippingIterator(this, n) deprecated("Use FilteringStream instead") -class FilterIterator(val iterator : Iterator, val predicate: (T)-> Boolean) : AbstractIterator() { +public class FilterIterator(private val iterator: Iterator, private val predicate: (T) -> Boolean) : + AbstractIterator() { override protected fun computeNext(): Unit { while (iterator.hasNext()) { val next = iterator.next() @@ -47,7 +48,7 @@ class FilterIterator(val iterator : Iterator, val predicate: (T)-> Boolean } deprecated("Use FilteringStream instead") -class FilterNotNullIterator(val iterator : Iterator?) : AbstractIterator() { +public class FilterNotNullIterator(private val iterator: Iterator?) : AbstractIterator() { override protected fun computeNext(): Unit { if (iterator != null) { while (iterator.hasNext()) { @@ -63,8 +64,9 @@ class FilterNotNullIterator(val iterator : Iterator?) : AbstractItera } deprecated("Use TransformingStream instead") -class MapIterator(val iterator : Iterator, val transform: (T) -> R) : AbstractIterator() { - override protected fun computeNext() : Unit { +public class MapIterator(private val iterator: Iterator, private val transform: (T) -> R) : + AbstractIterator() { + override protected fun computeNext(): Unit { if (iterator.hasNext()) { setNext((transform)(iterator.next())) } else { @@ -74,10 +76,11 @@ class MapIterator(val iterator : Iterator, val transform: (T) -> R) : A } deprecated("Use FlatteningStream instead") -class FlatMapIterator(val iterator : Iterator, val transform: (T) -> Iterator) : AbstractIterator() { - var transformed: Iterator = iterate { null } +public class FlatMapIterator(private val iterator: Iterator, private val transform: (T) -> Iterator) : + AbstractIterator() { + private var transformed: Iterator = iterate { null } - override protected fun computeNext() : Unit { + override protected fun computeNext(): Unit { while (true) { if (transformed.hasNext()) { setNext(transformed.next()) @@ -94,7 +97,8 @@ class FlatMapIterator(val iterator : Iterator, val transform: (T) -> It } deprecated("Use LimitedStream instead") -class TakeWhileIterator(val iterator: Iterator, val predicate: (T) -> Boolean) : AbstractIterator() { +public class TakeWhileIterator(private val iterator: Iterator, private val predicate: (T) -> Boolean) : + AbstractIterator() { override protected fun computeNext() : Unit { if (iterator.hasNext()) { val item = iterator.next() @@ -109,7 +113,7 @@ class TakeWhileIterator(val iterator: Iterator, val predicate: (T) -> Bool /** An [[Iterator]] which invokes a function to calculate the next value in the iteration until the function returns *null* */ deprecated("Use FunctionStream instead") -class FunctionIterator(val nextFunction: () -> T?): AbstractIterator() { +public class FunctionIterator(private val nextFunction: () -> T?) : AbstractIterator() { override protected fun computeNext(): Unit { val next = (nextFunction)() @@ -123,12 +127,12 @@ class FunctionIterator(val nextFunction: () -> T?): AbstractIterator() /** An [[Iterator]] which iterates over a number of iterators in sequence */ deprecated("Use Multistream instead") -fun CompositeIterator(vararg iterators: Iterator): CompositeIterator = CompositeIterator(iterators.iterator()) +public fun CompositeIterator(vararg iterators: Iterator): CompositeIterator = CompositeIterator(iterators.iterator()) deprecated("Use Multistream instead") -class CompositeIterator(val iterators: Iterator>): AbstractIterator() { +public class CompositeIterator(private val iterators: Iterator>) : AbstractIterator() { - var currentIter: Iterator? = null + private var currentIter: Iterator? = null override protected fun computeNext(): Unit { while (true) { @@ -155,8 +159,8 @@ class CompositeIterator(val iterators: Iterator>): AbstractIterat /** A singleton [[Iterator]] which invokes once over a value */ deprecated("Use streams for lazy collection operations.") -class SingleIterator(val value: T): AbstractIterator() { - var first = true +public class SingleIterator(private val value: T) : AbstractIterator() { + private var first = true override protected fun computeNext(): Unit { if (first) { @@ -169,8 +173,8 @@ class SingleIterator(val value: T): AbstractIterator() { } deprecated("Use streams for lazy collection operations.") -class IndexIterator(val iterator : Iterator): Iterator> { - private var index : Int = 0 +public class IndexIterator(private val iterator: Iterator) : Iterator> { + private var index: Int = 0 override fun next(): Pair { return Pair(index++, iterator.next()) @@ -183,7 +187,7 @@ class IndexIterator(val iterator : Iterator): Iterator> { deprecated("Use ZippingStream instead.") public class PairIterator( - val iterator1 : Iterator, val iterator2 : Iterator + private val iterator1: Iterator, private val iterator2: Iterator ): AbstractIterator>() { protected override fun computeNext() { if (iterator1.hasNext() && iterator2.hasNext()) { @@ -196,7 +200,7 @@ public class PairIterator( } deprecated("Use streams for lazy collection operations.") -class SkippingIterator(val iterator: Iterator, val n: Int): Iterator { +public class SkippingIterator(private val iterator: Iterator, private val n: Int) : Iterator { private var firstTime: Boolean = true private fun skip() { diff --git a/libraries/stdlib/src/kotlin/collections/iterators/IteratorsJVM.kt b/libraries/stdlib/src/kotlin/collections/iterators/IteratorsJVM.kt index 7340ec784d6..6970325a430 100644 --- a/libraries/stdlib/src/kotlin/collections/iterators/IteratorsJVM.kt +++ b/libraries/stdlib/src/kotlin/collections/iterators/IteratorsJVM.kt @@ -4,10 +4,11 @@ import kotlin.support.* /** Returns an iterator over elements that are instances of a given type *R* which is a subclass of *T* */ deprecated("Use streams for lazy collection operations.") -public fun Iterator.filterIsInstance(klass: Class): Iterator = FilterIsIterator(this, klass) +public fun Iterator.filterIsInstance(klass: Class): Iterator = FilterIsIterator(this, klass) deprecated("Use streams for lazy collection operations.") -private class FilterIsIterator(val iterator : Iterator, val klass: Class) : AbstractIterator() { +public class FilterIsIterator(private val iterator: Iterator, private val klass: Class) : + AbstractIterator() { override protected fun computeNext(): Unit { while (iterator.hasNext()) { val next = iterator.next() diff --git a/libraries/stdlib/src/kotlin/concurrent/FunctionalList.kt b/libraries/stdlib/src/kotlin/concurrent/FunctionalList.kt index ef0ff47d5a8..19797e8ad52 100644 --- a/libraries/stdlib/src/kotlin/concurrent/FunctionalList.kt +++ b/libraries/stdlib/src/kotlin/concurrent/FunctionalList.kt @@ -1,15 +1,15 @@ package kotlin.concurrent -abstract class FunctionalList(public val size: Int) { +public abstract class FunctionalList(public val size: Int) { public abstract val head: T public abstract val tail: FunctionalList - val empty : Boolean + public val empty: Boolean get() = size == 0 - public fun add(element: T) : FunctionalList = FunctionalList.Standard(element, this) + public fun add(element: T): FunctionalList = FunctionalList.Standard(element, this) - public fun reversed() : FunctionalList { + public fun reversed(): FunctionalList { if(empty) return this @@ -39,18 +39,18 @@ abstract class FunctionalList(public val size: Int) { } class object { - class Empty() : FunctionalList(0) { + private class Empty() : FunctionalList(0) { override val head: T - get() = throw java.util.NoSuchElementException() + get() = throw java.util.NoSuchElementException() override val tail: FunctionalList - get() = throw java.util.NoSuchElementException() + get() = throw java.util.NoSuchElementException() } - class Standard(override val head: T, override val tail: FunctionalList) : FunctionalList(tail.size+1) + private class Standard(override val head: T, override val tail: FunctionalList) : FunctionalList(tail.size + 1) - public fun emptyList() : FunctionalList = Empty() + public fun emptyList(): FunctionalList = Empty() - public fun of(element: T) : FunctionalList = FunctionalList.Standard(element,emptyList()) + public fun of(element: T): FunctionalList = FunctionalList.Standard(element, emptyList()) } } diff --git a/libraries/stdlib/src/kotlin/concurrent/FunctionalQueue.kt b/libraries/stdlib/src/kotlin/concurrent/FunctionalQueue.kt index 2d90e901e4d..33d3c18a822 100644 --- a/libraries/stdlib/src/kotlin/concurrent/FunctionalQueue.kt +++ b/libraries/stdlib/src/kotlin/concurrent/FunctionalQueue.kt @@ -2,28 +2,29 @@ package kotlin.concurrent import java.util.concurrent.Executor -class FunctionalQueue ( - val input: FunctionalList = FunctionalList.emptyList(), - val output: FunctionalList = FunctionalList.emptyList()) { +public class FunctionalQueue ( + private val input: FunctionalList = FunctionalList.emptyList(), + private val output: FunctionalList = FunctionalList.emptyList() +) { - val size : Int + public val size: Int get() = input.size + output.size - val empty : Boolean + public val empty: Boolean get() = size == 0 - public fun add(element: T) : FunctionalQueue = FunctionalQueue(input add element, output) + public fun add(element: T): FunctionalQueue = FunctionalQueue(input add element, output) - public fun addFirst(element: T) : FunctionalQueue = FunctionalQueue(input, output add element) + public fun addFirst(element: T): FunctionalQueue = FunctionalQueue(input, output add element) - public fun removeFirst() : Pair> = - if(output.empty) { - if(input.empty) - throw java.util.NoSuchElementException() - else - FunctionalQueue(FunctionalList.emptyList(), input.reversed()).removeFirst() - } - else { - Pair(output.head, FunctionalQueue(input, output.tail)) - } + public fun removeFirst(): Pair> = + if (output.empty) { + if (input.empty) + throw java.util.NoSuchElementException() + else + FunctionalQueue(FunctionalList.emptyList(), input.reversed()).removeFirst() + } + else { + Pair(output.head, FunctionalQueue(input, output.tail)) + } } diff --git a/libraries/stdlib/src/kotlin/concurrent/Locks.kt b/libraries/stdlib/src/kotlin/concurrent/Locks.kt index f7bc5914cf3..ac6ef86adb7 100644 --- a/libraries/stdlib/src/kotlin/concurrent/Locks.kt +++ b/libraries/stdlib/src/kotlin/concurrent/Locks.kt @@ -63,7 +63,7 @@ public inline fun ReentrantReadWriteLock.write([inlineOptions(ONLY_LOCAL_RET Execute given calculation and await for CountDownLatch Returns result of the calculation */ -fun Int.latch(op: CountDownLatch.() -> T) : T { +public fun Int.latch(op: CountDownLatch.() -> T): T { val cdl = CountDownLatch(this) val res = cdl.op() cdl.await() diff --git a/libraries/stdlib/src/kotlin/concurrent/Thread.kt b/libraries/stdlib/src/kotlin/concurrent/Thread.kt index 5cb2461f018..b00ae14389a 100644 --- a/libraries/stdlib/src/kotlin/concurrent/Thread.kt +++ b/libraries/stdlib/src/kotlin/concurrent/Thread.kt @@ -5,43 +5,43 @@ import java.util.concurrent.ExecutorService import java.util.concurrent.Future import java.util.concurrent.Callable -val currentThread : Thread +public val currentThread: Thread get() = Thread.currentThread() -var Thread.name : String +public var Thread.name: String get() = getName() set(name: String) { setName(name) } -var Thread.daemon : Boolean +public var Thread.daemon: Boolean get() = isDaemon() set(on: Boolean) { setDaemon(on) } -val Thread.alive : Boolean +public val Thread.alive: Boolean get() = isAlive() -var Thread.priority : Int +public var Thread.priority: Int get() = getPriority() set(prio: Int) { setPriority(prio) } -var Thread.contextClassLoader : ClassLoader? +public var Thread.contextClassLoader: ClassLoader? get() = getContextClassLoader() set(loader: ClassLoader?) { setContextClassLoader(loader) } -public fun thread(start: Boolean = true, daemon: Boolean = false, contextClassLoader: ClassLoader? = null, name: String? = null, priority: Int = -1, block: ()->Unit) : Thread { - val thread = object: Thread() { +public fun thread(start: Boolean = true, daemon: Boolean = false, contextClassLoader: ClassLoader? = null, name: String? = null, priority: Int = -1, block: () -> Unit): Thread { + val thread = object : Thread() { public override fun run() { block() } } - if(daemon) + if (daemon) thread.setDaemon(true) - if(priority > 0) + if (priority > 0) thread.setPriority(priority) - if(name != null) + if (name != null) thread.setName(name) - if(contextClassLoader != null) + if (contextClassLoader != null) thread.setContextClassLoader(contextClassLoader) - if(start) + if (start) thread.start() return thread } @@ -50,7 +50,7 @@ public fun thread(start: Boolean = true, daemon: Boolean = false, contextClassLo * Allows you to use the executor as a function to * execute the given block on the [[Executor]]. */ -public /*inline*/ fun Executor.invoke(action: ()->Unit) { +public /*inline*/ fun Executor.invoke(action: () -> Unit) { execute(runnable(action)) } @@ -58,6 +58,6 @@ public /*inline*/ fun Executor.invoke(action: ()->Unit) { * Allows you to use the executor as a function to * execute the given block on the [[Executor]]. */ -public /*inline*/ fun ExecutorService.invoke(action: ()->T):Future { +public /*inline*/ fun ExecutorService.invoke(action: () -> T): Future { return submit(action) } \ No newline at end of file diff --git a/libraries/stdlib/src/kotlin/dom/Dom.kt b/libraries/stdlib/src/kotlin/dom/Dom.kt index ffd4c2bb14a..7268068150a 100644 --- a/libraries/stdlib/src/kotlin/dom/Dom.kt +++ b/libraries/stdlib/src/kotlin/dom/Dom.kt @@ -13,15 +13,15 @@ import java.lang.IndexOutOfBoundsException private fun emptyElementList(): List = Collections.emptyList() private fun emptyNodeList(): List = Collections.emptyList() -var Node.text : String -get() { - return textContent -} -set(value) { - textContent = value -} +public var Node.text: String + get() { + return textContent + } + set(value) { + textContent = value + } -var Element.childrenText: String +public var Element.childrenText: String get() { val buffer = StringBuilder() val nodeList = this.childNodes @@ -49,77 +49,77 @@ var Element.childrenText: String element.addText(value) } -var Element.id : String -get() = this.getAttribute("id")?: "" -set(value) { - this.setAttribute("id", value) - this.setIdAttribute("id", true) -} +public var Element.id: String + get() = this.getAttribute("id") ?: "" + set(value) { + this.setAttribute("id", value) + this.setIdAttribute("id", true) + } -var Element.style : String -get() = this.getAttribute("style")?: "" -set(value) { - this.setAttribute("style", value) -} +public var Element.style: String + get() = this.getAttribute("style") ?: "" + set(value) { + this.setAttribute("style", value) + } -var Element.classes : String -get() = this.getAttribute("class")?: "" -set(value) { - this.setAttribute("class", value) -} +public var Element.classes: String + get() = this.getAttribute("class") ?: "" + set(value) { + this.setAttribute("class", value) + } /** Returns true if the element has the given CSS class style in its 'class' attribute */ -fun Element.hasClass(cssClass: String): Boolean { +public fun Element.hasClass(cssClass: String): Boolean { val c = this.classes return c.matches("""(^|.*\s+)$cssClass($|\s+.*)""") } /** Returns the children of the element as a list */ -fun Element?.children(): List { +public fun Element?.children(): List { return this?.childNodes.toList() } /** Returns the child elements of this element */ -fun Element?.childElements(): List { +public fun Element?.childElements(): List { return children().filter{ it.nodeType == Node.ELEMENT_NODE }.map { it as Element } } /** Returns the child elements of this element with the given name */ -fun Element?.childElements(name: String): List { +public fun Element?.childElements(name: String): List { return children().filter{ it.nodeType == Node.ELEMENT_NODE && it.nodeName == name }.map { it as Element } } /** The descendent elements of this document */ -val Document?.elements : List -get() = this?.getElementsByTagName("*").toElementList() +public val Document?.elements: List + get() = this?.getElementsByTagName("*").toElementList() /** The descendant elements of this elements */ -val Element?.elements : List -get() = this?.getElementsByTagName("*").toElementList() +public val Element?.elements: List + get() = this?.getElementsByTagName("*").toElementList() /** Returns all the descendant elements given the local element name */ -fun Element?.elements(localName: String): List { +public fun Element?.elements(localName: String): List { return this?.getElementsByTagName(localName).toElementList() } /** Returns all the descendant elements given the local element name */ -fun Document?.elements(localName: String): List { +public fun Document?.elements(localName: String): List { return this?.getElementsByTagName(localName).toElementList() } /** Returns all the descendant elements given the namespace URI and local element name */ -fun Element?.elements(namespaceUri: String, localName: String): List { +public fun Element?.elements(namespaceUri: String, localName: String): List { return this?.getElementsByTagNameNS(namespaceUri, localName).toElementList() } /** Returns all the descendant elements given the namespace URI and local element name */ -fun Document?.elements(namespaceUri: String, localName: String): List { +public fun Document?.elements(namespaceUri: String, localName: String): List { return this?.getElementsByTagNameNS(namespaceUri, localName).toElementList() } -fun NodeList?.toList(): List { +public fun NodeList?.toList(): List { return if (this == null) { // TODO the following is easier to convert to JS emptyNodeList() @@ -129,7 +129,7 @@ fun NodeList?.toList(): List { } } -fun NodeList?.toElementList(): List { +public fun NodeList?.toElementList(): List { return if (this == null) { // TODO the following is easier to convert to JS //emptyElementList() @@ -141,7 +141,7 @@ fun NodeList?.toElementList(): List { } /** Searches for elements using the element name, an element ID (if prefixed with dot) or element class (if prefixed with #) */ -fun Document?.get(selector: String): List { +public fun Document?.get(selector: String): List { val root = this?.documentElement return if (root != null) { if (selector == "*") { @@ -165,7 +165,7 @@ fun Document?.get(selector: String): List { } /** Searches for elements using the element name, an element ID (if prefixed with dot) or element class (if prefixed with #) */ -fun Element.get(selector: String): List { +public fun Element.get(selector: String): List { return if (selector == "*") { elements } else if (selector.startsWith(".")) { @@ -216,7 +216,7 @@ fun Element.removeClass(varargs cssClasses: Array): Boolean { } */ -class NodeListAsList(val nodeList: NodeList): AbstractList() { +private class NodeListAsList(private val nodeList: NodeList) : AbstractList() { override fun get(index: Int): Node { val node = nodeList.item(index) if (node == null) { @@ -229,7 +229,7 @@ class NodeListAsList(val nodeList: NodeList): AbstractList() { override fun size(): Int = nodeList.length } -class ElementListAsList(val nodeList: NodeList): AbstractList() { +private class ElementListAsList(private val nodeList: NodeList) : AbstractList() { override fun get(index: Int): Element { val node = nodeList.item(index) if (node == null) { @@ -246,7 +246,7 @@ class ElementListAsList(val nodeList: NodeList): AbstractList() { } /** Removes all the children from this node */ -fun Node.clear(): Unit { +public fun Node.clear(): Unit { while (true) { val child = firstChild if (child == null) { @@ -258,9 +258,9 @@ fun Node.clear(): Unit { } /** Returns an [[Iterator]] over the next siblings of this node */ -fun Node.nextSiblings() : Iterable = NextSiblings(this) +public fun Node.nextSiblings(): Iterable = NextSiblings(this) -class NextSiblings(var node: Node) : Iterable { +private class NextSiblings(private var node: Node) : Iterable { override fun iterator(): Iterator = object : AbstractIterator() { override fun computeNext(): Unit { val nextValue = node.nextSibling @@ -275,9 +275,9 @@ class NextSiblings(var node: Node) : Iterable { } /** Returns an [[Iterator]] over the next siblings of this node */ -fun Node.previousSiblings() : Iterable = PreviousSiblings(this) +public fun Node.previousSiblings(): Iterable = PreviousSiblings(this) -class PreviousSiblings(var node: Node) : Iterable { +private class PreviousSiblings(private var node: Node) : Iterable { override fun iterator(): Iterator = object : AbstractIterator() { override fun computeNext(): Unit { val nextValue = node.previousSibling @@ -292,38 +292,39 @@ class PreviousSiblings(var node: Node) : Iterable { } /** Returns true if this node is a Text node or a CDATA node */ -fun Node.isText(): Boolean { +public fun Node.isText(): Boolean { val nt = nodeType return nt == Node.TEXT_NODE || nt == Node.CDATA_SECTION_NODE } /** Returns the attribute value or empty string if its not present */ -fun Element.attribute(name: String): String { +public fun Element.attribute(name: String): String { return this.getAttribute(name) ?: "" } -val NodeList?.head : Node? -get() = if (this != null && this.length > 0) this.item(0) else null +public val NodeList?.head: Node? + get() = if (this != null && this.length > 0) this.item(0) else null -val NodeList?.first : Node? -get() = this.head +public val NodeList?.first: Node? + get() = this.head -val NodeList?.tail : Node? -get() { - if (this == null) { - return null - } else { - val s = this.length - return if (s > 0) this.item(s - 1) else null +public val NodeList?.tail: Node? + get() { + if (this == null) { + return null + } + else { + val s = this.length + return if (s > 0) this.item(s - 1) else null + } } -} -val NodeList?.last : Node? -get() = this.tail +public val NodeList?.last: Node? + get() = this.tail /** Converts the node list to an XML String */ -fun NodeList?.toXmlString(xmlDeclaration: Boolean = false): String { +public fun NodeList?.toXmlString(xmlDeclaration: Boolean = false): String { return if (this == null) "" else { nodesToXmlString(this.toList(), xmlDeclaration) @@ -343,16 +344,16 @@ public fun nodesToXmlString(nodes: Iterable, xmlDeclaration: Boolean = fal // Syntax sugar -fun Node.plus(child: Node?): Node { +public fun Node.plus(child: Node?): Node { if (child != null) { this.appendChild(child) } return this } -fun Element.plus(text: String?): Element = this.addText(text) +public fun Element.plus(text: String?): Element = this.addText(text) -fun Element.plusAssign(text: String?): Element = this.addText(text) +public fun Element.plusAssign(text: String?): Element = this.addText(text) // Builder @@ -360,7 +361,7 @@ fun Element.plusAssign(text: String?): Element = this.addText(text) /** * Creates a new element which can be configured via a function */ -fun Document.createElement(name: String, init: Element.()-> Unit): Element { +public fun Document.createElement(name: String, init: Element.() -> Unit): Element { val elem = this.createElement(name)!! elem.init() return elem @@ -369,14 +370,14 @@ fun Document.createElement(name: String, init: Element.()-> Unit): Element { /** * Creates a new element to an element which has an owner Document which can be configured via a function */ -fun Element.createElement(name: String, doc: Document? = null, init: Element.()-> Unit): Element { +public fun Element.createElement(name: String, doc: Document? = null, init: Element.() -> Unit): Element { val elem = ownerDocument(doc).createElement(name)!! elem.init() return elem } /** Returns the owner document of the element or uses the provided document */ -fun Node.ownerDocument(doc: Document? = null): Document { +public fun Node.ownerDocument(doc: Document? = null): Document { val answer = if (this.nodeType == Node.DOCUMENT_NODE) this as Document else if (doc == null) this.ownerDocument else doc @@ -391,7 +392,7 @@ fun Node.ownerDocument(doc: Document? = null): Document { /** Adds a newly created element which can be configured via a function */ -fun Document.addElement(name: String, init: Element.()-> Unit): Element { +public fun Document.addElement(name: String, init: Element.() -> Unit): Element { val child = createElement(name, init) this.appendChild(child) return child @@ -400,7 +401,7 @@ fun Document.addElement(name: String, init: Element.()-> Unit): Element { /** Adds a newly created element to an element which has an owner Document which can be configured via a function */ -fun Element.addElement(name: String, doc: Document? = null, init: Element.()-> Unit): Element { +public fun Element.addElement(name: String, doc: Document? = null, init: Element.() -> Unit): Element { val child = createElement(name, doc, init) this.appendChild(child) return child @@ -409,7 +410,7 @@ fun Element.addElement(name: String, doc: Document? = null, init: Element.()-> U /** Adds a newly created text node to an element which either already has an owner Document or one must be provided as a parameter */ -fun Element.addText(text: String?, doc: Document? = null): Element { +public fun Element.addText(text: String?, doc: Document? = null): Element { if (text != null) { val child = this.ownerDocument(doc).createTextNode(text)!! this.appendChild(child) diff --git a/libraries/stdlib/src/kotlin/dom/DomEvents.kt b/libraries/stdlib/src/kotlin/dom/DomEvents.kt index 1db2b63f9f5..9a16c460ceb 100644 --- a/libraries/stdlib/src/kotlin/dom/DomEvents.kt +++ b/libraries/stdlib/src/kotlin/dom/DomEvents.kt @@ -7,11 +7,11 @@ import org.w3c.dom.events.* /** * Turns an event handler function into an [EventListener] */ -fun eventHandler(handler: (Event) -> Unit): EventListener { +public fun eventHandler(handler: (Event) -> Unit): EventListener { return EventListenerHandler(handler) } -private class EventListenerHandler(val handler: (Event) -> Unit): EventListener { +private class EventListenerHandler(private val handler: (Event) -> Unit) : EventListener { public override fun handleEvent(e: Event) { if (e != null) { handler(e) @@ -24,7 +24,7 @@ private class EventListenerHandler(val handler: (Event) -> Unit): EventListener */ } -fun mouseEventHandler(handler: (MouseEvent) -> Unit): EventListener { +public fun mouseEventHandler(handler: (MouseEvent) -> Unit): EventListener { return eventHandler { e -> if (e is MouseEvent) { handler(e) @@ -51,7 +51,12 @@ public fun Node?.on(name: String, capture: Boolean, listener: EventListener): Cl } } -private class CloseableEventListener(val target: EventTarget, val listener: EventListener, val name: String, val capture: Boolean): Closeable { +private class CloseableEventListener( + private val target: EventTarget, + private val listener: EventListener, + private val name: String, + private val capture: Boolean +) : Closeable { public override fun close() { target.removeEventListener(name, listener, capture) } diff --git a/libraries/stdlib/src/kotlin/dom/DomEventsJVM.kt b/libraries/stdlib/src/kotlin/dom/DomEventsJVM.kt index b978f47c77f..8db6d0f2c4a 100644 --- a/libraries/stdlib/src/kotlin/dom/DomEventsJVM.kt +++ b/libraries/stdlib/src/kotlin/dom/DomEventsJVM.kt @@ -4,55 +4,55 @@ import org.w3c.dom.Node import org.w3c.dom.events.* // JavaScript style properties for JVM : TODO could auto-generate these -val Event.bubbles: Boolean +public val Event.bubbles: Boolean get() = getBubbles() -val Event.cancelable: Boolean +public val Event.cancelable: Boolean get() = getCancelable() -val Event.getCurrentTarget: EventTarget? +public val Event.getCurrentTarget: EventTarget? get() = getCurrentTarget() -val Event.eventPhase: Short +public val Event.eventPhase: Short get() = getEventPhase() -val Event.target: EventTarget? +public val Event.target: EventTarget? get() = getTarget() -val Event.timeStamp: Long +public val Event.timeStamp: Long get() = getTimeStamp() // TODO we can't use 'type' as the property name in Kotlin so we should fix it in JS -val Event.eventType: String +public val Event.eventType: String get() = getType()!! -val MouseEvent.altKey: Boolean +public val MouseEvent.altKey: Boolean get() = getAltKey() -val MouseEvent.button: Short +public val MouseEvent.button: Short get() = getButton() -val MouseEvent.clientX: Int +public val MouseEvent.clientX: Int get() = getClientX() -val MouseEvent.clientY: Int +public val MouseEvent.clientY: Int get() = getClientY() -val MouseEvent.ctrlKey: Boolean +public val MouseEvent.ctrlKey: Boolean get() = getCtrlKey() -val MouseEvent.metaKey: Boolean +public val MouseEvent.metaKey: Boolean get() = getMetaKey() -val MouseEvent.relatedTarget: EventTarget? +public val MouseEvent.relatedTarget: EventTarget? get() = getRelatedTarget() -val MouseEvent.screenX: Int +public val MouseEvent.screenX: Int get() = getScreenX() -val MouseEvent.screenY: Int +public val MouseEvent.screenY: Int get() = getScreenY() -val MouseEvent.shiftKey: Boolean +public val MouseEvent.shiftKey: Boolean get() = getShiftKey() diff --git a/libraries/stdlib/src/kotlin/dom/DomJVM.kt b/libraries/stdlib/src/kotlin/dom/DomJVM.kt index 1e40f5cf289..d826b56b709 100644 --- a/libraries/stdlib/src/kotlin/dom/DomJVM.kt +++ b/libraries/stdlib/src/kotlin/dom/DomJVM.kt @@ -20,121 +20,121 @@ import org.w3c.dom.* import org.xml.sax.InputSource // JavaScript style properties - TODO could auto-generate these -val Node.nodeName: String -get() = getNodeName() ?: "" +public val Node.nodeName: String + get() = getNodeName() ?: "" -val Node.nodeValue: String -get() = getNodeValue() ?: "" +public val Node.nodeValue: String + get() = getNodeValue() ?: "" -val Node.nodeType: Short -get() = getNodeType() +public val Node.nodeType: Short + get() = getNodeType() -val Node.parentNode: Node? -get() = getParentNode() +public val Node.parentNode: Node? + get() = getParentNode() -val Node.childNodes: NodeList -get() = getChildNodes()!! +public val Node.childNodes: NodeList + get() = getChildNodes()!! -val Node.firstChild: Node? -get() = getFirstChild() +public val Node.firstChild: Node? + get() = getFirstChild() -val Node.lastChild: Node? -get() = getLastChild() +public val Node.lastChild: Node? + get() = getLastChild() -val Node.nextSibling: Node? -get() = getNextSibling() +public val Node.nextSibling: Node? + get() = getNextSibling() -val Node.previousSibling: Node? -get() = getPreviousSibling() +public val Node.previousSibling: Node? + get() = getPreviousSibling() -val Node.attributes: NamedNodeMap? -get() = getAttributes() +public val Node.attributes: NamedNodeMap? + get() = getAttributes() -val Node.ownerDocument: Document? -get() = getOwnerDocument() +public val Node.ownerDocument: Document? + get() = getOwnerDocument() -val Document.documentElement: Element? -get() = this.getDocumentElement() +public val Document.documentElement: Element? + get() = this.getDocumentElement() -val Node.namespaceURI: String -get() = getNamespaceURI() ?: "" +public val Node.namespaceURI: String + get() = getNamespaceURI() ?: "" -val Node.prefix: String -get() = getPrefix() ?: "" +public val Node.prefix: String + get() = getPrefix() ?: "" -val Node.localName: String -get() = getLocalName() ?: "" +public val Node.localName: String + get() = getLocalName() ?: "" -val Node.baseURI: String -get() = getBaseURI() ?: "" +public val Node.baseURI: String + get() = getBaseURI() ?: "" -var Node.textContent: String -get() = getTextContent() ?: "" -set(value) { - setTextContent(value) -} +public var Node.textContent: String + get() = getTextContent() ?: "" + set(value) { + setTextContent(value) + } -val DOMStringList.length: Int -get() = this.getLength() +public val DOMStringList.length: Int + get() = this.getLength() -val NameList.length: Int -get() = this.getLength() +public val NameList.length: Int + get() = this.getLength() -val DOMImplementationList.length: Int -get() = this.getLength() +public val DOMImplementationList.length: Int + get() = this.getLength() -val NodeList.length: Int -get() = this.getLength() +public val NodeList.length: Int + get() = this.getLength() -val CharacterData.length: Int -get() = this.getLength() +public val CharacterData.length: Int + get() = this.getLength() -val NamedNodeMap.length: Int -get() = this.getLength() +public val NamedNodeMap.length: Int + get() = this.getLength() /** * Returns the HTML representation of the node */ public val Node.outerHTML: String -get() = toXmlString() + get() = toXmlString() /** * Returns the HTML representation of the node */ public val Node.innerHTML: String -get() = childNodes.outerHTML + get() = childNodes.outerHTML /** * Returns the HTML representation of the nodes */ public val NodeList.outerHTML: String -get() = toList().map { it.innerHTML }.join("") + get() = toList().map { it.innerHTML }.join("") /** Returns an [[Iterator]] of all the next [[Element]] siblings */ -fun Node.nextElements(): List = nextSiblings().filterIsInstance(javaClass()) +public fun Node.nextElements(): List = nextSiblings().filterIsInstance(javaClass()) /** Returns an [[Iterator]] of all the previous [[Element]] siblings */ -fun Node.previousElements(): List = previousSiblings().filterIsInstance(javaClass()) +public fun Node.previousElements(): List = previousSiblings().filterIsInstance(javaClass()) -var Element.classSet : MutableSet -get() { - val answer = LinkedHashSet() - val array = this.classes.split("""\s""") - for (s in array) { - if (s.size > 0) { - answer.add(s) +public var Element.classSet: MutableSet + get() { + val answer = LinkedHashSet() + val array = this.classes.split("""\s""") + for (s in array) { + if (s.size > 0) { + answer.add(s) + } } + return answer + } + set(value) { + this.classes = value.join(" ") } - return answer -} -set(value) { - this.classes = value.join(" ") -} /** Adds the given CSS class to this element's 'class' attribute */ -fun Element.addClass(cssClass: String): Boolean { +public fun Element.addClass(cssClass: String): Boolean { val classSet = this.classSet val answer = classSet.add(cssClass) if (answer) { @@ -144,7 +144,7 @@ fun Element.addClass(cssClass: String): Boolean { } /** Removes the given CSS class to this element's 'class' attribute */ -fun Element.removeClass(cssClass: String): Boolean { +public fun Element.removeClass(cssClass: String): Boolean { val classSet = this.classSet val answer = classSet.remove(cssClass) if (answer) { @@ -154,7 +154,6 @@ fun Element.removeClass(cssClass: String): Boolean { } - /** Creates a new document with the given document builder*/ public fun createDocument(builder: DocumentBuilder): Document { return builder.newDocument()!! diff --git a/libraries/stdlib/src/kotlin/io/Files.kt b/libraries/stdlib/src/kotlin/io/Files.kt index 9b872f267b5..4fa2e65fee4 100644 --- a/libraries/stdlib/src/kotlin/io/Files.kt +++ b/libraries/stdlib/src/kotlin/io/Files.kt @@ -23,40 +23,41 @@ public fun File.recurse(block: (File) -> Unit): Unit { /** * Returns this if the file is a directory or the parent if its a file inside a directory */ -val File.directory: File -get() = if (this.isDirectory()) this else this.getParentFile()!! +public val File.directory: File + get() = if (this.isDirectory()) this else this.getParentFile()!! /** * Returns the canonical path of the file */ -val File.canonicalPath: String -get() = getCanonicalPath() +public val File.canonicalPath: String + get() = getCanonicalPath() /** * Returns the file name or "" for an empty name */ -val File.name: String -get() = getName() +public val File.name: String + get() = getName() /** * Returns the file path or "" for an empty name */ -val File.path: String -get() = getPath() +public val File.path: String + get() = getPath() /** * Returns true if the file ends with the given extension */ -val File.extension: String -get() { - val text = this.name - val idx = text.lastIndexOf('.') - return if (idx >= 0) { - text.substring(idx + 1) - } else { - "" +public val File.extension: String + get() { + val text = this.name + val idx = text.lastIndexOf('.') + return if (idx >= 0) { + text.substring(idx + 1) + } + else { + "" + } } -} /** * Returns true if the given file is in the same directory or a descendant directory @@ -168,7 +169,7 @@ public fun File.copyTo(file: File, bufferSize: Int = defaultBufferSize): Long { * * You can use this function for huge files */ -fun File.forEachBlock(closure : (ByteArray, Int) -> Unit) : Unit { +public fun File.forEachBlock(closure: (ByteArray, Int) -> Unit): Unit { val arr = ByteArray(4096) val fis = FileInputStream(this) @@ -191,7 +192,7 @@ fun File.forEachBlock(closure : (ByteArray, Int) -> Unit) : Unit { * * You may use this function on huge files */ -fun File.forEachLine (charset : String = "UTF-8", closure : (line : String) -> Unit) : Unit { +public fun File.forEachLine(charset: String = "UTF-8", closure: (line: String) -> Unit): Unit { val reader = BufferedReader(InputStreamReader(FileInputStream(this), charset)) try { reader.forEachLine(closure) @@ -205,7 +206,7 @@ fun File.forEachLine (charset : String = "UTF-8", closure : (line : String) -> U * * Do not use this function for huge files. */ -fun File.readLines(charset : String = "UTF-8") : List { +public fun File.readLines(charset: String = "UTF-8"): List { val rs = ArrayList() this.forEachLine(charset) { (line : String) : Unit -> @@ -218,7 +219,7 @@ fun File.readLines(charset : String = "UTF-8") : List { /** * Returns an array of files and directories in the directory that satisfy the specified filter. */ -fun File.listFiles(filter : (file : File) -> Boolean) : Array? = listFiles( +public fun File.listFiles(filter: (file: File) -> Boolean): Array? = listFiles( object : FileFilter { override fun accept(file: File) = filter(file) } diff --git a/libraries/stdlib/src/kotlin/io/JIO.kt b/libraries/stdlib/src/kotlin/io/JIO.kt index 42bb6d35618..5faf8f73587 100644 --- a/libraries/stdlib/src/kotlin/io/JIO.kt +++ b/libraries/stdlib/src/kotlin/io/JIO.kt @@ -215,7 +215,7 @@ public fun BufferedReader.lines(): Stream = LinesStream(this) deprecated("Use lines() function which returns Stream") public fun BufferedReader.lineIterator(): Iterator = lines().iterator() -class LinesStream(val reader: BufferedReader) : Stream { +private class LinesStream(private val reader: BufferedReader) : Stream { override fun iterator(): Iterator { return object : Iterator { private var nextValue: String? = null diff --git a/libraries/stdlib/src/kotlin/modules/AllModules.kt b/libraries/stdlib/src/kotlin/modules/AllModules.kt index 9fe91187dc5..e441c7f5807 100644 --- a/libraries/stdlib/src/kotlin/modules/AllModules.kt +++ b/libraries/stdlib/src/kotlin/modules/AllModules.kt @@ -2,6 +2,6 @@ package kotlin.modules import java.util.ArrayList -object AllModules : ThreadLocal>() { +public object AllModules : ThreadLocal>() { override fun initialValue() = ArrayList() } diff --git a/libraries/stdlib/src/kotlin/modules/ModuleBuilder.kt b/libraries/stdlib/src/kotlin/modules/ModuleBuilder.kt index df57c732ab8..9a93f324446 100644 --- a/libraries/stdlib/src/kotlin/modules/ModuleBuilder.kt +++ b/libraries/stdlib/src/kotlin/modules/ModuleBuilder.kt @@ -8,38 +8,38 @@ public fun module(name: String, outputDir: String, callback: ModuleBuilder.() -> AllModules.get()?.add(builder) } -class SourcesBuilder(val parent: ModuleBuilder) { +public class SourcesBuilder(private val parent: ModuleBuilder) { public fun plusAssign(pattern: String) { parent.addSourceFiles(pattern) } } -class ClasspathBuilder(val parent: ModuleBuilder) { +public class ClasspathBuilder(private val parent: ModuleBuilder) { public fun plusAssign(name: String) { parent.addClasspathEntry(name) } } -class AnnotationsPathBuilder(val parent: ModuleBuilder) { +public class AnnotationsPathBuilder(private val parent: ModuleBuilder) { public fun plusAssign(name: String) { parent.addAnnotationsPathEntry(name) } } -open class ModuleBuilder(val name: String, val outputDir: String): Module { +public open class ModuleBuilder(private val name: String, private val outputDir: String) : Module { // http://youtrack.jetbrains.net/issue/KT-904 private val sourceFiles0 = ArrayList() private val classpathRoots0 = ArrayList() private val annotationsRoots0 = ArrayList() - val sources: SourcesBuilder - get() = SourcesBuilder(this) + public val sources: SourcesBuilder + get() = SourcesBuilder(this) - val classpath: ClasspathBuilder - get() = ClasspathBuilder(this) + public val classpath: ClasspathBuilder + get() = ClasspathBuilder(this) - val annotationsPath: AnnotationsPathBuilder - get() = AnnotationsPathBuilder(this) + public val annotationsPath: AnnotationsPathBuilder + get() = AnnotationsPathBuilder(this) public fun addSourceFiles(pattern: String) { sourceFiles0.add(pattern) diff --git a/libraries/stdlib/src/kotlin/platform/annotations.kt b/libraries/stdlib/src/kotlin/platform/annotations.kt index a3759935b7c..1eb961566c2 100644 --- a/libraries/stdlib/src/kotlin/platform/annotations.kt +++ b/libraries/stdlib/src/kotlin/platform/annotations.kt @@ -16,4 +16,4 @@ package kotlin.platform -public annotation class platformName(val name: String) \ No newline at end of file +public annotation class platformName(public val name: String) \ No newline at end of file diff --git a/libraries/stdlib/src/kotlin/properties/Delegation.kt b/libraries/stdlib/src/kotlin/properties/Delegation.kt index d2c3d420356..233208189d9 100644 --- a/libraries/stdlib/src/kotlin/properties/Delegation.kt +++ b/libraries/stdlib/src/kotlin/properties/Delegation.kt @@ -50,7 +50,9 @@ private class NotNullVar() : ReadWriteProperty { } } -class ObservableProperty(initialValue: T, val onChange: (name: PropertyMetadata, oldValue: T, newValue: T) -> Boolean): ReadWriteProperty { +public class ObservableProperty( + initialValue: T, private val onChange: (name: PropertyMetadata, oldValue: T, newValue: T) -> Boolean +) : ReadWriteProperty { private var value = initialValue public override fun get(thisRef: Any?, desc: PropertyMetadata): T { diff --git a/libraries/stdlib/src/kotlin/properties/Properties.kt b/libraries/stdlib/src/kotlin/properties/Properties.kt index dc072d2cd06..39cbf83e278 100644 --- a/libraries/stdlib/src/kotlin/properties/Properties.kt +++ b/libraries/stdlib/src/kotlin/properties/Properties.kt @@ -3,7 +3,12 @@ package kotlin.properties import java.util.HashMap import java.util.ArrayList -public class ChangeEvent(val source: Any, val name: String, val oldValue: Any?, val newValue: Any?) { +public class ChangeEvent( + public val source: Any, + public val name: String, + public val oldValue: Any?, + public val newValue: Any? +) { var propogationId: Any? = null override fun toString(): String = "ChangeEvent($name, $oldValue, $newValue)" diff --git a/libraries/stdlib/src/kotlin/template/Templates.kt b/libraries/stdlib/src/kotlin/template/Templates.kt index 8e90cb52a6b..f0890bf0c7f 100644 --- a/libraries/stdlib/src/kotlin/template/Templates.kt +++ b/libraries/stdlib/src/kotlin/template/Templates.kt @@ -10,21 +10,21 @@ import java.util.Date // TODO this class should move into the runtime // in kotlin.StringTemplate -class StringTemplate(val values : Array) { +public class StringTemplate(private val values: Array) { /** * Converts the template into a String */ - override fun toString() : String { + override fun toString(): String { val out = StringBuilder() - forEach{ out.append(it) } + forEach { out.append(it) } return out.toString() } /** * Performs the given function on each value in the collection */ - public fun forEach(fn : (Any?) -> Unit) : Unit { + public fun forEach(fn: (Any?) -> Unit): Unit { for (v in values) { fn(v) } @@ -38,7 +38,7 @@ class StringTemplate(val values : Array) { * * See [[HtmlFormatter] and [[LocaleFormatter] respectively. */ -public fun StringTemplate.toString(formatter : Formatter) : String { +public fun StringTemplate.toString(formatter: Formatter): String { val buffer = StringBuilder() append(buffer, formatter) return buffer.toString() @@ -48,7 +48,7 @@ public fun StringTemplate.toString(formatter : Formatter) : String { * Appends the text representation of this string template to the given output * using the supplied formatter */ -public fun StringTemplate.append(out : Appendable, formatter : Formatter) : Unit { +public fun StringTemplate.append(out: Appendable, formatter: Formatter): Unit { var constantText = true this.forEach { if (constantText) { @@ -69,12 +69,12 @@ public fun StringTemplate.append(out : Appendable, formatter : Formatter) : Unit * Converts this string template to internationalised text using the supplied * [[LocaleFormatter]] */ -public fun StringTemplate.toLocale(formatter : LocaleFormatter = LocaleFormatter()) : String = toString(formatter) +public fun StringTemplate.toLocale(formatter: LocaleFormatter = LocaleFormatter()): String = toString(formatter) /** * Converts this string template to HTML text */ -public fun StringTemplate.toHtml(formatter : HtmlFormatter = HtmlFormatter()) : String = toString(formatter) +public fun StringTemplate.toHtml(formatter: HtmlFormatter = HtmlFormatter()): String = toString(formatter) /** * Represents a formatter and encoder of values in a [[StringTemplate]] which understands @@ -82,7 +82,7 @@ public fun StringTemplate.toHtml(formatter : HtmlFormatter = HtmlFormatter()) : * to escape particular characters in different output formats such as [[HtmlFormatter] */ public trait Formatter { - public fun format(buffer : Appendable, value : Any?) : Unit + public fun format(buffer: Appendable, value: Any?): Unit } /** @@ -91,11 +91,11 @@ public trait Formatter { */ public open class ToStringFormatter : Formatter { - var nullString : String = "null" + private val nullString: String = "null" - override fun toString() : String = "ToStringFormatter" + override fun toString(): String = "ToStringFormatter" - public override fun format(out : Appendable, value : Any?) { + public override fun format(out: Appendable, value: Any?) { if (value == null) { format(out, nullString) } else if (value is StringTemplate) { @@ -109,25 +109,25 @@ public open class ToStringFormatter : Formatter { * Formats the given string allowing derived classes to override this method * to escape strings with special characters such as for HTML */ - public open fun format(out : Appendable, text : String) : Unit { + public open fun format(out: Appendable, text: String): Unit { out.append(text) } } -public val defaultLocale : Locale = Locale.getDefault() +public val defaultLocale: Locale = Locale.getDefault() /** * Formats values using a given [[Locale]] for internationalisation */ -public open class LocaleFormatter(val locale : Locale = defaultLocale) : ToStringFormatter() { +public open class LocaleFormatter(protected val locale: Locale = defaultLocale) : ToStringFormatter() { - override fun toString() : String = "LocaleFormatter{$locale}" + override fun toString(): String = "LocaleFormatter{$locale}" - public var numberFormat : NumberFormat = NumberFormat.getInstance(locale)!! + public var numberFormat: NumberFormat = NumberFormat.getInstance(locale)!! - public var dateFormat : DateFormat = DateFormat.getDateTimeInstance(DateFormat.DEFAULT, DateFormat.DEFAULT, locale)!! + public var dateFormat: DateFormat = DateFormat.getDateTimeInstance(DateFormat.DEFAULT, DateFormat.DEFAULT, locale)!! - public override fun format(out : Appendable, value : Any?) { + public override fun format(out: Appendable, value: Any?) { if (value is Number) { format(out, format(value)) } else if (value is Date) { @@ -137,11 +137,11 @@ public open class LocaleFormatter(val locale : Locale = defaultLocale) : ToStrin } } - public fun format(number : Number) : String { + public fun format(number: Number): String { return numberFormat.format(number) ?: "" } - public fun format(date : Date) : String { + public fun format(date: Date): String { return dateFormat.format(date) ?: "" } } @@ -149,11 +149,11 @@ public open class LocaleFormatter(val locale : Locale = defaultLocale) : ToStrin /** * Formats values for HTML encoding, escaping special characters in HTML. */ -public class HtmlFormatter(locale : Locale = defaultLocale) : LocaleFormatter(locale) { +public class HtmlFormatter(locale: Locale = defaultLocale) : LocaleFormatter(locale) { - override fun toString() : String = "HtmlFormatter{$locale}" + override fun toString(): String = "HtmlFormatter{$locale}" - public override fun format(out : Appendable, value : Any?) { + public override fun format(out: Appendable, value: Any?) { if (value is Node) { out.append(value.toXmlString()) } else { @@ -161,7 +161,7 @@ public class HtmlFormatter(locale : Locale = defaultLocale) : LocaleFormatter(lo } } - public override fun format(buffer : Appendable, text : String) : Unit { + public override fun format(buffer: Appendable, text: String): Unit { for (c in text) { if (c == '<') buffer.append("<") else if (c == '>') buffer.append(">") diff --git a/libraries/stdlib/src/kotlin/test/TestJVM.kt b/libraries/stdlib/src/kotlin/test/TestJVM.kt index 5547c8dd8ec..3e05ff64670 100644 --- a/libraries/stdlib/src/kotlin/test/TestJVM.kt +++ b/libraries/stdlib/src/kotlin/test/TestJVM.kt @@ -53,7 +53,7 @@ public var asserter: Asserter /** * Default implementation to avoid dependency on JUnit or TestNG */ -class DefaultAsserter() : Asserter { +private class DefaultAsserter() : Asserter { public override fun assertTrue(message : String, actual : Boolean) { if (!actual) { diff --git a/libraries/stdlib/src/kotlin/text/StringBuilderJVM.kt b/libraries/stdlib/src/kotlin/text/StringBuilderJVM.kt index 54a1f1e936c..e482656458b 100644 --- a/libraries/stdlib/src/kotlin/text/StringBuilderJVM.kt +++ b/libraries/stdlib/src/kotlin/text/StringBuilderJVM.kt @@ -3,7 +3,7 @@ package kotlin import kotlin.properties.* /** Line separator for current system. */ -val LINE_SEPARATOR: String by Delegates.lazy { System.getProperty("line.separator")!! } +private val LINE_SEPARATOR: String by Delegates.lazy { System.getProperty("line.separator")!! } /** Appends line separator to Appendable. */ public fun Appendable.appendln(): Appendable = append(LINE_SEPARATOR) diff --git a/libraries/stdlib/src/kotlin/text/StringsJVM.kt b/libraries/stdlib/src/kotlin/text/StringsJVM.kt index a0011d3d1ad..0946e803eb8 100644 --- a/libraries/stdlib/src/kotlin/text/StringsJVM.kt +++ b/libraries/stdlib/src/kotlin/text/StringsJVM.kt @@ -174,7 +174,7 @@ public fun String.toRegex(flags: Int = 0): java.util.regex.Pattern { return java.util.regex.Pattern.compile(this, flags) } -val String.reader: StringReader +public val String.reader: StringReader get() = StringReader(this) /** diff --git a/libraries/stdlib/validator/pom.xml b/libraries/stdlib/validator/pom.xml new file mode 100644 index 00000000000..ce64f51b2e1 --- /dev/null +++ b/libraries/stdlib/validator/pom.xml @@ -0,0 +1,52 @@ + + + 4.0.0 + + + org.jetbrains.kotlin + kotlin-project + 0.1-SNAPSHOT + ../../pom.xml + + + kotlin-stdlib-validator + + + + org.jetbrains.kotlin + kotlin-compiler + ${project.version} + + + + org.jetbrains.kotlin + kotlin-runtime + ${project.version} + + + + + src/test/kotlin + + + + org.jetbrains.kotlin + kotlin-maven-plugin + ${project.version} + + + + test-compile + test-compile + + test-compile + + + + + + + + \ No newline at end of file diff --git a/libraries/stdlib/validator/src/test/kotlin/NoInternalVisibilityInStdLibTest.kt b/libraries/stdlib/validator/src/test/kotlin/NoInternalVisibilityInStdLibTest.kt new file mode 100644 index 00000000000..1f5d1e204c5 --- /dev/null +++ b/libraries/stdlib/validator/src/test/kotlin/NoInternalVisibilityInStdLibTest.kt @@ -0,0 +1,144 @@ +/* + * Copyright 2010-2014 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import org.junit.Test +import org.jetbrains.jet.cli.jvm.compiler.JetCoreEnvironment +import com.intellij.openapi.util.Disposer +import org.jetbrains.jet.config.CompilerConfiguration +import org.jetbrains.jet.config.CommonConfigurationKeys +import org.jetbrains.jet.lang.resolve.java.AnalyzerFacadeForJVM +import org.jetbrains.jet.lang.resolve.BindingTraceContext +import org.jetbrains.jet.lang.resolve.name.Name +import org.jetbrains.jet.lang.resolve.name.FqName +import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor +import org.jetbrains.jet.lang.descriptors.DeclarationDescriptorWithVisibility +import org.jetbrains.jet.lang.descriptors.Visibilities +import org.jetbrains.jet.lang.resolve.DescriptorToSourceUtils +import org.jetbrains.jet.lang.descriptors.ClassDescriptor +import org.jetbrains.jet.lang.descriptors.PackageViewDescriptor +import java.util.ArrayList +import org.jetbrains.jet.lang.psi.JetFile +import org.jetbrains.jet.renderer.DescriptorRenderer +import kotlin.test.fail +import org.jetbrains.jet.cli.jvm.JVMConfigurationKeys +import org.jetbrains.jet.utils.PathUtil +import org.jetbrains.jet.lang.resolve.DescriptorUtils +import org.jetbrains.jet.lang.descriptors.ModuleDescriptor +import org.junit.Assert +import java.util.HashSet + +// this list is not designed to contain all packages, it is need for sanity check in case test code breaks +private val PACKAGES_SHOULD_BE_VALIDATED = listOf("kotlin", "kotlin.concurrent", "kotlin.jvm") map { FqName(it) } + +class NoInternalVisibilityInStdLibTest { + private class OutputSink { + private val internalDescriptors = ArrayList() + private val validatedPackages = HashSet() + + fun reportInternalVisibility(descriptor: DeclarationDescriptor) { + internalDescriptors.add(descriptor) + } + + fun reportValidatedPackage(packageFqName: FqName) { + validatedPackages.add(packageFqName) + } + + fun reportErrors() { + println("Validated packages: ") + validatedPackages.forEach { println(" $it") } + + Assert.assertTrue( + "Some of the expected stdlib packages were not validated, check code of the test", + validatedPackages.containsAll(PACKAGES_SHOULD_BE_VALIDATED) + ) + + if (internalDescriptors.isEmpty()) return + + val byFile = internalDescriptors.groupBy { descriptor -> + DescriptorToSourceUtils.descriptorToDeclarations(descriptor).firstOrNull()?.getContainingFile() as JetFile + } + val byPackage = byFile.keySet().groupBy { it.getPackageFqName() } + + val message = StringBuilder { + appendln("There are ${internalDescriptors.size} descriptors that have internal visibility:") + for ((packageFqName, files) in byPackage) { + + appendln("In package ${packageFqName}:") + for (file in files) { + + appendln("In file ${file.getName()}") + appendln("--------------") + val descriptors = byFile[file]!! + descriptors.forEach { + descriptor -> + appendln("* " + DescriptorRenderer.SHORT_NAMES_IN_TYPES.render(descriptor)) + } + appendln("--------------") + } + appendln() + } + }.toString() + fail(message) + } + } + + Test fun testNoInternalVisibility() { + val disposable = Disposer.newDisposable() + val module = try { + val configuration = CompilerConfiguration() + configuration.add(CommonConfigurationKeys.SOURCE_ROOTS_KEY, "../src/kotlin") + configuration.addAll(JVMConfigurationKeys.CLASSPATH_KEY, PathUtil.getJdkClassesRoots()) + val environment = JetCoreEnvironment.createForProduction(disposable, configuration) + AnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration( + environment.getProject(), + environment.getSourceFiles(), + BindingTraceContext(), + { true }, + AnalyzerFacadeForJVM.createJavaModule(""), + null, + null + ).getModuleDescriptor() + } + finally { + Disposer.dispose(disposable) + } + val kotlinPackage = module.getPackage(FqName("kotlin"))!! + val sink = OutputSink() + validateDescriptor(module, kotlinPackage, sink) + sink.reportErrors() + } + + private fun validateDescriptor(module: ModuleDescriptor, descriptor: DeclarationDescriptor, sink: OutputSink) { + if (DescriptorUtils.getContainingModule(descriptor) != module) return + + if (descriptor is DeclarationDescriptorWithVisibility) { + if (descriptor.getVisibility() == Visibilities.INTERNAL) { + sink.reportInternalVisibility(descriptor) + } + } + when (descriptor) { + is ClassDescriptor -> descriptor.getDefaultType().getMemberScope().getAllDescriptors().forEach { + validateDescriptor(module, it, sink) + } + is PackageViewDescriptor -> { + sink.reportValidatedPackage(DescriptorUtils.getFqName(descriptor).toSafe()) + descriptor.getMemberScope().getAllDescriptors().forEach { + validateDescriptor(module, it, sink) + } + } + } + } +} \ No newline at end of file