From 64f67f30f087d1c455983714275ce845925b7b37 Mon Sep 17 00:00:00 2001 From: Tuomas Tynkkynen Date: Wed, 5 Feb 2014 16:38:22 +0200 Subject: [PATCH] Prevent smartSelectExpression from breaking up 'this@outerClass' The previous commit made JetThisExpression not implement JetStatementExpression. This had the side effect that smartSelectExpression over a label-qualified this expression (e.g 'this@outerClass') would now also list a plain 'this' as a potential expression. Restore the old behaviour by adding an explicit check for JetThisExpression. --- .../jet/plugin/refactoring/JetRefactoringUtil.java | 2 +- idea/testData/smartSelection/labelledThis.kt | 9 +++++++++ .../jet/plugin/SmartSelectionTestGenerated.java | 5 +++++ 3 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 idea/testData/smartSelection/labelledThis.kt diff --git a/idea/src/org/jetbrains/jet/plugin/refactoring/JetRefactoringUtil.java b/idea/src/org/jetbrains/jet/plugin/refactoring/JetRefactoringUtil.java index 50345e9b618..aac35c44a27 100644 --- a/idea/src/org/jetbrains/jet/plugin/refactoring/JetRefactoringUtil.java +++ b/idea/src/org/jetbrains/jet/plugin/refactoring/JetRefactoringUtil.java @@ -411,7 +411,7 @@ public class JetRefactoringUtil { addExpression = false; } } - else if (element.getParent() instanceof JetCallElement) { + else if (element.getParent() instanceof JetCallElement || element.getParent() instanceof JetThisExpression) { addExpression = false; } else if (element.getParent() instanceof JetOperationExpression) { diff --git a/idea/testData/smartSelection/labelledThis.kt b/idea/testData/smartSelection/labelledThis.kt new file mode 100644 index 00000000000..18c78ade4f7 --- /dev/null +++ b/idea/testData/smartSelection/labelledThis.kt @@ -0,0 +1,9 @@ +class Foo() { + val s = this@Foo.toString() +} + +// 'this' should not be listed, only 'this@Foo' +/* +this@Foo +this@Foo.toString() +*/ diff --git a/idea/tests/org/jetbrains/jet/plugin/SmartSelectionTestGenerated.java b/idea/tests/org/jetbrains/jet/plugin/SmartSelectionTestGenerated.java index a9b34705922..41a9775db8a 100644 --- a/idea/tests/org/jetbrains/jet/plugin/SmartSelectionTestGenerated.java +++ b/idea/tests/org/jetbrains/jet/plugin/SmartSelectionTestGenerated.java @@ -36,6 +36,11 @@ public class SmartSelectionTestGenerated extends AbstractSmartSelectionTest { JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("idea/testData/smartSelection"), Pattern.compile("^([^\\.]+)\\.kt$"), true); } + @TestMetadata("labelledThis.kt") + public void testLabelledThis() throws Exception { + doTestSmartSelection("idea/testData/smartSelection/labelledThis.kt"); + } + @TestMetadata("simple.kt") public void testSimple() throws Exception { doTestSmartSelection("idea/testData/smartSelection/simple.kt");