All Downloads are FREE. Search and download functionalities are using the official Maven repository.

gsonpath.util.TypeSpecExt.kt Maven / Gradle / Ivy

There is a newer version: 2.0.0
Show newest version
package gsonpath.util

import com.squareup.javapoet.*
import javax.lang.model.element.Modifier

object TypeSpecExt {
    fun finalClassBuilder(name: String): TypeSpec.Builder {
        return TypeSpec.classBuilder(name)
                .addModifiers(Modifier.PUBLIC, Modifier.FINAL)
    }

    fun finalClassBuilder(className: ClassName): TypeSpec.Builder {
        return TypeSpec.classBuilder(className)
                .addModifiers(Modifier.PUBLIC, Modifier.FINAL)
    }
}

fun TypeSpec.Builder.field(name: String, type: TypeName, func: FieldSpec.Builder.() -> Unit) {
    addField(FieldSpec.builder(type, name).apply(func).build())
}

fun TypeSpec.Builder.overrideMethod(name: String, func: MethodSpec.Builder.() -> Unit) {
    addMethod(MethodSpecExt.overrideMethodBuilder(name).applyAndBuild(func))
}

fun TypeSpec.Builder.constructor(func: MethodSpec.Builder.() -> Unit) {
    addMethod(MethodSpec.constructorBuilder().applyAndBuild(func))
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy