Add this. to member variables/methods in IntelliJ Idea

前端 未结 4 1542
死守一世寂寞
死守一世寂寞 2021-01-01 12:46

Is there a way in IntelliJ Idea to force this. to be automatically placed into code on a format or save or at the very least show an error if it should be in there?

4条回答
  •  耶瑟儿~
    2021-01-01 13:15

    You can turn on the following inspections:

    • File > Settings > [Project Settings] > Inspections > Code Style Issues >
      • "Instance method call not qualified with 'this'"
      • "Instance fields access not qualified with 'this'"

    That will highlight any missing 'this.' declarations. With your cursor on the highlight, Alt+Enter will bring up the quick fix to add 'this". If on that initial pop-up you arrow to the right, You can select the "Fix All "Instance Method call not qualified with 'this'" problems" option to fix all issues in the current file. (you'll need to do this for both methods and fields)

    If you run the inspection on the project - either by the Analyze > Inspect Code... or by the Analyze > Run Inspection by Name... option you can then apply the fix to all files in the project (or module or package, etc.)

    There is no way to get the quick fix to occur on a reformat.

提交回复
热议问题