"Use destructuring declaration" should not be available for top-level and class properties (#1205)

Fixes #KT-19167
diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/DestructureIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/DestructureIntention.kt
index 63767f0..6363b14 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 @@
                         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 0000000..782401a
--- /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 = <caret>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 0000000..8a0bca8
--- /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 = <caret>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 4426bda..4ff7023 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 @@
             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 @@
             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");