Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom Lint Rule: how to handle fix button click

I followed this tutorial and it worked perfect for me. Now I want to add fix issue functionality. I am using Eclipse.

In Lint Warnings view we have Fix button, can I handle it?

For example when we have hard coded string (android:text="Test") in TextView when you click CTRL + 1, help pop up opens with possibility to Extract String. What I am trying to do is to add extract hard coded dp values functionality.

Also it would be great if you could point me where I could find source code of already implemented lint issues.

Thank You.

like image 826
Dmytro Danylyk Avatar asked Oct 07 '22 00:10

Dmytro Danylyk


2 Answers

Lint checks can be written standalone:

  • Writing a Lint check: http://tools.android.com/tips/lint/writing-a-lint-check
  • Lint checks source: https://android.googlesource.com/platform/tools/base/+/master/lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks

Lint fixes are part of the ADT pluggin: http://tools.android.com/tips/lint

Lint is integrated with ADT 16 and later. The integration offers a few features above the command line version of lint:

  • Automatic fixes for many warnings
  • Lint gets run automatically on various editing operations
  • Ability to suppress types of errors as well as specific instances of an error
  • Ability to configure issue severities
  • Jump directly to the problem source from the lint view
like image 67
Tanner Perrien Avatar answered Oct 10 '22 02:10

Tanner Perrien


Consider making a plugin for your Custom lint check in IntelliJ Idea Community edition, downloaded from https://www.jetbrains.com/idea/download/, and follow the tutorial at http://www.jetbrains.org/intellij/sdk/docs/index.html.

After then you will come to know that to handle light bulb for the fix of your custom Lint warning you have to extend the IntentionAction class particularly.

And then search for deploying the plugin in the tutorial and finally you will come to know to put the jar of the plugin thus created in the Android Studio/Contents/plugins folder.

like image 29
Yash_Singhal Avatar answered Oct 10 '22 02:10

Yash_Singhal