Generate equals()/hashCode(): Fix hashCode() implementation
#KT-11638 Fixed
This commit is contained in:
@@ -33,6 +33,7 @@
|
|||||||
- Add kotlinClassName() and kotlinFunctionName() macros for use in live templates
|
- Add kotlinClassName() and kotlinFunctionName() macros for use in live templates
|
||||||
- Complete private members from libraries in Evaluate Expression dialog
|
- Complete private members from libraries in Evaluate Expression dialog
|
||||||
- Show error message when debug info for some local variable is corrupted
|
- 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
|
## 1.0.1-2
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -221,7 +221,7 @@ class KotlinGenerateEqualsAndHashcodeAction : KotlinGenerateMemberActionBase<Kot
|
|||||||
val resultVarName = KotlinNameSuggester.suggestNameByName("result", validator)
|
val resultVarName = KotlinNameSuggester.suggestNameByName("result", validator)
|
||||||
StringBuilder().apply {
|
StringBuilder().apply {
|
||||||
append("var $resultVarName = $initialValue\n")
|
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")
|
append("return $resultVarName")
|
||||||
}.toString()
|
}.toString()
|
||||||
} else "return $initialValue"
|
} else "return $initialValue"
|
||||||
|
|||||||
@@ -22,8 +22,8 @@ class A(val n: IntArray, val s: Array<String>) {
|
|||||||
|
|
||||||
override fun hashCode(): Int{
|
override fun hashCode(): Int{
|
||||||
var result = Arrays.hashCode(n)
|
var result = Arrays.hashCode(n)
|
||||||
result += 31 * result + Arrays.hashCode(s)
|
result = 31 * result + Arrays.hashCode(s)
|
||||||
result += 31 * result + f.hashCode()
|
result = 31 * result + f.hashCode()
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+2
-2
@@ -20,8 +20,8 @@ class A(val n: Int, val s: String) {
|
|||||||
|
|
||||||
override fun hashCode(): Int{
|
override fun hashCode(): Int{
|
||||||
var result = n
|
var result = n
|
||||||
result += 31 * result + s.hashCode()
|
result = 31 * result + s.hashCode()
|
||||||
result += 31 * result + f.hashCode()
|
result = 31 * result + f.hashCode()
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+2
-2
@@ -20,8 +20,8 @@ class A(val n: Int?, val s: String) {
|
|||||||
|
|
||||||
override fun hashCode(): Int{
|
override fun hashCode(): Int{
|
||||||
var result = n ?: 0
|
var result = n ?: 0
|
||||||
result += 31 * result + s.hashCode()
|
result = 31 * result + s.hashCode()
|
||||||
result += 31 * result + (f?.hashCode() ?: 0)
|
result = 31 * result + (f?.hashCode() ?: 0)
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+3
-3
@@ -26,9 +26,9 @@ class A(val n: Int, val s: String) : X() {
|
|||||||
|
|
||||||
override fun hashCode(): Int{
|
override fun hashCode(): Int{
|
||||||
var result = super.hashCode()
|
var result = super.hashCode()
|
||||||
result += 31 * result + n
|
result = 31 * result + n
|
||||||
result += 31 * result + s.hashCode()
|
result = 31 * result + s.hashCode()
|
||||||
result += 31 * result + f.hashCode()
|
result = 31 * result + f.hashCode()
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -17,7 +17,7 @@ class A(val result: Int, val s: String) {
|
|||||||
|
|
||||||
override fun hashCode(): Int{
|
override fun hashCode(): Int{
|
||||||
var result1 = result
|
var result1 = result
|
||||||
result1 += 31 * result1 + s.hashCode()
|
result1 = 31 * result1 + s.hashCode()
|
||||||
return result1
|
return result1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+2
-2
@@ -22,8 +22,8 @@ class A(val n: IntArray?, val s: Array<String>?) {
|
|||||||
|
|
||||||
override fun hashCode(): Int{
|
override fun hashCode(): Int{
|
||||||
var result = n?.let { Arrays.hashCode(it) } ?: 0
|
var result = n?.let { Arrays.hashCode(it) } ?: 0
|
||||||
result += 31 * result + (s?.let { Arrays.hashCode(it) } ?: 0)
|
result = 31 * result + (s?.let { Arrays.hashCode(it) } ?: 0)
|
||||||
result += 31 * result + f.hashCode()
|
result = 31 * result + f.hashCode()
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+1
-1
@@ -17,7 +17,7 @@ class A(val n: Int) : X() {
|
|||||||
|
|
||||||
override fun hashCode(): Int{
|
override fun hashCode(): Int{
|
||||||
var result = super.hashCode()
|
var result = super.hashCode()
|
||||||
result += 31 * result + n
|
result = 31 * result + n
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+1
-1
@@ -22,7 +22,7 @@ class A(val n: Int) : X() {
|
|||||||
|
|
||||||
override fun hashCode(): Int{
|
override fun hashCode(): Int{
|
||||||
var result = super.hashCode()
|
var result = super.hashCode()
|
||||||
result += 31 * result + n
|
result = 31 * result + n
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user