diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/DestructureIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/DestructureIntention.kt index 63767f0c513..6363b149f0c 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/DestructureIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/DestructureIntention.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2016 JetBrains s.r.o. + * Copyright 2010-2017 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. @@ -156,7 +156,7 @@ class DestructureIntention : SelfTargetingRangeIntention( else -> null } } - is KtVariableDeclaration -> parent + is KtProperty -> parent.takeIf { isLocal } is KtFunctionLiteral -> if (!hasParameterSpecification() && lambdaSupported) this else null else -> null } diff --git a/idea/testData/intentions/destructuringVariables/classProperty.kt b/idea/testData/intentions/destructuringVariables/classProperty.kt new file mode 100644 index 00000000000..782401a6932 --- /dev/null +++ b/idea/testData/intentions/destructuringVariables/classProperty.kt @@ -0,0 +1,9 @@ +// IS_APPLICABLE: false + +data class XY(val x: Int, val y: Int) + +fun create() = XY(1, 2) + +class Foo { + val xy = create() +} \ No newline at end of file diff --git a/idea/testData/intentions/destructuringVariables/toplevel.kt b/idea/testData/intentions/destructuringVariables/toplevel.kt new file mode 100644 index 00000000000..8a0bca8459f --- /dev/null +++ b/idea/testData/intentions/destructuringVariables/toplevel.kt @@ -0,0 +1,7 @@ +// IS_APPLICABLE: false + +data class XY(val x: Int, val y: Int) + +fun create() = XY(1, 2) + +val xy = create() \ 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 4426bdaab25..4ff702312ea 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java @@ -7832,6 +7832,12 @@ public class IntentionTestGenerated extends AbstractIntentionTest { doTest(fileName); } + @TestMetadata("classProperty.kt") + public void testClassProperty() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/destructuringVariables/classProperty.kt"); + doTest(fileName); + } + @TestMetadata("noInitializer.kt") public void testNoInitializer() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/destructuringVariables/noInitializer.kt"); @@ -7844,6 +7850,12 @@ public class IntentionTestGenerated extends AbstractIntentionTest { doTest(fileName); } + @TestMetadata("toplevel.kt") + public void testToplevel() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/destructuringVariables/toplevel.kt"); + doTest(fileName); + } + @TestMetadata("var.kt") public void testVar() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/destructuringVariables/var.kt");