Extract refactoring: Make an extracted function 'inline' if any of its type parameters are reified (#KT-23983)
This commit is contained in:
+18
-2
@@ -71,7 +71,12 @@ private fun buildSignature(config: ExtractionGeneratorConfiguration, renderer: D
|
|||||||
}
|
}
|
||||||
return CallableBuilder(builderTarget).apply {
|
return CallableBuilder(builderTarget).apply {
|
||||||
val visibility = config.descriptor.visibility?.value ?: ""
|
val visibility = config.descriptor.visibility?.value ?: ""
|
||||||
val extraModifiers = config.descriptor.modifiers.map { it.value }
|
|
||||||
|
fun TypeParameter.isReified() = originalDeclaration.hasModifier(KtTokens.REIFIED_KEYWORD)
|
||||||
|
val shouldBeInline = config.descriptor.typeParameters.any { it.isReified() }
|
||||||
|
|
||||||
|
val extraModifiers = config.descriptor.modifiers.map { it.value } +
|
||||||
|
listOfNotNull(if (shouldBeInline) KtTokens.INLINE_KEYWORD.value else null)
|
||||||
val modifiers = if (visibility.isNotEmpty()) listOf(visibility) + extraModifiers else extraModifiers
|
val modifiers = if (visibility.isNotEmpty()) listOf(visibility) + extraModifiers else extraModifiers
|
||||||
modifier(modifiers.joinToString(separator = " "))
|
modifier(modifiers.joinToString(separator = " "))
|
||||||
|
|
||||||
@@ -79,7 +84,18 @@ private fun buildSignature(config: ExtractionGeneratorConfiguration, renderer: D
|
|||||||
config.descriptor.typeParameters.map {
|
config.descriptor.typeParameters.map {
|
||||||
val typeParameter = it.originalDeclaration
|
val typeParameter = it.originalDeclaration
|
||||||
val bound = typeParameter.extendsBound
|
val bound = typeParameter.extendsBound
|
||||||
typeParameter.name + (bound?.let { " : " + it.text } ?: "")
|
|
||||||
|
buildString {
|
||||||
|
if (it.isReified()) {
|
||||||
|
append(KtTokens.REIFIED_KEYWORD.value)
|
||||||
|
append(' ')
|
||||||
|
}
|
||||||
|
append(typeParameter.name)
|
||||||
|
if (bound != null) {
|
||||||
|
append(" : ")
|
||||||
|
append(bound.text)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
inline fun <reified T> foo() {
|
||||||
|
<selection>T::class</selection>
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
inline fun <reified T> foo() {
|
||||||
|
__dummyTestFun__<T>()
|
||||||
|
}
|
||||||
|
|
||||||
|
inline fun <reified T> __dummyTestFun__() {
|
||||||
|
T::class
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
inline fun <reified T : CharSequence, reified U, X> foo() {
|
||||||
|
<selection>listOf(T::class, U::class)</selection>
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
inline fun <reified T : CharSequence, reified U, X> foo() {
|
||||||
|
__dummyTestFun__<T, U>()
|
||||||
|
}
|
||||||
|
|
||||||
|
inline fun <reified T : CharSequence, reified U> __dummyTestFun__() {
|
||||||
|
listOf(T::class, U::class)
|
||||||
|
}
|
||||||
+10
@@ -861,6 +861,16 @@ public class ExtractionTestGenerated extends AbstractExtractionTest {
|
|||||||
runTest("idea/testData/refactoring/extractFunction/basic/identityEquals.kt");
|
runTest("idea/testData/refactoring/extractFunction/basic/identityEquals.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("inlineReified.kt")
|
||||||
|
public void testInlineReified() throws Exception {
|
||||||
|
runTest("idea/testData/refactoring/extractFunction/basic/inlineReified.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("inlineReified2.kt")
|
||||||
|
public void testInlineReified2() throws Exception {
|
||||||
|
runTest("idea/testData/refactoring/extractFunction/basic/inlineReified2.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("invisibleType.kt")
|
@TestMetadata("invisibleType.kt")
|
||||||
public void testInvisibleType() throws Exception {
|
public void testInvisibleType() throws Exception {
|
||||||
runTest("idea/testData/refactoring/extractFunction/basic/invisibleType.kt");
|
runTest("idea/testData/refactoring/extractFunction/basic/invisibleType.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user