Quick-fix for UNNECESSARY_LATEINIT

(cherry picked from commit 77f7bb0)
This commit is contained in:
Mikhail Glukhikh
2016-09-26 11:40:31 +03:00
committed by Mikhail Glukhikh
parent 025d063b27
commit 67cc83af05
14 changed files with 194 additions and 0 deletions
@@ -105,6 +105,7 @@ class QuickFixRegistrar : QuickFixContributor {
val removeRedundantModifierFactory = RemoveModifierFix.createRemoveModifierFactory(true)
REDUNDANT_MODIFIER.registerFactory(removeRedundantModifierFactory)
REDUNDANT_OPEN_IN_INTERFACE.registerFactory(RemoveModifierFix.createRemoveModifierFromListOwnerFactory(OPEN_KEYWORD))
UNNECESSARY_LATEINIT.registerFactory(RemoveModifierFix.createRemoveModifierFromListOwnerFactory(LATEINIT_KEYWORD))
REDUNDANT_PROJECTION.registerFactory(RemoveModifierFix.createRemoveProjectionFactory(true))
INCOMPATIBLE_MODIFIERS.registerFactory(RemoveModifierFix.createRemoveModifierFactory(false))
@@ -0,0 +1,9 @@
// "Remove 'lateinit' modifier" "true"
class Foo {
<caret>lateinit var bar: String
constructor(baz: Int) {
bar = ""
}
}
@@ -0,0 +1,9 @@
// "Remove 'lateinit' modifier" "true"
class Foo {
var bar: String
constructor(baz: Int) {
bar = ""
}
}
@@ -0,0 +1,9 @@
// "Remove 'lateinit' modifier" "true"
class Foo {
<caret>lateinit var bar: String
init {
bar = ""
}
}
@@ -0,0 +1,9 @@
// "Remove 'lateinit' modifier" "true"
class Foo {
var bar: String
init {
bar = ""
}
}
@@ -0,0 +1,13 @@
// "Remove 'lateinit' modifier" "true"
class Foo {
<caret>lateinit var bar: String
constructor() {
bar = ""
}
constructor(baz: Int) {
bar = ""
}
}
@@ -0,0 +1,13 @@
// "Remove 'lateinit' modifier" "true"
class Foo {
var bar: String
constructor() {
bar = ""
}
constructor(baz: Int) {
bar = ""
}
}
@@ -0,0 +1,15 @@
// "Remove 'lateinit' modifier" "true"
class Foo {
<caret>lateinit var bar: String
constructor() {
bar = ""
}
constructor(a: Int) : this() {
}
constructor(a: Int, b: Int) : this(a) {
}
}
@@ -0,0 +1,15 @@
// "Remove 'lateinit' modifier" "true"
class Foo {
var bar: String
constructor() {
bar = ""
}
constructor(a: Int) : this() {
}
constructor(a: Int, b: Int) : this(a) {
}
}
@@ -0,0 +1,14 @@
// "Remove 'lateinit' modifier" "true"
class Foo {
<caret>lateinit var bar: String
var baz: Int
init {
baz = 1
}
init {
bar = ""
}
}
@@ -0,0 +1,14 @@
// "Remove 'lateinit' modifier" "true"
class Foo {
var bar: String
var baz: Int
init {
baz = 1
}
init {
bar = ""
}
}
@@ -0,0 +1,14 @@
// "Remove 'lateinit' modifier" "true"
// ERROR: There's a cycle in the delegation calls chain
class Foo {
<caret>lateinit var bar: String
constructor() {
bar = ""
}
constructor(a: Int) : this(a) {
bar = "a"
}
}
@@ -0,0 +1,14 @@
// "Remove 'lateinit' modifier" "true"
// ERROR: There's a cycle in the delegation calls chain
class Foo {
<caret>var bar: String
constructor() {
bar = ""
}
constructor(a: Int) : this(a) {
bar = "a"
}
}
@@ -9362,6 +9362,51 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
}
}
@TestMetadata("idea/testData/quickfix/unnecessaryLateinit")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class UnnecessaryLateinit extends AbstractQuickFixTest {
public void testAllFilesPresentInUnnecessaryLateinit() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/quickfix/unnecessaryLateinit"), Pattern.compile("^([\\w\\-_]+)\\.kt$"), true);
}
@TestMetadata("lateinitWithConstructor.kt")
public void testLateinitWithConstructor() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/unnecessaryLateinit/lateinitWithConstructor.kt");
doTest(fileName);
}
@TestMetadata("lateinitWithInit.kt")
public void testLateinitWithInit() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/unnecessaryLateinit/lateinitWithInit.kt");
doTest(fileName);
}
@TestMetadata("lateinitWithMultipleConstructors.kt")
public void testLateinitWithMultipleConstructors() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/unnecessaryLateinit/lateinitWithMultipleConstructors.kt");
doTest(fileName);
}
@TestMetadata("lateinitWithMultipleConstructorsAndDelegation.kt")
public void testLateinitWithMultipleConstructorsAndDelegation() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/unnecessaryLateinit/lateinitWithMultipleConstructorsAndDelegation.kt");
doTest(fileName);
}
@TestMetadata("lateinitWithMultipleInit.kt")
public void testLateinitWithMultipleInit() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/unnecessaryLateinit/lateinitWithMultipleInit.kt");
doTest(fileName);
}
@TestMetadata("secondaryConstructorDelegateItself.kt")
public void testSecondaryConstructorDelegateItself() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/unnecessaryLateinit/secondaryConstructorDelegateItself.kt");
doTest(fileName);
}
}
@TestMetadata("idea/testData/quickfix/unusedSuppressAnnotation")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)