Do not suggest operation references in postfix templates
#KT-14087 Fixed
This commit is contained in:
@@ -24,6 +24,7 @@ import com.intellij.openapi.util.Condition
|
|||||||
import com.intellij.psi.PsiElement
|
import com.intellij.psi.PsiElement
|
||||||
import com.intellij.psi.PsiFile
|
import com.intellij.psi.PsiFile
|
||||||
import org.jetbrains.annotations.TestOnly
|
import org.jetbrains.annotations.TestOnly
|
||||||
|
import org.jetbrains.kotlin.KtNodeTypes
|
||||||
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
||||||
import org.jetbrains.kotlin.idea.intentions.negate
|
import org.jetbrains.kotlin.idea.intentions.negate
|
||||||
import org.jetbrains.kotlin.idea.refactoring.introduce.introduceVariable.KotlinIntroduceVariableHandler
|
import org.jetbrains.kotlin.idea.refactoring.introduce.introduceVariable.KotlinIntroduceVariableHandler
|
||||||
@@ -139,10 +140,13 @@ private class KtExpressionPostfixTemplateSelector(
|
|||||||
it !is KtBlockExpression &&
|
it !is KtBlockExpression &&
|
||||||
it !is KtDeclarationWithBody &&
|
it !is KtDeclarationWithBody &&
|
||||||
!it.isEffectivelyDeclaration()
|
!it.isEffectivelyDeclaration()
|
||||||
}.filter { !it.isSelector && it.parent !is KtUserType }
|
}.filter { !it.isSelector && it.parent !is KtUserType && !it.isOperationReference }
|
||||||
.toList()
|
.toList()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private val KtExpression.isOperationReference: Boolean
|
||||||
|
get() = this.node.elementType == KtNodeTypes.OPERATION_REFERENCE
|
||||||
|
|
||||||
private fun KtElement.isEffectivelyDeclaration() =
|
private fun KtElement.isEffectivelyDeclaration() =
|
||||||
this is KtNamedDeclaration &&
|
this is KtNamedDeclaration &&
|
||||||
// function literal is an expression while it's also a subtype of 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++)
|
||||||
|
}
|
||||||
+6
@@ -41,6 +41,12 @@ public class PostfixTemplateProviderTestGenerated extends AbstractPostfixTemplat
|
|||||||
doTest(fileName);
|
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")
|
@TestMetadata("else.kt")
|
||||||
public void testElse() throws Exception {
|
public void testElse() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/codeInsight/postfix/else.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/codeInsight/postfix/else.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user