简体   繁体   English

如何在Android中创建注释代码的编译时间库(作为编译器)

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

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. 我正在尝试创建一个库,例如retro-lambda,该库在编辑时或编译时读取代码,并为开发人员提供提示。

Let's say I'm using retro-lambda library and I created an interface that has only one method: 假设我使用的是retro-lambda库,并且创建了一个只有一种方法的接口:

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: 在这里,retro-lambda将为开发人员创建lambda函数提供一个障碍,如下所示:

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 ? 我需要了解什么有关如何创建库来检查代码并向用户添加提示的知识?

For providing an IDE hint you will want to build an Android Studio plugin. 为了提供IDE提示,您将需要构建一个Android Studio插件。

For inspecting, modifying or generating Java source code at compile-time you will want an annotation processor . 为了在编译时检查,修改或生成Java源代码,您需要使用注释处理器

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM