Inspection (and quickfix) for extension propeties conflicting with synthetic ones

This commit is contained in:
Valentin Kipyatkov
2015-08-31 19:08:01 +03:00
parent d41e01c0e4
commit 10f7d6d7dd
45 changed files with 620 additions and 16 deletions
@@ -0,0 +1,16 @@
import java.io.File
import java.io.Serializable
val File.name: String
get() = getName()
val Serializable.name: String
get() = ""
val File.parent: File
get() = getParentFile()
class MyFile : File("")
val MyFile.isFile: Boolean
get() = isFile()
@@ -0,0 +1,28 @@
<problems>
<problem>
<file>File.kt</file>
<line>4</line>
<module>light_idea_test_case</module>
<entry_point TYPE="file" FQNAME="File.kt" />
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Extension property conflicts with automatically produced one</problem_class>
<description>This property conflicts with synthetic extension and should be removed to avoid breaking code by future changes in the compiler</description>
</problem>
<problem>
<file>File.kt</file>
<line>10</line>
<module>light_idea_test_case</module>
<entry_point TYPE="file" FQNAME="File.kt" />
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Extension property conflicts with automatically produced one</problem_class>
<description>This property conflicts with synthetic extension and should be removed to avoid breaking code by future changes in the compiler</description>
</problem>
<problem>
<file>File.kt</file>
<line>15</line>
<module>light_idea_test_case</module>
<entry_point TYPE="file" FQNAME="File.kt" />
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Extension property conflicts with automatically produced one</problem_class>
<description>This property conflicts with synthetic extension and should be removed to avoid breaking code by future changes in the compiler</description>
</problem>
</problems>
@@ -0,0 +1 @@
// INSPECTION_CLASS: org.jetbrains.kotlin.idea.inspections.ConflictingExtensionPropertyInspection
@@ -1,5 +1,4 @@
// "class org.jetbrains.kotlin.idea.quickfix.DeprecatedSymbolUsageFix" "false"
// ACTION: Inspection 'DEPRECATED_SYMBOL_WITH_MESSAGE' options
fun foo() {
val c = JavaClass()
@@ -0,0 +1 @@
org.jetbrains.kotlin.idea.inspections.ConflictingExtensionPropertyInspection
@@ -0,0 +1,7 @@
// "Delete redundant extension property" "true"
var Thread.<caret>priority: Int
get() = this.getPriority()
set(value) {
this.setPriority(value)
}
@@ -0,0 +1,2 @@
// "Delete redundant extension property" "true"
@@ -0,0 +1,7 @@
// "Delete redundant extension property" "true"
import java.io.File
class C {
val File.<caret>name: String
get() = getName()
}
@@ -0,0 +1,5 @@
// "Delete redundant extension property" "true"
import java.io.File
class C {
}
@@ -0,0 +1,4 @@
package test
fun foo() {
}
@@ -0,0 +1,8 @@
package test
import java.io.File
import utils.*
fun foo(file: File) {
print(file.name)
}
@@ -0,0 +1,7 @@
package test
import java.io.File
fun foo(file: File) {
print(file.name)
}
@@ -0,0 +1,6 @@
// "Delete redundant extension property" "true"
package utils
import java.io.File
// WITH_RUNTIME
@@ -0,0 +1,6 @@
package test
import utils.name
fun foo() {
}
@@ -0,0 +1,9 @@
// "Delete redundant extension property" "true"
package utils
import java.io.File
val File.<caret>name: String
get() = getName()
// WITH_RUNTIME
@@ -0,0 +1,8 @@
package test
import java.io.File
import utils.*
fun foo(file: File) {
print(file.name)
}
@@ -0,0 +1,8 @@
package test
import java.io.File
import utils.name
fun foo(file: File) {
print(file.name)
}
@@ -0,0 +1,9 @@
package test
import java.io.File
import utils.name
fun foo(file: File, thread: Thread) {
print(file.name)
print(thread.name)
}
@@ -0,0 +1,9 @@
// "Delete redundant extension property" "true"
package utils
import java.io.File
val Thread.name: String
get() = getName()
// WITH_RUNTIME
@@ -0,0 +1,12 @@
// "Delete redundant extension property" "true"
package utils
import java.io.File
val File.<caret>name: String
get() = getName()
val Thread.name: String
get() = getName()
// WITH_RUNTIME
@@ -0,0 +1,9 @@
package test
import java.io.File
import utils.name
fun foo(file: File, thread: Thread) {
print(file.name)
print(thread.name)
}
@@ -0,0 +1,5 @@
// "Delete redundant extension property" "true"
import java.io.File
val File.<caret>name: String
get() { return getName() }
@@ -0,0 +1,3 @@
// "Delete redundant extension property" "true"
import java.io.File
@@ -0,0 +1,5 @@
// "Delete redundant extension property" "true"
import java.io.File
val File.<caret>name: String
get() = getName()
@@ -0,0 +1,3 @@
// "Delete redundant extension property" "true"
import java.io.File
@@ -0,0 +1,4 @@
// "Delete redundant extension property" "true"
val Thread.<caret>priority: Int
get() = getPriority()
@@ -0,0 +1,2 @@
// "Delete redundant extension property" "true"
@@ -0,0 +1,6 @@
// "Delete redundant extension property" "false"
import java.io.File
var File.<caret>name: String
get() = getName()
set(value) {}
@@ -0,0 +1,7 @@
// "Delete redundant extension property" "true"
var Thread.<caret>priority: Int
get() = getPriority()
set(value) {
setPriority(value)
}
@@ -0,0 +1,2 @@
// "Delete redundant extension property" "true"
@@ -0,0 +1,7 @@
// "Delete redundant extension property" "false"
// ACTION: Convert property to function
class C : Thread() {
val Thread.<caret>priority: Int
get() = this@C.getPriority()
}
@@ -0,0 +1,9 @@
// "Delete redundant extension property" "false"
class C : Thread() {
var Thread.<caret>priority: Int
get() = getPriority()
set(value) {
this@C.setPriority(value)
}
}
@@ -0,0 +1,7 @@
// "Delete redundant extension property" "false"
var Thread.<caret>priority: Int
get() = getPriority() + 1
set(value) {
setPriority(value)
}
@@ -0,0 +1,6 @@
// "Delete redundant extension property" "false"
// ACTION: Convert property to function
import java.io.File
public val File.<caret>parent: File?
get() = getParentFile()
@@ -0,0 +1,8 @@
// "Delete redundant extension property" "false"
var Thread.<caret>priority: Int
get() = this.getPriority()
set(value) {
this.setPriority(value)
System.out.print("set")
}