Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I deprecate usage of specific class (not under our control) in Android Studio?

Does Android Studio's inspection feature contain some option to mark certain classes as deprecated?

I suppose that the inspection rules currently do not support parametrized inspections e.g. "Mark following classes as deprecated: _______" but is there another way to fix that?

I want to move away from class X (which is not under our control) and use class XExtended and would like to reliably ensure that in our codebase no-one uses X again. Since we do use inspections regularly, having an inspection which looks for certain classes mark them as warning or error would be very useful.

Search and replace is somewhat tedious and does not protect for new uses. I also cannot remove the library where X is located as it is part of the android sdk.

Edit: During refactoring we find all those old uses due to unit test failures but not everything is yet fully covered with tests, so there might be undetected issues.

like image 664
Samuel Avatar asked Jan 24 '26 21:01

Samuel


1 Answers

It is possible. I managed to do it with Android Studio 3.1.1. I marked a WebView class as deprecated as follows:

Deprecate class

Then whenever I try to use WebView it will display deprecated as follows: deprecated

Steps to deprecate:

  1. Click on the class which you want to deprecate.
  2. Yellow bulb icon will appear at left
  3. Expand it and click on Annotate class <Class> as @Deprecated

Through out the project, this class will be deprecated.

like image 116
Sagar Avatar answered Jan 26 '26 11:01

Sagar