Make Pair and Triple data classes

This commit is contained in:
Alexander Udalov
2014-07-24 22:35:48 +04:00
parent 5dc37217c8
commit cdbdfaf182
5 changed files with 25 additions and 61 deletions
@@ -0,0 +1,15 @@
package a
class MyPair {
fun component1() = 1
fun component2() = 2
}
fun main(args: Array<String>) {
val p = MyPair()
val (a, b<caret>) = p
}
// MULTIRESOLVE
// REF: (in a.MyPair).component1()
// REF: (in a.MyPair).component2()
@@ -1,10 +0,0 @@
package a
fun main(args: Array<String>) {
val p = Pair(1, 2)
val (a, b<caret>) = p
}
// MULTIRESOLVE
// REF: (in kotlin.Pair).component1()
// REF: (in kotlin.Pair).component2()
@@ -157,9 +157,14 @@ public class ReferenceResolveTestGenerated extends AbstractReferenceResolveTest
doTest("idea/testData/resolve/references/JavaReference.kt");
}
@TestMetadata("MultiDeclarationReference.kt")
public void testMultiDeclarationReference() throws Exception {
doTest("idea/testData/resolve/references/MultiDeclarationReference.kt");
@TestMetadata("MultiDeclarationExtension.kt")
public void testMultiDeclarationExtension() throws Exception {
doTest("idea/testData/resolve/references/MultiDeclarationExtension.kt");
}
@TestMetadata("MultiDeclarationMember.kt")
public void testMultiDeclarationMember() throws Exception {
doTest("idea/testData/resolve/references/MultiDeclarationMember.kt");
}
@TestMetadata("PackageReference.kt")
@@ -172,11 +177,6 @@ public class ReferenceResolveTestGenerated extends AbstractReferenceResolveTest
doTest("idea/testData/resolve/references/PackageReferenceInImport.kt");
}
@TestMetadata("PairMultiDeclaration.kt")
public void testPairMultiDeclaration() throws Exception {
doTest("idea/testData/resolve/references/PairMultiDeclaration.kt");
}
@TestMetadata("PropertyPlaceInClassObjectInObject.kt")
public void testPropertyPlaceInClassObjectInObject() throws Exception {
doTest("idea/testData/resolve/references/PropertyPlaceInClassObjectInObject.kt");
+2 -43
View File
@@ -2,58 +2,17 @@ package kotlin
import java.io.Serializable
private fun Any?.safeHashCode() : Int = if (this == null) 0 else this.hashCode()
// TODO: make it a data class
public class Pair<out A, out B> (
public data class Pair<out A, out B>(
public val first: A,
public val second: B
) : Serializable {
public fun component1(): A = first
public fun component2(): B = second
override fun toString(): String = "($first, $second)"
override fun hashCode(): Int {
var result = first.safeHashCode()
result = 31 * result + second.safeHashCode()
return result;
}
override fun equals(o: Any?): Boolean {
if (this identityEquals o) return true;
if (o == null || this.javaClass != o.javaClass) return false;
val t = o as Pair<*, *>
return first == t.first && second == t.second;
}
}
public class Triple<A, B, C> (
public data class Triple<out A, out B, out C>(
public val first: A,
public val second: B,
public val third: C
) : Serializable {
public fun component1(): A = first
public fun component2(): B = second
public fun component3(): C = third
override fun toString(): String = "($first, $second, $third)"
override fun hashCode(): Int {
var result = first.safeHashCode()
result = 31 * result + second.safeHashCode()
result = 31 * result + third.safeHashCode()
return result;
}
override fun equals(o: Any?): Boolean {
if (this identityEquals o) return true;
if (o == null || this.javaClass != o.javaClass) return false;
val t = o as Triple<*, *, *>
return first == t.first &&
second == t.second &&
third == t.third;
}
}