mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-15 02:59:33 +07:00
[kotlin] KTIJ-32187, KTIJ-32178 trailing lambda template fully disabled
IJ-CR-149484 (cherry picked from commit 1622f0a0bf63651c86cb9892d9e453dc35ecf07f) GitOrigin-RevId: 9e5c6f21979a4b28b1d42b42452ebfb8e12bd6b9
This commit is contained in:
committed by
intellij-monorepo-bot
parent
088be2557f
commit
11136008d1
@@ -1,7 +1,6 @@
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package org.jetbrains.kotlin.idea.completion.implCommon.stringTemplates
|
||||
|
||||
import com.intellij.codeInsight.daemon.impl.quickfix.EmptyExpression
|
||||
import com.intellij.codeInsight.lookup.LookupElement
|
||||
import com.intellij.codeInsight.lookup.LookupElementBuilder
|
||||
import com.intellij.codeInsight.template.Expression
|
||||
@@ -14,11 +13,7 @@ import org.jetbrains.kotlin.analysis.api.renderer.base.annotations.KaRendererAnn
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.types.KaTypeRenderer
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.types.impl.KaTypeRendererForSource
|
||||
import org.jetbrains.kotlin.analysis.api.types.KaFunctionType
|
||||
import org.jetbrains.kotlin.analysis.api.types.KaType
|
||||
import org.jetbrains.kotlin.idea.base.codeInsight.KotlinNameSuggester
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.renderer.render
|
||||
|
||||
@KaExperimentalApi
|
||||
private val NoAnnotationsTypeRenderer: KaTypeRenderer = KaTypeRendererForSource.WITH_QUALIFIED_NAMES.with {
|
||||
@@ -36,44 +31,45 @@ fun Template.build(
|
||||
isToShortenLongNames = true
|
||||
// isToReformat = true //TODO
|
||||
|
||||
for (index in 0 until parametersCount) {
|
||||
if (index == 0) {
|
||||
addTextSegment("(")
|
||||
}
|
||||
|
||||
addVariable(
|
||||
/* expression = */ EmptyExpression(),
|
||||
/* isAlwaysStopAt = */ true,
|
||||
)
|
||||
|
||||
addTextSegment(if (index == parametersCount - 1) ")" else ", ")
|
||||
}
|
||||
|
||||
val typeNames = mutableMapOf<KaType, MutableSet<String>>()
|
||||
val kotlinNameSuggester = KotlinNameSuggester()
|
||||
//for (index in 0 until parametersCount) {
|
||||
// if (index == 0) {
|
||||
// addTextSegment("(")
|
||||
// }
|
||||
//
|
||||
// addVariable(
|
||||
// /* expression = */ EmptyExpression(),
|
||||
// /* isAlwaysStopAt = */ true,
|
||||
// )
|
||||
//
|
||||
// addTextSegment(if (index == parametersCount - 1) ")" else ", ")
|
||||
//}
|
||||
//
|
||||
//val typeNames = mutableMapOf<KaType, MutableSet<String>>()
|
||||
//val kotlinNameSuggester = KotlinNameSuggester()
|
||||
|
||||
addTextSegment(" { ")
|
||||
val parameterTypes = trailingFunctionType.parameterTypes
|
||||
.zip(suggestedParameterNames)
|
||||
val iterator = parameterTypes.iterator()
|
||||
while (iterator.hasNext()) {
|
||||
val (parameterType, suggestedName) = iterator.next()
|
||||
|
||||
//TODO: check for names in scope
|
||||
val validator = typeNames.getOrPut(parameterType) {
|
||||
mutableSetOf()
|
||||
}::add
|
||||
|
||||
val items = (suggestedName?.let { sequenceOf(it.render()) }
|
||||
?: kotlinNameSuggester.suggestTypeNames(parameterType))
|
||||
.map { KotlinNameSuggester.suggestNameByName(it, validator) }
|
||||
.toList()
|
||||
|
||||
addVariable(
|
||||
/* expression = */ LambdaParameterExpression(items),
|
||||
/* isAlwaysStopAt = */ true,
|
||||
)
|
||||
|
||||
//val parameterTypes = trailingFunctionType.parameterTypes
|
||||
// .zip(suggestedParameterNames)
|
||||
//val iterator = parameterTypes.iterator()
|
||||
//while (iterator.hasNext()) {
|
||||
// val (parameterType, suggestedName) = iterator.next()
|
||||
//
|
||||
// //TODO: check for names in scope
|
||||
// val validator = typeNames.getOrPut(parameterType) {
|
||||
// mutableSetOf()
|
||||
// }::add
|
||||
//
|
||||
// val items = (suggestedName?.let { sequenceOf(it.render()) }
|
||||
// ?: kotlinNameSuggester.suggestTypeNames(parameterType))
|
||||
// .map { KotlinNameSuggester.suggestNameByName(it, validator) }
|
||||
// .toList()
|
||||
//
|
||||
// addVariable(
|
||||
// /* expression = */ LambdaParameterExpression(items),
|
||||
// /* isAlwaysStopAt = */ true,
|
||||
// )
|
||||
//
|
||||
// parameterType.render(
|
||||
// renderer = NoAnnotationsTypeRenderer,
|
||||
// position = Variance.INVARIANT,
|
||||
@@ -82,18 +78,18 @@ fun Template.build(
|
||||
// addTextSegment(" ")
|
||||
// addTextSegment(typeText)
|
||||
// }
|
||||
|
||||
if (iterator.hasNext()) {
|
||||
addTextSegment(KtTokens.COMMA.value)
|
||||
addTextSegment(" ")
|
||||
}
|
||||
}
|
||||
|
||||
if (parameterTypes.isNotEmpty()) {
|
||||
addTextSegment(" ")
|
||||
addTextSegment(KtTokens.ARROW.value)
|
||||
addTextSegment(" ")
|
||||
}
|
||||
//
|
||||
// if (iterator.hasNext()) {
|
||||
// addTextSegment(KtTokens.COMMA.value)
|
||||
// addTextSegment(" ")
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//if (parameterTypes.isNotEmpty()) {
|
||||
// addTextSegment(" ")
|
||||
// addTextSegment(KtTokens.ARROW.value)
|
||||
// addTextSegment(" ")
|
||||
//}
|
||||
addEndVariable()
|
||||
addTextSegment(" }")
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ fun <T, C : Cn<T>> C.some(arg: (type: T) -> Unit): C {
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val x = Cn<String>()
|
||||
x.some { type -> <caret> }
|
||||
x.some { <caret> }
|
||||
}
|
||||
|
||||
//ELEMENT: some
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
fun <T> Array<T>.filter(predicate: (element: T) -> Boolean): java.util.List<T> = throw UnsupportedOperationException()
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
args.filter { element -> <caret> }
|
||||
args.filter { <caret> }
|
||||
}
|
||||
|
||||
// ELEMENT: filter
|
||||
|
||||
@@ -3,7 +3,7 @@ fun foo(f: (Int, Int, Int) -> Unit) {
|
||||
}
|
||||
|
||||
fun main() {
|
||||
foo { i, i1, i2 -> <caret> }
|
||||
foo { <caret> }
|
||||
}
|
||||
|
||||
// ELEMENT: foo
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
fun <T1, T2> T1.foo(handler: (T2) -> Boolean) {}
|
||||
|
||||
fun f() {
|
||||
"".foo { value -> <caret> }
|
||||
"".foo { <caret> }
|
||||
}
|
||||
|
||||
// ELEMENT: foo
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// FIR_COMPARISON
|
||||
fun f(list: List<String>) {
|
||||
list.map { string -> <caret> }
|
||||
list.map { <caret> }
|
||||
}
|
||||
|
||||
// ELEMENT: map
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
fun <T1, T2> T1.foo(handler: suspend (T2) -> Boolean) {}
|
||||
|
||||
fun f() {
|
||||
"".foo { value -> <caret> }
|
||||
"".foo { <caret> }
|
||||
}
|
||||
|
||||
// ELEMENT: foo
|
||||
|
||||
@@ -7,7 +7,7 @@ fun <T, R, C : MutableCollection<in R>> Iterable<T>.mapTo(destination: C, transf
|
||||
|
||||
fun main() {
|
||||
val strings = listOf("abc", "def")
|
||||
strings.mapTo(mutableSetOf(), { it.length }).map { i -> <caret> }
|
||||
strings.mapTo(mutableSetOf(), { it.length }).map { <caret> }
|
||||
}
|
||||
// ELEMENT: map
|
||||
// TAIL_TEXT: " { transform: (Int) -> R } for Iterable<T> in kotlin.collections"
|
||||
Reference in New Issue
Block a user