piranha icon indicating copy to clipboard operation
piranha copied to clipboard

PiranhaJava - Doesn't add required space while removing parentheses

Open pranavsb opened this issue 4 years ago • 6 comments

Piranha changed return(true); to returntrue;. This is sort of related to #35 - in the sense that PiranhaJava doesn't validate the parens/spaces of the output generated.

This error probably would not have occured if the code had been Google Java formatted.

However, I thought I will bring it to your attention, since this is a case of Piranha introducing a "bug" instead of erring on the side of caution, like #35

pranavsb avatar May 14 '20 15:05 pranavsb

Thanks for the report! Seems like we should either fix this bug or document that we assume proper (GJF) formatting

msridhar avatar May 14 '20 16:05 msridhar

@pranavsb can you please provide the input source code to replicate this.

swayamraina avatar Jun 22 '20 13:06 swayamraina

Hi @swayamraina

Just use a dummy method with the given statement. Like this:

public boolean someMethod() {
     return(true);
}

It's not necessary to add someMethod to Piranha config.

Btw, Piranha also simplifies if(true) by default, with no config.

pranavsb avatar Jun 23 '20 07:06 pranavsb

@mkr-plse IMO it would be better to remove all constant returning methods and substitute the values to variables. But i believe this would require to build the multi-pass layer (https://github.com/uber/piranha/issues/58)

Till then we can fix this issue by checking spacing before doing any fixes. Thoughts?

swayamraina avatar Jun 23 '20 09:06 swayamraina

  1. I think Piranha should discard refactoring code related to existing boolean constants, unless specified as an input option.
  2. If the input option is specified and the boolean constant is assigned or returned from a method, in the short term, code need not be updated.
  3. Long term, this will be resolved with #58.

I don't think the spacing should be updated here because the match will fail due to the presence of a boolean constant.

mkr-plse avatar Jun 23 '20 12:06 mkr-plse

agreed. But this isaue is valid when the app is passed through piranha multiple times.

on first pass, piranha reduces the feature flag in a method to a method that returns true (reducing to the above code) or false. on second pass, piranha resuces the above code to produce an output which produces compilation error.

swayamraina avatar Jun 23 '20 14:06 swayamraina