Writing custom lint warning to check for custom annotation

后端 未结 1 1134
一个人的身影
一个人的身影 2020-12-09 06:15

I have written the following annotation:

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.Retentio         


        
相关标签:
1条回答
  • 2020-12-09 06:41

    But I do not know how to proceed from here

    I suggest to write a test for your Detector first. Here is an example project which demonstrates how to write Detector tests [1]. That way you can try and adjust your Detector as you like.

    How can I check if an annoation exists on a method

    I suggest to have a look at Android's default detectors [2]. There you'll most probably find a good point to start. E.g. the AnnotationDetector.

    and raise a warning such that it will be visible in Android Studio?

    If you integrate your custom rules correctly into your project, then Lint will raise the warning for you. Please have a look here [3] for different options on how to integrate custom rules in your project. Note: AFAIK warnings of custom rules will only reported when running the corresponding Gradle task. The "auto-highlight" of Android Studio does not work with custom rules.

    1. https://github.com/a11n/CustomLintRules
    2. https://android.googlesource.com/platform/tools/base/+/master/lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks
    3. https://github.com/a11n/android-lint/tree/master/6_application
    0 讨论(0)
提交回复
热议问题