-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update to support generate record from java 14 #981
base: master
Are you sure you want to change the base?
Conversation
I think it is the most desirable feature for javapoet, but unfortunately, the tool maintenance consists only of small fixes. PR #840 does the same, but still not merged. The future of javapoet is discussed here. You could use the FabricMC/javapoet fork If you want to use records |
dc02cf7
to
f10b510
Compare
+1 on this. In the mean time for those who dont want to use a fork, there is another workaround for inner records (not top-level). return MethodSpec.methodBuilder("Record__%sEvent".formatted(toTypeName(name)))
.addModifiers(Modifier.PUBLIC)
// .... This creates a try(
OutputStreamWriter outputStream = new OutputStreamWriter(sourceFile.openOutputStream());
StringWriter writer = new StringWriter()
) {
JavaFile.builder(element.getQualifiedName().toString(), result)
.indent(" ")
.build()
.writeTo(writer);
outputStream.write(writer.toString().replace("void Record__", "record "));
} Not the most elegant solution but it works. |
Is this likely to land at any point? Records are extremely nice, just like javapoet! |
I'm planning on publishing this as a separate repo. See here: https://github.com/Randgalt/java-composer. Unless @JakeWharton/Square objects. |
From square/javapoet#981 User: @zzBBc
From: square/javapoet#981 User: @zzBBc
From: square/javapoet#981 User: @zzBBc
FYI - I've released v 1.0 of Java Composer with this change in it as well as support for sealed classes: https://github.com/Randgalt/java-composer |
Motivation:
Modifications:
Can you please review and merge the PR @JakeWharton