KSP-based library that generates lists from your annotation usages

Overview

ListGen, Generate Lists From Functions That Have @Listed Annotations!

Welcome to ListGen!

ListGen is a KSP-based library that can generate lists (and also arrays and maps) from your functions that are annotated with @Listed (also @Arrayed and @Mapped).

Usage

First, annotate your functions with your desired output. You can use @Listed to generate listOf , @Arrayed to generate arrayOf and @Mapped for generating mapOf.

All annotations require a name and @Mapped requires a key.

Let's see it in action:

// can be anywhere (or in any module) in your project
@Listed("mainList")
fun mainModule() = 2

// can be anywhere (or in any module) in your project
@Listed("otherList")
fun helloModule() = "hello!"

// can be anywhere (or in any module) in your project
@Listed("mainList")
fun secondModule() = 3

The code above will generate the following code with correct imports:

// in build/generated/ksp/debug|main/kotlin/com/snaky/ksp/GeneratedLists.kt
val mainList = listOf(mainModule(), secondModule())
val otherList = listOf(helloModule())

// in build/generated/ksp/debug|main/kotlin/com/snaky/ksp/GeneratedMaps.kt
val firstMap = mapOf("key1" to firstMapTest(), "key2" to firstMapTest2())

You can safely use the generated lists, arrays and maps for your needs.

Installation

Add the following to your build.gradle (or build.gradle.kts)

plugins {
    id 'com.google.devtools.ksp' version '1.6.20-1.0.5'
    // the version according to your Kotlin and KSP
}

// to add support for IDE
android {
    kotlin {
        sourceSets.debug {
            kotlin.srcDirs += 'build/generated/ksp/debug/kotlin'
        }
        sourceSets.release {
            kotlin.srcDirs += 'build/generated/ksp/release/kotlin'
        }
    }
}

dependencies {
    implementation "io.github.adibfara.listgen:ksp:1.0.0"
    ksp "io.github.adibfara.listgen:ksp:1.0.0"
}

Learning KSP

If you want to learn more about KSP, most of the documentation of KSP can be found on kotlinlang.org.

Feedback and Bug Reporting

Please let me know what you think about this project by filing a Github issue

Notes

The initial need for this library emerged when I was using Koin in a project. You have to pass your list of modules to Koin and each module is defined somewhere in the project and you'll have a file containing listOf(module1, module2, module3, ...) which can get ugly (and error-prone).

Using this library to generate that list can help not only the file being ugly, but also help with Open/Closed Principle for your modules.

You might also like...
KSP extension for the kotlin-maven-plugin

kotlin-maven-symbol-processing Extension for the kotlin-maven-plugin to support Kotlin Symbol Processing (KSP). Usage To use this extension, add the d

Kotlin Symbol Processing (KSP) sample project

Kotlin Symbol Processing (KSP) Sample Project Sample annotation processor created with Kotlin Symbol Processing (KSP) API. The repository supplements

Mocking for Kotlin/Native and Kotlin Multiplatform using the Kotlin Symbol Processing API (KSP)

Mockative Mocking for Kotlin/Native and Kotlin Multiplatform using the Kotlin Symbol Processing API (KSP). Installation Mockative uses KSP to generate

Ktorm KSP extension to help generate boilerplate code.
Ktorm KSP extension to help generate boilerplate code.

Ktorm KSP extension to help generate boilerplate code. It can automatically generate Table objects through entity classes, while making entities defined by data classes easier to use, and supports custom extension code generation logic.

glide's ksp compiler ,use kotlin symbol processor
glide's ksp compiler ,use kotlin symbol processor

glide-ksp glide's ksp compiler ,use kotlin symbol processor requirements library version kotlin = 1.6.10 ksp 1.6.10-1.0.2 usage add jitpack repositor

A webapp which generates a simple Discord profile banner image in real-time which shows user's status and activity.

DiscordProfileBanner This tool generates a Discord profile banner image in realtime. I wrote it for use in my AniList profile. An example in action: H

An AutoValue extension that generates binary and source compatible equivalent Kotlin data classes of AutoValue models.
An AutoValue extension that generates binary and source compatible equivalent Kotlin data classes of AutoValue models.

AutoValue Kotlin auto-value-kotlin (AVK) is an AutoValue extension that generates binary-and-source-compatible, equivalent Kotlin data classes. This i

A backend service that generates a random 32-chars length message and its sha256 hashcode and put them to DB
A backend service that generates a random 32-chars length message and its sha256 hashcode and put them to DB

This is an Android application in which a user can ask the server to generate a random message and its sha256, and ask to obtain this info from the server.

Automatically generates UI demos which allow users to call any function with any parameters
Automatically generates UI demos which allow users to call any function with any parameters

Automatically generates UI demos which allow users to call any function (including composable ones) with any parameters. Useful for building demo screens in playground apps of various design systems.

Owner
Adib Faramarzi
Senior Android Team Lead at TAPSI
Adib Faramarzi
Annotation-based library for registration commands

Cargo commands Annotation-based library for registration commands Examples: Plugin main class: class ExamplePlugin : Plugin() { override fun regis

Evgenij 3 Dec 27, 2022
Ksp-di-library - Small library for DI in KMM apps

DI-KSP Small library for DI in KMM apps. Uses KSP for processing DI annotations:

Anna Zharkova 3 Feb 6, 2022
BindsAdapter is an Android library to help you create and maintain Adapter class easier via ksp( Kotlin Symbol Processing).

BindsAdapter BindsAdapter is an Android library to help you create and maintain Adapter class easier via ksp( Kotlin Symbol Processing). Installation

Jintin 5 Jul 30, 2022
A ksp library to automatically generate navigation functions for jetpack compose.

Compose/Navigation/Generator ⚠️ This library is still under development and not considered stable! Content Introduction Usage Example: Single destinat

Steffen Eckardt 4 Sep 13, 2022
Take beautiful markdown notes and stay organized with task lists.

Take beautiful markdown notes whenever you feel inspired. Place them in notebooks and tag them accordingly. Stay organized by making task lists, set reminders and keep everything in one place by attaching related files.

null 412 Dec 27, 2022
This App lists Maverl comics and its detail

DisneyCodeChallenge This App lists Maverl comics and its detail. Development Environment The app is written entirely in Kotlin and uses the Gradle bui

null 0 Nov 10, 2021
The app is composed of 2 screens, first is the profile screen, it has the user_name and address pinned at the top and then it lists all of this user’s albums.

The app is composed of 2 screens, first is the profile screen, it has the user_name and address pinned at the top and then it lists all of this user’s albums. When you press on any album it navigates to the second screen which is an album details screen that contains list of the images in an recyclerview grid. Also you have search bar that you can filter within the photos album by the image title.

Mahmoud Ibrahim 4 Jul 10, 2022
android webview loader using ksp

KSPWebViewLoader ?? @WebViewBuilder Annotation can be automating your webview settings. (WIP) How to use @WebViewBuilder( url = "https://www.googl

sehee Jeong 8 Apr 8, 2022
Exploring Kotlin Symbol Processing - KSP. This is just an experiment.

KSP example Exploring Kotlin Symbol Processing - KSP. This is just an experiment. Project contains 2 modules Processing Example Processing module is t

Merab Tato Kutalia 12 Aug 23, 2022
A collection of code generators powered by ksp.

AutoKsp A collection of code generators powered by ksp. status: working in progress Projects AutoGradlePlugin - Generate gradle plugin properties file

shenghaiyang 0 Nov 8, 2021