-4

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

rinilnath
  • 136
  • 2
  • 15

1 Answers1

0

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.

Davide Lorenzo MARINO
  • 26,420
  • 4
  • 39
  • 56
  • 3
    I see what you mean, but this is just nitpicking on the meaning of the word "refactoring" (which I approve but I would better see addressed as a comment). Per @PeterLawrey comment this is an existing functionality in IntelliJ, so it *is* possible. – Federico klez Culloca Jun 26 '18 at 13:05
  • @FedericoklezCulloca As reported by PeterLawrey it is an autofix, is not a refactoring. – Davide Lorenzo MARINO Jun 26 '18 at 14:28
  • My point stands, I think. You can correct OP as much as you like, but it's clear what's being asked. – Federico klez Culloca Jun 26 '18 at 14:29
  • Thanks for your replies, i actually meant to know if there is any plugins available to integrate with RSA IDE that automatically helps developer to make a bulk change across classes to implement java coding standards for some out of standard coding methods. – rinilnath Dec 16 '18 at 16:50
  • @DavideLorenzoMARINO, Thanks for the edit, but that second condition is not always evaluated as "FALSE". do they ?The main aim of this refactor is only to avoid the NULL pointer, and the second condition will exactly avoid that nullpointerexception. Of course it is not IDE to auto convert but it can always be given as a suggestion by IDE that it is up to users based on the need – rinilnath Dec 23 '21 at 05:23