Skip to content

Instantly share code, notes, and snippets.

View miquelbeltran's full-sized avatar

Miguel Beltran miquelbeltran

View GitHub Profile
package work.beltran.sample
class Generated_Hello {
fun getName() = "World"
}
apply plugin: 'kotlin'
repositories {
mavenCentral()
}
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-jre8:$kotlin_version"
compile 'com.squareup:kotlinpoet:0.5.0'
compile "com.google.auto.service:auto-service:1.0-rc2"
package work.beltran.sample
import com.google.auto.service.AutoService
import com.squareup.kotlinpoet.FileSpec
import com.squareup.kotlinpoet.FunSpec
import com.squareup.kotlinpoet.TypeSpec
import java.io.File
import javax.annotation.processing.*
import javax.lang.model.SourceVersion
import javax.lang.model.element.TypeElement
apply plugin: 'kotlin'
kapt {
generateStubs = true
}
repositories {
mavenCentral()
}
package work.beltran.sample
@GenName
class Hello
fun main(args: Array<String>) {
println("Hello ${Generated_Hello().getName()}")
}
package work.beltran.sample
annotation class GenName
rootProject.name = 'kotlin-code-gen-sample'
include 'generator'
include 'sample-main'
group 'beltran.work'
version '1.0-SNAPSHOT'
buildscript {
ext.kotlin_version = '1.1.3-2'
repositories {
mavenCentral()
}
dependencies {
import kotlin.reflect.full.findAnnotation
annotation class HelloName(val name: String)
abstract class Hello {
fun getName(): String {
val ann = javaClass.kotlin.findAnnotation<HelloName>()
return ann?.name ?: throw IllegalStateException("Missing annotation @HelloName")
}
}
public final class DayViewHolder extends ViewHolder {
@NotNull
private final TextView title;
@NotNull
public final TextView getTitle() {
return this.title;
}
public final void bind(@NotNull Day day) {