From 6b49ac6b46d843692930cb6f802a577f46f2e471 Mon Sep 17 00:00:00 2001 From: Anton Sukhonosenko Date: Mon, 23 Nov 2015 23:33:38 +0300 Subject: [PATCH 1/3] #KT-9938 Fixed --- .../org/jetbrains/kotlin/psi/KtProperty.java | 9 ++- .../after.kt.template | 4 ++ .../before.kt.template | 3 + .../description.html | 5 ++ idea/src/META-INF/plugin.xml | 5 ++ ...ertPropertyInitializerToGetterIntention.kt | 62 +++++++++++++++++++ ...ExtensionPropertyInitializerToGetterFix.kt | 16 +---- .../.intention | 1 + .../inapplicableIfExtensionProperty.kt | 6 ++ .../inapplicableIfLocalVariableInFun.kt | 5 ++ .../inapplicableIfLocalVariableInInitBlock.kt | 7 +++ .../inapplicableIfNoInitializer.kt | 5 ++ .../inapplicableIfTopLevelDeclaration.kt | 3 + .../propertyWithInitializerWithSetter.kt | 6 ++ ...propertyWithInitializerWithSetter.kt.after | 7 +++ ...propertyWithInitializerWithoutAccessors.kt | 3 + ...tyWithInitializerWithoutAccessors.kt.after | 4 ++ .../semicolon.kt | 3 + .../semicolon.kt.after | 4 ++ .../createVariable/localVariable/inClass.kt | 1 + .../inPropertyInitializerInClassObject.kt | 1 + .../inPropertyInitializerInObject.kt | 1 + .../intentions/IntentionTestGenerated.java | 57 +++++++++++++++++ 23 files changed, 203 insertions(+), 15 deletions(-) create mode 100644 idea/resources/intentionDescriptions/ConvertPropertyInitializerToGetterIntention/after.kt.template create mode 100644 idea/resources/intentionDescriptions/ConvertPropertyInitializerToGetterIntention/before.kt.template create mode 100644 idea/resources/intentionDescriptions/ConvertPropertyInitializerToGetterIntention/description.html create mode 100644 idea/src/org/jetbrains/kotlin/idea/intentions/ConvertPropertyInitializerToGetterIntention.kt create mode 100644 idea/testData/intentions/convertPropertyInitializerToGetter/.intention create mode 100644 idea/testData/intentions/convertPropertyInitializerToGetter/inapplicableIfExtensionProperty.kt create mode 100644 idea/testData/intentions/convertPropertyInitializerToGetter/inapplicableIfLocalVariableInFun.kt create mode 100644 idea/testData/intentions/convertPropertyInitializerToGetter/inapplicableIfLocalVariableInInitBlock.kt create mode 100644 idea/testData/intentions/convertPropertyInitializerToGetter/inapplicableIfNoInitializer.kt create mode 100644 idea/testData/intentions/convertPropertyInitializerToGetter/inapplicableIfTopLevelDeclaration.kt create mode 100644 idea/testData/intentions/convertPropertyInitializerToGetter/propertyWithInitializerWithSetter.kt create mode 100644 idea/testData/intentions/convertPropertyInitializerToGetter/propertyWithInitializerWithSetter.kt.after create mode 100644 idea/testData/intentions/convertPropertyInitializerToGetter/propertyWithInitializerWithoutAccessors.kt create mode 100644 idea/testData/intentions/convertPropertyInitializerToGetter/propertyWithInitializerWithoutAccessors.kt.after create mode 100644 idea/testData/intentions/convertPropertyInitializerToGetter/semicolon.kt create mode 100644 idea/testData/intentions/convertPropertyInitializerToGetter/semicolon.kt.after diff --git a/compiler/frontend/src/org/jetbrains/kotlin/psi/KtProperty.java b/compiler/frontend/src/org/jetbrains/kotlin/psi/KtProperty.java index 246d602d2b3..01c0ef8059e 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/psi/KtProperty.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/psi/KtProperty.java @@ -243,7 +243,14 @@ public class KtProperty extends KtTypeParameterListOwnerStub return (KtExpression) oldInitializer.replace(initializer); } else { - deleteChildRange(findChildByType(EQ), oldInitializer); + PsiElement nextSibling = oldInitializer.getNextSibling(); + PsiElement last = + nextSibling != null + && nextSibling.getNode() != null + && nextSibling.getNode().getElementType() == KtTokens.SEMICOLON + ? nextSibling : oldInitializer; + + deleteChildRange(findChildByType(EQ), last); return null; } } diff --git a/idea/resources/intentionDescriptions/ConvertPropertyInitializerToGetterIntention/after.kt.template b/idea/resources/intentionDescriptions/ConvertPropertyInitializerToGetterIntention/after.kt.template new file mode 100644 index 00000000000..a3d557e0442 --- /dev/null +++ b/idea/resources/intentionDescriptions/ConvertPropertyInitializerToGetterIntention/after.kt.template @@ -0,0 +1,4 @@ +class A { + val foo: Int + get() = 1 +} \ No newline at end of file diff --git a/idea/resources/intentionDescriptions/ConvertPropertyInitializerToGetterIntention/before.kt.template b/idea/resources/intentionDescriptions/ConvertPropertyInitializerToGetterIntention/before.kt.template new file mode 100644 index 00000000000..45a9b7d4aa5 --- /dev/null +++ b/idea/resources/intentionDescriptions/ConvertPropertyInitializerToGetterIntention/before.kt.template @@ -0,0 +1,3 @@ +class A { + val foo: Int = 1 +} \ No newline at end of file diff --git a/idea/resources/intentionDescriptions/ConvertPropertyInitializerToGetterIntention/description.html b/idea/resources/intentionDescriptions/ConvertPropertyInitializerToGetterIntention/description.html new file mode 100644 index 00000000000..88ff37ca5a8 --- /dev/null +++ b/idea/resources/intentionDescriptions/ConvertPropertyInitializerToGetterIntention/description.html @@ -0,0 +1,5 @@ + + +This intention converts property initializer to getter. + + \ No newline at end of file diff --git a/idea/src/META-INF/plugin.xml b/idea/src/META-INF/plugin.xml index 02c0e62bcb2..4faae67eaab 100644 --- a/idea/src/META-INF/plugin.xml +++ b/idea/src/META-INF/plugin.xml @@ -1000,6 +1000,11 @@ Kotlin + + org.jetbrains.kotlin.idea.intentions.ConvertPropertyInitializerToGetterIntention + Kotlin + + org.jetbrains.kotlin.idea.intentions.InvertIfConditionIntention Kotlin diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertPropertyInitializerToGetterIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertPropertyInitializerToGetterIntention.kt new file mode 100644 index 00000000000..70c31289a2e --- /dev/null +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertPropertyInitializerToGetterIntention.kt @@ -0,0 +1,62 @@ +/* + * Copyright 2010-2015 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.kotlin.idea.intentions + +import com.intellij.openapi.editor.Editor +import org.jetbrains.kotlin.descriptors.PropertyDescriptor +import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade +import org.jetbrains.kotlin.psi.KtClassOrObject +import org.jetbrains.kotlin.psi.KtProperty +import org.jetbrains.kotlin.psi.KtPsiFactory +import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType +import org.jetbrains.kotlin.psi.psiUtil.isExtensionDeclaration +import org.jetbrains.kotlin.resolve.BindingContext + +class ConvertPropertyInitializerToGetterIntention : SelfTargetingIntention(javaClass(), "Convert property initializer to getter") { + override fun isApplicableTo(element: KtProperty, caretOffset: Int): Boolean { + return element.initializer != null + && element.initializer?.textRange?.containsOffset(caretOffset) == true + && element.getter == null + && !element.isExtensionDeclaration() + && !element.isLocal + && !element.isTopLevel + } + + override fun applyTo(property: KtProperty, editor: Editor) { + convertPropertyInitializerToGetter(property, editor) + } + + companion object { + fun convertPropertyInitializerToGetter(property: KtProperty, editor: Editor?) { + val type = SpecifyTypeExplicitlyIntention.getTypeForDeclaration(property) + SpecifyTypeExplicitlyIntention.addTypeAnnotation(editor, property, type) + + val initializer = property.initializer!! + val getter = KtPsiFactory(property).createPropertyGetter(initializer) + val setter = property.setter + + if (setter != null) { + property.addBefore(getter, setter) + } + else { + property.add(getter) + } + + property.setInitializer(null) + } + } +} diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/ConvertExtensionPropertyInitializerToGetterFix.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/ConvertExtensionPropertyInitializerToGetterFix.kt index 2ba6e5435e2..0da8ee14c38 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/ConvertExtensionPropertyInitializerToGetterFix.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/ConvertExtensionPropertyInitializerToGetterFix.kt @@ -20,6 +20,7 @@ import com.intellij.codeInsight.intention.IntentionAction import com.intellij.openapi.editor.Editor import com.intellij.openapi.project.Project import org.jetbrains.kotlin.diagnostics.Diagnostic +import org.jetbrains.kotlin.idea.intentions.ConvertPropertyInitializerToGetterIntention import org.jetbrains.kotlin.idea.intentions.SpecifyTypeExplicitlyIntention import org.jetbrains.kotlin.psi.KtExpression import org.jetbrains.kotlin.psi.KtFile @@ -34,20 +35,7 @@ class ConvertExtensionPropertyInitializerToGetterFix(element: KtExpression) : Ko override fun invoke(project: Project, editor: Editor?, file: KtFile) { val property = element.getParentOfType(true) ?: return - val type = SpecifyTypeExplicitlyIntention.getTypeForDeclaration(property) - SpecifyTypeExplicitlyIntention.addTypeAnnotation(editor, property, type) - - val getter = KtPsiFactory(element).createPropertyGetter(element) - val setter = property.setter - - if (setter != null) { - property.addBefore(getter, setter) - } - else { - property.add(getter) - } - - property.setInitializer(null) + ConvertPropertyInitializerToGetterIntention.convertPropertyInitializerToGetter(property, editor) } companion object : KotlinSingleIntentionActionFactory() { diff --git a/idea/testData/intentions/convertPropertyInitializerToGetter/.intention b/idea/testData/intentions/convertPropertyInitializerToGetter/.intention new file mode 100644 index 00000000000..52c0daa487e --- /dev/null +++ b/idea/testData/intentions/convertPropertyInitializerToGetter/.intention @@ -0,0 +1 @@ +org.jetbrains.kotlin.idea.intentions.ConvertPropertyInitializerToGetterIntention \ No newline at end of file diff --git a/idea/testData/intentions/convertPropertyInitializerToGetter/inapplicableIfExtensionProperty.kt b/idea/testData/intentions/convertPropertyInitializerToGetter/inapplicableIfExtensionProperty.kt new file mode 100644 index 00000000000..4a70ca68fa5 --- /dev/null +++ b/idea/testData/intentions/convertPropertyInitializerToGetter/inapplicableIfExtensionProperty.kt @@ -0,0 +1,6 @@ +// IS_APPLICABLE: false +// ERROR: Extension property cannot be initialized because it has no backing field + +class A + +val A.a: Int = 0 diff --git a/idea/testData/intentions/convertPropertyInitializerToGetter/inapplicableIfLocalVariableInFun.kt b/idea/testData/intentions/convertPropertyInitializerToGetter/inapplicableIfLocalVariableInFun.kt new file mode 100644 index 00000000000..0b861eae29e --- /dev/null +++ b/idea/testData/intentions/convertPropertyInitializerToGetter/inapplicableIfLocalVariableInFun.kt @@ -0,0 +1,5 @@ +// IS_APPLICABLE: false + +fun foo() { + val x: Int = 1 +} \ No newline at end of file diff --git a/idea/testData/intentions/convertPropertyInitializerToGetter/inapplicableIfLocalVariableInInitBlock.kt b/idea/testData/intentions/convertPropertyInitializerToGetter/inapplicableIfLocalVariableInInitBlock.kt new file mode 100644 index 00000000000..6b468c990b1 --- /dev/null +++ b/idea/testData/intentions/convertPropertyInitializerToGetter/inapplicableIfLocalVariableInInitBlock.kt @@ -0,0 +1,7 @@ +// IS_APPLICABLE: false + +class A { + init { + val x: Int = 1 + } +} \ No newline at end of file diff --git a/idea/testData/intentions/convertPropertyInitializerToGetter/inapplicableIfNoInitializer.kt b/idea/testData/intentions/convertPropertyInitializerToGetter/inapplicableIfNoInitializer.kt new file mode 100644 index 00000000000..e17f06e0b2e --- /dev/null +++ b/idea/testData/intentions/convertPropertyInitializerToGetter/inapplicableIfNoInitializer.kt @@ -0,0 +1,5 @@ +// IS_APPLICABLE: false + +abstract class A { + abstract val a: Int +} \ No newline at end of file diff --git a/idea/testData/intentions/convertPropertyInitializerToGetter/inapplicableIfTopLevelDeclaration.kt b/idea/testData/intentions/convertPropertyInitializerToGetter/inapplicableIfTopLevelDeclaration.kt new file mode 100644 index 00000000000..8947ef4836c --- /dev/null +++ b/idea/testData/intentions/convertPropertyInitializerToGetter/inapplicableIfTopLevelDeclaration.kt @@ -0,0 +1,3 @@ +// IS_APPLICABLE: false + +val x: Int = 1 \ No newline at end of file diff --git a/idea/testData/intentions/convertPropertyInitializerToGetter/propertyWithInitializerWithSetter.kt b/idea/testData/intentions/convertPropertyInitializerToGetter/propertyWithInitializerWithSetter.kt new file mode 100644 index 00000000000..81415531701 --- /dev/null +++ b/idea/testData/intentions/convertPropertyInitializerToGetter/propertyWithInitializerWithSetter.kt @@ -0,0 +1,6 @@ +class A { + var a = 1 + set(value) { + field = value + } +} \ No newline at end of file diff --git a/idea/testData/intentions/convertPropertyInitializerToGetter/propertyWithInitializerWithSetter.kt.after b/idea/testData/intentions/convertPropertyInitializerToGetter/propertyWithInitializerWithSetter.kt.after new file mode 100644 index 00000000000..247d9494355 --- /dev/null +++ b/idea/testData/intentions/convertPropertyInitializerToGetter/propertyWithInitializerWithSetter.kt.after @@ -0,0 +1,7 @@ +class A { + var a: Int + get() = 1 + set(value) { + field = value + } +} \ No newline at end of file diff --git a/idea/testData/intentions/convertPropertyInitializerToGetter/propertyWithInitializerWithoutAccessors.kt b/idea/testData/intentions/convertPropertyInitializerToGetter/propertyWithInitializerWithoutAccessors.kt new file mode 100644 index 00000000000..049e06c456e --- /dev/null +++ b/idea/testData/intentions/convertPropertyInitializerToGetter/propertyWithInitializerWithoutAccessors.kt @@ -0,0 +1,3 @@ +class A { + val a: Int = 1 +} \ No newline at end of file diff --git a/idea/testData/intentions/convertPropertyInitializerToGetter/propertyWithInitializerWithoutAccessors.kt.after b/idea/testData/intentions/convertPropertyInitializerToGetter/propertyWithInitializerWithoutAccessors.kt.after new file mode 100644 index 00000000000..97c360caedc --- /dev/null +++ b/idea/testData/intentions/convertPropertyInitializerToGetter/propertyWithInitializerWithoutAccessors.kt.after @@ -0,0 +1,4 @@ +class A { + val a: Int + get() = 1 +} \ No newline at end of file diff --git a/idea/testData/intentions/convertPropertyInitializerToGetter/semicolon.kt b/idea/testData/intentions/convertPropertyInitializerToGetter/semicolon.kt new file mode 100644 index 00000000000..fe71ea701ff --- /dev/null +++ b/idea/testData/intentions/convertPropertyInitializerToGetter/semicolon.kt @@ -0,0 +1,3 @@ +class A { + val a: Int = 1; +} \ No newline at end of file diff --git a/idea/testData/intentions/convertPropertyInitializerToGetter/semicolon.kt.after b/idea/testData/intentions/convertPropertyInitializerToGetter/semicolon.kt.after new file mode 100644 index 00000000000..97c360caedc --- /dev/null +++ b/idea/testData/intentions/convertPropertyInitializerToGetter/semicolon.kt.after @@ -0,0 +1,4 @@ +class A { + val a: Int + get() = 1 +} \ No newline at end of file diff --git a/idea/testData/quickfix/createFromUsage/createVariable/localVariable/inClass.kt b/idea/testData/quickfix/createFromUsage/createVariable/localVariable/inClass.kt index 6de5cd68e95..b785fe2e9db 100644 --- a/idea/testData/quickfix/createFromUsage/createVariable/localVariable/inClass.kt +++ b/idea/testData/quickfix/createFromUsage/createVariable/localVariable/inClass.kt @@ -1,4 +1,5 @@ // "Create local variable 'foo'" "false" +// ACTION: Convert property initializer to getter // ACTION: Create parameter 'foo' // ACTION: Create property 'foo' // ERROR: Unresolved reference: foo diff --git a/idea/testData/quickfix/createFromUsage/createVariable/parameter/inPropertyInitializerInClassObject.kt b/idea/testData/quickfix/createFromUsage/createVariable/parameter/inPropertyInitializerInClassObject.kt index dc9b3649593..0b319b6c6ef 100644 --- a/idea/testData/quickfix/createFromUsage/createVariable/parameter/inPropertyInitializerInClassObject.kt +++ b/idea/testData/quickfix/createFromUsage/createVariable/parameter/inPropertyInitializerInClassObject.kt @@ -1,4 +1,5 @@ // "Create parameter 'foo'" "false" +// ACTION: Convert property initializer to getter // ACTION: Create property 'foo' // ERROR: Unresolved reference: foo diff --git a/idea/testData/quickfix/createFromUsage/createVariable/parameter/inPropertyInitializerInObject.kt b/idea/testData/quickfix/createFromUsage/createVariable/parameter/inPropertyInitializerInObject.kt index 82981a1bd9b..a919c467f20 100644 --- a/idea/testData/quickfix/createFromUsage/createVariable/parameter/inPropertyInitializerInObject.kt +++ b/idea/testData/quickfix/createFromUsage/createVariable/parameter/inPropertyInitializerInObject.kt @@ -1,4 +1,5 @@ // "Create parameter 'foo'" "false" +// ACTION: Convert property initializer to getter // ACTION: Create property 'foo' // ERROR: Unresolved reference: foo diff --git a/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java index 5ad3af3c0c7..22d48f602f7 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java @@ -3707,6 +3707,63 @@ public class IntentionTestGenerated extends AbstractIntentionTest { } } + @TestMetadata("idea/testData/intentions/convertPropertyInitializerToGetter") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class ConvertPropertyInitializerToGetter extends AbstractIntentionTest { + public void testAllFilesPresentInConvertPropertyInitializerToGetter() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/intentions/convertPropertyInitializerToGetter"), Pattern.compile("^([\\w\\-_]+)\\.kt$"), true); + } + + @TestMetadata("inapplicableIfExtensionProperty.kt") + public void testInapplicableIfExtensionProperty() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertPropertyInitializerToGetter/inapplicableIfExtensionProperty.kt"); + doTest(fileName); + } + + @TestMetadata("inapplicableIfLocalVariableInFun.kt") + public void testInapplicableIfLocalVariableInFun() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertPropertyInitializerToGetter/inapplicableIfLocalVariableInFun.kt"); + doTest(fileName); + } + + @TestMetadata("inapplicableIfLocalVariableInInitBlock.kt") + public void testInapplicableIfLocalVariableInInitBlock() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertPropertyInitializerToGetter/inapplicableIfLocalVariableInInitBlock.kt"); + doTest(fileName); + } + + @TestMetadata("inapplicableIfNoInitializer.kt") + public void testInapplicableIfNoInitializer() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertPropertyInitializerToGetter/inapplicableIfNoInitializer.kt"); + doTest(fileName); + } + + @TestMetadata("inapplicableIfTopLevelDeclaration.kt") + public void testInapplicableIfTopLevelDeclaration() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertPropertyInitializerToGetter/inapplicableIfTopLevelDeclaration.kt"); + doTest(fileName); + } + + @TestMetadata("propertyWithInitializerWithSetter.kt") + public void testPropertyWithInitializerWithSetter() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertPropertyInitializerToGetter/propertyWithInitializerWithSetter.kt"); + doTest(fileName); + } + + @TestMetadata("propertyWithInitializerWithoutAccessors.kt") + public void testPropertyWithInitializerWithoutAccessors() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertPropertyInitializerToGetter/propertyWithInitializerWithoutAccessors.kt"); + doTest(fileName); + } + + @TestMetadata("semicolon.kt") + public void testSemicolon() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertPropertyInitializerToGetter/semicolon.kt"); + doTest(fileName); + } + } + @TestMetadata("idea/testData/intentions/convertPropertyToFunction") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) From da5f71773a9b6eea2254f1bca4ec4c60b3cadd14 Mon Sep 17 00:00:00 2001 From: Anton Sukhonosenko Date: Mon, 7 Dec 2015 22:48:47 +0300 Subject: [PATCH 2/3] #KT-9938 Fixed Code review fixes --- .../after.kt.template | 2 +- .../ConvertPropertyInitializerToGetterIntention.kt | 1 - .../inapplicableIfTopLevelDeclaration.kt | 3 --- .../noImportInQualifiedExpressionNotFirst.before.Main.kt | 1 + ...noImportInSafeQualifiedExpressionNotFirst.before.Main.kt | 1 + .../noImportsForClassInExcludedPackage.before.Main.kt | 1 + .../autoImports/noImportsForExcludedClass.before.Main.kt | 1 + .../noImportsForFunctionInExcludedPackage.before.Main.kt | 1 + .../createVariable/localVariable/onTopLevel.kt | 1 + .../parameter/inPropertyInitializerNoClass.kt | 1 + .../kotlin/idea/intentions/IntentionTestGenerated.java | 6 ------ 11 files changed, 8 insertions(+), 11 deletions(-) delete mode 100644 idea/testData/intentions/convertPropertyInitializerToGetter/inapplicableIfTopLevelDeclaration.kt diff --git a/idea/resources/intentionDescriptions/ConvertPropertyInitializerToGetterIntention/after.kt.template b/idea/resources/intentionDescriptions/ConvertPropertyInitializerToGetterIntention/after.kt.template index a3d557e0442..57717f73075 100644 --- a/idea/resources/intentionDescriptions/ConvertPropertyInitializerToGetterIntention/after.kt.template +++ b/idea/resources/intentionDescriptions/ConvertPropertyInitializerToGetterIntention/after.kt.template @@ -1,4 +1,4 @@ class A { val foo: Int - get() = 1 + get() = 1 } \ No newline at end of file diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertPropertyInitializerToGetterIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertPropertyInitializerToGetterIntention.kt index 70c31289a2e..0051d847b83 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertPropertyInitializerToGetterIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertPropertyInitializerToGetterIntention.kt @@ -33,7 +33,6 @@ class ConvertPropertyInitializerToGetterIntention : SelfTargetingIntention \ No newline at end of file diff --git a/idea/testData/quickfix/autoImports/noImportInQualifiedExpressionNotFirst.before.Main.kt b/idea/testData/quickfix/autoImports/noImportInQualifiedExpressionNotFirst.before.Main.kt index df00fd41501..41d153e5167 100644 --- a/idea/testData/quickfix/autoImports/noImportInQualifiedExpressionNotFirst.before.Main.kt +++ b/idea/testData/quickfix/autoImports/noImportInQualifiedExpressionNotFirst.before.Main.kt @@ -1,4 +1,5 @@ // "class org.jetbrains.kotlin.idea.quickfix.AutoImportFix" "false" +// ACTION: Convert property initializer to getter // ACTION: Create class 'SomeTest' // ERROR: Unresolved reference: SomeTest diff --git a/idea/testData/quickfix/autoImports/noImportInSafeQualifiedExpressionNotFirst.before.Main.kt b/idea/testData/quickfix/autoImports/noImportInSafeQualifiedExpressionNotFirst.before.Main.kt index 29a618e388b..53540f7f648 100644 --- a/idea/testData/quickfix/autoImports/noImportInSafeQualifiedExpressionNotFirst.before.Main.kt +++ b/idea/testData/quickfix/autoImports/noImportInSafeQualifiedExpressionNotFirst.before.Main.kt @@ -1,6 +1,7 @@ // "class org.jetbrains.kotlin.idea.quickfix.AutoImportFix" "false" // ERROR: Unresolved reference: SomeTest // ERROR: Expression expected, but a package name found +// ACTION: Convert property initializer to getter // ACTION: Create class 'SomeTest' // ACTION: Replace safe access expression with 'if' expression diff --git a/idea/testData/quickfix/autoImports/noImportsForClassInExcludedPackage.before.Main.kt b/idea/testData/quickfix/autoImports/noImportsForClassInExcludedPackage.before.Main.kt index 937fd51493c..0117a8cdc4e 100644 --- a/idea/testData/quickfix/autoImports/noImportsForClassInExcludedPackage.before.Main.kt +++ b/idea/testData/quickfix/autoImports/noImportsForClassInExcludedPackage.before.Main.kt @@ -1,4 +1,5 @@ // "class org.jetbrains.kotlin.idea.quickfix.AutoImportFix" "false" +// ACTION: Convert property initializer to getter // ACTION: Create class 'SomeClass' // ACTION: Create function 'SomeClass' // ERROR: Unresolved reference: SomeClass diff --git a/idea/testData/quickfix/autoImports/noImportsForExcludedClass.before.Main.kt b/idea/testData/quickfix/autoImports/noImportsForExcludedClass.before.Main.kt index 54a86b8f32b..f8acfd55db0 100644 --- a/idea/testData/quickfix/autoImports/noImportsForExcludedClass.before.Main.kt +++ b/idea/testData/quickfix/autoImports/noImportsForExcludedClass.before.Main.kt @@ -1,4 +1,5 @@ // "class org.jetbrains.kotlin.idea.quickfix.AutoImportFix" "false" +// ACTION: Convert property initializer to getter // ACTION: Create class 'ExcludedClass' // ACTION: Create function 'ExcludedClass' // ERROR: Unresolved reference: ExcludedClass diff --git a/idea/testData/quickfix/autoImports/noImportsForFunctionInExcludedPackage.before.Main.kt b/idea/testData/quickfix/autoImports/noImportsForFunctionInExcludedPackage.before.Main.kt index 795e4b70cdf..ef31b7b468a 100644 --- a/idea/testData/quickfix/autoImports/noImportsForFunctionInExcludedPackage.before.Main.kt +++ b/idea/testData/quickfix/autoImports/noImportsForFunctionInExcludedPackage.before.Main.kt @@ -1,4 +1,5 @@ // "class org.jetbrains.kotlin.idea.quickfix.AutoImportFix" "false" +// ACTION: Convert property initializer to getter // ACTION: Create function 'someFunction' // ERROR: Unresolved reference: someFunction diff --git a/idea/testData/quickfix/createFromUsage/createVariable/localVariable/onTopLevel.kt b/idea/testData/quickfix/createFromUsage/createVariable/localVariable/onTopLevel.kt index aec94ab0364..c05a88f7cfb 100644 --- a/idea/testData/quickfix/createFromUsage/createVariable/localVariable/onTopLevel.kt +++ b/idea/testData/quickfix/createFromUsage/createVariable/localVariable/onTopLevel.kt @@ -1,4 +1,5 @@ // "Create local variable 'foo'" "false" +// ACTION: Convert property initializer to getter // ACTION: Create property 'foo' // ERROR: Unresolved reference: foo diff --git a/idea/testData/quickfix/createFromUsage/createVariable/parameter/inPropertyInitializerNoClass.kt b/idea/testData/quickfix/createFromUsage/createVariable/parameter/inPropertyInitializerNoClass.kt index f000ac58d76..e548ed65713 100644 --- a/idea/testData/quickfix/createFromUsage/createVariable/parameter/inPropertyInitializerNoClass.kt +++ b/idea/testData/quickfix/createFromUsage/createVariable/parameter/inPropertyInitializerNoClass.kt @@ -1,4 +1,5 @@ // "Create parameter 'foo'" "false" +// ACTION: Convert property initializer to getter // ACTION: Create property 'foo' // ERROR: Unresolved reference: foo diff --git a/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java index 22d48f602f7..60833888b9d 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java @@ -3739,12 +3739,6 @@ public class IntentionTestGenerated extends AbstractIntentionTest { doTest(fileName); } - @TestMetadata("inapplicableIfTopLevelDeclaration.kt") - public void testInapplicableIfTopLevelDeclaration() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertPropertyInitializerToGetter/inapplicableIfTopLevelDeclaration.kt"); - doTest(fileName); - } - @TestMetadata("propertyWithInitializerWithSetter.kt") public void testPropertyWithInitializerWithSetter() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertPropertyInitializerToGetter/propertyWithInitializerWithSetter.kt"); From 4a0e33003b5a8d12efe7bb849d3123b07d680c9b Mon Sep 17 00:00:00 2001 From: mcgee Date: Tue, 8 Dec 2015 23:33:39 +0300 Subject: [PATCH 3/3] #KT-9938 Fixed Top level test case is added --- .../topLevelDeclaration.kt | 1 + .../topLevelDeclaration.kt.after | 2 ++ .../kotlin/idea/intentions/IntentionTestGenerated.java | 6 ++++++ 3 files changed, 9 insertions(+) create mode 100644 idea/testData/intentions/convertPropertyInitializerToGetter/topLevelDeclaration.kt create mode 100644 idea/testData/intentions/convertPropertyInitializerToGetter/topLevelDeclaration.kt.after diff --git a/idea/testData/intentions/convertPropertyInitializerToGetter/topLevelDeclaration.kt b/idea/testData/intentions/convertPropertyInitializerToGetter/topLevelDeclaration.kt new file mode 100644 index 00000000000..e24d69fbd4f --- /dev/null +++ b/idea/testData/intentions/convertPropertyInitializerToGetter/topLevelDeclaration.kt @@ -0,0 +1 @@ +val x: Int = 1 \ No newline at end of file diff --git a/idea/testData/intentions/convertPropertyInitializerToGetter/topLevelDeclaration.kt.after b/idea/testData/intentions/convertPropertyInitializerToGetter/topLevelDeclaration.kt.after new file mode 100644 index 00000000000..834c4b17fc4 --- /dev/null +++ b/idea/testData/intentions/convertPropertyInitializerToGetter/topLevelDeclaration.kt.after @@ -0,0 +1,2 @@ +val x: Int + get() = 1 \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java index 60833888b9d..2543b7bbee0 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java @@ -3756,6 +3756,12 @@ public class IntentionTestGenerated extends AbstractIntentionTest { String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertPropertyInitializerToGetter/semicolon.kt"); doTest(fileName); } + + @TestMetadata("topLevelDeclaration.kt") + public void testTopLevelDeclaration() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertPropertyInitializerToGetter/topLevelDeclaration.kt"); + doTest(fileName); + } } @TestMetadata("idea/testData/intentions/convertPropertyToFunction")