RFR: 7903132: Replace casts with type test pattern
Jorn Vernee
jvernee at openjdk.java.net
Fri Mar 25 16:22:35 UTC 2022
On Thu, 24 Mar 2022 22:48:41 GMT, Ethan McCue <duke at openjdk.java.net> wrote:
> Replaces a handful of casts following type tests with the equivalent pattern syntax.
>
> I cannot create a matching issue, as I do not have an account on the bug tracker.
I've filed an issue for this PR here: https://bugs.openjdk.java.net/browse/CODETOOLS-7903132 Please update the PR title to include the issue number.
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.
src/main/java/org/openjdk/jextract/impl/ClassSourceBuilder.java line 59:
> 57: ClassSourceBuilder(JavaSourceBuilder enclosing, Kind kind, String name) {
> 58: this.enclosing = enclosing;
> 59: this.align = (enclosing instanceof ClassSourceBuilder enclosing) ? enclosing.align : 0;
This is resulting in a compilation error:
jextract\src\main\java\org\openjdk\jextract\impl\ClassSourceBuilder.java:59: error: variable enclosing is already defined in constructor ClassSourceBuilder(JavaSourceBuilder,Kind,String)
this.align = (enclosing instanceof ClassSourceBuilder enclosing) ? enclosing.align : 0;
Please build and test the patch locally on your machine as well, if you haven't done so already. (This should be done before suggesting changes).
-------------
PR: https://git.openjdk.java.net/jextract/pull/5
More information about the jextract-dev
mailing list