RFR: 7903132: Replace casts with type test pattern

Jorn Vernee jvernee at openjdk.java.net
Fri Mar 25 16:22:35 UTC 2022


On Fri, 25 Mar 2022 15:39:18 GMT, Ethan McCue <duke at openjdk.java.net> wrote:

>> src/main/java/org/openjdk/jextract/clang/Cursor.java line 243:
>> 
>>> 241:             return false;
>>> 242:         }
>>> 243:         return (Index_h.clang_equalCursors(cursor, otherCursor.cursor) != 0);
>> 
>> I think in these cases we can do better by merging the `instanceof` check above this in the condition. i.e.
>> Suggestion:
>> 
>>         return other instanceof Cursor otherCursor
>>             && (Index_h.clang_equalCursors(cursor, otherCursor.cursor) != 0);
>> 
>> 
>> And similar for other places that are computing a boolean value, such as all the equals methods.
>
> Strictly speaking, the whole method body could be merged into one expression. Its the realm of infinite bikesheds though, and I did not / do not know if there is a set of implicit style choices there.

Well, we're on the topic of style changes already, so let's pull the string. This is new territory, so I think this is where we decide this :)

Merging the `instanceof` into the expression avoids having the pattern variable be carried over to outside of the `if` block, which I think is better.

The `this == other` check above that doesn't have the same problem.

-------------

PR: https://git.openjdk.java.net/jextract/pull/5


More information about the jextract-dev mailing list