Skip to content
/ Eden Public

Real-time IDE annotation processor for Kotlin. / 用于 kotlin 的实现 IDE 实时提示的注解处理器

License

Notifications You must be signed in to change notification settings

zsqw123/Eden

Repository files navigation

Eden

No more wasted time waiting for kapt/ksp to generate classes for compilation! Scan annotated elements and generating the classes we want to generate automatically, while giving the IDE real-time hints!

再也不需要等待 kapt/ksp 生成类的编译浪费时间!使用 IDE 插件实时扫描带注解的类、方法、属性,并生成我们想生成的类,同时给予实时提示!

Version 2.0 compared with version 1.0 is completely incapable, version 1.0: README-1

Notice: 2.0 版本与 1.0 版本为完全不兼容改动,1.0 版本的 README: README-1

Preview

It will generate files produced by the annotation processor in real-time when modifying elements containing specified annotations.

它会在改动包含指定注解的元素的时候,实时生成注解处理器产生的文件

Usage

1. Add Dependencies

maven-central release version: Maven Central

repositories {
    mavenCentral()
}
dependencies {
    implementation("io.github.zsqw123:eden-idea:$version")
    // implementation following if kotlin-poet is needed
    implementation("io.github.zsqw123:eden-poet:$version")
}

2. Implement Annotation Processor

  1. Define the annotations to be processed
  2. Handling the KtDeclaration which annotated by the specified annotation.
  3. Generate files in real-time
private const val FAKE_FQN = "com.fake.FakeClass" // the annotation full qualified name

class FakeApt : EdenPoetApt() {
    override val annotationFqn: String = FAKE_FQN
    override fun processWithPoet(all: List<KtNamedDeclaration>): List<FileSpec> {
        return all.mapNotNull { it.name }.map { name ->
            val className = "Fake${name.capitalizeAsciiOnly()}"
            // generate codes by kotlinpoet
            val type = TypeSpec.classBuilder(className).build()
            FileSpec.builder("com.zsu", className).addType(type).build()
        }
    }
}

and register it in plugin.xml, don't forget include Eden-plugin.xml!

<idea-plugin xmlns:xi="http://www.w3.org/2001/XInclude">
    <xi:include href="/META-INF/Eden-plugin.xml"/>
    <extensions defaultExtensionNs="com.zsu.eden">
        <edenApt implementation="com.zsu.eden.sample.FakeApt"/>
    </extensions>
</idea-plugin>

More

  • For an example, see the sample module: sample

Environment

java idea
11+ 201.6858.69+

License & References

Apache License 2.0

This project uses the following open source projects:

  • JetBrains IDEA
  • JetBrains Kotlin
  • Android IDEA Plugin

About

Real-time IDE annotation processor for Kotlin. / 用于 kotlin 的实现 IDE 实时提示的注解处理器

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages