Inspection "can be primary constructor property" with relevant quick-fix #KT-8477 Fixed
(cherry picked from commit 2db7562)
This commit is contained in:
+18
@@ -0,0 +1,18 @@
|
||||
<problems>
|
||||
<problem>
|
||||
<file>properties.kt</file>
|
||||
<line>3</line>
|
||||
<module>light_idea_test_case</module>
|
||||
<entry_point TYPE="file" FQNAME="temp:///src/properties.kt" />
|
||||
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Property is explicitly assigned to constructor parameter</problem_class>
|
||||
<description>Property is explicitly assigned by parameter simple, can be declared directly in constructor</description>
|
||||
</problem>
|
||||
<problem>
|
||||
<file>properties.kt</file>
|
||||
<line>5</line>
|
||||
<module>light_idea_test_case</module>
|
||||
<entry_point TYPE="file" FQNAME="temp:///src/properties.kt" />
|
||||
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Property is explicitly assigned to constructor parameter</problem_class>
|
||||
<description>Property is explicitly assigned by parameter withType, can be declared directly in constructor</description>
|
||||
</problem>
|
||||
</problems>
|
||||
+1
@@ -0,0 +1 @@
|
||||
// INSPECTION_CLASS: org.jetbrains.kotlin.idea.inspections.CanBePrimaryConstructorPropertyInspection
|
||||
@@ -0,0 +1,34 @@
|
||||
class Correct(simple: String, withType: Int, otherName: Double) {
|
||||
|
||||
val simple = simple
|
||||
|
||||
val withType: Int = withType
|
||||
|
||||
// Questionable case (due to possible named parameters), not allowed now
|
||||
val anotherName = otherName
|
||||
}
|
||||
|
||||
// Inspection should not work here anywhere
|
||||
class Incorrect(val property: String, withGetter: Double, withSetter: Int, differentType: String) {
|
||||
|
||||
val another = property
|
||||
|
||||
val fromProperty = another
|
||||
|
||||
val withGetter = withGetter
|
||||
get() = 2 * field
|
||||
|
||||
val withSetter = withSetter
|
||||
private set
|
||||
|
||||
val differentType: String? = differentType
|
||||
|
||||
constructor(param: Int): this("", 0.0, param, "") {
|
||||
val local = param
|
||||
}
|
||||
}
|
||||
|
||||
// For data class inspection also should not work
|
||||
data class Data(name: String) {
|
||||
val name = name
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
org.jetbrains.kotlin.idea.inspections.CanBePrimaryConstructorPropertyInspection
|
||||
@@ -0,0 +1,4 @@
|
||||
// "Move to constructor" "true"
|
||||
class Container(index: Int) {
|
||||
protected open var <caret>index = index
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
// "Move to constructor" "true"
|
||||
class Container(protected open var index: Int) {
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
// "Move to constructor" "true"
|
||||
class Correct(name: String) {
|
||||
val <caret>name: String = name
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
// "Move to constructor" "true"
|
||||
class Correct(val name: String) {
|
||||
}
|
||||
Reference in New Issue
Block a user