Can be parameter inspection #KT-10819 Fixed
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
<problems>
|
||||
<problem>
|
||||
<file>test.kt</file>
|
||||
<line>5</line>
|
||||
<module>light_idea_test_case</module>
|
||||
<entry_point TYPE="file" FQNAME="temp:///src/test.kt" />
|
||||
<problem_class severity="WARNING" attribute_key="NOT_USED_ELEMENT_ATTRIBUTES">Constructor parameter is never used as a property</problem_class>
|
||||
<description>Constructor parameter is never used as a property</description>
|
||||
</problem>
|
||||
<problem>
|
||||
<file>test.kt</file>
|
||||
<line>9</line>
|
||||
<module>light_idea_test_case</module>
|
||||
<entry_point TYPE="file" FQNAME="temp:///src/test.kt" />
|
||||
<problem_class severity="WARNING" attribute_key="NOT_USED_ELEMENT_ATTRIBUTES">Constructor parameter is never used as a property</problem_class>
|
||||
<description>Constructor parameter is never used as a property</description>
|
||||
</problem>
|
||||
<problem>
|
||||
<file>test.kt</file>
|
||||
<line>16</line>
|
||||
<module>light_idea_test_case</module>
|
||||
<entry_point TYPE="file" FQNAME="temp:///src/test.kt" />
|
||||
<problem_class severity="WARNING" attribute_key="NOT_USED_ELEMENT_ATTRIBUTES">Constructor parameter is never used as a property</problem_class>
|
||||
<description>Constructor parameter is never used as a property</description>
|
||||
</problem>
|
||||
<problem>
|
||||
<file>test.kt</file>
|
||||
<line>52</line>
|
||||
<module>light_idea_test_case</module>
|
||||
<entry_point TYPE="file" FQNAME="temp:///src/test.kt" />
|
||||
<problem_class severity="WARNING" attribute_key="NOT_USED_ELEMENT_ATTRIBUTES">Constructor parameter is never used as a property</problem_class>
|
||||
<description>Constructor parameter is never used as a property</description>
|
||||
</problem>
|
||||
<problem>
|
||||
<file>test.kt</file>
|
||||
<line>62</line>
|
||||
<module>light_idea_test_case</module>
|
||||
<entry_point TYPE="file" FQNAME="temp:///src/test.kt" />
|
||||
<problem_class severity="WARNING" attribute_key="NOT_USED_ELEMENT_ATTRIBUTES">Constructor parameter is never used as a property</problem_class>
|
||||
<description>Constructor parameter is never used as a property</description>
|
||||
</problem>
|
||||
<problem>
|
||||
<file>test.kt</file>
|
||||
<line>70</line>
|
||||
<module>light_idea_test_case</module>
|
||||
<entry_point TYPE="file" FQNAME="temp:///src/test.kt" />
|
||||
<problem_class severity="WARNING" attribute_key="NOT_USED_ELEMENT_ATTRIBUTES">Constructor parameter is never used as a property</problem_class>
|
||||
<description>Constructor parameter is never used as a property</description>
|
||||
</problem>
|
||||
</problems>
|
||||
@@ -0,0 +1 @@
|
||||
// INSPECTION_CLASS: org.jetbrains.kotlin.idea.inspections.CanBeParameterInspection
|
||||
+105
@@ -0,0 +1,105 @@
|
||||
class NonUsed(val x: Int) // NO
|
||||
// NO
|
||||
data class UsedInData(val x: Int)
|
||||
// YES
|
||||
class UsedInProperty(val x: Int) {
|
||||
val y = x
|
||||
}
|
||||
// YES
|
||||
class UsedInInitializer(val x: Int) {
|
||||
val y: Int
|
||||
init {
|
||||
y = x
|
||||
}
|
||||
}
|
||||
// YES
|
||||
class UsedInConstructor(val x: Int) {
|
||||
fun foo(arg: Int) = arg
|
||||
|
||||
constructor(): this(42) {
|
||||
foo(x)
|
||||
}
|
||||
}
|
||||
// NO
|
||||
class UsedInFunction(val x: Int) {
|
||||
fun get() = x
|
||||
}
|
||||
// NO
|
||||
class UsedInGetter(val x: Int) {
|
||||
val y: Int
|
||||
get() = x
|
||||
}
|
||||
// NO
|
||||
class UsedInSetter(val x: Int) {
|
||||
var y: Int
|
||||
get() = field
|
||||
set(arg) { field = x + arg }
|
||||
}
|
||||
// NO
|
||||
class UsedInInnerClass(val x: Int) {
|
||||
inner class Inner {
|
||||
fun foo() = x
|
||||
}
|
||||
}
|
||||
// NO
|
||||
class UsedOutside(val x: Int)
|
||||
|
||||
fun use(): Int {
|
||||
val used = UsedOutside(30)
|
||||
return used.x
|
||||
}
|
||||
// YES
|
||||
class PrivateUsedInProperty(private val x: Int) {
|
||||
val y = x
|
||||
}
|
||||
// NO
|
||||
open class Base(protected open val x: Int)
|
||||
// NO
|
||||
override class UsedOverridden(override val x: Int) {
|
||||
val y = x
|
||||
}
|
||||
// YES
|
||||
class UsedInPropertyVar(var x: Int) {
|
||||
var y = x
|
||||
}
|
||||
// NO
|
||||
class UsedInPropertyAnnotated(@JvmField val x: Int) {
|
||||
val y = x
|
||||
}
|
||||
// YES
|
||||
class UsedWithoutThisInInitProperty(val x: Int) {
|
||||
init {
|
||||
val y = x
|
||||
}
|
||||
}
|
||||
// NO
|
||||
class UsedWithThisInInitProperty(val x: Int) {
|
||||
init {
|
||||
val y = this.x
|
||||
}
|
||||
}
|
||||
// NO
|
||||
class UsedWithLabeledThisInInitProperty(val x: Int) {
|
||||
init {
|
||||
run {
|
||||
val y = this@UsedWithLabeledThisInInitProperty.x
|
||||
}
|
||||
}
|
||||
}
|
||||
// NO
|
||||
class UsedInFunctionProperty(val x: Int) {
|
||||
fun get() {
|
||||
val y = x
|
||||
return y
|
||||
}
|
||||
}
|
||||
// NO
|
||||
class ModifiedInInit(var x: Int) {
|
||||
init {
|
||||
x += 2
|
||||
}
|
||||
}
|
||||
// NO
|
||||
open class UsedInOverride(val x: Int)
|
||||
|
||||
class UserInOverride(override val x: Int) : UsedInOverride(x)
|
||||
@@ -0,0 +1,2 @@
|
||||
// NO
|
||||
class UsedFromJava(val z: Int, val w: Int)
|
||||
@@ -0,0 +1,9 @@
|
||||
package user;
|
||||
|
||||
class User {
|
||||
public static void main(String[] args) {
|
||||
UsedFromJava used = new UsedFromJava(1, 2);
|
||||
System.out.println(used.getZ());
|
||||
System.out.println(used.getW());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
org.jetbrains.kotlin.idea.inspections.CanBeParameterInspection
|
||||
@@ -0,0 +1,6 @@
|
||||
// "Remove 'val' from parameter" "true"
|
||||
open class Base(open <caret>val x: Int) {
|
||||
val y = x
|
||||
}
|
||||
|
||||
class Derived(y: Int) : Base(y)
|
||||
@@ -0,0 +1,6 @@
|
||||
// "Remove 'val' from parameter" "true"
|
||||
open class Base(x: Int) {
|
||||
val y = x
|
||||
}
|
||||
|
||||
class Derived(y: Int) : Base(y)
|
||||
@@ -0,0 +1,4 @@
|
||||
// "Remove 'var' from parameter" "true"
|
||||
class UsedInProperty(<caret>var x: Int) {
|
||||
var y = x
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
// "Remove 'var' from parameter" "true"
|
||||
class UsedInProperty(x: Int) {
|
||||
var y = x
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
// "Remove 'val' from parameter" "true"
|
||||
class UsedInProperty(private <caret>val x: Int) {
|
||||
var y: String
|
||||
|
||||
init {
|
||||
y = x.toString()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
// "Remove 'val' from parameter" "true"
|
||||
class UsedInProperty(x: Int) {
|
||||
var y: String
|
||||
|
||||
init {
|
||||
y = x.toString()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user