Thanks to visit codestin.com
Credit goes to github.com

Skip to content

CFR omits parentheses in expressions with mixed operators #352

@DecompExplorer

Description

@DecompExplorer

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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions