Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Annotation Code Generation - Android Classes

When starting to build my first code generation annotation, I've found I can't generate Android classes, such as SharedPreferences, since I start with a Java Library module in order to extend AbstractProcessor. I'm using kotlinpoet to generate my class, but need to create a property that is of type SharedPreferences.Editor which doesn't seem to be supported. I'm trying to something like the following:

val editorProperty = PropertySpec.builder("editor", android.content.SharedPreferences.Editor)

but this fails since the android package is not available. Does anyone know a workaround for this or is it just not possible?

like image 393
James B Avatar asked Sep 05 '25 02:09

James B


1 Answers

You can simply use

PropertySpec.builder("editor",ClassName("android.content", "SharedPreferences.Editor"))

as kotlin poet doc says - Type names are dumb identifiers only and do not model the values they name.

like image 84
Yrii Borodkin Avatar answered Sep 08 '25 00:09

Yrii Borodkin