Generate equals()/hashCode(): Fix hashCode() implementation

#KT-11638 Fixed
This commit is contained in:
Alexey Sedunov
2016-03-28 18:21:57 +03:00
parent 768da05ba9
commit cbb6f7ed63
10 changed files with 16 additions and 15 deletions
+1
View File
@@ -33,6 +33,7 @@
- Add kotlinClassName() and kotlinFunctionName() macros for use in live templates
- Complete private members from libraries in Evaluate Expression dialog
- Show error message when debug info for some local variable is corrupted
- [KT-11638](https://youtrack.jetbrains.com/issue/KT-11638) Fixed hashCode() implementation in "Generate equals/hashCode" action
## 1.0.1-2
@@ -221,7 +221,7 @@ class KotlinGenerateEqualsAndHashcodeAction : KotlinGenerateMemberActionBase<Kot
val resultVarName = KotlinNameSuggester.suggestNameByName("result", validator)
StringBuilder().apply {
append("var $resultVarName = $initialValue\n")
propertyIterator.forEach { append("$resultVarName += 31 * $resultVarName + ${it.genVariableHashCode(true)}\n") }
propertyIterator.forEach { append("$resultVarName = 31 * $resultVarName + ${it.genVariableHashCode(true)}\n") }
append("return $resultVarName")
}.toString()
} else "return $initialValue"
@@ -22,8 +22,8 @@ class A(val n: IntArray, val s: Array<String>) {
override fun hashCode(): Int{
var result = Arrays.hashCode(n)
result += 31 * result + Arrays.hashCode(s)
result += 31 * result + f.hashCode()
result = 31 * result + Arrays.hashCode(s)
result = 31 * result + f.hashCode()
return result
}
}
@@ -20,8 +20,8 @@ class A(val n: Int, val s: String) {
override fun hashCode(): Int{
var result = n
result += 31 * result + s.hashCode()
result += 31 * result + f.hashCode()
result = 31 * result + s.hashCode()
result = 31 * result + f.hashCode()
return result
}
}
@@ -20,8 +20,8 @@ class A(val n: Int?, val s: String) {
override fun hashCode(): Int{
var result = n ?: 0
result += 31 * result + s.hashCode()
result += 31 * result + (f?.hashCode() ?: 0)
result = 31 * result + s.hashCode()
result = 31 * result + (f?.hashCode() ?: 0)
return result
}
}
@@ -26,9 +26,9 @@ class A(val n: Int, val s: String) : X() {
override fun hashCode(): Int{
var result = super.hashCode()
result += 31 * result + n
result += 31 * result + s.hashCode()
result += 31 * result + f.hashCode()
result = 31 * result + n
result = 31 * result + s.hashCode()
result = 31 * result + f.hashCode()
return result
}
}
@@ -17,7 +17,7 @@ class A(val result: Int, val s: String) {
override fun hashCode(): Int{
var result1 = result
result1 += 31 * result1 + s.hashCode()
result1 = 31 * result1 + s.hashCode()
return result1
}
}
@@ -22,8 +22,8 @@ class A(val n: IntArray?, val s: Array<String>?) {
override fun hashCode(): Int{
var result = n?.let { Arrays.hashCode(it) } ?: 0
result += 31 * result + (s?.let { Arrays.hashCode(it) } ?: 0)
result += 31 * result + f.hashCode()
result = 31 * result + (s?.let { Arrays.hashCode(it) } ?: 0)
result = 31 * result + f.hashCode()
return result
}
}
@@ -17,7 +17,7 @@ class A(val n: Int) : X() {
override fun hashCode(): Int{
var result = super.hashCode()
result += 31 * result + n
result = 31 * result + n
return result
}
}
@@ -22,7 +22,7 @@ class A(val n: Int) : X() {
override fun hashCode(): Int{
var result = super.hashCode()
result += 31 * result + n
result = 31 * result + n
return result
}
}