From 5f92c22df307f691fc3abbfbc1006ac834f42ac9 Mon Sep 17 00:00:00 2001 From: Alexey Sedunov Date: Thu, 17 Apr 2014 16:18:39 +0400 Subject: [PATCH] Smart Selector: Do not suggest expressions contained in the super-expression #KT-4824 Fixed --- .../refactoring/JetRefactoringUtil.java | 5 +++- .../smartSelection/superExpression.kt | 11 +++++++ .../superExpressionWithLabel.kt | 11 +++++++ .../superExpressionWithLabelAndType.kt | 11 +++++++ .../smartSelection/superExpressionWithType.kt | 11 +++++++ .../smartSelection/typeInSuperExpression.kt | 11 +++++++ .../typeInSuperExpressionWithLabel.kt | 11 +++++++ .../plugin/SmartSelectionTestGenerated.java | 30 +++++++++++++++++++ 8 files changed, 100 insertions(+), 1 deletion(-) create mode 100644 idea/testData/smartSelection/superExpression.kt create mode 100644 idea/testData/smartSelection/superExpressionWithLabel.kt create mode 100644 idea/testData/smartSelection/superExpressionWithLabelAndType.kt create mode 100644 idea/testData/smartSelection/superExpressionWithType.kt create mode 100644 idea/testData/smartSelection/typeInSuperExpression.kt create mode 100644 idea/testData/smartSelection/typeInSuperExpressionWithLabel.kt diff --git a/idea/src/org/jetbrains/jet/plugin/refactoring/JetRefactoringUtil.java b/idea/src/org/jetbrains/jet/plugin/refactoring/JetRefactoringUtil.java index 37816a91eac..2509d0e1c92 100644 --- a/idea/src/org/jetbrains/jet/plugin/refactoring/JetRefactoringUtil.java +++ b/idea/src/org/jetbrains/jet/plugin/refactoring/JetRefactoringUtil.java @@ -31,6 +31,7 @@ import com.intellij.psi.*; import com.intellij.psi.search.searches.OverridingMethodsSearch; import com.intellij.psi.util.PsiFormatUtil; import com.intellij.psi.util.PsiFormatUtilBase; +import com.intellij.psi.util.PsiTreeUtil; import com.intellij.ui.components.JBList; import com.intellij.util.Function; import com.intellij.util.containers.ContainerUtil; @@ -423,7 +424,9 @@ public class JetRefactoringUtil { addExpression = false; } } - else if (element.getParent() instanceof JetCallElement || element.getParent() instanceof JetThisExpression) { + else if (element.getParent() instanceof JetCallElement + || element.getParent() instanceof JetThisExpression + || PsiTreeUtil.getParentOfType(element, JetSuperExpression.class) != null) { addExpression = false; } else if (element.getParent() instanceof JetOperationExpression) { diff --git a/idea/testData/smartSelection/superExpression.kt b/idea/testData/smartSelection/superExpression.kt new file mode 100644 index 00000000000..c0352b357a4 --- /dev/null +++ b/idea/testData/smartSelection/superExpression.kt @@ -0,0 +1,11 @@ +open class EE() { + open fun f() = 43 +} + +class FF() : EE() { + override fun f() = super.f() - 1 +} +/* +super.f() +super.f() - 1 +*/ \ No newline at end of file diff --git a/idea/testData/smartSelection/superExpressionWithLabel.kt b/idea/testData/smartSelection/superExpressionWithLabel.kt new file mode 100644 index 00000000000..001f62ad13a --- /dev/null +++ b/idea/testData/smartSelection/superExpressionWithLabel.kt @@ -0,0 +1,11 @@ +open class EE() { + open fun f() = 43 +} + +class FF() : EE() { + override fun f() = super@FF.f() - 1 +} +/* +super@FF.f() +super@FF.f() - 1 +*/ \ No newline at end of file diff --git a/idea/testData/smartSelection/superExpressionWithLabelAndType.kt b/idea/testData/smartSelection/superExpressionWithLabelAndType.kt new file mode 100644 index 00000000000..1c2cdd5d6d3 --- /dev/null +++ b/idea/testData/smartSelection/superExpressionWithLabelAndType.kt @@ -0,0 +1,11 @@ +open class EE() { + open fun f() = 43 +} + +class FF() : EE() { + override fun f() = super@FF.f() - 1 +} +/* +super@FF.f() +super@FF.f() - 1 +*/ \ No newline at end of file diff --git a/idea/testData/smartSelection/superExpressionWithType.kt b/idea/testData/smartSelection/superExpressionWithType.kt new file mode 100644 index 00000000000..6d9d0f5c673 --- /dev/null +++ b/idea/testData/smartSelection/superExpressionWithType.kt @@ -0,0 +1,11 @@ +open class EE() { + open fun f() = 43 +} + +class FF() : EE() { + override fun f() = super.f() - 1 +} +/* +super.f() +super.f() - 1 +*/ \ No newline at end of file diff --git a/idea/testData/smartSelection/typeInSuperExpression.kt b/idea/testData/smartSelection/typeInSuperExpression.kt new file mode 100644 index 00000000000..930776512ea --- /dev/null +++ b/idea/testData/smartSelection/typeInSuperExpression.kt @@ -0,0 +1,11 @@ +open class EE() { + open fun f() = 43 +} + +class FF() : EE() { + override fun f() = super<EE>.f() - 1 +} +/* +super.f() +super.f() - 1 +*/ \ No newline at end of file diff --git a/idea/testData/smartSelection/typeInSuperExpressionWithLabel.kt b/idea/testData/smartSelection/typeInSuperExpressionWithLabel.kt new file mode 100644 index 00000000000..c2312289778 --- /dev/null +++ b/idea/testData/smartSelection/typeInSuperExpressionWithLabel.kt @@ -0,0 +1,11 @@ +open class EE() { + open fun f() = 43 +} + +class FF() : EE() { + override fun f() = super<EE>@FF.f() - 1 +} +/* +super@FF.f() +super@FF.f() - 1 +*/ \ No newline at end of file diff --git a/idea/tests/org/jetbrains/jet/plugin/SmartSelectionTestGenerated.java b/idea/tests/org/jetbrains/jet/plugin/SmartSelectionTestGenerated.java index b09014eed0d..f94ff7d0b52 100644 --- a/idea/tests/org/jetbrains/jet/plugin/SmartSelectionTestGenerated.java +++ b/idea/tests/org/jetbrains/jet/plugin/SmartSelectionTestGenerated.java @@ -51,4 +51,34 @@ public class SmartSelectionTestGenerated extends AbstractSmartSelectionTest { doTestSmartSelection("idea/testData/smartSelection/simple.kt"); } + @TestMetadata("superExpression.kt") + public void testSuperExpression() throws Exception { + doTestSmartSelection("idea/testData/smartSelection/superExpression.kt"); + } + + @TestMetadata("superExpressionWithLabel.kt") + public void testSuperExpressionWithLabel() throws Exception { + doTestSmartSelection("idea/testData/smartSelection/superExpressionWithLabel.kt"); + } + + @TestMetadata("superExpressionWithLabelAndType.kt") + public void testSuperExpressionWithLabelAndType() throws Exception { + doTestSmartSelection("idea/testData/smartSelection/superExpressionWithLabelAndType.kt"); + } + + @TestMetadata("superExpressionWithType.kt") + public void testSuperExpressionWithType() throws Exception { + doTestSmartSelection("idea/testData/smartSelection/superExpressionWithType.kt"); + } + + @TestMetadata("typeInSuperExpression.kt") + public void testTypeInSuperExpression() throws Exception { + doTestSmartSelection("idea/testData/smartSelection/typeInSuperExpression.kt"); + } + + @TestMetadata("typeInSuperExpressionWithLabel.kt") + public void testTypeInSuperExpressionWithLabel() throws Exception { + doTestSmartSelection("idea/testData/smartSelection/typeInSuperExpressionWithLabel.kt"); + } + }