"Calculator"-quickfix

Is there a quickfix which can convert

foo(1 + 2, 3 + 4 * 5);

to

foo(3, 23);

Thanks in advance.

Tom

6 comments

I don't think any exists, but if you compute the value like this, I believe it's better to keep the computation in place (for clarity purposes).

What I would do is create constants
public static int MY_CONSTANT = 1+2;

and use those in your code, this way you have both the explanation of the value, and the optimization (not computing it every time)

0

Hello Tom,

AFAIK, there's a "Compute constant value" intention available on each operator sign.

Sascha

0

Thanks. I was searching the inspection profile for "constant" or "math" but
could not find one. But clicking Alt+Enter on the operator shows the
quickfix - weird.

Tom

0

I've inlined a constant ...

0

It is not a quick fix but an intention. You can find it in the intention
setings.

Bas

Tom wrote:

Thanks. I was searching the inspection profile for "constant" or "math" but
could not find one. But clicking Alt+Enter on the operator shows the
quickfix - weird.

Tom

0

Thanks (again). Did not know intentions and inspections were separate things.

Tom

0

Please sign in to leave a comment.