Repository: apple/pkl
File: pkl-codegen-java/src/main/kotlin/org/pkl/codegen/java/JavaCodeGenerator.kt (Kotlin)

Code before:
          // (potential improvement: make type available for direct injection if it occurs exactly
          // once in property tree)
          builder.addAnnotation(
            AnnotationSpec.builder(
                ClassName.get(
                  "org.springframework.boot.context.properties",
                  "ConfigurationProperties"
                )
              )
              // use "value" instead of "prefix" to entice JavaPoet to generate a single-line
              // annotation
              // that can easily be filtered out by JavaCodeGeneratorTest.`spring boot config`
              .addMember("value", "\$S", modulePropertiesWithMatchingType.first().simpleName)
              .build()
          )
        }
      }
    }

    @Suppress("DuplicatedCode")
    fun generateClass(): TypeSpec.Builder {
      val builder =
        TypeSpec.classBuilder(javaPoetClassName.simpleName()).addModifiers(Modifier.PUBLIC)

      // stateless classes aren't instantiable by choice, i.e., no public ctor is generated
      val isInstantiable = !pClass.isAbstract && allProperties.isNotEmpty()

      if (codegenOptions.implementSerializable && isInstantiable) {
        builder.addSuperinterface(java.io.Serializable::class.java)
        builder.addField(generateSerialVersionUIDField())
      }

      val docComment = pClass.docComment
      val hasJavadoc = docComment != null && codegenOptions.generateJavadoc
      if (hasJavadoc) {
        builder.addJavadoc(renderAsJavadoc(docComment!!))
      }

      generateDeprecation(
        pClass.annotations,
        hasJavadoc,
        { builder.addAnnotation(it) },
        { builder.addJavadoc(it) }
      )

      if (!isModuleClass) {
        builder.addModifiers(Modifier.STATIC)
      }

      if (pClass.isAbstract) {
        builder.addModifiers(Modifier.ABSTRACT)

Review comment (refactor):
We should let empty modules to be instantiable too, unless I'm missing something obvious here?

```suggestion
      val isInstantiable = !pClass.isAbstract;
```

Code after:
          // (potential improvement: make type available for direct injection if it occurs exactly
          // once in property tree)
          builder.addAnnotation(
            AnnotationSpec.builder(
                ClassName.get(
                  "org.springframework.boot.context.properties",
                  "ConfigurationProperties"
                )
              )
              // use "value" instead of "prefix" to entice JavaPoet to generate a single-line
              // annotation
              // that can easily be filtered out by JavaCodeGeneratorTest.`spring boot config`
              .addMember("value", "\$S", modulePropertiesWithMatchingType.first().simpleName)
              .build()
          )
        }
      }
    }

    @Suppress("DuplicatedCode")
    fun generateClass(): TypeSpec.Builder {
      val builder =
        TypeSpec.classBuilder(javaPoetClassName.simpleName()).addModifiers(Modifier.PUBLIC)

      // stateless final module classes are non-instantiable by choice
      val isInstantiable =
        !(pClass.isAbstract || (isModuleClass && !pClass.isOpen && allProperties.isEmpty()))

      if (codegenOptions.implementSerializable && isInstantiable) {
        builder.addSuperinterface(java.io.Serializable::class.java)
        builder.addField(generateSerialVersionUIDField())
      }

      val docComment = pClass.docComment
      val hasJavadoc = docComment != null && codegenOptions.generateJavadoc
      if (hasJavadoc) {
        builder.addJavadoc(renderAsJavadoc(docComment!!))
      }

      generateDeprecation(
        pClass.annotations,
        hasJavadoc,
        { builder.addAnnotation(it) },
        { builder.addJavadoc(it) }
      )

      if (!isModuleClass) {
        builder.addModifiers(Modifier.STATIC)
      }

      if (pClass.isAbstract) {