Provide inspection and quickfixes for usages of static fields which will be no longer accessible in future versions

For this inspection three kinds of fixes are potentially available:
- Add 'const' modifier to kotlin property
- Add '@JvmField' annotation to kotlin property
- Change field reference to getter invocation

In case user chooses to 'cleanup code', these fixes are prioritized in this order
This commit is contained in:
Pavel V. Talanov
2015-10-12 21:35:47 +03:00
parent 47cca7db1f
commit d603142cc6
44 changed files with 679 additions and 35 deletions
@@ -0,0 +1 @@
org.jetbrains.kotlin.idea.inspections.DeprecatedUsageOfStaticFieldInspection
@@ -0,0 +1,22 @@
package a
class A
class Cl {
companion object {
@JvmField val property1 = A()
const val property2 = 2
}
}
interface Int {
companion object {
val property1 = A()
const val property2 = 2
}
}
object Obj {
@JvmField val property1 = A()
const val property2 = 2
}
@@ -0,0 +1,19 @@
// "Cleanup code" "true"
import a.*;
class B {
void bar() {
Cl.property1;
Cl.property2;
Cl.property1;
Cl.property2;
Int.Companion.getProperty1();
Int.property2;
Int.Companion.getProperty1();
Int.property2;
Obj.property1;
Obj.property2;
Obj.property1;
Obj.property2;
}
}
@@ -0,0 +1,19 @@
// "Cleanup code" "true"
import a.*;
class B {
void bar() {
Cl.prope<caret>rty1;
Cl.property2;
Cl.Companion.getProperty1();
Cl.Companion.getProperty2();
Int.property1;
Int.property2;
Int.Companion.getProperty1();
Int.Companion.getProperty2();
Obj.property1;
Obj.property2;
Obj.INSTANCE.getProperty1();
Obj.INSTANCE.getProperty2();
}
}
@@ -0,0 +1,22 @@
package a
class A
class Cl {
companion object {
val property1 = A()
val property2 = 2
}
}
interface Int {
companion object {
val property1 = A()
val property2 = 2
}
}
object Obj {
val property1 = A()
val property2 = 2
}
@@ -0,0 +1,7 @@
package a
class A {
companion object Named {
const val property = 1
}
}
@@ -0,0 +1,10 @@
// "Add 'const' modifier to a property" "true"
import a.A;
class B {
void bar() {
A a = A.property;
A a2 = a.A.property;
A a3 = A.property;
}
}
@@ -0,0 +1,10 @@
// "Add 'const' modifier to a property" "true"
import a.A;
class B {
void bar() {
A a = A.pro<caret>perty;
A a2 = A.Named.getProperty();
A a3 = A.property;
}
}
@@ -0,0 +1,7 @@
package a
class A {
companion object Named {
val property = 1
}
}
@@ -0,0 +1,10 @@
// "Replace with getter invocation" "true"
import a.A;
class B {
void bar() {
A a = a.A.Named.getProperty();
A a2 = A.Named.getProperty();
A a3 = A.property;
}
}
@@ -0,0 +1,10 @@
// "Replace with getter invocation" "true"
import a.A;
class B {
void bar() {
A a = A.pro<caret>perty;
A a2 = A.Named.getProperty();
A a3 = A.property;
}
}
@@ -0,0 +1,7 @@
package a
class A {
companion object Named {
val property = A()
}
}
@@ -0,0 +1,7 @@
package a
class A {
companion object {
@JvmField val property = A()
}
}
@@ -0,0 +1,10 @@
// "Annotate property with @JvmField" "true"
import a.A;
class B {
void bar() {
A a = A.property;
A a2 = a.A.property;
A a3 = A.property;
}
}
@@ -0,0 +1,10 @@
// "Annotate property with @JvmField" "true"
import a.A;
class B {
void bar() {
A a = A.pro<caret>perty;
A a2 = A.Companion.getProperty();
A a3 = A.property;
}
}
@@ -0,0 +1,7 @@
package a
class A {
companion object {
val property = A()
}
}
@@ -0,0 +1,7 @@
package a
interface A {
companion object Named {
const val property = 1
}
}
@@ -0,0 +1,10 @@
// "Add 'const' modifier to a property" "true"
import a.A;
class B {
void bar() {
A a = A.property;
A a2 = a.A.property;
A a3 = A.property;
}
}
@@ -0,0 +1,10 @@
// "Add 'const' modifier to a property" "true"
import a.A;
class B {
void bar() {
A a = A.prop<caret>erty;
A a2 = A.Named.getProperty();
A a3 = A.property;
}
}
@@ -0,0 +1,7 @@
package a
interface A {
companion object Named {
val property = 1
}
}
@@ -0,0 +1,10 @@
// "Replace with getter invocation" "true"
import a.A;
class B {
void bar() {
A a = a.A.Companion.getProperty();
A a2 = A.Companion.getProperty();
A a3 = A.property;
}
}
@@ -0,0 +1,10 @@
// "Replace with getter invocation" "true"
import a.A;
class B {
void bar() {
A a = A.prop<caret>erty;
A a2 = A.Companion.getProperty();
A a3 = A.property;
}
}
@@ -0,0 +1,7 @@
package a
interface A {
companion object {
val property = 1
}
}
@@ -0,0 +1,20 @@
// "Annotate property with @JvmField" "false"
import a.A;
class B {
void bar() {
A a = A.prop<caret>erty;
A a2 = A.Named.getProperty();
A a3 = A.property;
}
}
// ACTION: Add 'const' modifier to a property
// ACTION: Add static import for 'a.A.property'
// ACTION: Annotate 'property' as @Deprecated
// ACTION: Annotate 'property' as @NotNull
// ACTION: Annotate 'property' as @Nullable
// ACTION: Change variable 'a' type to 'int'
// ACTION: Migrate 'a' type to 'int'
// ACTION: Replace with getter invocation
// ACTION: Split into declaration and assignment
@@ -0,0 +1,7 @@
package a
interface A {
companion object Named {
val property = 1
}
}
@@ -0,0 +1,5 @@
package a
object Obj {
const val property = 1
}
@@ -0,0 +1,11 @@
// "Add 'const' modifier to a property" "true"
import a.Obj;
import a.A;
class B {
void bar() {
A a = Obj.property;
A a2 = a.Obj.property;
A a3 = Obj.property;
}
}
@@ -0,0 +1,11 @@
// "Add 'const' modifier to a property" "true"
import a.Obj;
import a.A;
class B {
void bar() {
A a = Obj.pro<caret>perty;
A a2 = Obj.INSTANCE.getProperty();
A a3 = Obj.property;
}
}
@@ -0,0 +1,5 @@
package a
object Obj {
val property = 1
}
@@ -0,0 +1,16 @@
// "Add 'const' modifier to a property" "false"
import a.Obj;
import a.A;
class B {
void bar() {
A a = Obj.pro<caret>perty;
Obj.INSTANCE.getProperty();
}
}
// ACTION: Annotate 'property' as @Deprecated
// ACTION: Add static import for 'a.Obj.property'
// ACTION: Annotate property with @JvmField
// ACTION: Split into declaration and assignment
// ACTION: Replace with getter invocation
@@ -0,0 +1,7 @@
package a
object Obj {
val property = A()
}
class A
@@ -0,0 +1,11 @@
// "Replace with getter invocation" "true"
import a.Obj;
import a.A;
class B {
void bar() {
A a = a.Obj.INSTANCE.getProperty();
A a2 = Obj.getProperty();
A a3 = Obj.property;
}
}
@@ -0,0 +1,11 @@
// "Replace with getter invocation" "true"
import a.Obj;
import a.A;
class B {
void bar() {
A a = Obj.pro<caret>perty;
A a2 = Obj.getProperty();
A a3 = Obj.property;
}
}
@@ -0,0 +1,7 @@
package a
object Obj {
val property = A()
}
class A
@@ -0,0 +1,7 @@
package a
object Obj {
@JvmField val property = A()
}
class A
@@ -0,0 +1,11 @@
// "Annotate property with @JvmField" "true"
import a.Obj;
import a.A;
class B {
void bar() {
A a = Obj.property;
A a2 = a.Obj.property;
A a3 = Obj.property;
}
}
@@ -0,0 +1,11 @@
// "Annotate property with @JvmField" "true"
import a.Obj;
import a.A;
class B {
void bar() {
A a = Obj.pro<caret>perty;
A a2 = Obj.getProperty();
A a3 = Obj.property;
}
}
@@ -0,0 +1,7 @@
package a
object Obj {
val property = A()
}
class A