简体中文 | English |
Xerath 是一个通过 [自定义注解]+ASM + Gradle Transform API
实现的一套功能强大,方便开发,并且能够有效减少重复代码的Android Aop 框架。
旨在编译器进行全局性的修改,来完成一些诸如方法耗时统计,异常收集,拦截,动态代理等特殊需求。
核心思想基于AOP编程,AOP为Aspect Oriented Programming的缩写,意为:面向切面编程。
本项目为AOP思想在Android上的运用与实战,功能部分对标基于AspectJ的开源项目AopArms
待上传到Maven,目前可以clone项目然后主动依赖
1.统计方法耗时
在目标方法上增加@CalculateTime注解
@CalculateTime
public static void CalculateTimeMethod() {
//do something
}
2.限制方法频繁调用
在目标方法上增加@Xerath_LimitCall(time = 1000L)注解,其中time为频繁调用的时间阈值
@Xerath_LimitCall(time = 1000L)
public static void doubleClick() {
//do something
}
3.try-catch异常捕获
在目标方法上增加@TryCatch注解
@TryCatch
public static void tryCatchMethod() {
int a = 1 / 0;
}
4.方法入参和返回值统计
在目标方法上增加@Xerath_CollectParams
@Xerath_CollectParams
public static String testParams(boolean boolParam, byte byteParam, char charParam, short shortParam, int intParam, long longParam,
float floatParam, double doubleParam, String stringParam, int[] intArrParam, JSONObject json) {
String result = boolParam + " " + byteParam + " " + charParam + " " + shortParam + " " + intParam + " " +
longParam + " " + floatParam + " " + doubleParam + " " + stringParam + " " + intArrParam.length + json.toString();
return result;
}
5 .弹出Toast
在目标方法上增加@Xerath_PopToast注解,其中str为需要显示Toast的内容
@Xerath_PopToast(str = "测试Toast")
public static void popToast() {
//do something
}
- Fork 本仓库
- 新建 Feat_xxx 分支
- 提交代码
- 新建 Pull Request
Copyright 2021, Jiang Zhengnan
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.