From 5351f606b81ffefd0e7031b2655dd6fb97583ab3 Mon Sep 17 00:00:00 2001 From: Michael Rittmeister Date: Sat, 16 Sep 2023 19:10:20 +0200 Subject: [PATCH] No longer mark lambdas as NoInline if the underlying function is marked as inline --- .../AnnotationSpecBuildersReified.kt | 6 +- .../AnnotationSpecFactoriesReified.kt | 4 +- .../kotlinpoet/FileSpecFactoriesReified.kt | 2 +- .../ParameterSpecBuildersReified.kt | 4 +- .../ParameterSpecFactoriesReified.kt | 4 +- .../kotlinpoet/PropertySpecBuildersReified.kt | 8 +-- .../PropertySpecFactoriesReified.kt | 4 +- .../TypeAliasSpecFactoriesReified.kt | 4 +- .../kotlinpoet/TypeSpecBuildersReified.kt | 56 +++++++++---------- .../kotlinpoet/TypeSpecFactoriesReified.kt | 14 ++--- .../src/main/kotlin/reification/Reifyer.kt | 4 +- .../src/main/kotlin/utils/KSPUtils.kt | 5 +- 12 files changed, 59 insertions(+), 56 deletions(-) diff --git a/kotlinpoet/build/generated/ksp/generationSource/generationSourceMain/kotlin/dev/kord/codegen/kotlinpoet/AnnotationSpecBuildersReified.kt b/kotlinpoet/build/generated/ksp/generationSource/generationSourceMain/kotlin/dev/kord/codegen/kotlinpoet/AnnotationSpecBuildersReified.kt index aaa84fc..c828eb1 100644 --- a/kotlinpoet/build/generated/ksp/generationSource/generationSourceMain/kotlin/dev/kord/codegen/kotlinpoet/AnnotationSpecBuildersReified.kt +++ b/kotlinpoet/build/generated/ksp/generationSource/generationSourceMain/kotlin/dev/kord/codegen/kotlinpoet/AnnotationSpecBuildersReified.kt @@ -5,6 +5,6 @@ import com.squareup.kotlinpoet.AnnotationSpec import com.squareup.kotlinpoet.asClassName import kotlin.Annotation -public inline fun Annotatable.Builder<*>.addAnnotation(noinline - block: AnnotationSpecBuilderScope = {}): AnnotationSpec = addAnnotation(T::class.asClassName(), - block) +public inline fun + Annotatable.Builder<*>.addAnnotation(block: AnnotationSpecBuilderScope = {}): AnnotationSpec = + addAnnotation(T::class.asClassName(), block) diff --git a/kotlinpoet/build/generated/ksp/generationSource/generationSourceMain/kotlin/dev/kord/codegen/kotlinpoet/AnnotationSpecFactoriesReified.kt b/kotlinpoet/build/generated/ksp/generationSource/generationSourceMain/kotlin/dev/kord/codegen/kotlinpoet/AnnotationSpecFactoriesReified.kt index 74c129d..b71957f 100644 --- a/kotlinpoet/build/generated/ksp/generationSource/generationSourceMain/kotlin/dev/kord/codegen/kotlinpoet/AnnotationSpecFactoriesReified.kt +++ b/kotlinpoet/build/generated/ksp/generationSource/generationSourceMain/kotlin/dev/kord/codegen/kotlinpoet/AnnotationSpecFactoriesReified.kt @@ -4,5 +4,5 @@ import com.squareup.kotlinpoet.AnnotationSpec import com.squareup.kotlinpoet.asClassName import kotlin.Annotation -public inline fun AnnotationSpec(noinline block: AnnotationSpecBuilderScope - = {}): AnnotationSpec = AnnotationSpec(T::class.asClassName(), block) +public inline fun AnnotationSpec(block: AnnotationSpecBuilderScope = {}): + AnnotationSpec = AnnotationSpec(T::class.asClassName(), block) diff --git a/kotlinpoet/build/generated/ksp/generationSource/generationSourceMain/kotlin/dev/kord/codegen/kotlinpoet/FileSpecFactoriesReified.kt b/kotlinpoet/build/generated/ksp/generationSource/generationSourceMain/kotlin/dev/kord/codegen/kotlinpoet/FileSpecFactoriesReified.kt index 92f2225..5553b78 100644 --- a/kotlinpoet/build/generated/ksp/generationSource/generationSourceMain/kotlin/dev/kord/codegen/kotlinpoet/FileSpecFactoriesReified.kt +++ b/kotlinpoet/build/generated/ksp/generationSource/generationSourceMain/kotlin/dev/kord/codegen/kotlinpoet/FileSpecFactoriesReified.kt @@ -3,5 +3,5 @@ package dev.kord.codegen.kotlinpoet import com.squareup.kotlinpoet.FileSpec import com.squareup.kotlinpoet.asClassName -public inline fun FileSpec(noinline block: FileSpecBuilderScope = {}): FileSpec = +public inline fun FileSpec(block: FileSpecBuilderScope = {}): FileSpec = FileSpec(C::class.asClassName(), block) diff --git a/kotlinpoet/build/generated/ksp/generationSource/generationSourceMain/kotlin/dev/kord/codegen/kotlinpoet/ParameterSpecBuildersReified.kt b/kotlinpoet/build/generated/ksp/generationSource/generationSourceMain/kotlin/dev/kord/codegen/kotlinpoet/ParameterSpecBuildersReified.kt index bd8f3f8..3d1d560 100644 --- a/kotlinpoet/build/generated/ksp/generationSource/generationSourceMain/kotlin/dev/kord/codegen/kotlinpoet/ParameterSpecBuildersReified.kt +++ b/kotlinpoet/build/generated/ksp/generationSource/generationSourceMain/kotlin/dev/kord/codegen/kotlinpoet/ParameterSpecBuildersReified.kt @@ -11,7 +11,7 @@ import kotlin.collections.Iterable public inline fun FunSpec.Builder.addParameter( name: String, vararg modifiers: KModifier, - noinline block: ParameterSpecBuilderScope = {}, + block: ParameterSpecBuilderScope = {}, ): ParameterSpec = addParameter(name, typeNameOf(), modifiers = modifiers, block) public inline fun FunSpec.Builder.addParameter(vararg modifiers: KModifier, noinline @@ -21,7 +21,7 @@ public inline fun FunSpec.Builder.addParameter(vararg modifiers: KMo public inline fun FunSpec.Builder.addParameter( name: String, modifiers: Iterable, - noinline block: ParameterSpecBuilderScope = {}, + block: ParameterSpecBuilderScope = {}, ): ParameterSpec = addParameter(name, typeNameOf(), modifiers, block) public inline fun FunSpec.Builder.addParameter(modifiers: Iterable, noinline diff --git a/kotlinpoet/build/generated/ksp/generationSource/generationSourceMain/kotlin/dev/kord/codegen/kotlinpoet/ParameterSpecFactoriesReified.kt b/kotlinpoet/build/generated/ksp/generationSource/generationSourceMain/kotlin/dev/kord/codegen/kotlinpoet/ParameterSpecFactoriesReified.kt index 5ed1927..0e10060 100644 --- a/kotlinpoet/build/generated/ksp/generationSource/generationSourceMain/kotlin/dev/kord/codegen/kotlinpoet/ParameterSpecFactoriesReified.kt +++ b/kotlinpoet/build/generated/ksp/generationSource/generationSourceMain/kotlin/dev/kord/codegen/kotlinpoet/ParameterSpecFactoriesReified.kt @@ -9,11 +9,11 @@ import kotlin.collections.Iterable public inline fun ParameterSpec( name: String, vararg modifiers: KModifier, - noinline block: ParameterSpecBuilderScope = {}, + block: ParameterSpecBuilderScope = {}, ): ParameterSpec = ParameterSpec(name, typeNameOf(), modifiers = modifiers, block) public inline fun ParameterSpec( name: String, modifiers: Iterable, - noinline block: ParameterSpecBuilderScope = {}, + block: ParameterSpecBuilderScope = {}, ): ParameterSpec = ParameterSpec(name, typeNameOf(), modifiers, block) diff --git a/kotlinpoet/build/generated/ksp/generationSource/generationSourceMain/kotlin/dev/kord/codegen/kotlinpoet/PropertySpecBuildersReified.kt b/kotlinpoet/build/generated/ksp/generationSource/generationSourceMain/kotlin/dev/kord/codegen/kotlinpoet/PropertySpecBuildersReified.kt index b022527..1e30960 100644 --- a/kotlinpoet/build/generated/ksp/generationSource/generationSourceMain/kotlin/dev/kord/codegen/kotlinpoet/PropertySpecBuildersReified.kt +++ b/kotlinpoet/build/generated/ksp/generationSource/generationSourceMain/kotlin/dev/kord/codegen/kotlinpoet/PropertySpecBuildersReified.kt @@ -12,7 +12,7 @@ import kotlin.collections.Iterable public inline fun TypeSpec.Builder.addProperty( name: String, vararg modifiers: KModifier, - noinline block: PropertySpecBuilderScope = {}, + block: PropertySpecBuilderScope = {}, ): PropertySpec = addProperty(name, typeNameOf(), modifiers = modifiers, block) public inline fun TypeSpec.Builder.addProperty(vararg modifiers: KModifier, noinline @@ -22,7 +22,7 @@ public inline fun TypeSpec.Builder.addProperty(vararg modifiers: KMo public inline fun TypeSpec.Builder.addProperty( name: String, modifiers: Iterable, - noinline block: PropertySpecBuilderScope = {}, + block: PropertySpecBuilderScope = {}, ): PropertySpec = addProperty(name, typeNameOf(), modifiers, block) public inline fun TypeSpec.Builder.addProperty(modifiers: Iterable, noinline @@ -32,7 +32,7 @@ public inline fun TypeSpec.Builder.addProperty(modifiers: Iterable FileSpec.Builder.addProperty( name: String, vararg modifiers: KModifier, - noinline block: PropertySpecBuilderScope = {}, + block: PropertySpecBuilderScope = {}, ): PropertySpec = addProperty(name, typeNameOf(), modifiers = modifiers, block) public inline fun FileSpec.Builder.addProperty(vararg modifiers: KModifier, noinline @@ -42,7 +42,7 @@ public inline fun FileSpec.Builder.addProperty(vararg modifiers: KMo public inline fun FileSpec.Builder.addProperty( name: String, modifiers: Iterable, - noinline block: PropertySpecBuilderScope = {}, + block: PropertySpecBuilderScope = {}, ): PropertySpec = addProperty(name, typeNameOf(), modifiers, block) public inline fun FileSpec.Builder.addProperty(modifiers: Iterable, noinline diff --git a/kotlinpoet/build/generated/ksp/generationSource/generationSourceMain/kotlin/dev/kord/codegen/kotlinpoet/PropertySpecFactoriesReified.kt b/kotlinpoet/build/generated/ksp/generationSource/generationSourceMain/kotlin/dev/kord/codegen/kotlinpoet/PropertySpecFactoriesReified.kt index f24b852..a9bbb15 100644 --- a/kotlinpoet/build/generated/ksp/generationSource/generationSourceMain/kotlin/dev/kord/codegen/kotlinpoet/PropertySpecFactoriesReified.kt +++ b/kotlinpoet/build/generated/ksp/generationSource/generationSourceMain/kotlin/dev/kord/codegen/kotlinpoet/PropertySpecFactoriesReified.kt @@ -9,11 +9,11 @@ import kotlin.collections.Iterable public inline fun PropertySpec( name: String, vararg modifiers: KModifier, - noinline block: PropertySpecBuilderScope = {}, + block: PropertySpecBuilderScope = {}, ): PropertySpec = PropertySpec(name, typeNameOf(), modifiers = modifiers, block) public inline fun PropertySpec( name: String, modifiers: Iterable, - noinline block: PropertySpecBuilderScope = {}, + block: PropertySpecBuilderScope = {}, ): PropertySpec = PropertySpec(name, typeNameOf(), modifiers, block) diff --git a/kotlinpoet/build/generated/ksp/generationSource/generationSourceMain/kotlin/dev/kord/codegen/kotlinpoet/TypeAliasSpecFactoriesReified.kt b/kotlinpoet/build/generated/ksp/generationSource/generationSourceMain/kotlin/dev/kord/codegen/kotlinpoet/TypeAliasSpecFactoriesReified.kt index 331d51f..ed700b7 100644 --- a/kotlinpoet/build/generated/ksp/generationSource/generationSourceMain/kotlin/dev/kord/codegen/kotlinpoet/TypeAliasSpecFactoriesReified.kt +++ b/kotlinpoet/build/generated/ksp/generationSource/generationSourceMain/kotlin/dev/kord/codegen/kotlinpoet/TypeAliasSpecFactoriesReified.kt @@ -4,5 +4,5 @@ import com.squareup.kotlinpoet.TypeAliasSpec import com.squareup.kotlinpoet.typeNameOf import kotlin.String -public inline fun TypeAliasSpec(name: String, noinline block: TypeAliasSpecBuilderScope - = {}): TypeAliasSpec = TypeAliasSpec(name, typeNameOf(), block) +public inline fun TypeAliasSpec(name: String, block: TypeAliasSpecBuilderScope = {}): + TypeAliasSpec = TypeAliasSpec(name, typeNameOf(), block) diff --git a/kotlinpoet/build/generated/ksp/generationSource/generationSourceMain/kotlin/dev/kord/codegen/kotlinpoet/TypeSpecBuildersReified.kt b/kotlinpoet/build/generated/ksp/generationSource/generationSourceMain/kotlin/dev/kord/codegen/kotlinpoet/TypeSpecBuildersReified.kt index d78635d..7437250 100644 --- a/kotlinpoet/build/generated/ksp/generationSource/generationSourceMain/kotlin/dev/kord/codegen/kotlinpoet/TypeSpecBuildersReified.kt +++ b/kotlinpoet/build/generated/ksp/generationSource/generationSourceMain/kotlin/dev/kord/codegen/kotlinpoet/TypeSpecBuildersReified.kt @@ -4,44 +4,44 @@ import com.squareup.kotlinpoet.FileSpec import com.squareup.kotlinpoet.TypeSpec import com.squareup.kotlinpoet.asClassName -public inline fun TypeSpec.Builder.addClass(noinline block: TypeSpecBuilderScope = {}): - TypeSpec = addClass(C::class.asClassName(), block) +public inline fun TypeSpec.Builder.addClass(block: TypeSpecBuilderScope = {}): TypeSpec + = addClass(C::class.asClassName(), block) -public inline fun FileSpec.Builder.addClass(noinline block: TypeSpecBuilderScope = {}): - TypeSpec = addClass(C::class.asClassName(), block) +public inline fun FileSpec.Builder.addClass(block: TypeSpecBuilderScope = {}): TypeSpec + = addClass(C::class.asClassName(), block) -public inline fun TypeSpec.Builder.addExpectClass(noinline block: TypeSpecBuilderScope = - {}): TypeSpec = addExpectClass(C::class.asClassName(), block) +public inline fun TypeSpec.Builder.addExpectClass(block: TypeSpecBuilderScope = {}): + TypeSpec = addExpectClass(C::class.asClassName(), block) -public inline fun FileSpec.Builder.addExpectClass(noinline block: TypeSpecBuilderScope = - {}): TypeSpec = addExpectClass(C::class.asClassName(), block) +public inline fun FileSpec.Builder.addExpectClass(block: TypeSpecBuilderScope = {}): + TypeSpec = addExpectClass(C::class.asClassName(), block) -public inline fun TypeSpec.Builder.addObject(noinline block: TypeSpecBuilderScope = {}): - TypeSpec = addObject(C::class.asClassName(), block) +public inline fun TypeSpec.Builder.addObject(block: TypeSpecBuilderScope = {}): TypeSpec + = addObject(C::class.asClassName(), block) -public inline fun FileSpec.Builder.addObject(noinline block: TypeSpecBuilderScope = {}): - TypeSpec = addObject(C::class.asClassName(), block) +public inline fun FileSpec.Builder.addObject(block: TypeSpecBuilderScope = {}): TypeSpec + = addObject(C::class.asClassName(), block) -public inline fun TypeSpec.Builder.addInterface(noinline block: TypeSpecBuilderScope = - {}): TypeSpec = addInterface(C::class.asClassName(), block) +public inline fun TypeSpec.Builder.addInterface(block: TypeSpecBuilderScope = {}): + TypeSpec = addInterface(C::class.asClassName(), block) -public inline fun FileSpec.Builder.addInterface(noinline block: TypeSpecBuilderScope = - {}): TypeSpec = addInterface(C::class.asClassName(), block) +public inline fun FileSpec.Builder.addInterface(block: TypeSpecBuilderScope = {}): + TypeSpec = addInterface(C::class.asClassName(), block) -public inline fun TypeSpec.Builder.addFunInterface(noinline block: TypeSpecBuilderScope - = {}): TypeSpec = addFunInterface(C::class.asClassName(), block) +public inline fun TypeSpec.Builder.addFunInterface(block: TypeSpecBuilderScope = {}): + TypeSpec = addFunInterface(C::class.asClassName(), block) -public inline fun FileSpec.Builder.addFunInterface(noinline block: TypeSpecBuilderScope - = {}): TypeSpec = addFunInterface(C::class.asClassName(), block) +public inline fun FileSpec.Builder.addFunInterface(block: TypeSpecBuilderScope = {}): + TypeSpec = addFunInterface(C::class.asClassName(), block) -public inline fun TypeSpec.Builder.addEnum(noinline block: TypeSpecBuilderScope = {}): - TypeSpec = addEnum(C::class.asClassName(), block) +public inline fun TypeSpec.Builder.addEnum(block: TypeSpecBuilderScope = {}): TypeSpec = + addEnum(C::class.asClassName(), block) -public inline fun FileSpec.Builder.addEnum(noinline block: TypeSpecBuilderScope = {}): - TypeSpec = addEnum(C::class.asClassName(), block) +public inline fun FileSpec.Builder.addEnum(block: TypeSpecBuilderScope = {}): TypeSpec = + addEnum(C::class.asClassName(), block) -public inline fun TypeSpec.Builder.addAnnotationClass(noinline - block: TypeSpecBuilderScope = {}): TypeSpec = addAnnotationClass(C::class.asClassName(), block) +public inline fun TypeSpec.Builder.addAnnotationClass(block: TypeSpecBuilderScope = {}): + TypeSpec = addAnnotationClass(C::class.asClassName(), block) -public inline fun FileSpec.Builder.addAnnotationClass(noinline - block: TypeSpecBuilderScope = {}): TypeSpec = addAnnotationClass(C::class.asClassName(), block) +public inline fun FileSpec.Builder.addAnnotationClass(block: TypeSpecBuilderScope = {}): + TypeSpec = addAnnotationClass(C::class.asClassName(), block) diff --git a/kotlinpoet/build/generated/ksp/generationSource/generationSourceMain/kotlin/dev/kord/codegen/kotlinpoet/TypeSpecFactoriesReified.kt b/kotlinpoet/build/generated/ksp/generationSource/generationSourceMain/kotlin/dev/kord/codegen/kotlinpoet/TypeSpecFactoriesReified.kt index 47af076..17ec1eb 100644 --- a/kotlinpoet/build/generated/ksp/generationSource/generationSourceMain/kotlin/dev/kord/codegen/kotlinpoet/TypeSpecFactoriesReified.kt +++ b/kotlinpoet/build/generated/ksp/generationSource/generationSourceMain/kotlin/dev/kord/codegen/kotlinpoet/TypeSpecFactoriesReified.kt @@ -3,23 +3,23 @@ package dev.kord.codegen.kotlinpoet import com.squareup.kotlinpoet.TypeSpec import com.squareup.kotlinpoet.asClassName -public inline fun `class`(noinline block: TypeSpecBuilderScope = {}): TypeSpec = +public inline fun `class`(block: TypeSpecBuilderScope = {}): TypeSpec = `class`(C::class.asClassName(), block) -public inline fun expectClass(noinline block: TypeSpecBuilderScope = {}): TypeSpec = +public inline fun expectClass(block: TypeSpecBuilderScope = {}): TypeSpec = expectClass(C::class.asClassName(), block) -public inline fun `object`(noinline block: TypeSpecBuilderScope = {}): TypeSpec = +public inline fun `object`(block: TypeSpecBuilderScope = {}): TypeSpec = `object`(C::class.asClassName(), block) -public inline fun `interface`(noinline block: TypeSpecBuilderScope = {}): TypeSpec = +public inline fun `interface`(block: TypeSpecBuilderScope = {}): TypeSpec = `interface`(C::class.asClassName(), block) -public inline fun funInterface(noinline block: TypeSpecBuilderScope = {}): TypeSpec = +public inline fun funInterface(block: TypeSpecBuilderScope = {}): TypeSpec = funInterface(C::class.asClassName(), block) -public inline fun `enum`(noinline block: TypeSpecBuilderScope = {}): TypeSpec = +public inline fun `enum`(block: TypeSpecBuilderScope = {}): TypeSpec = `enum`(C::class.asClassName(), block) -public inline fun `annotation`(noinline block: TypeSpecBuilderScope = {}): TypeSpec = +public inline fun `annotation`(block: TypeSpecBuilderScope = {}): TypeSpec = `annotation`(C::class.asClassName(), block) diff --git a/kotlinpoet/processor/src/main/kotlin/reification/Reifyer.kt b/kotlinpoet/processor/src/main/kotlin/reification/Reifyer.kt index 3d58490..3a5d33e 100644 --- a/kotlinpoet/processor/src/main/kotlin/reification/Reifyer.kt +++ b/kotlinpoet/processor/src/main/kotlin/reification/Reifyer.kt @@ -9,6 +9,7 @@ import dev.kord.codegen.generator.utils.toParameterSpec import dev.kord.codegen.generator.utils.toTypeParameterResolver import dev.kord.codegen.kotlinpoet.CodeBlock import dev.kord.codegen.kotlinpoet.FunSpec +import com.google.devtools.ksp.symbol.Modifier import kotlin.reflect.KClass val AS_CLASS_NAME = MemberName("com.squareup.kotlinpoet", "asClassName") @@ -67,7 +68,8 @@ fun MaybeReifiableFunction.reify(): FunSpec { .map { it.toParameterSpec( typeVariableResolver, - simpleName.asString().endsWith("Builder") + simpleName.asString().endsWith("Builder"), + Modifier.INLINE !in this@reify.modifiers ) } .toList() diff --git a/kotlinpoet/processor/src/main/kotlin/utils/KSPUtils.kt b/kotlinpoet/processor/src/main/kotlin/utils/KSPUtils.kt index f481107..82750c5 100644 --- a/kotlinpoet/processor/src/main/kotlin/utils/KSPUtils.kt +++ b/kotlinpoet/processor/src/main/kotlin/utils/KSPUtils.kt @@ -8,11 +8,12 @@ import com.squareup.kotlinpoet.ksp.toTypeName fun KSValueParameter.toParameterSpec( typeParamResolver: TypeParameterResolver = TypeParameterResolver.EMPTY, - useParent: Boolean = false + useParent: Boolean = false, + noInline: Boolean = false ) = ParameterSpec.builder(name!!.asString(), type.toTypeName(typeParamResolver), modifiers) .apply { - if (name!!.asString() == "block") { + if (name!!.asString() == "block" && noInline) { addModifiers(KModifier.NOINLINE) } if (hasDefault) {