Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IntelliJ Idea: How to automatically remove commented out code?

I've run SonarQube analysis on my Android/Java project and it resulted, among others, with issues:

Sections of code should not be "commented out"

If SonarQube is able to identify them, is it possible to automatically commented out code in Android Studio? I can't just remove all comments, because there are also some that are legit.

I have 500+ of them and don't want to do it manually. Any ideas?

like image 505
Zbigniew Malinowski Avatar asked Dec 04 '15 13:12

Zbigniew Malinowski


People also ask

How do I add a comment to an IntelliJ code?

IntelliJ IDEA To create a line comment, do the following: Place the cursor on a line of code . Select Code→Comment with Line Comment ... Select Code→Comment with Block Comment again in order to uncomment a block of code . MyFirstCIass.java Created IDEA. User: bburd Date: 7/14/12

How do I complete code in IntelliJ IDEA?

By default, IntelliJ IDEA displays the code completion popup automatically as you type. If automatic completion is disabled, press Ctrl+Shift+Space or choose Code | Code Completion | Type-Matching from the main menu. If necessary, press Ctrl+Shift+Space once again. This lets you complete:

How do I delegate behavior in IntelliJ IDEA?

IntelliJ IDEA can generate methods that delegate behavior to the fields or methods of your class. This approach makes it possible to give access to the data of a field or method without directly exposing this field or method. On the Code menu, click Generate Alt+Insert.

How do I narrow down the suggestions list in IntelliJ IDEA?

You can narrow down the suggestions list by typing any part of a word (even characters from somewhere in the middle) or invoking code completion after a dot separator. IntelliJ IDEA will show suggestions that include the characters you've entered in any positions.


1 Answers

There is no general solution for issues reported by SonarQube since SonarQube only finds problems, it doesn't offer a way to fix them.

In this particular case of commented out code, the same check is available directly in IntelliJ.

  • from the menu, select "Code | Analyze Code | Run Inspection by Name"
  • type "commented" to select the inspection about commented code
  • run it on the whole project

This inspection now lists the occurrences, and the Problems tool window offers you to fix all of them at once.

like image 91
Roland Illig Avatar answered Sep 27 '22 19:09

Roland Illig