Transform *Array.size to properties
This commit is contained in:
@@ -16,12 +16,16 @@
|
||||
|
||||
package org.jetbrains.kotlin.codegen.intrinsics
|
||||
|
||||
import org.jetbrains.kotlin.codegen.Callable
|
||||
import org.jetbrains.kotlin.codegen.CallableMethod
|
||||
import org.jetbrains.kotlin.codegen.ExpressionCodegen
|
||||
import org.jetbrains.kotlin.codegen.StackValue
|
||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
|
||||
import org.jetbrains.org.objectweb.asm.Type
|
||||
|
||||
public class ArraySize : IntrinsicMethod() {
|
||||
override fun toCallable(method: CallableMethod): Callable =
|
||||
createUnaryIntrinsicCallable(method) { adapter ->
|
||||
adapter.arraylength()
|
||||
}
|
||||
public class ArraySize : IntrinsicPropertyGetter() {
|
||||
override fun generate(
|
||||
resolvedCall: ResolvedCall<*>?, codegen: ExpressionCodegen, returnType: Type, receiver: StackValue
|
||||
) = StackValue.operation(returnType) {
|
||||
receiver.put(receiver.type, it)
|
||||
it.arraylength()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -134,7 +134,7 @@ public class IntrinsicMethods {
|
||||
declareArrayMethodsForPrimitive(jvmPrimitiveType);
|
||||
}
|
||||
|
||||
declareIntrinsicFunction("Array", "size", 0, ARRAY_SIZE);
|
||||
declareIntrinsicFunction("Array", "size", -1, ARRAY_SIZE);
|
||||
declareIntrinsicFunction("Array", "set", 2, ARRAY_SET);
|
||||
declareIntrinsicFunction("Array", "get", 1, ARRAY_GET);
|
||||
declareIntrinsicFunction("Array", "clone", 0, CLONE);
|
||||
@@ -143,7 +143,7 @@ public class IntrinsicMethods {
|
||||
|
||||
private void declareArrayMethodsForPrimitive(@NotNull JvmPrimitiveType jvmPrimitiveType) {
|
||||
String arrayTypeName = jvmPrimitiveType.getPrimitiveType().getArrayTypeName().asString();
|
||||
declareIntrinsicFunction(arrayTypeName, "size", 0, ARRAY_SIZE);
|
||||
declareIntrinsicFunction(arrayTypeName, "size", -1, ARRAY_SIZE);
|
||||
declareIntrinsicFunction(arrayTypeName, "set", 2, ARRAY_SET);
|
||||
declareIntrinsicFunction(arrayTypeName, "get", 1, ARRAY_GET);
|
||||
declareIntrinsicFunction(arrayTypeName, "clone", 0, CLONE);
|
||||
|
||||
+18
-9
@@ -14,11 +14,12 @@ public open class Any {
|
||||
|
||||
public final class Array</*0*/ T> : kotlin.Cloneable {
|
||||
/*primary*/ private constructor Array</*0*/ T>()
|
||||
public final val size: kotlin.Int
|
||||
public final fun <get-size>(): kotlin.Int
|
||||
public open override /*1*/ fun clone(): kotlin.Array<T>
|
||||
public final operator fun get(/*0*/ index: kotlin.Int): T
|
||||
public final operator fun iterator(): kotlin.Iterator<T>
|
||||
public final operator fun set(/*0*/ index: kotlin.Int, /*1*/ value: T): kotlin.Unit
|
||||
public final fun size(): kotlin.Int
|
||||
}
|
||||
|
||||
public final class Boolean : kotlin.Comparable<kotlin.Boolean> {
|
||||
@@ -32,11 +33,12 @@ public final class Boolean : kotlin.Comparable<kotlin.Boolean> {
|
||||
|
||||
public final class BooleanArray : kotlin.Cloneable {
|
||||
/*primary*/ public constructor BooleanArray(/*0*/ size: kotlin.Int)
|
||||
public final val size: kotlin.Int
|
||||
public final fun <get-size>(): kotlin.Int
|
||||
public open override /*1*/ fun clone(): kotlin.BooleanArray
|
||||
public final operator fun get(/*0*/ index: kotlin.Int): kotlin.Boolean
|
||||
public final operator fun iterator(): kotlin.BooleanIterator
|
||||
public final operator fun set(/*0*/ index: kotlin.Int, /*1*/ value: kotlin.Boolean): kotlin.Unit
|
||||
public final fun size(): kotlin.Int
|
||||
}
|
||||
|
||||
public abstract class BooleanIterator : kotlin.Iterator<kotlin.Boolean> {
|
||||
@@ -113,11 +115,12 @@ public final class Byte : kotlin.Number, kotlin.Comparable<kotlin.Byte> {
|
||||
|
||||
public final class ByteArray : kotlin.Cloneable {
|
||||
/*primary*/ public constructor ByteArray(/*0*/ size: kotlin.Int)
|
||||
public final val size: kotlin.Int
|
||||
public final fun <get-size>(): kotlin.Int
|
||||
public open override /*1*/ fun clone(): kotlin.ByteArray
|
||||
public final operator fun get(/*0*/ index: kotlin.Int): kotlin.Byte
|
||||
public final operator fun iterator(): kotlin.ByteIterator
|
||||
public final operator fun set(/*0*/ index: kotlin.Int, /*1*/ value: kotlin.Byte): kotlin.Unit
|
||||
public final fun size(): kotlin.Int
|
||||
}
|
||||
|
||||
public abstract class ByteIterator : kotlin.Iterator<kotlin.Byte> {
|
||||
@@ -199,11 +202,12 @@ public final class Char : kotlin.Comparable<kotlin.Char> {
|
||||
|
||||
public final class CharArray : kotlin.Cloneable {
|
||||
/*primary*/ public constructor CharArray(/*0*/ size: kotlin.Int)
|
||||
public final val size: kotlin.Int
|
||||
public final fun <get-size>(): kotlin.Int
|
||||
public open override /*1*/ fun clone(): kotlin.CharArray
|
||||
public final operator fun get(/*0*/ index: kotlin.Int): kotlin.Char
|
||||
public final operator fun iterator(): kotlin.CharIterator
|
||||
public final operator fun set(/*0*/ index: kotlin.Int, /*1*/ value: kotlin.Char): kotlin.Unit
|
||||
public final fun size(): kotlin.Int
|
||||
}
|
||||
|
||||
public abstract class CharIterator : kotlin.Iterator<kotlin.Char> {
|
||||
@@ -388,11 +392,12 @@ public final class Double : kotlin.Number, kotlin.Comparable<kotlin.Double> {
|
||||
|
||||
public final class DoubleArray : kotlin.Cloneable {
|
||||
/*primary*/ public constructor DoubleArray(/*0*/ size: kotlin.Int)
|
||||
public final val size: kotlin.Int
|
||||
public final fun <get-size>(): kotlin.Int
|
||||
public open override /*1*/ fun clone(): kotlin.DoubleArray
|
||||
public final operator fun get(/*0*/ index: kotlin.Int): kotlin.Double
|
||||
public final operator fun iterator(): kotlin.DoubleIterator
|
||||
public final operator fun set(/*0*/ index: kotlin.Int, /*1*/ value: kotlin.Double): kotlin.Unit
|
||||
public final fun size(): kotlin.Int
|
||||
}
|
||||
|
||||
public abstract class DoubleIterator : kotlin.Iterator<kotlin.Double> {
|
||||
@@ -538,11 +543,12 @@ public final class Float : kotlin.Number, kotlin.Comparable<kotlin.Float> {
|
||||
|
||||
public final class FloatArray : kotlin.Cloneable {
|
||||
/*primary*/ public constructor FloatArray(/*0*/ size: kotlin.Int)
|
||||
public final val size: kotlin.Int
|
||||
public final fun <get-size>(): kotlin.Int
|
||||
public open override /*1*/ fun clone(): kotlin.FloatArray
|
||||
public final operator fun get(/*0*/ index: kotlin.Int): kotlin.Float
|
||||
public final operator fun iterator(): kotlin.FloatIterator
|
||||
public final operator fun set(/*0*/ index: kotlin.Int, /*1*/ value: kotlin.Float): kotlin.Unit
|
||||
public final fun size(): kotlin.Int
|
||||
}
|
||||
|
||||
public abstract class FloatIterator : kotlin.Iterator<kotlin.Float> {
|
||||
@@ -691,11 +697,12 @@ public final class Int : kotlin.Number, kotlin.Comparable<kotlin.Int> {
|
||||
|
||||
public final class IntArray : kotlin.Cloneable {
|
||||
/*primary*/ public constructor IntArray(/*0*/ size: kotlin.Int)
|
||||
public final val size: kotlin.Int
|
||||
public final fun <get-size>(): kotlin.Int
|
||||
public open override /*1*/ fun clone(): kotlin.IntArray
|
||||
public final operator fun get(/*0*/ index: kotlin.Int): kotlin.Int
|
||||
public final operator fun iterator(): kotlin.IntIterator
|
||||
public final operator fun set(/*0*/ index: kotlin.Int, /*1*/ value: kotlin.Int): kotlin.Unit
|
||||
public final fun size(): kotlin.Int
|
||||
}
|
||||
|
||||
public abstract class IntIterator : kotlin.Iterator<kotlin.Int> {
|
||||
@@ -867,11 +874,12 @@ public final class Long : kotlin.Number, kotlin.Comparable<kotlin.Long> {
|
||||
|
||||
public final class LongArray : kotlin.Cloneable {
|
||||
/*primary*/ public constructor LongArray(/*0*/ size: kotlin.Int)
|
||||
public final val size: kotlin.Int
|
||||
public final fun <get-size>(): kotlin.Int
|
||||
public open override /*1*/ fun clone(): kotlin.LongArray
|
||||
public final operator fun get(/*0*/ index: kotlin.Int): kotlin.Long
|
||||
public final operator fun iterator(): kotlin.LongIterator
|
||||
public final operator fun set(/*0*/ index: kotlin.Int, /*1*/ value: kotlin.Long): kotlin.Unit
|
||||
public final fun size(): kotlin.Int
|
||||
}
|
||||
|
||||
public abstract class LongIterator : kotlin.Iterator<kotlin.Long> {
|
||||
@@ -1178,11 +1186,12 @@ public final class Short : kotlin.Number, kotlin.Comparable<kotlin.Short> {
|
||||
|
||||
public final class ShortArray : kotlin.Cloneable {
|
||||
/*primary*/ public constructor ShortArray(/*0*/ size: kotlin.Int)
|
||||
public final val size: kotlin.Int
|
||||
public final fun <get-size>(): kotlin.Int
|
||||
public open override /*1*/ fun clone(): kotlin.ShortArray
|
||||
public final operator fun get(/*0*/ index: kotlin.Int): kotlin.Short
|
||||
public final operator fun iterator(): kotlin.ShortIterator
|
||||
public final operator fun set(/*0*/ index: kotlin.Int, /*1*/ value: kotlin.Short): kotlin.Unit
|
||||
public final fun size(): kotlin.Int
|
||||
}
|
||||
|
||||
public abstract class ShortIterator : kotlin.Iterator<kotlin.Short> {
|
||||
|
||||
+9
-9
@@ -5,48 +5,48 @@ fun foo(a: Any): Int {
|
||||
a.get(0)
|
||||
a.set(0, 1)
|
||||
a.iterator()
|
||||
return a.size()
|
||||
return a.size
|
||||
}
|
||||
if (a is ShortArray) {
|
||||
a.get(0)
|
||||
a.set(0, 1)
|
||||
a.iterator()
|
||||
return a.size()
|
||||
return a.size
|
||||
}
|
||||
if (a is ByteArray) {
|
||||
a.get(0)
|
||||
a.set(0, 1)
|
||||
a.iterator()
|
||||
return a.size()
|
||||
return a.size
|
||||
}
|
||||
if (a is FloatArray) {
|
||||
a.get(0)
|
||||
a.set(0, 1.toFloat())
|
||||
a.iterator()
|
||||
return a.size()
|
||||
return a.size
|
||||
}
|
||||
if (a is DoubleArray) {
|
||||
a.get(0)
|
||||
a.set(0, 1.0)
|
||||
a.iterator()
|
||||
return a.size()
|
||||
return a.size
|
||||
}
|
||||
if (a is BooleanArray) {
|
||||
a.get(0)
|
||||
a.set(0, false)
|
||||
a.iterator()
|
||||
return a.size()
|
||||
return a.size
|
||||
}
|
||||
if (a is CharArray) {
|
||||
a.get(0)
|
||||
a.set(0, 'a')
|
||||
a.iterator()
|
||||
return a.size()
|
||||
return a.size
|
||||
}
|
||||
if (a is Array<*>) {
|
||||
if (a.size() > 0) a.get(0)
|
||||
if (a.size > 0) a.get(0)
|
||||
a.iterator()
|
||||
return a.size()
|
||||
return a.size
|
||||
}
|
||||
|
||||
return 0
|
||||
|
||||
+1
-1
@@ -26,4 +26,4 @@ fun box() : String {
|
||||
}
|
||||
|
||||
fun thirdElementIsThree(a : IntArray) =
|
||||
a.size() >= 3 && a[2] == 3
|
||||
a.size >= 3 && a[2] == 3
|
||||
|
||||
+1
-1
@@ -1,3 +1,3 @@
|
||||
val <T> Array<T>.length : Int get() = this.size()
|
||||
val <T> Array<T>.length : Int get() = this.size
|
||||
|
||||
fun box() = if(arrayOfNulls<Int>(10).length == 10) "OK" else "fail"
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
public class StockMarketTableModel() {
|
||||
|
||||
public fun getColumnCount() : Int {
|
||||
return COLUMN_TITLES?.size()!!
|
||||
return COLUMN_TITLES?.size!!
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
@@ -4,7 +4,7 @@ fun IntArray.swap(i:Int, j:Int) {
|
||||
this[j] = temp
|
||||
}
|
||||
|
||||
fun IntArray.quicksort() = quicksort(0, size()-1)
|
||||
fun IntArray.quicksort() = quicksort(0, size-1)
|
||||
|
||||
fun IntArray.quicksort(L: Int, R:Int) {
|
||||
val m = this[(L + R) / 2]
|
||||
@@ -34,7 +34,7 @@ fun box() : String {
|
||||
a[2*i+1] = -2*i-1
|
||||
}
|
||||
a.quicksort()
|
||||
for(i in 0..a.size()-2) {
|
||||
for(i in 0..a.size-2) {
|
||||
if (a[i] > a[i+1]) return "Fail $i: ${a[i]} > ${a[i+1]}"
|
||||
}
|
||||
return "OK"
|
||||
|
||||
@@ -14,9 +14,9 @@ enum class Game {
|
||||
fun box(): String {
|
||||
if (Game.foo() != Game.ROCK) return "Fail 1"
|
||||
if (Game.bar != Game.PAPER) return "Fail 2: ${Game.bar}"
|
||||
if (Game.values().size() != 3) return "Fail 3"
|
||||
if (Game.values().size != 3) return "Fail 3"
|
||||
if (Game.valueOf("SCISSORS") != Game.SCISSORS) return "Fail 4"
|
||||
if (Game.values2.size() != 3) return "Fail 5"
|
||||
if (Game.values2.size != 3) return "Fail 5"
|
||||
if (Game.scissors != Game.SCISSORS) return "Fail 6"
|
||||
return "OK"
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
enum class Empty
|
||||
|
||||
fun box(): String {
|
||||
if (Empty.values().size() != 0) return "Fail: ${Empty.values()}"
|
||||
if (Empty.values().size != 0) return "Fail: ${Empty.values()}"
|
||||
|
||||
try {
|
||||
val found = Empty.valueOf("nonExistentEntry")
|
||||
|
||||
+2
-2
@@ -1,9 +1,9 @@
|
||||
class A {
|
||||
fun get(vararg x: Int) = x.size()
|
||||
fun get(vararg x: Int) = x.size
|
||||
}
|
||||
|
||||
class B {
|
||||
fun get(vararg x: Unit) = x.size()
|
||||
fun get(vararg x: Unit) = x.size
|
||||
}
|
||||
|
||||
fun test1(a: A): Int {
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@ fun checkLess(x: Array<Int>, y: Array<Int>) = when {
|
||||
else -> "OK"
|
||||
}
|
||||
|
||||
fun Array<Int>.compareTo(other: Array<Int>) = size() - other.size()
|
||||
fun Array<Int>.compareTo(other: Array<Int>) = size - other.size
|
||||
|
||||
fun box(): String {
|
||||
val a = arrayOfNulls<Int>(0) as Array<Int>
|
||||
|
||||
+1
-1
@@ -27,4 +27,4 @@ fun bottlesOfBeer(count : Int) : String {
|
||||
fun print(message : String) { System.out?.print(message) }
|
||||
fun println(message : String) { System.out?.println(message) }
|
||||
fun StringBuilder.plusAssign(o : Any) { append(o) }
|
||||
val <T> Array<T>.isEmpty : Boolean get() = size() == 0
|
||||
val <T> Array<T>.isEmpty : Boolean get() = size == 0
|
||||
|
||||
@@ -19,7 +19,7 @@ fun box() : String {
|
||||
P(""""" """"", "\"\" \"\"")
|
||||
)
|
||||
|
||||
for (i in 0..data.size()-1) {
|
||||
for (i in 0..data.size-1) {
|
||||
val p = data[i]
|
||||
if (p.actual != p.expected) return "Fail at #$i. actual='${p.actual}', expected='${p.expected}'"
|
||||
}
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ import java.util.HashSet
|
||||
|
||||
fun iarray(vararg a : Int) = a // BUG
|
||||
val IntArray.indices: IntRange get() = IntRange(0, lastIndex())
|
||||
fun IntArray.lastIndex() = size() - 1
|
||||
fun IntArray.lastIndex() = size - 1
|
||||
|
||||
fun box() : String {
|
||||
val vals = iarray(789, 678, 567, 456, 345, 234, 123, 12)
|
||||
|
||||
+17
-17
@@ -50,21 +50,21 @@ fun box(): String {
|
||||
val aZ = BooleanArray(3)
|
||||
|
||||
|
||||
if (barB(*aB, 23.toByte()).size() != 4) return "fail: Byte"
|
||||
if (barB(11.toByte(), *aB, 23.toByte(), *aB).size() != 8) return "fail: Byte"
|
||||
if (barB(*aB, 23.toByte()).size != 4) return "fail: Byte"
|
||||
if (barB(11.toByte(), *aB, 23.toByte(), *aB).size != 8) return "fail: Byte"
|
||||
|
||||
if (barC(*aC, 'A').size() != 4) return "fail: Char"
|
||||
if (barC('A', *aC, 'A', *aC).size() != 8) return "fail: Char"
|
||||
if (barC(*aC, 'A').size != 4) return "fail: Char"
|
||||
if (barC('A', *aC, 'A', *aC).size != 8) return "fail: Char"
|
||||
|
||||
if (barD(*aD, 2.3).size() != 4) return "fail: Double"
|
||||
if (barD(*aD, *aD, 2.3).size() != 7) return "fail: Double"
|
||||
if (barD(*aD, 2.3).size != 4) return "fail: Double"
|
||||
if (barD(*aD, *aD, 2.3).size != 7) return "fail: Double"
|
||||
|
||||
if (barF(*aF, 2.3f).size() != 4) return "fail: Float"
|
||||
if (barF(*aF, 2.3f, 1.1f).size() != 5) return "fail: Float"
|
||||
if (barF(*aF, 2.3f).size != 4) return "fail: Float"
|
||||
if (barF(*aF, 2.3f, 1.1f).size != 5) return "fail: Float"
|
||||
|
||||
if (barI(*aI, 23).size() != 4) return "fail: Int"
|
||||
if (barI(11, 10, *aI, 23).size() != 6) return "fail: Int"
|
||||
if (barI(100, *aI, *aI).size() != 7) return "fail: Int 3"
|
||||
if (barI(*aI, 23).size != 4) return "fail: Int"
|
||||
if (barI(11, 10, *aI, 23).size != 6) return "fail: Int"
|
||||
if (barI(100, *aI, *aI).size != 7) return "fail: Int 3"
|
||||
|
||||
if (sumInt(100, *aI) != 106) return "fail: sumInt 1"
|
||||
if (sumInt(100, *aI, 200) != 306) return "fail: sumInt 2"
|
||||
@@ -80,14 +80,14 @@ fun box(): String {
|
||||
if (concatParameters(*aI, 7, 8, *bI) != "1237845") return "fail: concatParameters 6"
|
||||
if (concatParameters(*aI, 7, *bI, *aI, 9) != "1237451239") return "fail: concatParameters 7"
|
||||
|
||||
if (barJ(*aJ, 23L).size() != 4) return "fail: Long"
|
||||
if (barJ(*aJ, 23L, *aJ, *aJ).size() != 10) return "fail: Long"
|
||||
if (barJ(*aJ, 23L).size != 4) return "fail: Long"
|
||||
if (barJ(*aJ, 23L, *aJ, *aJ).size != 10) return "fail: Long"
|
||||
|
||||
if (barS(*aS, 23.toShort()).size() != 4) return "fail: Short"
|
||||
if (barS(*aS, *aS, 23.toShort(), *aS).size() != 10) return "fail: Short"
|
||||
if (barS(*aS, 23.toShort()).size != 4) return "fail: Short"
|
||||
if (barS(*aS, *aS, 23.toShort(), *aS).size != 10) return "fail: Short"
|
||||
|
||||
if (barZ(*aZ, true).size() != 4) return "fail: Boolean"
|
||||
if (barZ(false, *aZ, true, *aZ).size() != 8) return "fail: Boolean"
|
||||
if (barZ(*aZ, true).size != 4) return "fail: Boolean"
|
||||
if (barZ(false, *aZ, true, *aZ).size != 8) return "fail: Boolean"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
|
||||
@@ -3,13 +3,13 @@ fun foo(a: Int, vararg b: Int, f: (IntArray) -> String): String {
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val test1 = foo(1) {a -> "" + a.size()}
|
||||
val test1 = foo(1) {a -> "" + a.size}
|
||||
if (test1 != "test1 0") return test1
|
||||
|
||||
val test2 = foo(2, 2) {a -> "" + a.size()}
|
||||
val test2 = foo(2, 2) {a -> "" + a.size}
|
||||
if (test2 != "test2 1") return test2
|
||||
|
||||
val test3 = foo(3, 2, 3) {a -> "" + a.size()}
|
||||
val test3 = foo(3, 2, 3) {a -> "" + a.size}
|
||||
if (test3 != "test3 2") return test3
|
||||
|
||||
return "OK"
|
||||
|
||||
@@ -4,6 +4,6 @@ fun main(args : Array<String>) {
|
||||
var ints : Array<Int?> = arrayOfNulls<Int>(31)
|
||||
|
||||
ints[0] = 4; ints[11] = 5; ints[2] =7
|
||||
for(i in 0..ints.size())
|
||||
for(i in 0..ints.size)
|
||||
ints[i<!SYNTAX!><!>
|
||||
}
|
||||
+2
-2
@@ -2,9 +2,9 @@ package c
|
||||
|
||||
import java.util.ArrayList
|
||||
|
||||
fun Array<Int>.toIntArray(): IntArray = this.<!TYPE_INFERENCE_UPPER_BOUND_VIOLATED!>mapTo<!>(IntArray(size()), {it})
|
||||
fun Array<Int>.toIntArray(): IntArray = this.<!TYPE_INFERENCE_UPPER_BOUND_VIOLATED!>mapTo<!>(IntArray(size), {it})
|
||||
|
||||
fun Array<Int>.toArrayList(): ArrayList<Int> = this.mapTo(ArrayList<Int>(size()), {it})
|
||||
fun Array<Int>.toArrayList(): ArrayList<Int> = this.mapTo(ArrayList<Int>(size), {it})
|
||||
|
||||
public fun <T, R, C: MutableCollection<in R>> Array<out T>.mapTo(result: C, transform : (T) -> R) : C =
|
||||
throw Exception("$result $transform")
|
||||
|
||||
@@ -22,7 +22,7 @@ fun test() {
|
||||
// ---------------------
|
||||
// copy from kotlin util
|
||||
|
||||
fun <T> arrayList(vararg values: T) : ArrayList<T> = values.toCollection(ArrayList<T>(values.size()))
|
||||
fun <T> arrayList(vararg values: T) : ArrayList<T> = values.toCollection(ArrayList<T>(values.size))
|
||||
|
||||
fun <T, C: MutableCollection<in T>> Array<T>.toCollection(result: C) : C {
|
||||
for (element in this) result.add(element)
|
||||
|
||||
@@ -25,7 +25,7 @@ fun test() {
|
||||
|
||||
//------------
|
||||
|
||||
fun <T> arrayList(vararg values: T) : ArrayList<T> = values.toCollection(ArrayList<T>(values.size()))
|
||||
fun <T> arrayList(vararg values: T) : ArrayList<T> = values.toCollection(ArrayList<T>(values.size))
|
||||
|
||||
fun <T, R> Collection<T>.map(transform : (T) -> R) : List<R> {
|
||||
return mapTo(java.util.ArrayList<R>(this.size), transform)
|
||||
|
||||
@@ -27,7 +27,7 @@ fun testSomeFunction() {
|
||||
fun assertEquals(<!UNUSED_PARAMETER!>expected<!>: Any?, <!UNUSED_PARAMETER!>actual<!>: Any?, <!UNUSED_PARAMETER!>message<!>: String = "") {
|
||||
}
|
||||
|
||||
fun <T> arrayList(vararg values: T) : ArrayList<T> = values.toCollection(ArrayList<T>(values.size()))
|
||||
fun <T> arrayList(vararg values: T) : ArrayList<T> = values.toCollection(ArrayList<T>(values.size))
|
||||
|
||||
fun <T, C: MutableCollection<in T>> Array<T>.toCollection(result: C) : C {
|
||||
for (element in this) result.add(element)
|
||||
|
||||
@@ -4,7 +4,7 @@ public inline fun <reified T> Array(n: Int, block: (Int) -> T): Array<T> = null!
|
||||
// KT-312 Nullability problem when a nullable version of a generic type is returned
|
||||
|
||||
fun <T> Array<out T>.safeGet(index : Int) : T? {
|
||||
return if (index < size()) this[index] else null
|
||||
return if (index < size) this[index] else null
|
||||
}
|
||||
|
||||
val args : Array<String> = Array<String>(1, {""})
|
||||
|
||||
@@ -17,6 +17,6 @@ fun main() {
|
||||
}
|
||||
}
|
||||
|
||||
fun <T> Array<T>.lastIndex() = size() - 1
|
||||
val <T> Array<T>.lastIndex : Int get() = size() - 1
|
||||
fun <T> Array<T>.lastIndex() = size - 1
|
||||
val <T> Array<T>.lastIndex : Int get() = size - 1
|
||||
val <T> Array<T>.indices : IntRange get() = IntRange(0, lastIndex)
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
// See also KT-7186
|
||||
|
||||
fun IntArray.forEachIndexed( op: (i: Int, value: Int) -> Unit) {
|
||||
for (i in 0..this.size()-1)
|
||||
for (i in 0..this.size)
|
||||
op(i, this[i])
|
||||
}
|
||||
|
||||
|
||||
@@ -350,7 +350,7 @@ public class PackageGenTest extends CodegenTestCase {
|
||||
}
|
||||
|
||||
public void testArraySize() throws Exception {
|
||||
loadText("fun foo(a: Array<Int>) = a.size()");
|
||||
loadText("fun foo(a: Array<Int>) = a.size");
|
||||
Method main = generateFunction();
|
||||
Object[] args = new Object[] { new Integer[4] };
|
||||
int result = (Integer) main.invoke(null, args);
|
||||
@@ -358,7 +358,7 @@ public class PackageGenTest extends CodegenTestCase {
|
||||
}
|
||||
|
||||
public void testIntArraySize() throws Exception {
|
||||
loadText("fun foo(a: IntArray) = a.size()");
|
||||
loadText("fun foo(a: IntArray) = a.size");
|
||||
Method main = generateFunction();
|
||||
Object[] args = new Object[] { new int[4] };
|
||||
int result = (Integer) main.invoke(null, args);
|
||||
|
||||
@@ -45,7 +45,7 @@ public class Array<T> private (): Cloneable {
|
||||
/**
|
||||
* Returns the number of elements in the array.
|
||||
*/
|
||||
public fun size(): Int
|
||||
public val size: Int
|
||||
|
||||
/**
|
||||
* Creates an iterator for iterating over the elements of the array.
|
||||
|
||||
@@ -29,7 +29,7 @@ public class ByteArray(size: Int) : Cloneable {
|
||||
public operator fun set(index: Int, value: Byte): Unit
|
||||
|
||||
/** Returns the number of elements in the array. */
|
||||
public fun size(): Int
|
||||
public val size: Int
|
||||
|
||||
/** Creates an iterator over the elements of the array. */
|
||||
public operator fun iterator(): ByteIterator
|
||||
@@ -48,7 +48,7 @@ public class CharArray(size: Int) : Cloneable {
|
||||
public operator fun set(index: Int, value: Char): Unit
|
||||
|
||||
/** Returns the number of elements in the array. */
|
||||
public fun size(): Int
|
||||
public val size: Int
|
||||
|
||||
/** Creates an iterator over the elements of the array. */
|
||||
public operator fun iterator(): CharIterator
|
||||
@@ -67,7 +67,7 @@ public class ShortArray(size: Int) : Cloneable {
|
||||
public operator fun set(index: Int, value: Short): Unit
|
||||
|
||||
/** Returns the number of elements in the array. */
|
||||
public fun size(): Int
|
||||
public val size: Int
|
||||
|
||||
/** Creates an iterator over the elements of the array. */
|
||||
public operator fun iterator(): ShortIterator
|
||||
@@ -86,7 +86,7 @@ public class IntArray(size: Int) : Cloneable {
|
||||
public operator fun set(index: Int, value: Int): Unit
|
||||
|
||||
/** Returns the number of elements in the array. */
|
||||
public fun size(): Int
|
||||
public val size: Int
|
||||
|
||||
/** Creates an iterator over the elements of the array. */
|
||||
public operator fun iterator(): IntIterator
|
||||
@@ -105,7 +105,7 @@ public class LongArray(size: Int) : Cloneable {
|
||||
public operator fun set(index: Int, value: Long): Unit
|
||||
|
||||
/** Returns the number of elements in the array. */
|
||||
public fun size(): Int
|
||||
public val size: Int
|
||||
|
||||
/** Creates an iterator over the elements of the array. */
|
||||
public operator fun iterator(): LongIterator
|
||||
@@ -124,7 +124,7 @@ public class FloatArray(size: Int) : Cloneable {
|
||||
public operator fun set(index: Int, value: Float): Unit
|
||||
|
||||
/** Returns the number of elements in the array. */
|
||||
public fun size(): Int
|
||||
public val size: Int
|
||||
|
||||
/** Creates an iterator over the elements of the array. */
|
||||
public operator fun iterator(): FloatIterator
|
||||
@@ -143,7 +143,7 @@ public class DoubleArray(size: Int) : Cloneable {
|
||||
public operator fun set(index: Int, value: Double): Unit
|
||||
|
||||
/** Returns the number of elements in the array. */
|
||||
public fun size(): Int
|
||||
public val size: Int
|
||||
|
||||
/** Creates an iterator over the elements of the array. */
|
||||
public operator fun iterator(): DoubleIterator
|
||||
@@ -162,7 +162,7 @@ public class BooleanArray(size: Int) : Cloneable {
|
||||
public operator fun set(index: Int, value: Boolean): Unit
|
||||
|
||||
/** Returns the number of elements in the array. */
|
||||
public fun size(): Int
|
||||
public val size: Int
|
||||
|
||||
/** Creates an iterator over the elements of the array. */
|
||||
public operator fun iterator(): BooleanIterator
|
||||
|
||||
@@ -18,7 +18,7 @@ package kotlin.jvm.internal
|
||||
|
||||
private class ArrayIterator<T>(val array: Array<T>) : Iterator<T> {
|
||||
private var index = 0
|
||||
override fun hasNext() = index < array.size()
|
||||
override fun hasNext() = index < array.size
|
||||
override fun next() = array[index++]
|
||||
}
|
||||
|
||||
|
||||
@@ -20,49 +20,49 @@ package kotlin.jvm.internal
|
||||
|
||||
private class ArrayByteIterator(private val array: ByteArray) : ByteIterator() {
|
||||
private var index = 0
|
||||
override fun hasNext() = index < array.size()
|
||||
override fun hasNext() = index < array.size
|
||||
override fun nextByte() = array[index++]
|
||||
}
|
||||
|
||||
private class ArrayCharIterator(private val array: CharArray) : CharIterator() {
|
||||
private var index = 0
|
||||
override fun hasNext() = index < array.size()
|
||||
override fun hasNext() = index < array.size
|
||||
override fun nextChar() = array[index++]
|
||||
}
|
||||
|
||||
private class ArrayShortIterator(private val array: ShortArray) : ShortIterator() {
|
||||
private var index = 0
|
||||
override fun hasNext() = index < array.size()
|
||||
override fun hasNext() = index < array.size
|
||||
override fun nextShort() = array[index++]
|
||||
}
|
||||
|
||||
private class ArrayIntIterator(private val array: IntArray) : IntIterator() {
|
||||
private var index = 0
|
||||
override fun hasNext() = index < array.size()
|
||||
override fun hasNext() = index < array.size
|
||||
override fun nextInt() = array[index++]
|
||||
}
|
||||
|
||||
private class ArrayLongIterator(private val array: LongArray) : LongIterator() {
|
||||
private var index = 0
|
||||
override fun hasNext() = index < array.size()
|
||||
override fun hasNext() = index < array.size
|
||||
override fun nextLong() = array[index++]
|
||||
}
|
||||
|
||||
private class ArrayFloatIterator(private val array: FloatArray) : FloatIterator() {
|
||||
private var index = 0
|
||||
override fun hasNext() = index < array.size()
|
||||
override fun hasNext() = index < array.size
|
||||
override fun nextFloat() = array[index++]
|
||||
}
|
||||
|
||||
private class ArrayDoubleIterator(private val array: DoubleArray) : DoubleIterator() {
|
||||
private var index = 0
|
||||
override fun hasNext() = index < array.size()
|
||||
override fun hasNext() = index < array.size
|
||||
override fun nextDouble() = array[index++]
|
||||
}
|
||||
|
||||
private class ArrayBooleanIterator(private val array: BooleanArray) : BooleanIterator() {
|
||||
private var index = 0
|
||||
override fun hasNext() = index < array.size()
|
||||
override fun hasNext() = index < array.size
|
||||
override fun nextBoolean() = array[index++]
|
||||
}
|
||||
|
||||
|
||||
@@ -62,7 +62,7 @@ private abstract class PrimitiveSpreadBuilder<T : Any>(private val size: Int) {
|
||||
|
||||
public class ByteSpreadBuilder(size: Int) : PrimitiveSpreadBuilder<ByteArray>(size) {
|
||||
private val values: ByteArray = ByteArray(size)
|
||||
override fun ByteArray.getSize(): Int = this.size()
|
||||
override fun ByteArray.getSize(): Int = this.size
|
||||
|
||||
public fun add(value: Byte) {
|
||||
values[position++] = value
|
||||
@@ -73,7 +73,7 @@ public class ByteSpreadBuilder(size: Int) : PrimitiveSpreadBuilder<ByteArray>(si
|
||||
|
||||
public class CharSpreadBuilder(size: Int) : PrimitiveSpreadBuilder<CharArray>(size) {
|
||||
private val values: CharArray = CharArray(size)
|
||||
override fun CharArray.getSize(): Int = this.size()
|
||||
override fun CharArray.getSize(): Int = this.size
|
||||
|
||||
public fun add(value: Char) {
|
||||
values[position++] = value
|
||||
@@ -84,7 +84,7 @@ public class CharSpreadBuilder(size: Int) : PrimitiveSpreadBuilder<CharArray>(si
|
||||
|
||||
public class DoubleSpreadBuilder(size: Int) : PrimitiveSpreadBuilder<DoubleArray>(size) {
|
||||
private val values: DoubleArray = DoubleArray(size)
|
||||
override fun DoubleArray.getSize(): Int = this.size()
|
||||
override fun DoubleArray.getSize(): Int = this.size
|
||||
|
||||
public fun add(value: Double) {
|
||||
values[position++] = value
|
||||
@@ -95,7 +95,7 @@ public class DoubleSpreadBuilder(size: Int) : PrimitiveSpreadBuilder<DoubleArray
|
||||
|
||||
public class FloatSpreadBuilder(size: Int) : PrimitiveSpreadBuilder<FloatArray>(size) {
|
||||
private val values: FloatArray = FloatArray(size)
|
||||
override fun FloatArray.getSize(): Int = this.size()
|
||||
override fun FloatArray.getSize(): Int = this.size
|
||||
|
||||
public fun add(value: Float) {
|
||||
values[position++] = value
|
||||
@@ -106,7 +106,7 @@ public class FloatSpreadBuilder(size: Int) : PrimitiveSpreadBuilder<FloatArray>(
|
||||
|
||||
public class IntSpreadBuilder(size: Int) : PrimitiveSpreadBuilder<IntArray>(size) {
|
||||
private val values: IntArray = IntArray(size)
|
||||
override fun IntArray.getSize(): Int = this.size()
|
||||
override fun IntArray.getSize(): Int = this.size
|
||||
|
||||
public fun add(value: Int) {
|
||||
values[position++] = value
|
||||
@@ -117,7 +117,7 @@ public class IntSpreadBuilder(size: Int) : PrimitiveSpreadBuilder<IntArray>(size
|
||||
|
||||
public class LongSpreadBuilder(size: Int) : PrimitiveSpreadBuilder<LongArray>(size) {
|
||||
private val values: LongArray = LongArray(size)
|
||||
override fun LongArray.getSize(): Int = this.size()
|
||||
override fun LongArray.getSize(): Int = this.size
|
||||
|
||||
public fun add(value: Long) {
|
||||
values[position++] = value
|
||||
@@ -128,7 +128,7 @@ public class LongSpreadBuilder(size: Int) : PrimitiveSpreadBuilder<LongArray>(si
|
||||
|
||||
public class ShortSpreadBuilder(size: Int) : PrimitiveSpreadBuilder<ShortArray>(size) {
|
||||
private val values: ShortArray = ShortArray(size)
|
||||
override fun ShortArray.getSize(): Int = this.size()
|
||||
override fun ShortArray.getSize(): Int = this.size
|
||||
|
||||
public fun add(value: Short) {
|
||||
values[position++] = value
|
||||
@@ -139,7 +139,7 @@ public class ShortSpreadBuilder(size: Int) : PrimitiveSpreadBuilder<ShortArray>(
|
||||
|
||||
public class BooleanSpreadBuilder(size: Int) : PrimitiveSpreadBuilder<BooleanArray>(size) {
|
||||
private val values: BooleanArray = BooleanArray(size)
|
||||
override fun BooleanArray.getSize(): Int = this.size()
|
||||
override fun BooleanArray.getSize(): Int = this.size
|
||||
|
||||
public fun add(value: Boolean) {
|
||||
values[position++] = value
|
||||
|
||||
@@ -28,7 +28,7 @@ class GenerateArrayIterators(out: PrintWriter) : BuiltInsSourceGenerator(out) {
|
||||
val s = kind.capitalized
|
||||
out.println("private class Array${s}Iterator(private val array: ${s}Array) : ${s}Iterator() {")
|
||||
out.println(" private var index = 0")
|
||||
out.println(" override fun hasNext() = index < array.size()")
|
||||
out.println(" override fun hasNext() = index < array.size")
|
||||
out.println(" override fun next$s() = array[index++]")
|
||||
out.println("}")
|
||||
out.println()
|
||||
|
||||
@@ -39,7 +39,7 @@ class GenerateArrays(out: PrintWriter) : BuiltInsSourceGenerator(out) {
|
||||
out.println(" public operator fun set(index: Int, value: $s): Unit")
|
||||
out.println()
|
||||
out.println(" /** Returns the number of elements in the array. */")
|
||||
out.println(" public fun size(): Int")
|
||||
out.println(" public val size: Int")
|
||||
out.println()
|
||||
out.println(" /** Creates an iterator over the elements of the array. */")
|
||||
out.println(" public operator fun iterator(): ${s}Iterator")
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
// WITH_DEFAULT_VALUE: false
|
||||
fun foo(vararg a: Int): Int {
|
||||
return (<selection>a.size() + 1</selection>) * 2
|
||||
return (<selection>a.size + 1</selection>) * 2
|
||||
}
|
||||
|
||||
fun test() {
|
||||
|
||||
@@ -4,7 +4,7 @@ fun foo(i: Int): Int {
|
||||
}
|
||||
|
||||
fun test() {
|
||||
foo(a.size() + 1)
|
||||
foo(a.size() + 1)
|
||||
foo(a.size() + 1)
|
||||
foo(a.size + 1)
|
||||
foo(a.size + 1)
|
||||
foo(a.size + 1)
|
||||
}
|
||||
+1
-1
@@ -121,7 +121,7 @@ public final class ArrayFIF extends CompositeFIF {
|
||||
private ArrayFIF() {
|
||||
add(pattern(ARRAYS, "get"), GET_INTRINSIC);
|
||||
add(pattern(ARRAYS, "set"), SET_INTRINSIC);
|
||||
add(pattern(ARRAYS, "size"), LENGTH_PROPERTY_INTRINSIC);
|
||||
add(pattern(ARRAYS, "<get-size>"), LENGTH_PROPERTY_INTRINSIC);
|
||||
add(pattern(ARRAYS, "iterator"), new KotlinFunctionIntrinsic("arrayIterator"));
|
||||
add(pattern(NUMBER_ARRAY, "<init>"),new KotlinFunctionIntrinsic("numberArrayOfSize"));
|
||||
add(pattern(CHAR_ARRAY, "<init>"), new KotlinFunctionIntrinsic("charArrayOfSize"));
|
||||
|
||||
@@ -6,4 +6,4 @@ class A() {
|
||||
val a1 = arrayOfNulls<Int>(3)
|
||||
val a2 = arrayOfNulls<A>(2)
|
||||
|
||||
fun box() = (a1.size() == 3 && a2.size() == 2)
|
||||
fun box() = (a1.size == 3 && a2.size == 2)
|
||||
@@ -23,3 +23,30 @@ public inline fun Throwable.getMessage(): String? = message
|
||||
|
||||
@Deprecated("Use property 'cause' instead", ReplaceWith("this.cause"))
|
||||
public inline fun Throwable.getCause(): Throwable? = cause
|
||||
|
||||
@Deprecated("Use property 'size' instead", ReplaceWith("this.size"))
|
||||
public inline fun Array<*>.size() = size
|
||||
|
||||
@Deprecated("Use property 'size' instead", ReplaceWith("this.size"))
|
||||
public inline fun ByteArray.size() = size
|
||||
|
||||
@Deprecated("Use property 'size' instead", ReplaceWith("this.size"))
|
||||
public inline fun CharArray.size() = size
|
||||
|
||||
@Deprecated("Use property 'size' instead", ReplaceWith("this.size"))
|
||||
public inline fun ShortArray.size() = size
|
||||
|
||||
@Deprecated("Use property 'size' instead", ReplaceWith("this.size"))
|
||||
public inline fun IntArray.size() = size
|
||||
|
||||
@Deprecated("Use property 'size' instead", ReplaceWith("this.size"))
|
||||
public inline fun LongArray.size() = size
|
||||
|
||||
@Deprecated("Use property 'size' instead", ReplaceWith("this.size"))
|
||||
public inline fun FloatArray.size() = size
|
||||
|
||||
@Deprecated("Use property 'size' instead", ReplaceWith("this.size"))
|
||||
public inline fun DoubleArray.size() = size
|
||||
|
||||
@Deprecated("Use property 'size' instead", ReplaceWith("this.size"))
|
||||
public inline fun BooleanArray.size() = size
|
||||
|
||||
Reference in New Issue
Block a user