Skip to content

Commit

Permalink
introduce KotlinContextReceivableBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
jangalinski committed Aug 29, 2024
1 parent e2ab1bf commit 896b696
Show file tree
Hide file tree
Showing 13 changed files with 39 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class KotlinAnnotationClassSpecBuilder internal constructor(
) : KotlinGeneratorTypeSpecBuilder<KotlinAnnotationClassSpecBuilder, KotlinAnnotationClassSpec>,
ConstructorPropertySupport<KotlinAnnotationClassSpecBuilder>,
KotlinAnnotatableBuilder<KotlinAnnotationClassSpecBuilder>,
KotlinContextReceivableBuilder<KotlinAnnotationClassSpecBuilder>,
KotlinDocumentableBuilder<KotlinAnnotationClassSpecBuilder>,
KotlinMemberSpecHolderBuilder<KotlinAnnotationClassSpecBuilder>,
KotlinModifiableBuilder<KotlinAnnotationClassSpecBuilder>,
Expand Down Expand Up @@ -52,19 +53,15 @@ class KotlinAnnotationClassSpecBuilder internal constructor(
}

override fun addAnnotation(spec: KotlinAnnotationSpecSupplier): KotlinAnnotationClassSpecBuilder = apply { delegate.addAnnotation(spec.get()) }
override fun contextReceivers(vararg receiverTypes: TypeName): KotlinAnnotationClassSpecBuilder = builder { this.contextReceivers(*receiverTypes) }
override fun addFunction(funSpec: KotlinFunSpecSupplier): KotlinAnnotationClassSpecBuilder = apply { delegate.addFunction(funSpec.get()) }
override fun addKdoc(kdoc: KDoc): KotlinAnnotationClassSpecBuilder = apply { delegate.addKdoc(kdoc.get()) }
override fun addModifiers(vararg modifiers: KModifier) = builder { this.addModifiers(*modifiers) }
override fun addProperty(propertySpec: KotlinPropertySpecSupplier): KotlinAnnotationClassSpecBuilder = apply { delegate.addProperty(propertySpec.get()) }
override fun addType(typeSpec: TypeSpecSupplier) = builder { this.addType(typeSpec.get()) }

fun contextReceivers(vararg receiverTypes: TypeName): KotlinAnnotationClassSpecBuilder = builder { this.contextReceivers(*receiverTypes) }

fun addOriginatingElement(originatingElement: Element) = builder { this.addOriginatingElement(originatingElement) }




override fun builder(block: TypeSpecBuilderReceiver) = apply { delegate.builder.block() }
override fun build(): KotlinAnnotationClassSpec {
if (constructorProperties.isNotEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class KotlinAnonymousClassSpecBuilder internal constructor(
private val delegate: TypeSpecBuilder
) : KotlinGeneratorTypeSpecBuilder<KotlinAnonymousClassSpecBuilder, KotlinAnonymousClassSpec>,
KotlinAnnotatableBuilder<KotlinAnonymousClassSpecBuilder>,
KotlinContextReceivableBuilder<KotlinAnonymousClassSpecBuilder>,
KotlinDocumentableBuilder<KotlinAnonymousClassSpecBuilder>,
KotlinMemberSpecHolderBuilder<KotlinAnonymousClassSpecBuilder>,
KotlinModifiableBuilder<KotlinAnonymousClassSpecBuilder>,
Expand All @@ -33,13 +34,13 @@ class KotlinAnonymousClassSpecBuilder internal constructor(
internal constructor() : this(delegate = TypeSpecBuilder.anonymousClassBuilder())

override fun addAnnotation(spec: KotlinAnnotationSpecSupplier): KotlinAnonymousClassSpecBuilder = apply { delegate.addAnnotation(spec.get()) }
override fun contextReceivers(vararg receiverTypes: TypeName): KotlinAnonymousClassSpecBuilder = builder { this.contextReceivers(*receiverTypes) }
override fun addFunction(funSpec: KotlinFunSpecSupplier): KotlinAnonymousClassSpecBuilder = apply { delegate.addFunction(funSpec.get()) }
override fun addKdoc(kdoc: KDoc): KotlinAnonymousClassSpecBuilder = apply { delegate.addKdoc(kdoc.get()) }
override fun addModifiers(vararg modifiers: KModifier) = builder { this.addModifiers(*modifiers) }
override fun addProperty(propertySpec: KotlinPropertySpecSupplier): KotlinAnonymousClassSpecBuilder = apply { delegate.addProperty(propertySpec.get()) }
override fun addType(typeSpec: TypeSpecSupplier) = builder { this.addType(typeSpec.get()) }

fun contextReceivers(vararg receiverTypes: TypeName): KotlinAnonymousClassSpecBuilder = builder { this.contextReceivers(*receiverTypes) }
fun addOriginatingElement(originatingElement: Element) = builder { this.addOriginatingElement(originatingElement) }

fun addTypeVariable(typeVariable: TypeVariableName) = builder { this.addTypeVariable(typeVariable) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class KotlinClassSpecBuilder internal constructor(
private val delegate: TypeSpecBuilder
) : KotlinGeneratorTypeSpecBuilder<KotlinClassSpecBuilder, KotlinClassSpec>,
KotlinAnnotatableBuilder<KotlinClassSpecBuilder>,
KotlinContextReceivableBuilder<KotlinClassSpecBuilder>,
KotlinDocumentableBuilder<KotlinClassSpecBuilder>,
KotlinMemberSpecHolderBuilder<KotlinClassSpecBuilder>,
KotlinModifiableBuilder<KotlinClassSpecBuilder>,
Expand All @@ -32,13 +33,13 @@ class KotlinClassSpecBuilder internal constructor(
internal constructor(className: ClassName) : this(className, TypeSpecBuilder.classBuilder(className))

override fun addAnnotation(spec: KotlinAnnotationSpecSupplier): KotlinClassSpecBuilder = apply { delegate.addAnnotation(spec.get()) }
override fun contextReceivers(vararg receiverTypes: TypeName): KotlinClassSpecBuilder = builder { this.contextReceivers(*receiverTypes) }
override fun addFunction(funSpec: KotlinFunSpecSupplier): KotlinClassSpecBuilder = apply { delegate.addFunction(funSpec.get()) }
override fun addKdoc(kdoc: KDoc): KotlinClassSpecBuilder = apply { delegate.addKdoc(kdoc.get()) }
override fun addModifiers(vararg modifiers: KModifier) = builder { this.addModifiers(*modifiers) }
override fun addProperty(propertySpec: KotlinPropertySpecSupplier): KotlinClassSpecBuilder = apply { delegate.addProperty(propertySpec.get()) }
override fun addType(typeSpec: TypeSpecSupplier) = builder { this.addType(typeSpec.get()) }

fun contextReceivers(vararg receiverTypes: TypeName): KotlinClassSpecBuilder = builder { this.contextReceivers(*receiverTypes) }
fun addOriginatingElement(originatingElement: Element) = builder { this.addOriginatingElement(originatingElement) }
fun addTypeVariable(typeVariable: TypeVariableName) = builder { this.addTypeVariable(typeVariable) }
fun primaryConstructor(primaryConstructor: FunSpecSupplier?) = builder { this.primaryConstructor(primaryConstructor?.get()) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class KotlinCompanionObjectSpecBuilder internal constructor(
private val delegate: TypeSpecBuilder
) : KotlinGeneratorTypeSpecBuilder<KotlinCompanionObjectSpecBuilder, KotlinCompanionObjectSpec>,
KotlinAnnotatableBuilder<KotlinCompanionObjectSpecBuilder>,
KotlinContextReceivableBuilder<KotlinCompanionObjectSpecBuilder>,
KotlinDocumentableBuilder<KotlinCompanionObjectSpecBuilder>,
KotlinMemberSpecHolderBuilder<KotlinCompanionObjectSpecBuilder>,
KotlinModifiableBuilder<KotlinCompanionObjectSpecBuilder>,
Expand All @@ -34,25 +35,19 @@ class KotlinCompanionObjectSpecBuilder internal constructor(
internal constructor(name: String? = null) : this(TypeSpecBuilder.Companion.companionObjectBuilder(name))

override fun addAnnotation(spec: KotlinAnnotationSpecSupplier): KotlinCompanionObjectSpecBuilder = apply { delegate.addAnnotation(spec.get()) }
override fun contextReceivers(vararg receiverTypes: TypeName): KotlinCompanionObjectSpecBuilder = builder { delegate.contextReceivers(*receiverTypes) }
override fun addFunction(funSpec: KotlinFunSpecSupplier): KotlinCompanionObjectSpecBuilder = apply { delegate.addFunction(funSpec.get()) }
override fun addKdoc(kdoc: KDoc): KotlinCompanionObjectSpecBuilder = apply { delegate.addKdoc(kdoc.get()) }
override fun addModifiers(vararg modifiers: KModifier) = builder { delegate.addModifiers(*modifiers) }
override fun addProperty(propertySpec: KotlinPropertySpecSupplier): KotlinCompanionObjectSpecBuilder = apply { delegate.addProperty(propertySpec.get()) }
override fun addType(typeSpec: TypeSpecSupplier) = builder { delegate.addType(typeSpec.get()) }

fun contextReceivers(vararg receiverTypes: TypeName): KotlinCompanionObjectSpecBuilder = builder {
delegate.contextReceivers(
*receiverTypes
)
}

fun addOriginatingElement(originatingElement: Element) = builder {
delegate.addOriginatingElement(
originatingElement
)
}


fun addTypeVariable(typeVariable: TypeVariableName) = builder { delegate.addTypeVariable(typeVariable) }
fun primaryConstructor(primaryConstructor: FunSpecSupplier?) = builder {
delegate.primaryConstructor(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class KotlinDataClassSpecBuilder internal constructor(
) : KotlinGeneratorTypeSpecBuilder<KotlinDataClassSpecBuilder, KotlinDataClassSpec>,
ConstructorPropertySupport<KotlinDataClassSpecBuilder>,
KotlinAnnotatableBuilder<KotlinDataClassSpecBuilder>,
KotlinContextReceivableBuilder<KotlinDataClassSpecBuilder>,
KotlinDocumentableBuilder<KotlinDataClassSpecBuilder>,
KotlinMemberSpecHolderBuilder<KotlinDataClassSpecBuilder>,
KotlinModifiableBuilder<KotlinDataClassSpecBuilder>,
Expand All @@ -44,13 +45,13 @@ class KotlinDataClassSpecBuilder internal constructor(

override fun addAnnotation(spec: KotlinAnnotationSpecSupplier): KotlinDataClassSpecBuilder = apply { delegate.addAnnotation(spec.get()) }
override fun addConstructorProperty(spec: KotlinConstructorPropertySpecSupplier): KotlinDataClassSpecBuilder = apply { this.constructorProperties[spec.name] = spec }
override fun contextReceivers(vararg receiverTypes: TypeName) = builder { this.contextReceivers(*receiverTypes) }
override fun addFunction(funSpec: KotlinFunSpecSupplier): KotlinDataClassSpecBuilder = apply { delegate.addFunction(funSpec.get()) }
override fun addKdoc(kdoc: KDoc): KotlinDataClassSpecBuilder = apply { delegate.addKdoc(kdoc.get()) }
override fun addModifiers(vararg modifiers: KModifier) = builder { this.addModifiers(*modifiers) }
override fun addProperty(propertySpec: KotlinPropertySpecSupplier): KotlinDataClassSpecBuilder = apply { delegate.addProperty(propertySpec.get()) }
override fun addType(typeSpec: TypeSpecSupplier) = builder { this.addType(typeSpec.get()) }

fun contextReceivers(vararg receiverTypes: TypeName) = builder { this.contextReceivers(*receiverTypes) }

fun addOriginatingElement(originatingElement: Element) = builder { this.addOriginatingElement(originatingElement) }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class KotlinEnumClassSpecBuilder internal constructor(
private val delegate: TypeSpecBuilder
) : KotlinGeneratorTypeSpecBuilder<KotlinEnumClassSpecBuilder, KotlinEnumClassSpec>,
KotlinAnnotatableBuilder<KotlinEnumClassSpecBuilder>,
KotlinContextReceivableBuilder<KotlinEnumClassSpecBuilder>,
KotlinDocumentableBuilder<KotlinEnumClassSpecBuilder>,
KotlinMemberSpecHolderBuilder<KotlinEnumClassSpecBuilder>,
KotlinModifiableBuilder<KotlinEnumClassSpecBuilder>,
Expand All @@ -37,6 +38,7 @@ class KotlinEnumClassSpecBuilder internal constructor(
}

override fun addAnnotation(spec: KotlinAnnotationSpecSupplier): KotlinEnumClassSpecBuilder = apply { delegate.addAnnotation(spec.get()) }
override fun contextReceivers(vararg receiverTypes: TypeName): KotlinEnumClassSpecBuilder = builder { this.contextReceivers(*receiverTypes) }
override fun addFunction(funSpec: KotlinFunSpecSupplier): KotlinEnumClassSpecBuilder = apply { delegate.addFunction(funSpec.get()) }
override fun addKdoc(kdoc: KDoc): KotlinEnumClassSpecBuilder = apply { delegate.addKdoc(kdoc.get()) }
override fun addModifiers(vararg modifiers: KModifier): KotlinEnumClassSpecBuilder = builder { this.addModifiers(*modifiers) }
Expand All @@ -46,7 +48,6 @@ class KotlinEnumClassSpecBuilder internal constructor(
fun addEnumConstant(name: String): KotlinEnumClassSpecBuilder = apply { delegate.addEnumConstant(name) }
fun addEnumConstant(name: String, typeSpec: TypeSpec = TypeSpec.anonymousClassBuilder().build()): KotlinEnumClassSpecBuilder = builder { this.addEnumConstant(name, typeSpec) }

fun contextReceivers(vararg receiverTypes: TypeName): KotlinEnumClassSpecBuilder = builder { this.contextReceivers(*receiverTypes) }
fun addOriginatingElement(originatingElement: Element): KotlinEnumClassSpecBuilder = builder { this.addOriginatingElement(originatingElement) }

fun addTypeVariable(typeVariable: TypeVariableName): KotlinEnumClassSpecBuilder = builder { this.addTypeVariable(typeVariable) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class KotlinFunSpecBuilder internal constructor(
) : BuilderSupplier<KotlinFunSpec, FunSpec>,
DelegatingBuilder<KotlinFunSpecBuilder, FunSpecBuilderReceiver>,
KotlinAnnotatableBuilder<KotlinFunSpecBuilder>,
KotlinContextReceivableBuilder<KotlinFunSpecBuilder>,
KotlinDocumentableBuilder<KotlinFunSpecBuilder>,
KotlinModifiableBuilder<KotlinFunSpecBuilder>,
KotlinFunSpecSupplier {
Expand Down Expand Up @@ -56,10 +57,10 @@ class KotlinFunSpecBuilder internal constructor(
fun addParameter(parameter: KotlinParameterSpecSupplier) = builder { this.addParameter(parameter.get()) }

override fun addAnnotation(spec: KotlinAnnotationSpecSupplier): KotlinFunSpecBuilder = apply { delegate.addAnnotation(spec.get()) }
override fun contextReceivers(vararg receiverTypes: TypeName) = builder { this.contextReceivers(*receiverTypes) }
override fun addKdoc(kdoc: KDoc): KotlinFunSpecBuilder = apply { delegate.addKdoc(kdoc.get()) }
override fun addModifiers(vararg modifiers: KModifier) = builder { this.addModifiers(*modifiers) }

fun contextReceivers(vararg receiverTypes: TypeName) = builder { this.contextReceivers(*receiverTypes) }
fun addOriginatingElement(originatingElement: Element) = builder { this.addOriginatingElement(originatingElement) }
fun jvmModifiers(modifiers: Iterable<Modifier>) = builder { this.jvmModifiers(modifiers) }
fun addTypeVariables(typeVariables: Iterable<TypeVariableName>) = builder { this.addTypeVariables(typeVariables) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class KotlinInterfaceSpecBuilder internal constructor(
private val delegate: TypeSpecBuilder
) : KotlinGeneratorTypeSpecBuilder<KotlinInterfaceSpecBuilder, KotlinInterfaceSpec>,
KotlinAnnotatableBuilder<KotlinInterfaceSpecBuilder>,
KotlinContextReceivableBuilder<KotlinInterfaceSpecBuilder>,
KotlinDocumentableBuilder<KotlinInterfaceSpecBuilder>,
KotlinMemberSpecHolderBuilder<KotlinInterfaceSpecBuilder>,
KotlinModifiableBuilder<KotlinInterfaceSpecBuilder>,
Expand All @@ -38,13 +39,13 @@ class KotlinInterfaceSpecBuilder internal constructor(
)

override fun addAnnotation(spec: KotlinAnnotationSpecSupplier): KotlinInterfaceSpecBuilder = apply { delegate.addAnnotation(spec.get()) }
override fun contextReceivers(vararg receiverTypes: TypeName): KotlinInterfaceSpecBuilder = builder { this.contextReceivers(*receiverTypes) }
override fun addFunction(funSpec: KotlinFunSpecSupplier): KotlinInterfaceSpecBuilder = apply { delegate.addFunction(funSpec.get()) }
override fun addKdoc(kdoc: KDoc): KotlinInterfaceSpecBuilder = apply { delegate.addKdoc(kdoc.get()) }
override fun addModifiers(vararg modifiers: KModifier) = builder { this.addModifiers(*modifiers) }
override fun addProperty(propertySpec: KotlinPropertySpecSupplier): KotlinInterfaceSpecBuilder = apply { delegate.addProperty(propertySpec.get()) }
override fun addType(typeSpec: TypeSpecSupplier) = builder { this.addType(typeSpec.get()) }

fun contextReceivers(vararg receiverTypes: TypeName): KotlinInterfaceSpecBuilder = builder { this.contextReceivers(*receiverTypes) }
fun addOriginatingElement(originatingElement: Element) = builder { this.addOriginatingElement(originatingElement) }
fun addTypeVariable(typeVariable: TypeVariableName) = builder { this.addTypeVariable(typeVariable) }
fun primaryConstructor(primaryConstructor: FunSpecSupplier?) = builder { this.primaryConstructor(primaryConstructor?.get()) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class KotlinObjectSpecBuilder internal constructor(
private val delegate: TypeSpecBuilder
) : KotlinGeneratorTypeSpecBuilder<KotlinObjectSpecBuilder, KotlinObjectSpec>,
KotlinAnnotatableBuilder<KotlinObjectSpecBuilder>,
KotlinContextReceivableBuilder<KotlinObjectSpecBuilder>,
KotlinDocumentableBuilder<KotlinObjectSpecBuilder>,
KotlinMemberSpecHolderBuilder<KotlinObjectSpecBuilder>,
KotlinModifiableBuilder<KotlinObjectSpecBuilder>,
Expand All @@ -34,14 +35,13 @@ class KotlinObjectSpecBuilder internal constructor(
internal constructor(className: ClassName) : this(className, TypeSpecBuilder.objectBuilder(className))

override fun addAnnotation(spec: KotlinAnnotationSpecSupplier): KotlinObjectSpecBuilder = apply { delegate.addAnnotation(spec.get()) }
override fun contextReceivers(vararg receiverTypes: TypeName): KotlinObjectSpecBuilder = builder { this.contextReceivers(*receiverTypes) }
override fun addFunction(funSpec: KotlinFunSpecSupplier): KotlinObjectSpecBuilder = apply { delegate.addFunction(funSpec.get()) }
override fun addKdoc(kdoc: KDoc): KotlinObjectSpecBuilder = apply { delegate.addKdoc(kdoc.get()) }
override fun addModifiers(vararg modifiers: KModifier) = builder { this.addModifiers(*modifiers) }
override fun addProperty(propertySpec: KotlinPropertySpecSupplier): KotlinObjectSpecBuilder = apply { delegate.addProperty(propertySpec.get()) }
override fun addType(typeSpec: TypeSpecSupplier) = builder { this.addType(typeSpec.get()) }

fun contextReceivers(vararg receiverTypes: TypeName): KotlinObjectSpecBuilder = builder { this.contextReceivers(*receiverTypes) }

fun addOriginatingElement(originatingElement: Element) = builder { this.addOriginatingElement(originatingElement) }

fun addTypeVariable(typeVariable: TypeVariableName) = builder { this.addTypeVariable(typeVariable) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class KotlinPropertySpecBuilder internal constructor(
) : BuilderSupplier<KotlinPropertySpec, PropertySpec>,
DelegatingBuilder<KotlinPropertySpecBuilder, PropertySpecBuilderReceiver>,
KotlinAnnotatableBuilder<KotlinPropertySpecBuilder>,
KotlinContextReceivableBuilder<KotlinPropertySpecBuilder>,
KotlinDocumentableBuilder<KotlinPropertySpecBuilder>,
KotlinModifiableBuilder<KotlinPropertySpecBuilder>,
KotlinPropertySpecSupplier {
Expand Down Expand Up @@ -53,10 +54,10 @@ class KotlinPropertySpecBuilder internal constructor(
}

override fun addAnnotation(spec: KotlinAnnotationSpecSupplier): KotlinPropertySpecBuilder = apply { delegate.addAnnotation(spec.get()) }
override fun contextReceivers(vararg receiverTypes: TypeName) = builder { this.contextReceivers(*receiverTypes) }
override fun addKdoc(kdoc: KDoc): KotlinPropertySpecBuilder = apply { delegate.addKdoc(kdoc.get()) }
override fun addModifiers(vararg modifiers: KModifier) = builder { this.addModifiers(*modifiers) }

fun contextReceivers(vararg receiverTypes: TypeName) = builder { this.contextReceivers(*receiverTypes) }
fun addOriginatingElement(originatingElement: Element) = builder { this.addOriginatingElement(originatingElement) }

fun mutable(mutable: Boolean = true) = builder { this.mutable(mutable) }
Expand Down
Loading

0 comments on commit 896b696

Please sign in to comment.