How to create compile time library that annotates the code (as compiler) in Android

110 Views Asked by At

I'm trying to create a library such as retro-lambda that reads the code at edit time or compile time and provides hints for the developer.

Let's say I'm using retro-lambda library and I created an interface that has only one method:

public interface Callback{
    void onResult(boolean isSuccess, Object result);
}

When I create an instance:

Callback callback = new Callback() {

    public void onResult(boolean isSuccess, Object result) {

    }
}

Here the retro-lambda will create a hind for the developer to use the lambda function as following:

Callback callback = (isSuccess, result) -> {

}

What do I need to learn about how to create library that inspects the code and adds hints to the user ?

1

There are 1 best solutions below

1
urgentx On

For providing an IDE hint you will want to build an Android Studio plugin.

For inspecting, modifying or generating Java source code at compile-time you will want an annotation processor.