Skip to content
/ fwrap Public

Kotlin compiler plugin that allows to receive callbacks before and after function body is executed.

License

Notifications You must be signed in to change notification settings

staakk/fwrap

Repository files navigation

FWrap

License Build Status

This project uses Semantic Versioning

FWrap is a Kotlin compiler plugin that allows you to provide callbacks for arbitrary function that will be called before and after its execution.

Example

To get callbacks before and after function execution you just need to register provider with an identifier. Then you can use it to wrap function using @Wrap annotation.

registerProvider(
        id = "foo",
        callBefore = { println("Hello from function `${it.name}()`.") },
        callAfter = { println("Goodbye, return value was `$it`.") }
)

@Wrap(["foo"])
fun bar() = 42

Executing function bar will produce following output:

Hello from function `bar()`.
Goodbye, return value was `42`.

You can find more usage examples in fwrap-samples directory.

Usage

To use the plugin add following to your build.gradle:

plugins {
  id "fwrap.plugin" version "0.0.2"
}

//...

allprojects {
    repositories {
        maven { url 'https://jitpack.io' }
    }
}

//...

dependencies {
    implementation "com.github.staakk.fwrap:fwrap-lib:0.0.2"
}

Alternatively if you are using Gradle with Kotlin:

plugins {
  id("fwrap.plugin") version "0.0.2"
}

//...

allprojects {
    repositories {
        maven(url = "https://jitpack.io")
    }
}

//...

dependencies {
    implementation("com.github.staakk.fwrap:fwrap-lib:0.0.2")
}

About

Kotlin compiler plugin that allows to receive callbacks before and after function body is executed.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages