Open lppedd opened 4 years ago
Thanks for reporting! I will find time to check Java 14 (including records) next week and will report in this issue 👍
@bsideup That's how they get compiled using JDK 14 😄
Pattern matching:
final Object v = "";
if (v instanceof String s) {
System.out.println(s);
}
is compiled into
Object v = "";
String s;
if (v instanceof String && (s = (String)v) == (String)v) {
System.out.println(s);
}
Record
public record Range(int lo, int hi) {
public Range {
if (lo > hi) {
throw new IllegalArgumentException(String.format("%d, %d", lo, hi));
}
}
}
is compiled into
public final class Range extends java.lang.Record {
private final int lo;
private final int hi;
public Range(int lo, int hi) { /* compiled code */ }
public java.lang.String toString() { /* compiled code */ }
public final int hashCode() { /* compiled code */ }
public final boolean equals(java.lang.Object o) { /* compiled code */ }
public int lo() { /* compiled code */ }
public int hi() { /* compiled code */ }
}
@bsideup it seems to use your plugin we'll have to wait the non-EA version of JDK 14.
Can't target class level 52 with enable-preview
(to have access to records)
@lppedd with Jabel, you don't need to enable preview features. Pattern matching is supported in master
already, records will follow soon
@bsideup I was testing with a clone of the project by enabling the RECORDS
feature and using JDK 14. It seems that to have access to the Record
base-class one must enable preview features.
unlike other features, Records require some pre/post processing, so you can't just "enable" them. I have a working prototype (see the screenshot here: https://twitter.com/bsideup/status/1233696266653249537 ), will submit a PR as soon as I feel confident about it.
@bsideup oh that's good to know! Thanks a lot!
See #16
@bsideup thanks! Awesome work. 😁 Now I think a semi blocking issue is #9
@lppedd you should not enable preview features with Jabel.
@bsideup but if I don't enable them on Gradle build it will conflict with idea language settings
@lppedd I just pushed a commit that explains how to configure IDEA & Gradle: https://github.com/bsideup/jabel/pull/16/commits/099fdb88e6f81a9d16fe8908fd5bf6e74728f68b
@bsideup interesting! I'll give it a try, thanks!
@bsideup works! Although it seems command line and IDEA have different behaviors.
@lppedd you're right! I've changed it again, now it should work fine :)
@bsideup works nicely now :) What's the magic here?
@bsideup it compiles, but as soon as you start using preview features it complains :(.
@lppedd make sure you have everything configured correctly. I just tried running the example project and it works fine: https://github.com/bsideup/jabel/tree/records/example
There is no magic, just we set it so that IDEA thinks that we're using preview features, but later, when the task gets executed, we remove the flag since we don't need it
@bsideup my fault, I wanted to write manually instead of copy pasting and I was missing a -
...
Works ;)
@bsideup with IDEA it's useful to add options.fork = true
to the compileJava
task, to allow the agent to attach even during debug sessions. See https://youtrack.jetbrains.com/issue/IDEA-235411
Hi!
Can't get it to work. Maybe, the problem with the dependency.
I tried to use the latest master commit because 0.2.0
version doesn't contain Java14's instanceof.
annotationProcessor 'com.github.bsideup:jabel:ed36f1882a14263881d0318581b752e38b504ee9'
But it didn't work.
annotationProcessor 'com.github.bsideup.jabel:jabel-javac-plugin:0.2.0'
And this doesn't work either for me, the same error.
Commenting out this dependency shows the different problem, this time about the compilation:
I can confirm that it works with both records and pattern matching. Kudos @bsideup ! The only problem I had is that jitpack is not keeping those branch-artifacts around for long. Please merge and create a new release. Thanks! I'd be happy to contribute the updated README.md for Maven, then.
In the meanwhile, I forked the project and created a pre-release. Feel free to use: https://jitpack.io/#Treehopper/jabel/0.3.0-records (artifact version is still 0.2.0 - because I am lazy and this is only meant as a temporary workaround)
@Treehopper thanks for trying it! I will finish the branch and merge it hopefully soon, so that you don't need to build it from branch anymore. Sorry that it took so long, non-sideproject work has stolen most of my time recently, but it is getting better :)
Looking forward to it! Hope #30 makes wrapping it up a bit easier. I could also add something for @Desugar. Let me know.
FYI Jabel 0.3.0 adds support for the pattern matching (the records are still WIP)
Hi! This plugin should already support pattern matching, we just need to wait for a Gradle release which supports JDK 14 😄 Opened issue so it can be seen by others and closed when it's tested.