Code refactoring plugins equivalent to Intentions of Jetbrains Idea for Eclipse

429 Views Asked by At

Are there any plugins in eclipse based IDEs which can suggest a better way to refactor any particular statement (in Java), for example

Let's say you have the following code:

if ( someString.equals("whatImLookingFor") ) {
}

The plugin should offer to flip the equals to:

if ( "whatImLookingFor".equals( someString ) ) {
}

Such that, this helps in enforcing better coding practices

As per the one of the suggestions given below by @Peter Lawrey, it was possible in IntelliJ Idea IDE through Flip Commutative Method call, which as I searched was part of Intentions Power Pack plugins from Jetbrains (back in 2004).

Is there any equivalent of this plugin in Eclipse ?

Version of IDE I searched for plugin is : IBM Rational Software Architect 9.6.1, but nothing relevant was found

1

There are 1 best solutions below

5
Davide Lorenzo MARINO On

No because as you told they are not equivalent.

Refactoring create a code with the same behaviour.

The refactored code must be equivalent to the original. In this case it is not, that happens for example because if someString is null the first condition

someString.equals("whatImLookingFor")

will generate a NullPointerException, while the second condition

"whatImLookingFor".equals( someString )

is evaluated to false. It is not the ide that could refactor a code in a code with a different behaviour also if the new behaviour can be considered a better code.