Skip to content

anthonycr/Tagger

Repository files navigation

Tagger

An annotation processor example, written in Kotlin, generating Kotlin

Abstract

This annotation processor acts as an example of how to generate Kotlin code using the annotation processing framework. Using Kapt, we can generate idiomatic Kotlin code, which means annotation processors become more powerful with access to features like extension functions and properties. This example generates tag properties which are commonly used for logging, and unlike if they were generated from a Java specific annotation processor, this example is able to generate the tag properties as extensions of the annotated class.

Gradle

apply plugin: 'kotlin-kapt'

kapt project(':tagger-compiler')
compile project(':tagger')

Usage

Apply the @Tag annotation to a class, and Tagger will auto-generate a log tag for the class.

@Tag
class HelloWorld {

  fun hello() {
    println("$TAG - is the class name")
  }

}

The annotation processor generates an extension property for the annotated class.

val HelloWorld.TAG: String
  get() = "HelloWorld"

License

tagger is available under the MIT license. See the LICENSE file for more information.

About

An annotation processor example, written in Kotlin, generating Kotlin

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages