"Convert lambda to anonymous function": Don't suggest in inline function
So #KT-24792 Fixed
This commit is contained in:
committed by
Mikhail Glukhikh
parent
fa58da85ee
commit
3292137acb
@@ -15,6 +15,7 @@ import org.jetbrains.kotlin.idea.core.replaced
|
||||
import org.jetbrains.kotlin.idea.intentions.branchedTransformations.BranchedFoldingUtils
|
||||
import org.jetbrains.kotlin.idea.search.usagesSearch.descriptor
|
||||
import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.collectDescendantsOfType
|
||||
import org.jetbrains.kotlin.psi.psiUtil.endOffset
|
||||
@@ -32,6 +33,7 @@ class LambdaToAnonymousFunctionIntention : SelfTargetingIntention<KtLambdaExpres
|
||||
|
||||
override fun isApplicableTo(element: KtLambdaExpression, caretOffset: Int): Boolean {
|
||||
if (element.getStrictParentOfType<KtValueArgument>() == null) return false
|
||||
if (element.getStrictParentOfType<KtFunction>()?.hasModifier(KtTokens.INLINE_KEYWORD) == true) return false
|
||||
val descriptor = element.functionLiteral.descriptor as? AnonymousFunctionDescriptor ?: return false
|
||||
if (descriptor.valueParameters.any { it.name.isSpecial }) return false
|
||||
val lastElement = element.functionLiteral.arrow ?: element.functionLiteral.lBrace
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
// IS_APPLICABLE: false
|
||||
|
||||
inline fun test() {
|
||||
foo <caret>{ "" }
|
||||
}
|
||||
|
||||
fun foo(f: (Int) -> String) {}
|
||||
@@ -9767,6 +9767,11 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
|
||||
runTest("idea/testData/intentions/lambdaToAnonymousFunction/implicitParameterName.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("inInlineFunction.kt")
|
||||
public void testInInlineFunction() throws Exception {
|
||||
runTest("idea/testData/intentions/lambdaToAnonymousFunction/inInlineFunction.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("incorrectOffset.kt")
|
||||
public void testIncorrectOffset() throws Exception {
|
||||
runTest("idea/testData/intentions/lambdaToAnonymousFunction/incorrectOffset.kt");
|
||||
|
||||
Reference in New Issue
Block a user