apple / pkl

A configuration as code language with rich validation and tooling.
https://pkl-lang.org
Apache License 2.0
10.38k stars 280 forks source link

codegen-java: Support generating @Nullable annotations #811

Open translatenix opened 1 week ago

translatenix commented 1 week ago

Motivation: codegen-java already supports generating @NonNull annotations. However, many projects prefer @Nullable over @NonNull annotations. JSpecify also recommends @Nullable.

Changes:

As part of this feature, I propose to also make the following changes:

Open question: @Nullable must be accompanied by @NullMarked (JSpecify) or @NonnullByDefault (JSR 305). I can think of two ways to go about this:

  1. Introduce --null-marked-annotation and annotate config classes accordingly. This is the most consistent solution, but it requires yet another CLI parameter and property. It can be made more convenient by inferring the correct annotation based on --nullable-annotation and --non-null-annotation for popular libraries such as JSpecify and JSR 305.
  2. Leave it to users to add a package-info.java with a @NullMarked annotation. This is a clean and simple solution. However, it is less convenient than (1). It could, in theory, cause problems if users compile generated and handwritten code separately and don't have a place where to put package-info.java.

Final thought: The Java ecosystem is converging on JSpecify. For many users, the best option would be --generate-jspecify-annotations.