Do not suggest operation references in postfix templates

#KT-14087 Fixed
This commit is contained in:
Denis Zharkov
2016-09-28 18:06:34 +03:00
parent d5d18b2ad6
commit ce128c5d6e
4 changed files with 17 additions and 1 deletions
@@ -24,6 +24,7 @@ import com.intellij.openapi.util.Condition
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiFile
import org.jetbrains.annotations.TestOnly
import org.jetbrains.kotlin.KtNodeTypes
import org.jetbrains.kotlin.idea.caches.resolve.analyze
import org.jetbrains.kotlin.idea.intentions.negate
import org.jetbrains.kotlin.idea.refactoring.introduce.introduceVariable.KotlinIntroduceVariableHandler
@@ -139,10 +140,13 @@ private class KtExpressionPostfixTemplateSelector(
it !is KtBlockExpression &&
it !is KtDeclarationWithBody &&
!it.isEffectivelyDeclaration()
}.filter { !it.isSelector && it.parent !is KtUserType }
}.filter { !it.isSelector && it.parent !is KtUserType && !it.isOperationReference }
.toList()
}
private val KtExpression.isOperationReference: Boolean
get() = this.node.elementType == KtNodeTypes.OPERATION_REFERENCE
private fun KtElement.isEffectivelyDeclaration() =
this is KtNamedDeclaration &&
// function literal is an expression while it's also a subtype of KtNamedDeclaration
@@ -0,0 +1,3 @@
fun foo(x: Int) {
x++.par<caret>
}
@@ -0,0 +1,3 @@
fun foo(x: Int) {
(x++)
}
@@ -41,6 +41,12 @@ public class PostfixTemplateProviderTestGenerated extends AbstractPostfixTemplat
doTest(fileName);
}
@TestMetadata("doNotProposeWrappingIncrement.kt")
public void testDoNotProposeWrappingIncrement() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/codeInsight/postfix/doNotProposeWrappingIncrement.kt");
doTest(fileName);
}
@TestMetadata("else.kt")
public void testElse() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/codeInsight/postfix/else.kt");