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:
@@ -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;
|
||||
}
|
||||
}
|
||||
+19
@@ -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();
|
||||
}
|
||||
}
|
||||
+22
@@ -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
|
||||
}
|
||||
Vendored
+7
@@ -0,0 +1,7 @@
|
||||
package a
|
||||
|
||||
class A {
|
||||
companion object Named {
|
||||
const val property = 1
|
||||
}
|
||||
}
|
||||
Vendored
+10
@@ -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;
|
||||
}
|
||||
}
|
||||
idea/testData/quickfix/migration/deprecatedStaticField/companionObjectOfClass_const.before.Main.java
Vendored
+10
@@ -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;
|
||||
}
|
||||
}
|
||||
Vendored
+7
@@ -0,0 +1,7 @@
|
||||
package a
|
||||
|
||||
class A {
|
||||
companion object Named {
|
||||
val property = 1
|
||||
}
|
||||
}
|
||||
+10
@@ -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;
|
||||
}
|
||||
}
|
||||
+10
@@ -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;
|
||||
}
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
package a
|
||||
|
||||
class A {
|
||||
companion object Named {
|
||||
val property = A()
|
||||
}
|
||||
}
|
||||
idea/testData/quickfix/migration/deprecatedStaticField/companionObjectOfClass_jvmField.after.data.kt
Vendored
+7
@@ -0,0 +1,7 @@
|
||||
package a
|
||||
|
||||
class A {
|
||||
companion object {
|
||||
@JvmField val property = A()
|
||||
}
|
||||
}
|
||||
Vendored
+10
@@ -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;
|
||||
}
|
||||
}
|
||||
+10
@@ -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;
|
||||
}
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
package a
|
||||
|
||||
class A {
|
||||
companion object {
|
||||
val property = A()
|
||||
}
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
package a
|
||||
|
||||
interface A {
|
||||
companion object Named {
|
||||
const val property = 1
|
||||
}
|
||||
}
|
||||
Vendored
+10
@@ -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;
|
||||
}
|
||||
}
|
||||
+10
@@ -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;
|
||||
}
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
package a
|
||||
|
||||
interface A {
|
||||
companion object Named {
|
||||
val property = 1
|
||||
}
|
||||
}
|
||||
+10
@@ -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;
|
||||
}
|
||||
}
|
||||
+10
@@ -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;
|
||||
}
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
package a
|
||||
|
||||
interface A {
|
||||
companion object {
|
||||
val property = 1
|
||||
}
|
||||
}
|
||||
+20
@@ -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
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
package a
|
||||
|
||||
interface A {
|
||||
companion object Named {
|
||||
val property = 1
|
||||
}
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
package a
|
||||
|
||||
object Obj {
|
||||
const val property = 1
|
||||
}
|
||||
+11
@@ -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;
|
||||
}
|
||||
}
|
||||
+11
@@ -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;
|
||||
}
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
package a
|
||||
|
||||
object Obj {
|
||||
val property = 1
|
||||
}
|
||||
Vendored
+16
@@ -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
|
||||
Vendored
+7
@@ -0,0 +1,7 @@
|
||||
package a
|
||||
|
||||
object Obj {
|
||||
val property = A()
|
||||
}
|
||||
|
||||
class A
|
||||
+11
@@ -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;
|
||||
}
|
||||
}
|
||||
Vendored
+11
@@ -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;
|
||||
}
|
||||
}
|
||||
Vendored
+7
@@ -0,0 +1,7 @@
|
||||
package a
|
||||
|
||||
object Obj {
|
||||
val property = A()
|
||||
}
|
||||
|
||||
class A
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
package a
|
||||
|
||||
object Obj {
|
||||
@JvmField val property = A()
|
||||
}
|
||||
|
||||
class A
|
||||
+11
@@ -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;
|
||||
}
|
||||
}
|
||||
+11
@@ -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;
|
||||
}
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
package a
|
||||
|
||||
object Obj {
|
||||
val property = A()
|
||||
}
|
||||
|
||||
class A
|
||||
Reference in New Issue
Block a user