A demonstration project showcasing a custom Kotlin Symbol Processing (KSP) implementation. This project illustrates how to create and use annotation processors in Kotlin to generate code at compile time.
This project demonstrates:
- Creating custom annotations in Kotlin
- Implementing a KSP processor to generate extension functions
- Using the generated code in a Kotlin application
- annotation: Contains the annotation definition and processor implementation
MockingTextAnnotation.kt
: Defines the@MockingText
annotationMockingTextProcessor.kt
: Implements the KSP processor that generates extension functions
- app: Contains the main application code
ThisIsSerious.kt
: Contains data classes annotated with@MockingText
Main.kt
: Demonstrates the usage of the generated extension functions
- The
@MockingText
annotation is applied to data classes - The KSP processor generates an extension function called
mockMe()
for each annotated class - The
mockMe()
function transforms string properties by alternating between uppercase and lowercase characters - The generated code is automatically included in the build
- Clone the repository
- Navigate to the root directory of the project
- Run the following command:
./gradlew run
This will compile the project, process the annotations, generate the extension functions, and run the main application, which demonstrates the usage of the generated code.
The project includes unit tests that verify the functionality of the generated code.
To run all tests in the project:
./gradlew test
To run tests for a specific class:
./gradlew test --tests "io.cursedfunction.app.ThisIsSeriousTest"
To run a specific test method:
./gradlew test --tests "io.cursedfunction.app.ThisIsSeriousTest.testThisIsSeriousMockMe"
The tests cover:
- Verification of the generated
mockMe()
extension functions - Testing with various input types (normal text, empty strings, single characters, special characters)
- JDK 17 or higher
- Gradle 7.0 or higher