sunxin8086
sunxin8086

Reputation: 565

How to remove all unnecessary semicolons (at end of blocks)?

Some of our code written a while have unnecessary semi-colon. I wonder whats the easiest way to remove them. For example, the last semi-colon in the following

 if(i == 2)
   {
       System.out.println("if statement");
   }
   else
   {
       System.out.println("else statement");
   };

Upvotes: 4

Views: 5424

Answers (4)

Rodolfo Becerra
Rodolfo Becerra

Reputation: 1

It may be too late for you but this could help others:

CTRL + F

write what you want to delete in your case ; and then:

CTRL + ALT + SHIFT + J

This will select all the matches for your search in that file.

Then you just have to delete DELETE

Upvotes: 0

opticyclic
opticyclic

Reputation: 8116

It is probably too late for you but, you can Analyze your code with Intellij IDEA using the Inspection "Unnecessary semi-colon" then after it has found them all you can apply the Fix.

http://www.jetbrains.com/idea/documentation/inspections.jsp

Eclipse can also do this too but it suffers from a bug that doesn't allow you to apply the Quick Fix in bulk.

Upvotes: 5

Matt
Matt

Reputation: 95

As the above said, by typing ctrl + f and searching for }; and replacing it with } would work great, but could break the code.

They are not necessary to be removed, as it is just the equivalent of:

if(true){
  //...
}
/*Empty Line*/;

It won't effect the code in any way, but is best to remove them just for preference.

Upvotes: 0

Jon Skeet
Jon Skeet

Reputation: 1500665

You can find them easily enough by going into the Java Compiler / Error and Warnings preferences, then under "Potential Programming Problems" change "Empty Statements" to warning or error. Then it'll just be a matter of going through them. There may be a way of automating it, but I wouldn't bother unless there are loads :)

Upvotes: 7

Related Questions