Questions tagged [kotlinpoet]

A library from Square providing a Kotlin API for generating .kt source files.

A library from Square providing a Kotlin API for generating .kt source files. https://square.github.io/kotlinpoet/

72 questions
1
vote
1 answer

How to get proper kotlin types from RoundEnvironment for custom Annotation processor?

Lets say my annotation processor's process function looks like below override fun process( annotations: MutableSet, roundEnv: RoundEnvironment ): Boolean { try { …
Bhargav
  • 8,118
  • 6
  • 40
  • 63
1
vote
2 answers

How to initialize a variable and calling "apply { }" at the end

I'm trying to auto-generate classes were we create variables like this with KotlinPoet: class test { var testObj: CustomObject = CustomObject().apply { custom = "custom" } } So far I've tried looking at the PropertySpec in KotlinPoet, but can't…
user12124207
  • 33
  • 1
  • 4
1
vote
1 answer

How can I get generate map init code with KotlinPoet?

I am new one about KotlinPoet. Actaully, I want to generate code lines like the bellow with KAPT. There is not proper sample to generated init 'map' data. Is there anyone help me? ===> like this package com.example.kotlintest import…
1
vote
1 answer

How can I generate protobuf in Kotlin for Android applications?

Anyone help me to understand how can I generate protobuf in Kotlin? I heard about gRPC, wire, KotlinPoet, but I don't understand what are the differences, which one should I use any samples, any simple documents please fill free to share with…
Artur A
  • 257
  • 3
  • 20
1
vote
1 answer

Getting annotation from constructor value parameter using kotlinpoet-metadata

I have data class like this @Tagme("Response") @TagResponse data class Response( val id: Int, val title: String, val label: String, val images: List, @Input(Parameter::class) val slug: Slug ) Using annotation…
1
vote
0 answers

Can't figure out how to generate a @TypeParceler annotation with KotlinPoet using class names

I'm trying to generate code to declare a class with a @TypeParceler annotation. I can create a ParameterizedTypeName with: val myParcelerClass = ClassName("com.example", "MyParceler") val genericTypeParcelerClass =…
1
vote
1 answer

KotlinPoet how to use FunSpec.overriding when the class is not present?

I have a package name and a class name as Strings but I don't have the class specifically in my annotation processor. I need to use: FunSpec.overriding(getOnlyElement(methodsIn(//stuck here))) The stuck here should be a setOf ExecutableElements?…
coroutineDispatcher
  • 7,718
  • 6
  • 30
  • 58
1
vote
2 answers

Kotlin Poet super interface with type argument

I'm trying to generate an object which implements an interface with type parameter like the following example: object HelloWorld : Feature I can generate the object that implements my interface like the following code: val typeSpecBuilder =…
savepopulation
  • 11,736
  • 4
  • 55
  • 80
1
vote
1 answer

How to get the default value of an annotated variable

I have an annotation like following: @Arg internal var stringArg1: String? = null @Arg internal var stringArg2: String = "default value" And I iterate over all of my annotated classes variables like following: for (e in…
prom85
  • 16,896
  • 17
  • 122
  • 242
1
vote
1 answer

Is roundEnv.getElementsAnnotatedWith(AnnotationName::class.java) reflection broken when used with a @Repeatable @Retention(AnnotationRetention.Source)

When building a AbstractProcessor in Android studio using kapt/kotlinpoet. When I try to use the repeatable annotation tag it stop getting data back from roundEnv.getElementsAnnotatedWith(AnnotationName::class.java), I am able get the annotated…
1
vote
1 answer

Kotlin poet filet not getting generated

I tried to create a class with annotation processor and Kotlin Poet. This is my code: @AutoService(Processor::class) class TailProcessor : AbstractProcessor() { override fun process(elementTypeSet: MutableSet?,…
coroutineDispatcher
  • 7,718
  • 6
  • 30
  • 58
1
vote
1 answer

KotlinPoet - Generate Koin module

I'm new to KotlinPoet and I cannot find how to create the following Koin module statement: internal val apiModules = module { single { get().create(Name1::class.java) } single {…
m0skit0
  • 25,268
  • 11
  • 79
  • 127
1
vote
2 answers

How to set Map> as property type?

How can I generate below line of code using Kotlinpoet? val myMap:Map> I initialize myMap in init block.
Ankit Kumar
  • 339
  • 2
  • 5
1
vote
1 answer

java.lang.NoSuchMethodError: com.squareup.kotlinpoet.PropertySpec$Companion.varBuilder

I'm trying yo add this third party to my project this third party used annotation processing with kotlinpoet to generate analytics classes for log user events on firebase or whatever analytical tools, but i faced this issue e: [kapt] An exception…
1
vote
1 answer

How can I force function parameters onto new lines?

I want all function parameters to be generated on a new line, like so: fun test( a: Int, b: Int, c: Int ) How can I do this? At the moment the parameter lists wrap arbitrarily. I have an unknown number of function parameters to…
jimmy_terra
  • 1,430
  • 2
  • 18
  • 36