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
0
votes
1 answer

Creating a static extension property for Kotlin with KotlinPoet

I am a complete newbie to using KotlinPoet. I would like to programmatically generate the following code using KotlinPoet: public val MyClass.Companion.classID: Long get() = 0x100 Unfortunately, after many attempts, I have not yet found a way to…
0
votes
1 answer

How to add KotlinPoet dependency to simple console app?

I'm writing a simple console app which should to generate some kotlin code on execution. I faced a strange problem I can't add KotlinPoen dependency. My build.gradle: plugins { id 'java-library' id 'kotlin' } java { sourceCompatibility…
0
votes
2 answers

How to generate a class with a typealias parameter via kotlinpoet

I want to generate a kotlin class definition with typealias. typealias MyAlias = BigDecimal class TemplateState(var test: MyAlias) { } Any suggestions?
Sahka
  • 210
  • 3
  • 12
0
votes
2 answers

How do I build a constructor where the field is `var` and can be `@annotated`?

How do I use Kotlinpoet to generate the following code? data class Test ( @Id var id: Long ) : Interface { override fun primaryKey() : Serializable = this }
eahau
  • 1
  • 1
0
votes
1 answer

KotlinPoet how to get TypeName of generated class

I want to use a class generated with TypeSpec.classBuilder as a property in another class that I am generating. But for this I need to get a TypeName and I cannot find a way to access it. Only from the superclass. Anyone knows a way to do this?
ligi
  • 39,001
  • 44
  • 144
  • 244
0
votes
1 answer

Create extension function (function with . in name)

I want to generate a very simply class that just contains extension functions, like e.g. following: import com.my.app.SomeClass fun SomeClass.function() { } What I try: val packageName = ... val annotatedClassName = annotatedElement.simpleName val…
prom85
  • 16,896
  • 17
  • 122
  • 242
0
votes
1 answer

Looking for correct kotlinpoet syntax to initialize a PropertySpec.Builder for IntArrays and Array values

Don't see the correct syntax for initializing the Array types to the values from an existing types from within the project, primitive types works fine and programmer defined classes Target( AnnotationTarget.FIELD, …
0
votes
1 answer

CodeBlock throwing IAE because CassName does not pass is TypeName check

I tried to initialize a property, though CodeBlock#of throws an IllegalArgumentException in CodeBlock#argToType I looked into the root cause of the error which was at CodeBlock#argToType. Even if o is a ClassName(which also is a TypeName) it does…
Zctrap
  • 15
  • 5
0
votes
1 answer

KotlinPoet: Add function to existing class

I want to build an annotation processor that generates a public "non-mutable class" getter function of a private "mutable class" field (e.g. returning a LiveData version of a MutableLiveData field). What I want to write: class MyClass { …
Manuel Huber
  • 121
  • 2
  • 14
0
votes
1 answer

Android - How to generate type safe builder function using Kotlin Poet library

I am trying to generate one kotlin class using kotlin poet library which should have one function and one inner static class as given below. class SampleClass{ class TestClass{ lateinit var id: String lateinit var…
Rock
  • 9
  • 1
  • 8
0
votes
1 answer

How to implement Comparable in KotlinPoet?

Submitted by Fleshgrinder on GitHub. How is it possible to implement Comparable for the class that is currently being generated? There is the ParameterizedTypeName.get(Comparable::class, ?) method but it is unclear how the second parameter could be…
Egor
  • 39,695
  • 10
  • 113
  • 130
0
votes
1 answer

How should I add property within a function in kotlinpoet

I saw that TypeSpec.classBuilder has addProperty function which can generate below format of code override val propertyName: PropertyType = PropertyValue But when I tried to add the same property definition within one function of the class, there…
Jiachuan Li
  • 195
  • 9
1 2 3 4
5