Giter Club home page Giter Club logo

firstkotlincompilerplugin's Introduction

FirstKotlinCompilerPlugin

日本語版はこちら

This repository contains a simple Kotlin compiler plugin implementation for the purpose of demonstrating how to write a Kotlin compiler plugin.

Module structure

  • gradle-plugin: Gradle plugin to apply the Kotlin compiler plugin to any projects.
  • kotlin-plugin: Custom compiler plugin implementation.

Note demo is an independent project to test the compiler plugin. It is not a part of the compiler plugin itself.

How it modifies the code

This compiler plugin is quite simple. It just adds statements to print out current system time at the beginning of function. Annotation classes to be processed can be specified in the Gradle plugin configuration.

Input code:

annotation class HogeAnnotation

@HogeAnnotation
fun main() {
}

Output code should be something like this:

fun main() {
    val startTime = System.currentTimeMillis()
    println(startTime)
}

Gradle plugin configuration

If enabled is set to false, the compiler plugin will not be applied. annotations is a list of annotation classes to be processed by the compiler plugin.

Groovy

myPlugin {
    enabled = true
    annotations = ["HogeAnnotation"]
}

KTS

configure<MyPluginExtension> {
    enabled = true
    annotations = listOf("HogeAnnotation")
}

How to test on your local machine

  1. Run ./gradlew publishToMavenLocal at the root directory to publish gradle-plugin and kotlin-plugin to maven local.
  2. Run cd demo to move to the root directory of the demo project.
  3. Run ./gradlew run to see the compiler plugin in action.

By default, you will see the output like this:

> Task :run
1696419167450

Additional resources

Want to know more about Kotlin compiler plugin? These resources might be helpful for you. Note that some of them are a bit outdated.

firstkotlincompilerplugin's People

Contributors

kitakkun avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.