let @VisibleForTesting tells original visibility of annotated element
See original GitHub issueOriginal issue created by skypencil on 2014-01-22 at 02:13 AM
Hello, I am trying to implement static code analysis tool which detects illegal method call like below:
// an implementation which has a method annotated by @VisibleForTesting class MyImplementation { @VisibleForTesting /* private */ void method() { … } }
// another implementation class AnotherImplementation { void method() { new MyImplementation().method(); // illegal method call, because this class is not test code } }
To find illegal method calling, we should know the original visibility of annotated element (method in this case). In some case it is difficult to guess original visibility, so I want to enhance @VisibleForTesting to explain it like below:
@VisibleForTesting(original = Visibility.PRIVATE)
void method() { ... }
I think all static analysis tool which uses this annotation needs method to judge illegality of method call, so I have added methods into Visibility enum in attached diff. It is also good to make this enum simple like com.android.internal.annotations.VisibleForTesting annotation. See https://github.com/android/platform_frameworks_base/blob/8b2c3a14603d163d7564e6f60286995079687690/core/java/com/android/internal/annotations/VisibleForTesting.java
Issue Analytics
- State:
- Created 9 years ago
- Comments:15 (4 by maintainers)
Top GitHub Comments
@eaftan Any chance we could get error-prone to support (check) the visibility field?
@jbduncan Thank you for your reply. I agree with you about this issue. I put the code here just as a reference, that means, we can use reflections implements that ,but It has it’s limitations.