Add inspection to detect copy() calls in a data class without named arguments

So #KT-17660 Fixed
This commit is contained in:
Kirill Rakhman
2017-05-02 21:05:26 +02:00
committed by Mikhail Glukhikh
parent 2c10f253c5
commit a8b2d3b4e8
15 changed files with 166 additions and 0 deletions
@@ -0,0 +1,10 @@
<problems>
<problem>
<file>test.kt</file>
<line>10</line>
<module>light_idea_test_case</module>
<entry_point TYPE="file" FQNAME="temp:///src/test.kt" />
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">'copy' method of data class is called without named arguments</problem_class>
<description>'copy' method of data class is called without named arguments</description>
</problem>
</problems>
@@ -0,0 +1 @@
// INSPECTION_CLASS: org.jetbrains.kotlin.idea.inspections.CopyWithoutNamedArgumentsInspection
@@ -0,0 +1,15 @@
data class Foo(val a: String) {
fun copy(i: Int) {}
}
class Foo2() {
fun copy(i: Int) {}
}
fun bar(f: Foo, f2: Foo2) {
f.copy("")
f.copy()
f.copy(a = "")
f.copy(1)
f2.copy(1)
}
@@ -0,0 +1 @@
org.jetbrains.kotlin.idea.inspections.CopyWithoutNamedArgumentsInspection
@@ -0,0 +1,7 @@
// PROBLEM: 'copy' method of data class is called without named arguments
data class Foo(val a: String)
fun bar(f: Foo) {
f.co<caret>py("")
}
@@ -0,0 +1,7 @@
// PROBLEM: 'copy' method of data class is called without named arguments
data class Foo(val a: String)
fun bar(f: Foo) {
f.copy(a = "")
}
@@ -0,0 +1,5 @@
data class SomeName(val a: Int, val b: Int, val c: String)
fun foo(f: SomeName) {
f.<caret>copy(2, c = "")
}
@@ -0,0 +1,5 @@
data class SomeName(val a: Int, val b: Int, val c: String)
fun foo(f: SomeName) {
f.copy(a = 2, c = "")
}
@@ -0,0 +1,3 @@
data class SomeName(val a: Int, val b: Int, val c: String)
fun SomeName.func() = <caret>copy(1, 0)
@@ -0,0 +1,3 @@
data class SomeName(val a: Int, val b: Int, val c: String)
fun SomeName.func() = copy(a = 1, b = 0)