RFR: 7903132: Replace casts with type test pattern
Ethan McCue
duke at openjdk.java.net
Fri Mar 25 16:22:35 UTC 2022
On Fri, 25 Mar 2022 15:04:05 GMT, Jorn Vernee <jvernee at openjdk.org> 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.
>
> 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.
> 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).
So yes, 100% on me. But in my defense I am getting a particularly obtuse error before compilation and there isn't exactly someone to ask without pretense.
$ /usr/bin/clang --version
Apple clang version 13.1.6 (clang-1316.0.21.2)
Target: arm64-apple-darwin21.3.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
---------------------
$ sh ./gradlew -Pjdk18_home=/Users/emccue/Library/Java/JavaVirtualMachines/openjdk-18/Contents/Home clean verify
FAILURE: Build failed with an exception.
* Where:
Build file '/Users/emccue/Development/jextract/build.gradle' line: 13
* What went wrong:
A problem occurred evaluating root project 'jextract'.
> Could not get unknown property 'libclang_home' for root project 'jextract' of type org.gradle.api.Project.
* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 297ms
---------------------
$ sh ./gradlew -Pjdk18_home=/Users/emccue/Library/Java/JavaVirtualMachines/openjdk-18/Contents/Home -Plibclang_home=/usr/bin/clang clean verify
FAILURE: Build failed with an exception.
* Where:
Build file '/Users/emccue/Development/jextract/build.gradle' line: 14
* What went wrong:
A problem occurred evaluating root project 'jextract'.
> Cannot invoke method getAt() on null object
* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 287ms
---------------------
$ sh ./gradlew -Pjdk18_home=/Users/emccue/Library/Java/JavaVirtualMachines/openjdk-18/Contents/Home -Plibclang_home=/usr/bin/ clean verify
FAILURE: Build failed with an exception.
* Where:
Build file '/Users/emccue/Development/jextract/build.gradle' line: 14
* What went wrong:
A problem occurred evaluating root project 'jextract'.
> Cannot invoke method getAt() on null object
* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 290ms
-------------
PR: https://git.openjdk.java.net/jextract/pull/5
More information about the jextract-dev
mailing list