Transform CharSequence.length to property
This commit is contained in:
committed by
Mikhail Glukhikh
parent
6c0d55e4ed
commit
1305d9755a
-1
@@ -98,7 +98,6 @@ internal val unaryOperations: HashMap<UnaryOperationKey<*>, Pair<Function1<Any?,
|
||||
unaryOperation(SHORT, "toLong", { a -> a.toLong() }, emptyUnaryFun),
|
||||
unaryOperation(SHORT, "toShort", { a -> a.toShort() }, emptyUnaryFun),
|
||||
unaryOperation(SHORT, "toString", { a -> a.toString() }, emptyUnaryFun),
|
||||
unaryOperation(STRING, "length", { a -> a.length() }, emptyUnaryFun),
|
||||
unaryOperation(STRING, "toString", { a -> a.toString() }, emptyUnaryFun)
|
||||
)
|
||||
|
||||
|
||||
+4
-2
@@ -262,8 +262,9 @@ public final class CharRange : kotlin.Range<kotlin.Char>, kotlin.Progression<kot
|
||||
}
|
||||
|
||||
public interface CharSequence {
|
||||
public abstract val length: kotlin.Int
|
||||
public abstract fun <get-length>(): kotlin.Int
|
||||
public abstract operator fun get(/*0*/ index: kotlin.Int): kotlin.Char
|
||||
public abstract fun length(): kotlin.Int
|
||||
public abstract fun subSequence(/*0*/ start: kotlin.Int, /*1*/ end: kotlin.Int): kotlin.CharSequence
|
||||
}
|
||||
|
||||
@@ -1247,9 +1248,10 @@ public final class ShortRange : kotlin.Range<kotlin.Short>, kotlin.Progression<k
|
||||
|
||||
public final class String : kotlin.Comparable<kotlin.String>, kotlin.CharSequence {
|
||||
/*primary*/ public constructor String()
|
||||
public open override /*1*/ val length: kotlin.Int
|
||||
public open override /*1*/ fun <get-length>(): kotlin.Int
|
||||
public open override /*1*/ fun compareTo(/*0*/ other: kotlin.String): kotlin.Int
|
||||
public open override /*1*/ fun get(/*0*/ index: kotlin.Int): kotlin.Char
|
||||
public open override /*1*/ fun length(): kotlin.Int
|
||||
public final operator fun plus(/*0*/ other: kotlin.Any?): kotlin.String
|
||||
public open override /*1*/ fun subSequence(/*0*/ start: kotlin.Int, /*1*/ end: kotlin.Int): kotlin.CharSequence
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ import java.util.*;
|
||||
public class J {
|
||||
|
||||
public static class B extends A {
|
||||
public int getLength() { return 456; }
|
||||
public char get(int index) {
|
||||
if (index == 1) return 'a';
|
||||
return super.get(index);
|
||||
@@ -13,6 +14,10 @@ public class J {
|
||||
B b = new B();
|
||||
CharSequence cs = (CharSequence) b;
|
||||
|
||||
if (cs.length() != 456) return "fail 01";
|
||||
if (b.length() != 456) return "fail 02";
|
||||
if (b.getLength() != 456) return "fail 03";
|
||||
|
||||
if (cs.charAt(0) != 'z') return "fail 1";
|
||||
if (b.get(0) != 'z') return "fail 2";
|
||||
|
||||
|
||||
+9
-3
@@ -1,7 +1,5 @@
|
||||
open class A : CharSequence {
|
||||
override fun length(): Int {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
override val length: Int = 123
|
||||
|
||||
override fun get(index: Int) = 'z';
|
||||
|
||||
@@ -24,5 +22,13 @@ fun box(): String {
|
||||
if (b.get(1) != 'a') return "fail 12"
|
||||
if (a.get(1) != 'z') return "fail 13"
|
||||
|
||||
var cs: CharSequence = a
|
||||
if (a.length != 123) return "fail 14"
|
||||
if (cs.length != 123) return "fail 15"
|
||||
|
||||
cs = b
|
||||
if (b.length != 456) return "fail 16"
|
||||
if (b.length != 456) return "fail 17"
|
||||
|
||||
return J.foo();
|
||||
}
|
||||
|
||||
@@ -14,10 +14,10 @@ public final class JSub : java.lang.CharSequence {
|
||||
|
||||
public final class Sub : kotlin.CharSequence {
|
||||
public constructor Sub()
|
||||
public abstract override /*1*/ /*fake_override*/ val length: kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public abstract override /*1*/ /*fake_override*/ fun get(/*0*/ index: kotlin.Int): kotlin.Char
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public abstract override /*1*/ /*fake_override*/ fun length(): kotlin.Int
|
||||
public abstract override /*1*/ /*fake_override*/ fun subSequence(/*0*/ start: kotlin.Int, /*1*/ end: kotlin.Int): kotlin.CharSequence
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
|
||||
+5
@@ -1,17 +1,20 @@
|
||||
// FILE: A.java
|
||||
abstract public class A implements CharSequence {
|
||||
public char charAt(int x) { }
|
||||
public int length() { return 1; }
|
||||
}
|
||||
|
||||
// FILE: C.java
|
||||
abstract public class C implements CharSequence {
|
||||
public char get(int x) { }
|
||||
public int length() { return 1; }
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
|
||||
abstract class B : A(), CharSequence {
|
||||
override operator fun get(index: Int) = '1'
|
||||
override val length: Int get() = 1
|
||||
}
|
||||
|
||||
fun main(a: A, b: B, c: C) {
|
||||
@@ -22,4 +25,6 @@ fun main(a: A, b: B, c: C) {
|
||||
a.get(0)
|
||||
b.get(0)
|
||||
c.get(0)
|
||||
|
||||
a.length + b.length + c.length
|
||||
}
|
||||
|
||||
+3
-3
@@ -4,30 +4,30 @@ public fun main(/*0*/ a: A, /*1*/ b: B, /*2*/ c: C): kotlin.Unit
|
||||
|
||||
public abstract class A : kotlin.CharSequence {
|
||||
public constructor A()
|
||||
public open override /*1*/ val length: kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ fun get(/*0*/ x: kotlin.Int): kotlin.Char
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public abstract override /*1*/ /*fake_override*/ fun length(): kotlin.Int
|
||||
public abstract override /*1*/ /*fake_override*/ fun subSequence(/*0*/ start: kotlin.Int, /*1*/ end: kotlin.Int): kotlin.CharSequence
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
|
||||
public abstract class B : A, kotlin.CharSequence {
|
||||
public constructor B()
|
||||
public open override /*2*/ val length: kotlin.Int
|
||||
public open override /*2*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*2*/ fun get(/*0*/ index: kotlin.Int): kotlin.Char
|
||||
public open override /*2*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public abstract override /*2*/ /*fake_override*/ fun length(): kotlin.Int
|
||||
public abstract override /*2*/ /*fake_override*/ fun subSequence(/*0*/ start: kotlin.Int, /*1*/ end: kotlin.Int): kotlin.CharSequence
|
||||
public open override /*2*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
|
||||
public abstract class C : kotlin.CharSequence {
|
||||
public constructor C()
|
||||
public open override /*1*/ val length: kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ fun get(/*0*/ index: kotlin.Int): kotlin.Char
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public abstract override /*1*/ /*fake_override*/ fun length(): kotlin.Int
|
||||
public abstract override /*1*/ /*fake_override*/ fun subSequence(/*0*/ start: kotlin.Int, /*1*/ end: kotlin.Int): kotlin.CharSequence
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
|
||||
+2
-1
@@ -5,8 +5,9 @@ package test
|
||||
}
|
||||
|
||||
public interface Foo</*0*/ T : @test.A() kotlin.Number> : @test.A() kotlin.CharSequence {
|
||||
public abstract override /*1*/ /*fake_override*/ val length: kotlin.Int
|
||||
public abstract override /*1*/ /*fake_override*/ fun <get-length>(): kotlin.Int
|
||||
public abstract fun </*0*/ E, /*1*/ F : @test.A() E> bar(): kotlin.Unit
|
||||
public abstract override /*1*/ /*fake_override*/ fun get(/*0*/ index: kotlin.Int): kotlin.Char
|
||||
public abstract override /*1*/ /*fake_override*/ fun length(): kotlin.Int
|
||||
public abstract override /*1*/ /*fake_override*/ fun subSequence(/*0*/ start: kotlin.Int, /*1*/ end: kotlin.Int): kotlin.CharSequence
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user