leibnitz27 / cfr

This is the public repository for the CFR Java decompiler
https://www.benf.org/other/cfr
MIT License
1.93k stars 249 forks source link

CFR omits parentheses in expressions with mixed operators #352

Open DecompExplorer opened 5 months ago

DecompExplorer commented 5 months ago

I've found that CFR chooses to omit parentheses in expressions with mixed operators, which may have a negative impact on the code readability and understandability. I think that using parentheses explicitly, especially in the ones with mixed operators might be a helpful improvement. It matches 10.5.1 Parentheses in https://www.oracle.com/java/technologies/javase/codeconventions-contents.html .

Here is an example:

The following code snippet is from org/apache/commons/imaging/common/mylzw/MyBitInputStream.java in the project commons-imaging (commit:92440e4206a12ffd455def326c181058b53b6681):

if (byteOrder == ByteOrder.BIG_ENDIAN) {
    sample = sampleMask & (bitCache >> (bitsInCache - sampleBits));
} else {
    sample = sampleMask & bitCache;
    bitCache >>= sampleBits;
}

The corresponding code generated by CFR:

if (this.byteOrder == ByteOrder.BIG_ENDIAN) {
    sample = sampleMask & this.bitCache >> this.bitsInCache - sampleBits;
} else {
    sample = sampleMask & this.bitCache;
    this.bitCache >>= sampleBits;
}

Parentheses conventionally serve the purpose of aiding readers in deducing the proper execution order of a given expression. The absence of such parentheses can potentially lead to confusion for readers. As we can see, the original code that makes use of the parentheses brings about relatively more clear meaning. While the code generated by CFR omits the parentheses, resulting in a reduction in both code readability and understandability.

The corresponding .class file can be found here

DecompExplorer commented 1 month ago

Hi, is there any progress?