kevinmost
02/14/2019, 7:39 PM@JvmBuilder
compiler plugin in the stdlib + Kotlin IntelliJ plugin that would generate synthetic members to make builders on `data class`es for use in Java. Using `data class`es with many properties is currently pretty clunky in Java.
For example:
@JvmBuilder
data class Foo(val bar: String, val baz: Int = 0, val qux: String? = null)
should generate Foo.builder()
that returns an object like:
public final class FooBuilder {
public static FooBuilder builder() {
return new FooBuilder().baz(0).qux(null);
}
// fields...
public FooBuilder bar(String bar) { ... }
public FooBuilder baz(int baz) { ... }
public FooBuilder qux(@Nullable String qux) { ... }
public Foo build() {
// assert that properties with no default value were set
}
}
xenoterracide
02/14/2019, 7:41 PMkevinmost
02/14/2019, 8:02 PMpublic abstract
everywhere)
3) Default values and optional values are hard to express in AutoValue. You put all the defaults into the .builder()
method, not next to the property itself, so it's a lot of jumping aroundkevinmost
02/14/2019, 8:03 PM@AutoValue
classes in Kotlin is less painful than using `data class`es in Java. But writing @AutoValue
classes is very painful compared to writing `data class`esxenoterracide
02/14/2019, 8:08 PMxenoterracide
02/14/2019, 8:08 PMxenoterracide
02/14/2019, 8:08 PMjw
02/14/2019, 8:29 PMjw
02/14/2019, 8:33 PMkevinmost
02/14/2019, 8:36 PMkevinmost
02/14/2019, 8:38 PMxenoterracide
02/14/2019, 8:39 PMxenoterracide
02/14/2019, 8:39 PMkevinmost
02/14/2019, 8:40 PMkevinmost
02/14/2019, 8:40 PMFoo(bar = "str1", baz = 2)
kevinmost
02/14/2019, 8:41 PM@Jvm___
annotations, this is an enhancement for Java, not for Kotlin. In mixed codebases, you either have to make the decision to keep your data classes in Java, or convert them to Kotlin and force Java consumers to call constructors with 10+ parameters (comma-separated, with no named param support, as you said)kevinmost
02/14/2019, 8:41 PMFoo
class in Java, it would be new Foo("str1", 2, null);
. That's unclear (and requires duplication of the null
for qux
, which could be error-prone if we changed the default value of qux
in the future)kevinmost
02/14/2019, 8:42 PMFoo.builder().bar("str1").baz(2).build();
is way less error-pronexenoterracide
02/14/2019, 8:42 PMxenoterracide
02/14/2019, 8:42 PMkevinmost
02/14/2019, 8:43 PMxenoterracide
02/14/2019, 8:43 PMxenoterracide
02/14/2019, 8:43 PMxenoterracide
02/14/2019, 8:46 PMjw
02/14/2019, 8:47 PMbuilder { }
where I could put logic in a mutation/construction operationkevinmost
02/14/2019, 8:48 PMkevinmost
02/14/2019, 8:49 PMbuilder {
bar = computeFoo()
baz = bar.length()
}
xenoterracide
02/14/2019, 8:50 PMxenoterracide
02/14/2019, 8:51 PMelizarov
02/15/2019, 12:28 PMkevinmost
02/15/2019, 5:43 PM@Parcelize
is implemented.
Is the Kotlin team discouraging the addition of new compiler plugins using the currently bytecode-generation approach? I know IR is the future of compiler plugins and that the team is working hard on that, but it doesn't seem like there's a clear timeline for it. And I know that there's work going on for other compiler plugins at the moment (like the cross-platform serialization plugin). Not sure if you're targeting that for IR or bytecode+JS+LLVM generation thoughkevinmost
02/15/2019, 5:45 PMelizarov
02/16/2019, 12:49 PMkevinmost
02/16/2019, 5:32 PMelizarov
02/16/2019, 8:31 PMjw
02/17/2019, 5:12 AMelizarov
02/17/2019, 11:18 AMkevinmost
02/17/2019, 7:22 PMkevinmost
02/19/2019, 6:01 PMIrGenerationExtension
(which isn't the Kotlin IR in question here, but LLVM IR, right?)