From 4113a6fd6a241477d03c2bd846b8be049ec5ba27 Mon Sep 17 00:00:00 2001 From: Mikhail Glukhikh Date: Tue, 21 Aug 2018 15:43:27 +0300 Subject: [PATCH] Extend fixes of experimental errors to property & type alias #KT-25525 Fixed #KT-25526 Fixed --- .../idea/quickfix/ExperimentalFixesFactory.kt | 4 +++- .../experimental/annotationInTopLevelProperty.kt | 15 +++++++++++++++ .../annotationInTopLevelProperty.kt.after | 16 ++++++++++++++++ idea/testData/quickfix/experimental/typeAlias.kt | 12 ++++++++++++ .../quickfix/experimental/typeAlias.kt.after | 12 ++++++++++++ .../experimental/typeInTopLevelProperty.kt | 15 +++++++++++++++ .../experimental/typeInTopLevelProperty.kt.after | 16 ++++++++++++++++ .../idea/quickfix/QuickFixTestGenerated.java | 15 +++++++++++++++ 8 files changed, 104 insertions(+), 1 deletion(-) create mode 100644 idea/testData/quickfix/experimental/annotationInTopLevelProperty.kt create mode 100644 idea/testData/quickfix/experimental/annotationInTopLevelProperty.kt.after create mode 100644 idea/testData/quickfix/experimental/typeAlias.kt create mode 100644 idea/testData/quickfix/experimental/typeAlias.kt.after create mode 100644 idea/testData/quickfix/experimental/typeInTopLevelProperty.kt create mode 100644 idea/testData/quickfix/experimental/typeInTopLevelProperty.kt.after diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/ExperimentalFixesFactory.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/ExperimentalFixesFactory.kt index 6e50e8855b8..d3a8ac13844 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/ExperimentalFixesFactory.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/ExperimentalFixesFactory.kt @@ -29,7 +29,9 @@ object ExperimentalFixesFactory : KotlinIntentionActionsFactory() { val containingDeclaration: KtDeclaration = element.getParentOfTypesAndPredicate( true, KtDeclarationWithBody::class.java, - KtClassOrObject::class.java + KtClassOrObject::class.java, + KtProperty::class.java, + KtTypeAlias::class.java ) { !KtPsiUtil.isLocal(it) } ?: return emptyList() diff --git a/idea/testData/quickfix/experimental/annotationInTopLevelProperty.kt b/idea/testData/quickfix/experimental/annotationInTopLevelProperty.kt new file mode 100644 index 00000000000..7787ec827bf --- /dev/null +++ b/idea/testData/quickfix/experimental/annotationInTopLevelProperty.kt @@ -0,0 +1,15 @@ +// "Add '@TopMarker' annotation to 'topUserVal'" "true" +// COMPILER_ARGUMENTS: -Xuse-experimental=kotlin.Experimental +// WITH_RUNTIME + +@Experimental +annotation class TopMarker + +@TopMarker +class TopClass + +@Target(AnnotationTarget.TYPE) +@TopMarker +annotation class TopAnn + +val topUserVal: @TopAnn TopClass? = null \ No newline at end of file diff --git a/idea/testData/quickfix/experimental/annotationInTopLevelProperty.kt.after b/idea/testData/quickfix/experimental/annotationInTopLevelProperty.kt.after new file mode 100644 index 00000000000..d2b05b7e5f3 --- /dev/null +++ b/idea/testData/quickfix/experimental/annotationInTopLevelProperty.kt.after @@ -0,0 +1,16 @@ +// "Add '@TopMarker' annotation to 'topUserVal'" "true" +// COMPILER_ARGUMENTS: -Xuse-experimental=kotlin.Experimental +// WITH_RUNTIME + +@Experimental +annotation class TopMarker + +@TopMarker +class TopClass + +@Target(AnnotationTarget.TYPE) +@TopMarker +annotation class TopAnn + +@TopMarker +val topUserVal: @TopAnn TopClass? = null \ No newline at end of file diff --git a/idea/testData/quickfix/experimental/typeAlias.kt b/idea/testData/quickfix/experimental/typeAlias.kt new file mode 100644 index 00000000000..c0cf890e5d3 --- /dev/null +++ b/idea/testData/quickfix/experimental/typeAlias.kt @@ -0,0 +1,12 @@ +// "Add '@UseExperimental(AliasMarker::class)' annotation to 'AliasMarkerUsage'" "true" +// COMPILER_ARGUMENTS: -Xuse-experimental=kotlin.Experimental +// WITH_RUNTIME +// ACTION: Add '-Xuse-experimental=AliasMarker' to module light_idea_test_case compiler arguments + +@Experimental +annotation class AliasMarker + +@AliasMarker +class AliasTarget + +typealias AliasMarkerUsage = AliasTarget \ No newline at end of file diff --git a/idea/testData/quickfix/experimental/typeAlias.kt.after b/idea/testData/quickfix/experimental/typeAlias.kt.after new file mode 100644 index 00000000000..e8e5041dd54 --- /dev/null +++ b/idea/testData/quickfix/experimental/typeAlias.kt.after @@ -0,0 +1,12 @@ +// "Add '@UseExperimental(AliasMarker::class)' annotation to 'AliasMarkerUsage'" "true" +// COMPILER_ARGUMENTS: -Xuse-experimental=kotlin.Experimental +// WITH_RUNTIME +// ACTION: Add '-Xuse-experimental=AliasMarker' to module light_idea_test_case compiler arguments + +@Experimental +annotation class AliasMarker + +@AliasMarker +class AliasTarget + +@UseExperimental(AliasMarker::class) typealias AliasMarkerUsage = AliasTarget \ No newline at end of file diff --git a/idea/testData/quickfix/experimental/typeInTopLevelProperty.kt b/idea/testData/quickfix/experimental/typeInTopLevelProperty.kt new file mode 100644 index 00000000000..8e936cb58e8 --- /dev/null +++ b/idea/testData/quickfix/experimental/typeInTopLevelProperty.kt @@ -0,0 +1,15 @@ +// "Add '@TopMarker' annotation to 'topUserVal'" "true" +// COMPILER_ARGUMENTS: -Xuse-experimental=kotlin.Experimental +// WITH_RUNTIME + +@Experimental +annotation class TopMarker + +@TopMarker +class TopClass + +@Target(AnnotationTarget.TYPE) +@TopMarker +annotation class TopAnn + +val topUserVal: @TopAnn TopClass? = null \ No newline at end of file diff --git a/idea/testData/quickfix/experimental/typeInTopLevelProperty.kt.after b/idea/testData/quickfix/experimental/typeInTopLevelProperty.kt.after new file mode 100644 index 00000000000..d2b05b7e5f3 --- /dev/null +++ b/idea/testData/quickfix/experimental/typeInTopLevelProperty.kt.after @@ -0,0 +1,16 @@ +// "Add '@TopMarker' annotation to 'topUserVal'" "true" +// COMPILER_ARGUMENTS: -Xuse-experimental=kotlin.Experimental +// WITH_RUNTIME + +@Experimental +annotation class TopMarker + +@TopMarker +class TopClass + +@Target(AnnotationTarget.TYPE) +@TopMarker +annotation class TopAnn + +@TopMarker +val topUserVal: @TopAnn TopClass? = null \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java index 8fea2054496..8fd0cf6fd76 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java @@ -6164,6 +6164,11 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest { KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/quickfix/experimental"), Pattern.compile("^([\\w\\-_]+)\\.kt$"), TargetBackend.ANY, true); } + @TestMetadata("annotationInTopLevelProperty.kt") + public void testAnnotationInTopLevelProperty() throws Exception { + runTest("idea/testData/quickfix/experimental/annotationInTopLevelProperty.kt"); + } + @TestMetadata("basicFunction.kt") public void testBasicFunction() throws Exception { runTest("idea/testData/quickfix/experimental/basicFunction.kt"); @@ -6223,6 +6228,16 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest { public void testSwitchOn() throws Exception { runTest("idea/testData/quickfix/experimental/switchOn.kt"); } + + @TestMetadata("typeAlias.kt") + public void testTypeAlias() throws Exception { + runTest("idea/testData/quickfix/experimental/typeAlias.kt"); + } + + @TestMetadata("typeInTopLevelProperty.kt") + public void testTypeInTopLevelProperty() throws Exception { + runTest("idea/testData/quickfix/experimental/typeInTopLevelProperty.kt"); + } } @TestMetadata("idea/testData/quickfix/expressions")