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