From bd37a10677e9676e962577be587c7b48f3606a5c Mon Sep 17 00:00:00 2001 From: Denis Zharkov Date: Wed, 14 Oct 2015 13:56:18 +0300 Subject: [PATCH] Transform *Array.size to properties --- .../kotlin/codegen/intrinsics/ArraySize.kt | 18 ++++++---- .../codegen/intrinsics/IntrinsicMethods.java | 4 +-- compiler/testData/builtin-classes.txt | 27 ++++++++++----- .../testData/codegen/box/arrays/kt2997.kt | 18 +++++----- compiler/testData/codegen/box/arrays/kt503.kt | 2 +- compiler/testData/codegen/box/arrays/kt779.kt | 2 +- .../testData/codegen/box/classes/kt1018.kt | 2 +- .../box/controlStructures/quicksort.kt | 4 +-- .../codegen/box/enum/companionObjectInEnum.kt | 4 +-- .../box/enum/emptyEnumValuesValueOf.kt | 2 +- .../testData/codegen/box/functions/kt3214.kt | 4 +-- .../compareTo/extensionArray.kt | 2 +- .../codegen/box/primitiveTypes/kt935.kt | 2 +- .../box/strings/rawStringsWithManyQuotes.kt | 2 +- compiler/testData/codegen/box/vararg/kt581.kt | 2 +- .../testData/codegen/box/vararg/kt6192.kt | 34 +++++++++---------- .../box/vararg/varargsAndFunctionLiterals.kt | 6 ++-- .../incompleteCode/arrayBracketsRange.kt | 2 +- .../constraintOnFunctionLiteral.kt | 4 +-- .../tests/inference/listConstructor.kt | 2 +- .../tests/inference/regressions/kt2179.kt | 2 +- .../tests/inference/regressions/kt2324.kt | 2 +- .../diagnostics/tests/regressions/kt312.kt | 2 +- .../diagnostics/tests/regressions/kt580.kt | 4 +-- .../varnotnull/varCapturedInInlineClosure.kt | 2 +- .../kotlin/codegen/PackageGenTest.java | 4 +-- core/builtins/native/kotlin/Array.kt | 2 +- core/builtins/native/kotlin/Arrays.kt | 16 ++++----- .../src/kotlin/jvm/internal/ArrayIterator.kt | 2 +- .../src/kotlin/jvm/internal/ArrayIterators.kt | 16 ++++----- .../jvm/internal/PrimitiveSpreadBuilders.kt | 16 ++++----- .../generators/builtins/arrayIterators.kt | 2 +- .../kotlin/generators/builtins/arrays.kt | 2 +- .../refactoring/introduceParameter/varargs.kt | 2 +- .../introduceParameter/varargs.kt.after | 6 ++-- .../functions/factories/ArrayFIF.java | 2 +- .../standardClasses/cases/arraySize.kt | 2 +- .../kotlin/collections/DeprecatedBuiltins.kt | 27 +++++++++++++++ 38 files changed, 147 insertions(+), 107 deletions(-) diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/intrinsics/ArraySize.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/intrinsics/ArraySize.kt index 558b2a8607b..a3ce902f8b8 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/intrinsics/ArraySize.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/intrinsics/ArraySize.kt @@ -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() + } } diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/intrinsics/IntrinsicMethods.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/intrinsics/IntrinsicMethods.java index 78ca676c10b..527e9bdf10d 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/intrinsics/IntrinsicMethods.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/intrinsics/IntrinsicMethods.java @@ -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); diff --git a/compiler/testData/builtin-classes.txt b/compiler/testData/builtin-classes.txt index 1a6a81ca57d..0fa231bef3f 100644 --- a/compiler/testData/builtin-classes.txt +++ b/compiler/testData/builtin-classes.txt @@ -14,11 +14,12 @@ public open class Any { public final class Array : kotlin.Cloneable { /*primary*/ private constructor Array() + public final val size: kotlin.Int + public final fun (): kotlin.Int public open override /*1*/ fun clone(): kotlin.Array public final operator fun get(/*0*/ index: kotlin.Int): T public final operator fun iterator(): kotlin.Iterator 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 { @@ -32,11 +33,12 @@ public final class Boolean : kotlin.Comparable { public final class BooleanArray : kotlin.Cloneable { /*primary*/ public constructor BooleanArray(/*0*/ size: kotlin.Int) + public final val size: kotlin.Int + public final fun (): 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 { @@ -113,11 +115,12 @@ public final class Byte : kotlin.Number, kotlin.Comparable { public final class ByteArray : kotlin.Cloneable { /*primary*/ public constructor ByteArray(/*0*/ size: kotlin.Int) + public final val size: kotlin.Int + public final fun (): 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 { @@ -199,11 +202,12 @@ public final class Char : kotlin.Comparable { public final class CharArray : kotlin.Cloneable { /*primary*/ public constructor CharArray(/*0*/ size: kotlin.Int) + public final val size: kotlin.Int + public final fun (): 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 { @@ -388,11 +392,12 @@ public final class Double : kotlin.Number, kotlin.Comparable { public final class DoubleArray : kotlin.Cloneable { /*primary*/ public constructor DoubleArray(/*0*/ size: kotlin.Int) + public final val size: kotlin.Int + public final fun (): 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 { @@ -538,11 +543,12 @@ public final class Float : kotlin.Number, kotlin.Comparable { public final class FloatArray : kotlin.Cloneable { /*primary*/ public constructor FloatArray(/*0*/ size: kotlin.Int) + public final val size: kotlin.Int + public final fun (): 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 { @@ -691,11 +697,12 @@ public final class Int : kotlin.Number, kotlin.Comparable { public final class IntArray : kotlin.Cloneable { /*primary*/ public constructor IntArray(/*0*/ size: kotlin.Int) + public final val size: kotlin.Int + public final fun (): 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 { @@ -867,11 +874,12 @@ public final class Long : kotlin.Number, kotlin.Comparable { public final class LongArray : kotlin.Cloneable { /*primary*/ public constructor LongArray(/*0*/ size: kotlin.Int) + public final val size: kotlin.Int + public final fun (): 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 { @@ -1178,11 +1186,12 @@ public final class Short : kotlin.Number, kotlin.Comparable { public final class ShortArray : kotlin.Cloneable { /*primary*/ public constructor ShortArray(/*0*/ size: kotlin.Int) + public final val size: kotlin.Int + public final fun (): 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 { diff --git a/compiler/testData/codegen/box/arrays/kt2997.kt b/compiler/testData/codegen/box/arrays/kt2997.kt index e38fce8c3b2..f42acc4a2e9 100644 --- a/compiler/testData/codegen/box/arrays/kt2997.kt +++ b/compiler/testData/codegen/box/arrays/kt2997.kt @@ -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 diff --git a/compiler/testData/codegen/box/arrays/kt503.kt b/compiler/testData/codegen/box/arrays/kt503.kt index 07209d310b2..4f230bd7d99 100644 --- a/compiler/testData/codegen/box/arrays/kt503.kt +++ b/compiler/testData/codegen/box/arrays/kt503.kt @@ -26,4 +26,4 @@ fun box() : String { } fun thirdElementIsThree(a : IntArray) = - a.size() >= 3 && a[2] == 3 + a.size >= 3 && a[2] == 3 diff --git a/compiler/testData/codegen/box/arrays/kt779.kt b/compiler/testData/codegen/box/arrays/kt779.kt index ab496bf2d13..a56d1e0874b 100644 --- a/compiler/testData/codegen/box/arrays/kt779.kt +++ b/compiler/testData/codegen/box/arrays/kt779.kt @@ -1,3 +1,3 @@ -val Array.length : Int get() = this.size() +val Array.length : Int get() = this.size fun box() = if(arrayOfNulls(10).length == 10) "OK" else "fail" diff --git a/compiler/testData/codegen/box/classes/kt1018.kt b/compiler/testData/codegen/box/classes/kt1018.kt index a4b6f375edc..6e192f5e0be 100644 --- a/compiler/testData/codegen/box/classes/kt1018.kt +++ b/compiler/testData/codegen/box/classes/kt1018.kt @@ -1,7 +1,7 @@ public class StockMarketTableModel() { public fun getColumnCount() : Int { - return COLUMN_TITLES?.size()!! + return COLUMN_TITLES?.size!! } companion object { diff --git a/compiler/testData/codegen/box/controlStructures/quicksort.kt b/compiler/testData/codegen/box/controlStructures/quicksort.kt index fb694664eee..381a8cf44bb 100644 --- a/compiler/testData/codegen/box/controlStructures/quicksort.kt +++ b/compiler/testData/codegen/box/controlStructures/quicksort.kt @@ -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" diff --git a/compiler/testData/codegen/box/enum/companionObjectInEnum.kt b/compiler/testData/codegen/box/enum/companionObjectInEnum.kt index 726f41b4f05..3e6d423f64e 100644 --- a/compiler/testData/codegen/box/enum/companionObjectInEnum.kt +++ b/compiler/testData/codegen/box/enum/companionObjectInEnum.kt @@ -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" } diff --git a/compiler/testData/codegen/box/enum/emptyEnumValuesValueOf.kt b/compiler/testData/codegen/box/enum/emptyEnumValuesValueOf.kt index 83b12c9e691..6cad0c98a04 100644 --- a/compiler/testData/codegen/box/enum/emptyEnumValuesValueOf.kt +++ b/compiler/testData/codegen/box/enum/emptyEnumValuesValueOf.kt @@ -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") diff --git a/compiler/testData/codegen/box/functions/kt3214.kt b/compiler/testData/codegen/box/functions/kt3214.kt index df246c0dabb..b675ae4f3cd 100644 --- a/compiler/testData/codegen/box/functions/kt3214.kt +++ b/compiler/testData/codegen/box/functions/kt3214.kt @@ -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 { diff --git a/compiler/testData/codegen/box/operatorConventions/compareTo/extensionArray.kt b/compiler/testData/codegen/box/operatorConventions/compareTo/extensionArray.kt index 14af95c1068..e9216c54ce1 100644 --- a/compiler/testData/codegen/box/operatorConventions/compareTo/extensionArray.kt +++ b/compiler/testData/codegen/box/operatorConventions/compareTo/extensionArray.kt @@ -7,7 +7,7 @@ fun checkLess(x: Array, y: Array) = when { else -> "OK" } -fun Array.compareTo(other: Array) = size() - other.size() +fun Array.compareTo(other: Array) = size - other.size fun box(): String { val a = arrayOfNulls(0) as Array diff --git a/compiler/testData/codegen/box/primitiveTypes/kt935.kt b/compiler/testData/codegen/box/primitiveTypes/kt935.kt index dd9a4fa4d26..7ca6d8b4dc2 100644 --- a/compiler/testData/codegen/box/primitiveTypes/kt935.kt +++ b/compiler/testData/codegen/box/primitiveTypes/kt935.kt @@ -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 Array.isEmpty : Boolean get() = size() == 0 +val Array.isEmpty : Boolean get() = size == 0 diff --git a/compiler/testData/codegen/box/strings/rawStringsWithManyQuotes.kt b/compiler/testData/codegen/box/strings/rawStringsWithManyQuotes.kt index 13a33ee8b95..1fb97bd718e 100644 --- a/compiler/testData/codegen/box/strings/rawStringsWithManyQuotes.kt +++ b/compiler/testData/codegen/box/strings/rawStringsWithManyQuotes.kt @@ -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}'" } diff --git a/compiler/testData/codegen/box/vararg/kt581.kt b/compiler/testData/codegen/box/vararg/kt581.kt index c3e0a729819..72c306274b5 100644 --- a/compiler/testData/codegen/box/vararg/kt581.kt +++ b/compiler/testData/codegen/box/vararg/kt581.kt @@ -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) diff --git a/compiler/testData/codegen/box/vararg/kt6192.kt b/compiler/testData/codegen/box/vararg/kt6192.kt index bd9b8f93a7d..89296cf18c2 100644 --- a/compiler/testData/codegen/box/vararg/kt6192.kt +++ b/compiler/testData/codegen/box/vararg/kt6192.kt @@ -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" } diff --git a/compiler/testData/codegen/box/vararg/varargsAndFunctionLiterals.kt b/compiler/testData/codegen/box/vararg/varargsAndFunctionLiterals.kt index d65aab45c5a..3c7dca68c44 100644 --- a/compiler/testData/codegen/box/vararg/varargsAndFunctionLiterals.kt +++ b/compiler/testData/codegen/box/vararg/varargsAndFunctionLiterals.kt @@ -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" diff --git a/compiler/testData/diagnostics/tests/incompleteCode/arrayBracketsRange.kt b/compiler/testData/diagnostics/tests/incompleteCode/arrayBracketsRange.kt index 5ec4070fce5..363bd2d7842 100644 --- a/compiler/testData/diagnostics/tests/incompleteCode/arrayBracketsRange.kt +++ b/compiler/testData/diagnostics/tests/incompleteCode/arrayBracketsRange.kt @@ -4,6 +4,6 @@ fun main(args : Array) { var ints : Array = arrayOfNulls(31) ints[0] = 4; ints[11] = 5; ints[2] =7 - for(i in 0..ints.size()) + for(i in 0..ints.size) ints[i } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/constraints/constraintOnFunctionLiteral.kt b/compiler/testData/diagnostics/tests/inference/constraints/constraintOnFunctionLiteral.kt index 29af4560871..cb4aefda33a 100644 --- a/compiler/testData/diagnostics/tests/inference/constraints/constraintOnFunctionLiteral.kt +++ b/compiler/testData/diagnostics/tests/inference/constraints/constraintOnFunctionLiteral.kt @@ -2,9 +2,9 @@ package c import java.util.ArrayList -fun Array.toIntArray(): IntArray = this.mapTo(IntArray(size()), {it}) +fun Array.toIntArray(): IntArray = this.mapTo(IntArray(size), {it}) -fun Array.toArrayList(): ArrayList = this.mapTo(ArrayList(size()), {it}) +fun Array.toArrayList(): ArrayList = this.mapTo(ArrayList(size), {it}) public fun > Array.mapTo(result: C, transform : (T) -> R) : C = throw Exception("$result $transform") diff --git a/compiler/testData/diagnostics/tests/inference/listConstructor.kt b/compiler/testData/diagnostics/tests/inference/listConstructor.kt index c4012f35f62..65e308bcd3a 100644 --- a/compiler/testData/diagnostics/tests/inference/listConstructor.kt +++ b/compiler/testData/diagnostics/tests/inference/listConstructor.kt @@ -22,7 +22,7 @@ fun test() { // --------------------- // copy from kotlin util -fun arrayList(vararg values: T) : ArrayList = values.toCollection(ArrayList(values.size())) +fun arrayList(vararg values: T) : ArrayList = values.toCollection(ArrayList(values.size)) fun > Array.toCollection(result: C) : C { for (element in this) result.add(element) diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt2179.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt2179.kt index d079e8e0ca1..b19c3e751d1 100644 --- a/compiler/testData/diagnostics/tests/inference/regressions/kt2179.kt +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt2179.kt @@ -25,7 +25,7 @@ fun test() { //------------ -fun arrayList(vararg values: T) : ArrayList = values.toCollection(ArrayList(values.size())) +fun arrayList(vararg values: T) : ArrayList = values.toCollection(ArrayList(values.size)) fun Collection.map(transform : (T) -> R) : List { return mapTo(java.util.ArrayList(this.size), transform) diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt2324.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt2324.kt index a59130b0b3c..3af09afefac 100644 --- a/compiler/testData/diagnostics/tests/inference/regressions/kt2324.kt +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt2324.kt @@ -27,7 +27,7 @@ fun testSomeFunction() { fun assertEquals(expected: Any?, actual: Any?, message: String = "") { } -fun arrayList(vararg values: T) : ArrayList = values.toCollection(ArrayList(values.size())) +fun arrayList(vararg values: T) : ArrayList = values.toCollection(ArrayList(values.size)) fun > Array.toCollection(result: C) : C { for (element in this) result.add(element) diff --git a/compiler/testData/diagnostics/tests/regressions/kt312.kt b/compiler/testData/diagnostics/tests/regressions/kt312.kt index 347b91a678f..b6ebf389e72 100644 --- a/compiler/testData/diagnostics/tests/regressions/kt312.kt +++ b/compiler/testData/diagnostics/tests/regressions/kt312.kt @@ -4,7 +4,7 @@ public inline fun Array(n: Int, block: (Int) -> T): Array = null! // KT-312 Nullability problem when a nullable version of a generic type is returned fun Array.safeGet(index : Int) : T? { - return if (index < size()) this[index] else null + return if (index < size) this[index] else null } val args : Array = Array(1, {""}) diff --git a/compiler/testData/diagnostics/tests/regressions/kt580.kt b/compiler/testData/diagnostics/tests/regressions/kt580.kt index 460aa8cc956..c85036ad700 100644 --- a/compiler/testData/diagnostics/tests/regressions/kt580.kt +++ b/compiler/testData/diagnostics/tests/regressions/kt580.kt @@ -17,6 +17,6 @@ fun main() { } } -fun Array.lastIndex() = size() - 1 -val Array.lastIndex : Int get() = size() - 1 +fun Array.lastIndex() = size - 1 +val Array.lastIndex : Int get() = size - 1 val Array.indices : IntRange get() = IntRange(0, lastIndex) diff --git a/compiler/testData/diagnostics/tests/smartCasts/varnotnull/varCapturedInInlineClosure.kt b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/varCapturedInInlineClosure.kt index 5f992909d43..8acd935b33f 100644 --- a/compiler/testData/diagnostics/tests/smartCasts/varnotnull/varCapturedInInlineClosure.kt +++ b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/varCapturedInInlineClosure.kt @@ -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]) } diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/PackageGenTest.java b/compiler/tests/org/jetbrains/kotlin/codegen/PackageGenTest.java index 1a593e1ac72..5329b63a53c 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/PackageGenTest.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/PackageGenTest.java @@ -350,7 +350,7 @@ public class PackageGenTest extends CodegenTestCase { } public void testArraySize() throws Exception { - loadText("fun foo(a: Array) = a.size()"); + loadText("fun foo(a: Array) = 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); diff --git a/core/builtins/native/kotlin/Array.kt b/core/builtins/native/kotlin/Array.kt index 9f98407486b..95bb2d5d068 100644 --- a/core/builtins/native/kotlin/Array.kt +++ b/core/builtins/native/kotlin/Array.kt @@ -45,7 +45,7 @@ public class Array 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. diff --git a/core/builtins/native/kotlin/Arrays.kt b/core/builtins/native/kotlin/Arrays.kt index 953b77ef4db..416ecc2831b 100644 --- a/core/builtins/native/kotlin/Arrays.kt +++ b/core/builtins/native/kotlin/Arrays.kt @@ -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 diff --git a/core/runtime.jvm/src/kotlin/jvm/internal/ArrayIterator.kt b/core/runtime.jvm/src/kotlin/jvm/internal/ArrayIterator.kt index 0facf625915..09cc5c6d939 100644 --- a/core/runtime.jvm/src/kotlin/jvm/internal/ArrayIterator.kt +++ b/core/runtime.jvm/src/kotlin/jvm/internal/ArrayIterator.kt @@ -18,7 +18,7 @@ package kotlin.jvm.internal private class ArrayIterator(val array: Array) : Iterator { private var index = 0 - override fun hasNext() = index < array.size() + override fun hasNext() = index < array.size override fun next() = array[index++] } diff --git a/core/runtime.jvm/src/kotlin/jvm/internal/ArrayIterators.kt b/core/runtime.jvm/src/kotlin/jvm/internal/ArrayIterators.kt index 1e44baec9e8..4442e816e52 100644 --- a/core/runtime.jvm/src/kotlin/jvm/internal/ArrayIterators.kt +++ b/core/runtime.jvm/src/kotlin/jvm/internal/ArrayIterators.kt @@ -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++] } diff --git a/core/runtime.jvm/src/kotlin/jvm/internal/PrimitiveSpreadBuilders.kt b/core/runtime.jvm/src/kotlin/jvm/internal/PrimitiveSpreadBuilders.kt index fb37ca7e6c0..e877fe3ae0f 100644 --- a/core/runtime.jvm/src/kotlin/jvm/internal/PrimitiveSpreadBuilders.kt +++ b/core/runtime.jvm/src/kotlin/jvm/internal/PrimitiveSpreadBuilders.kt @@ -62,7 +62,7 @@ private abstract class PrimitiveSpreadBuilder(private val size: Int) { public class ByteSpreadBuilder(size: Int) : PrimitiveSpreadBuilder(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(si public class CharSpreadBuilder(size: Int) : PrimitiveSpreadBuilder(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(si public class DoubleSpreadBuilder(size: Int) : PrimitiveSpreadBuilder(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(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( public class IntSpreadBuilder(size: Int) : PrimitiveSpreadBuilder(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(size public class LongSpreadBuilder(size: Int) : PrimitiveSpreadBuilder(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(si public class ShortSpreadBuilder(size: Int) : PrimitiveSpreadBuilder(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( public class BooleanSpreadBuilder(size: Int) : PrimitiveSpreadBuilder(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 diff --git a/generators/src/org/jetbrains/kotlin/generators/builtins/arrayIterators.kt b/generators/src/org/jetbrains/kotlin/generators/builtins/arrayIterators.kt index e44cc1985a5..b4f917beadf 100644 --- a/generators/src/org/jetbrains/kotlin/generators/builtins/arrayIterators.kt +++ b/generators/src/org/jetbrains/kotlin/generators/builtins/arrayIterators.kt @@ -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() diff --git a/generators/src/org/jetbrains/kotlin/generators/builtins/arrays.kt b/generators/src/org/jetbrains/kotlin/generators/builtins/arrays.kt index 17b74c82ede..f994abb0402 100644 --- a/generators/src/org/jetbrains/kotlin/generators/builtins/arrays.kt +++ b/generators/src/org/jetbrains/kotlin/generators/builtins/arrays.kt @@ -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") diff --git a/idea/testData/refactoring/introduceParameter/varargs.kt b/idea/testData/refactoring/introduceParameter/varargs.kt index 84fe8bc008a..69b45828aa6 100644 --- a/idea/testData/refactoring/introduceParameter/varargs.kt +++ b/idea/testData/refactoring/introduceParameter/varargs.kt @@ -1,6 +1,6 @@ // WITH_DEFAULT_VALUE: false fun foo(vararg a: Int): Int { - return (a.size() + 1) * 2 + return (a.size + 1) * 2 } fun test() { diff --git a/idea/testData/refactoring/introduceParameter/varargs.kt.after b/idea/testData/refactoring/introduceParameter/varargs.kt.after index 1d8f873e49e..66f017189eb 100644 --- a/idea/testData/refactoring/introduceParameter/varargs.kt.after +++ b/idea/testData/refactoring/introduceParameter/varargs.kt.after @@ -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) } \ No newline at end of file diff --git a/js/js.translator/src/org/jetbrains/kotlin/js/translate/intrinsic/functions/factories/ArrayFIF.java b/js/js.translator/src/org/jetbrains/kotlin/js/translate/intrinsic/functions/factories/ArrayFIF.java index 61203eced5e..b0815f9547d 100644 --- a/js/js.translator/src/org/jetbrains/kotlin/js/translate/intrinsic/functions/factories/ArrayFIF.java +++ b/js/js.translator/src/org/jetbrains/kotlin/js/translate/intrinsic/functions/factories/ArrayFIF.java @@ -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, ""), LENGTH_PROPERTY_INTRINSIC); add(pattern(ARRAYS, "iterator"), new KotlinFunctionIntrinsic("arrayIterator")); add(pattern(NUMBER_ARRAY, ""),new KotlinFunctionIntrinsic("numberArrayOfSize")); add(pattern(CHAR_ARRAY, ""), new KotlinFunctionIntrinsic("charArrayOfSize")); diff --git a/js/js.translator/testData/standardClasses/cases/arraySize.kt b/js/js.translator/testData/standardClasses/cases/arraySize.kt index b8569f677f5..919fc4c3100 100644 --- a/js/js.translator/testData/standardClasses/cases/arraySize.kt +++ b/js/js.translator/testData/standardClasses/cases/arraySize.kt @@ -6,4 +6,4 @@ class A() { val a1 = arrayOfNulls(3) val a2 = arrayOfNulls(2) -fun box() = (a1.size() == 3 && a2.size() == 2) \ No newline at end of file +fun box() = (a1.size == 3 && a2.size == 2) \ No newline at end of file diff --git a/libraries/stdlib/src/kotlin/collections/DeprecatedBuiltins.kt b/libraries/stdlib/src/kotlin/collections/DeprecatedBuiltins.kt index 00f7bf2b948..4a012a8447e 100644 --- a/libraries/stdlib/src/kotlin/collections/DeprecatedBuiltins.kt +++ b/libraries/stdlib/src/kotlin/collections/DeprecatedBuiltins.kt @@ -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