Code Insight: Allow properties with custom setters to be used in generated equals/hashCode/toString

#KT-11908 Fixed
This commit is contained in:
Alexey Sedunov
2016-04-14 17:07:30 +03:00
parent beb5d5e271
commit 38522b09ce
10 changed files with 96 additions and 1 deletions
+1
View File
@@ -22,6 +22,7 @@ Issues fixed:
- [KT-11495](https://youtrack.jetbrains.com/issue/KT-11495) Show recursion line markers for extension function calls with different receiver
- [KT-11659](https://youtrack.jetbrains.com/issue/KT-11659) Generate abstract overrides for Any members inside of Kotlin interfaces
- [KT-11866](https://youtrack.jetbrains.com/issue/KT-11866) Suggest "Create secondary constructor" when constructors exist but are not applicable
- [KT-11908](https://youtrack.jetbrains.com/issue/KT-11866) Allow properties with custom setters to be used in generated equals/hashCode/toString
#### Debugger
@@ -52,7 +52,7 @@ fun getPropertiesToUseInGeneratedMember(classOrObject: KtClassOrObject): List<Kt
val descriptor = it.resolveToDescriptor()
when (descriptor) {
is ValueParameterDescriptor -> true
is PropertyDescriptor -> descriptor.accessors.all { it.isDefault }
is PropertyDescriptor -> descriptor.getter?.isDefault ?: true
else -> false
}
}
@@ -0,0 +1,8 @@
class Test {
var serial: String = ""
set(value) {
field = value.toUpperCase()
}
var name: String = ""
<caret>
}
@@ -0,0 +1,25 @@
class Test {
var serial: String = ""
set(value) {
field = value.toUpperCase()
}
var name: String = ""
<caret>override fun equals(other: Any?): Boolean{
if (this === other) return true
if (other?.javaClass != javaClass) return false
other as Test
if (serial != other.serial) return false
if (name != other.name) return false
return true
}
override fun hashCode(): Int{
var result = serial.hashCode()
result = 31 * result + name.hashCode()
return result
}
}
@@ -0,0 +1,9 @@
// GENERATOR: MULTIPLE_TEMPLATES
class Test {
var serial: String = ""
set(value) {
field = value.toUpperCase()
}
var name: String = ""
<caret>
}
@@ -0,0 +1,15 @@
// GENERATOR: MULTIPLE_TEMPLATES
class Test {
var serial: String = ""
set(value) {
field = value.toUpperCase()
}
var name: String = ""
<caret>override fun toString(): String{
return "Test(" +
"serial='$serial'," +
"name='$name'" +
")"
}
}
@@ -0,0 +1,8 @@
class Test {
var serial: String = ""
set(value) {
field = value.toUpperCase()
}
var name: String = ""
<caret>
}
@@ -0,0 +1,11 @@
class Test {
var serial: String = ""
set(value) {
field = value.toUpperCase()
}
var name: String = ""
<caret>override fun toString(): String{
return "Test(serial='$serial', name='$name')"
}
}
@@ -47,6 +47,12 @@ public class GenerateHashCodeAndEqualsActionTestGenerated extends AbstractGenera
doTest(fileName);
}
@TestMetadata("customAccessors.kt")
public void testCustomAccessors() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/codeInsight/generate/equalsWithHashCode/customAccessors.kt");
doTest(fileName);
}
@TestMetadata("dataClass.kt")
public void testDataClass() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/codeInsight/generate/equalsWithHashCode/dataClass.kt");
@@ -82,6 +82,12 @@ public class GenerateToStringActionTestGenerated extends AbstractGenerateToStrin
doTest(fileName);
}
@TestMetadata("customAccessors.kt")
public void testCustomAccessors() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/codeInsight/generate/toString/multipeTemplates/customAccessors.kt");
doTest(fileName);
}
@TestMetadata("multipleVars.kt")
public void testMultipleVars() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/codeInsight/generate/toString/multipeTemplates/multipleVars.kt");
@@ -127,6 +133,12 @@ public class GenerateToStringActionTestGenerated extends AbstractGenerateToStrin
doTest(fileName);
}
@TestMetadata("customAccessors.kt")
public void testCustomAccessors() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/codeInsight/generate/toString/singleTemplate/customAccessors.kt");
doTest(fileName);
}
@TestMetadata("multipleVars.kt")
public void testMultipleVars() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/codeInsight/generate/toString/singleTemplate/multipleVars.kt");