Skip to content

Commit

Permalink
No longer mark lambdas as NoInline if the underlying function is mark…
Browse files Browse the repository at this point in the history
…ed as inline
  • Loading branch information
DRSchlaubi committed Sep 16, 2023
1 parent 3ba861f commit 5351f60
Show file tree
Hide file tree
Showing 12 changed files with 59 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ import com.squareup.kotlinpoet.AnnotationSpec
import com.squareup.kotlinpoet.asClassName
import kotlin.Annotation

public inline fun <reified T : Annotation> Annotatable.Builder<*>.addAnnotation(noinline
block: AnnotationSpecBuilderScope = {}): AnnotationSpec = addAnnotation(T::class.asClassName(),
block)
public inline fun <reified T : Annotation>
Annotatable.Builder<*>.addAnnotation(block: AnnotationSpecBuilderScope = {}): AnnotationSpec =
addAnnotation(T::class.asClassName(), block)
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ import com.squareup.kotlinpoet.AnnotationSpec
import com.squareup.kotlinpoet.asClassName
import kotlin.Annotation

public inline fun <reified T : Annotation> AnnotationSpec(noinline block: AnnotationSpecBuilderScope
= {}): AnnotationSpec = AnnotationSpec(T::class.asClassName(), block)
public inline fun <reified T : Annotation> AnnotationSpec(block: AnnotationSpecBuilderScope = {}):
AnnotationSpec = AnnotationSpec(T::class.asClassName(), block)
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ package dev.kord.codegen.kotlinpoet
import com.squareup.kotlinpoet.FileSpec
import com.squareup.kotlinpoet.asClassName

public inline fun <reified C> FileSpec(noinline block: FileSpecBuilderScope = {}): FileSpec =
public inline fun <reified C> FileSpec(block: FileSpecBuilderScope = {}): FileSpec =
FileSpec(C::class.asClassName(), block)
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import kotlin.collections.Iterable
public inline fun <reified T> FunSpec.Builder.addParameter(
name: String,
vararg modifiers: KModifier,
noinline block: ParameterSpecBuilderScope = {},
block: ParameterSpecBuilderScope = {},
): ParameterSpec = addParameter(name, typeNameOf<T>(), modifiers = modifiers, block)

public inline fun <reified T> FunSpec.Builder.addParameter(vararg modifiers: KModifier, noinline
Expand All @@ -21,7 +21,7 @@ public inline fun <reified T> FunSpec.Builder.addParameter(vararg modifiers: KMo
public inline fun <reified T> FunSpec.Builder.addParameter(
name: String,
modifiers: Iterable<KModifier>,
noinline block: ParameterSpecBuilderScope = {},
block: ParameterSpecBuilderScope = {},
): ParameterSpec = addParameter(name, typeNameOf<T>(), modifiers, block)

public inline fun <reified T> FunSpec.Builder.addParameter(modifiers: Iterable<KModifier>, noinline
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import kotlin.collections.Iterable
public inline fun <reified T> ParameterSpec(
name: String,
vararg modifiers: KModifier,
noinline block: ParameterSpecBuilderScope = {},
block: ParameterSpecBuilderScope = {},
): ParameterSpec = ParameterSpec(name, typeNameOf<T>(), modifiers = modifiers, block)

public inline fun <reified T> ParameterSpec(
name: String,
modifiers: Iterable<KModifier>,
noinline block: ParameterSpecBuilderScope = {},
block: ParameterSpecBuilderScope = {},
): ParameterSpec = ParameterSpec(name, typeNameOf<T>(), modifiers, block)
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import kotlin.collections.Iterable
public inline fun <reified T> TypeSpec.Builder.addProperty(
name: String,
vararg modifiers: KModifier,
noinline block: PropertySpecBuilderScope = {},
block: PropertySpecBuilderScope = {},
): PropertySpec = addProperty(name, typeNameOf<T>(), modifiers = modifiers, block)

public inline fun <reified T> TypeSpec.Builder.addProperty(vararg modifiers: KModifier, noinline
Expand All @@ -22,7 +22,7 @@ public inline fun <reified T> TypeSpec.Builder.addProperty(vararg modifiers: KMo
public inline fun <reified T> TypeSpec.Builder.addProperty(
name: String,
modifiers: Iterable<KModifier>,
noinline block: PropertySpecBuilderScope = {},
block: PropertySpecBuilderScope = {},
): PropertySpec = addProperty(name, typeNameOf<T>(), modifiers, block)

public inline fun <reified T> TypeSpec.Builder.addProperty(modifiers: Iterable<KModifier>, noinline
Expand All @@ -32,7 +32,7 @@ public inline fun <reified T> TypeSpec.Builder.addProperty(modifiers: Iterable<K
public inline fun <reified T> FileSpec.Builder.addProperty(
name: String,
vararg modifiers: KModifier,
noinline block: PropertySpecBuilderScope = {},
block: PropertySpecBuilderScope = {},
): PropertySpec = addProperty(name, typeNameOf<T>(), modifiers = modifiers, block)

public inline fun <reified T> FileSpec.Builder.addProperty(vararg modifiers: KModifier, noinline
Expand All @@ -42,7 +42,7 @@ public inline fun <reified T> FileSpec.Builder.addProperty(vararg modifiers: KMo
public inline fun <reified T> FileSpec.Builder.addProperty(
name: String,
modifiers: Iterable<KModifier>,
noinline block: PropertySpecBuilderScope = {},
block: PropertySpecBuilderScope = {},
): PropertySpec = addProperty(name, typeNameOf<T>(), modifiers, block)

public inline fun <reified T> FileSpec.Builder.addProperty(modifiers: Iterable<KModifier>, noinline
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import kotlin.collections.Iterable
public inline fun <reified T> PropertySpec(
name: String,
vararg modifiers: KModifier,
noinline block: PropertySpecBuilderScope = {},
block: PropertySpecBuilderScope = {},
): PropertySpec = PropertySpec(name, typeNameOf<T>(), modifiers = modifiers, block)

public inline fun <reified T> PropertySpec(
name: String,
modifiers: Iterable<KModifier>,
noinline block: PropertySpecBuilderScope = {},
block: PropertySpecBuilderScope = {},
): PropertySpec = PropertySpec(name, typeNameOf<T>(), modifiers, block)
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ import com.squareup.kotlinpoet.TypeAliasSpec
import com.squareup.kotlinpoet.typeNameOf
import kotlin.String

public inline fun <reified T> TypeAliasSpec(name: String, noinline block: TypeAliasSpecBuilderScope
= {}): TypeAliasSpec = TypeAliasSpec(name, typeNameOf<T>(), block)
public inline fun <reified T> TypeAliasSpec(name: String, block: TypeAliasSpecBuilderScope = {}):
TypeAliasSpec = TypeAliasSpec(name, typeNameOf<T>(), block)
Original file line number Diff line number Diff line change
Expand Up @@ -4,44 +4,44 @@ import com.squareup.kotlinpoet.FileSpec
import com.squareup.kotlinpoet.TypeSpec
import com.squareup.kotlinpoet.asClassName

public inline fun <reified C> TypeSpec.Builder.addClass(noinline block: TypeSpecBuilderScope = {}):
TypeSpec = addClass(C::class.asClassName(), block)
public inline fun <reified C> TypeSpec.Builder.addClass(block: TypeSpecBuilderScope = {}): TypeSpec
= addClass(C::class.asClassName(), block)

public inline fun <reified C> FileSpec.Builder.addClass(noinline block: TypeSpecBuilderScope = {}):
TypeSpec = addClass(C::class.asClassName(), block)
public inline fun <reified C> FileSpec.Builder.addClass(block: TypeSpecBuilderScope = {}): TypeSpec
= addClass(C::class.asClassName(), block)

public inline fun <reified C> TypeSpec.Builder.addExpectClass(noinline block: TypeSpecBuilderScope =
{}): TypeSpec = addExpectClass(C::class.asClassName(), block)
public inline fun <reified C> TypeSpec.Builder.addExpectClass(block: TypeSpecBuilderScope = {}):
TypeSpec = addExpectClass(C::class.asClassName(), block)

public inline fun <reified C> FileSpec.Builder.addExpectClass(noinline block: TypeSpecBuilderScope =
{}): TypeSpec = addExpectClass(C::class.asClassName(), block)
public inline fun <reified C> FileSpec.Builder.addExpectClass(block: TypeSpecBuilderScope = {}):
TypeSpec = addExpectClass(C::class.asClassName(), block)

public inline fun <reified C> TypeSpec.Builder.addObject(noinline block: TypeSpecBuilderScope = {}):
TypeSpec = addObject(C::class.asClassName(), block)
public inline fun <reified C> TypeSpec.Builder.addObject(block: TypeSpecBuilderScope = {}): TypeSpec
= addObject(C::class.asClassName(), block)

public inline fun <reified C> FileSpec.Builder.addObject(noinline block: TypeSpecBuilderScope = {}):
TypeSpec = addObject(C::class.asClassName(), block)
public inline fun <reified C> FileSpec.Builder.addObject(block: TypeSpecBuilderScope = {}): TypeSpec
= addObject(C::class.asClassName(), block)

public inline fun <reified C> TypeSpec.Builder.addInterface(noinline block: TypeSpecBuilderScope =
{}): TypeSpec = addInterface(C::class.asClassName(), block)
public inline fun <reified C> TypeSpec.Builder.addInterface(block: TypeSpecBuilderScope = {}):
TypeSpec = addInterface(C::class.asClassName(), block)

public inline fun <reified C> FileSpec.Builder.addInterface(noinline block: TypeSpecBuilderScope =
{}): TypeSpec = addInterface(C::class.asClassName(), block)
public inline fun <reified C> FileSpec.Builder.addInterface(block: TypeSpecBuilderScope = {}):
TypeSpec = addInterface(C::class.asClassName(), block)

public inline fun <reified C> TypeSpec.Builder.addFunInterface(noinline block: TypeSpecBuilderScope
= {}): TypeSpec = addFunInterface(C::class.asClassName(), block)
public inline fun <reified C> TypeSpec.Builder.addFunInterface(block: TypeSpecBuilderScope = {}):
TypeSpec = addFunInterface(C::class.asClassName(), block)

public inline fun <reified C> FileSpec.Builder.addFunInterface(noinline block: TypeSpecBuilderScope
= {}): TypeSpec = addFunInterface(C::class.asClassName(), block)
public inline fun <reified C> FileSpec.Builder.addFunInterface(block: TypeSpecBuilderScope = {}):
TypeSpec = addFunInterface(C::class.asClassName(), block)

public inline fun <reified C> TypeSpec.Builder.addEnum(noinline block: TypeSpecBuilderScope = {}):
TypeSpec = addEnum(C::class.asClassName(), block)
public inline fun <reified C> TypeSpec.Builder.addEnum(block: TypeSpecBuilderScope = {}): TypeSpec =
addEnum(C::class.asClassName(), block)

public inline fun <reified C> FileSpec.Builder.addEnum(noinline block: TypeSpecBuilderScope = {}):
TypeSpec = addEnum(C::class.asClassName(), block)
public inline fun <reified C> FileSpec.Builder.addEnum(block: TypeSpecBuilderScope = {}): TypeSpec =
addEnum(C::class.asClassName(), block)

public inline fun <reified C> TypeSpec.Builder.addAnnotationClass(noinline
block: TypeSpecBuilderScope = {}): TypeSpec = addAnnotationClass(C::class.asClassName(), block)
public inline fun <reified C> TypeSpec.Builder.addAnnotationClass(block: TypeSpecBuilderScope = {}):
TypeSpec = addAnnotationClass(C::class.asClassName(), block)

public inline fun <reified C> FileSpec.Builder.addAnnotationClass(noinline
block: TypeSpecBuilderScope = {}): TypeSpec = addAnnotationClass(C::class.asClassName(), block)
public inline fun <reified C> FileSpec.Builder.addAnnotationClass(block: TypeSpecBuilderScope = {}):
TypeSpec = addAnnotationClass(C::class.asClassName(), block)
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@ package dev.kord.codegen.kotlinpoet
import com.squareup.kotlinpoet.TypeSpec
import com.squareup.kotlinpoet.asClassName

public inline fun <reified C> `class`(noinline block: TypeSpecBuilderScope = {}): TypeSpec =
public inline fun <reified C> `class`(block: TypeSpecBuilderScope = {}): TypeSpec =
`class`(C::class.asClassName(), block)

public inline fun <reified C> expectClass(noinline block: TypeSpecBuilderScope = {}): TypeSpec =
public inline fun <reified C> expectClass(block: TypeSpecBuilderScope = {}): TypeSpec =
expectClass(C::class.asClassName(), block)

public inline fun <reified C> `object`(noinline block: TypeSpecBuilderScope = {}): TypeSpec =
public inline fun <reified C> `object`(block: TypeSpecBuilderScope = {}): TypeSpec =
`object`(C::class.asClassName(), block)

public inline fun <reified C> `interface`(noinline block: TypeSpecBuilderScope = {}): TypeSpec =
public inline fun <reified C> `interface`(block: TypeSpecBuilderScope = {}): TypeSpec =
`interface`(C::class.asClassName(), block)

public inline fun <reified C> funInterface(noinline block: TypeSpecBuilderScope = {}): TypeSpec =
public inline fun <reified C> funInterface(block: TypeSpecBuilderScope = {}): TypeSpec =
funInterface(C::class.asClassName(), block)

public inline fun <reified C> `enum`(noinline block: TypeSpecBuilderScope = {}): TypeSpec =
public inline fun <reified C> `enum`(block: TypeSpecBuilderScope = {}): TypeSpec =
`enum`(C::class.asClassName(), block)

public inline fun <reified C> `annotation`(noinline block: TypeSpecBuilderScope = {}): TypeSpec =
public inline fun <reified C> `annotation`(block: TypeSpecBuilderScope = {}): TypeSpec =
`annotation`(C::class.asClassName(), block)
4 changes: 3 additions & 1 deletion kotlinpoet/processor/src/main/kotlin/reification/Reifyer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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()
Expand Down
5 changes: 3 additions & 2 deletions kotlinpoet/processor/src/main/kotlin/utils/KSPUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 5351f60

Please sign in to comment.