Spring clean unused Methods & Local variables

We are happy to announce that jSparrow March release introduces two new rules for removing unused code and adds 10 jSparrow markers for existing rules.

Remove Unused Methods

This rule finds and removes method declarations that are never used. A dedicated configuration wizard allows users to choose the kind of methods they want to remove and how to handle the related test cases.

If users choose to remove private methods, the following class:

public class UnusedMethodsSample {

private void unusedPrivateMethod() {}

private void run() {

System.out.println(“Running…);

}

public static void main() {

UnusedMethodsSample instance = new UnusedMethodsSample();

instance.run();

}

}

Is transformed to:

public class UnusedMethodsSample {

private void run() {

System.out.println(“Running…);

}

public static void main() {

UnusedMethodsSample instance = new UnusedMethodsSample();

instance.run();

}

}

Remove Unused Local Variables

This rule finds declarations of local variables that are never used and removes them. Reassignments as well as increment and decrement operations are not counted as active usages. Any annotation except for @Deprecated and @SuppressWarnings prevents the local variable from being considered as unused.

As an example, the following code:

String usedLocalVariable = “”;

String unusedLocalVariable = “”;

BlackHole blackHole = new BlackHole();

blackHole.use(usedLocalVariable);

Is refactored to:

String usedLocalVariable = “”;

BlackHole blackHole = new BlackHole();

blackHole.use(usedLocalVariable);

More jSparrow Markers

Ten new markers for existing rules are added to jSparrow. Thus, brining the total number of jSparrow markers to 66.

jSparrow provides now a total of 111 automatic refactoring rules.

Find out more information in the Release Notes for jSparrow Eclipse and jSparrow Maven!

Deleted code is debugged code.” ― Jeff Sickel

Happy Coding!

Leave a Reply

Your email address will not be published. Required fields are marked *