Android lint检查fix自动导入包
fix自动修复代码时自动将类导入。
示例
例如Log使用封装的工具类修复后:
代码里自动 import com.lkl.lint.commonlib.utils.LogUtils;
实现
核心代码:
fix().replace()
.name(fixDisplayName)
.range(location)
.with("${fixClassName}.${method.name}")
.shortenNames()
.autoFix()
.build()
fixClassName
是配置文件里配置的要使用的工具类的全类名
shortenNames()
The IDE should simplify fully qualified names in the element after this fix has been run (off by default)
从注释可以看到这个是起作用的关键所在。
参考文献
https://googlesamples.github.io/android-custom-lint-rules/api-guide/quickfixes.md.html