Construct java_common with explicit fields (#388) `java_common` is currently the result of an unannotated factory. [sty](https://github.com/tamird/sty) loses its field types at that boundary: `java_common.BootClassPathInfo` becomes unknown instead of a provider key, and `java_common.compile` loses its callable signature. Construct the unconditional fields directly in `struct(...)` and collect conditional fields in a helper. The field values, conditions, and evaluation order are preserved. A downstream sty check now resolves the provider key and callable signature. Prepared with OpenAI Codex. Closes #388 COPYBARA_INTEGRATE_REVIEW=https://github.com/bazelbuild/rules_java/pull/388 from tamird:codex/sty-ratchet-java-common-fields ddd484a4dc5e46879bca1df691f6648fa274d63d PiperOrigin-RevId: 1033360418 Change-Id: I42811aa436dca932577afaec76c993d6692e1589
diff --git a/java/private/java_common.bzl b/java/private/java_common.bzl index 120d7fc..40dabc8 100644 --- a/java/private/java_common.bzl +++ b/java/private/java_common.bzl
@@ -302,34 +302,35 @@ get_internal_java_common().check_provider_instances([java_toolchain], "java_toolchain", JavaToolchainInfo) return java_toolchain.label -def _make_java_common(): - methods = { - "provider": JavaInfo, - "compile": _compile, - "compile_header": _compile_header, - "run_ijar": _run_ijar, - "stamp_jar": _stamp_jar, - "pack_sources": _pack_sources, - "default_javac_opts": _default_javac_opts, - "default_javac_opts_depset": _default_javac_opts_depset, - "merge": _merge, - "JavaPluginInfo": JavaPluginInfo, - "JavaToolchainInfo": JavaToolchainInfo, - "JavaRuntimeInfo": JavaRuntimeInfo, - "BootClassPathInfo": BootClassPathInfo, - "JavaRuntimeClasspathInfo": JavaRuntimeClasspathInfo, - } +def _conditional_java_common_fields(): + fields = {} if get_internal_java_common().google_legacy_api_enabled(): - methods.update( + fields.update( MessageBundleInfo = _get_message_bundle_info(), # struct field that is None in bazel get_constraints = _get_constraints, set_annotation_processing = _set_annotation_processing, java_toolchain_label = _java_toolchain_label, ) if semantics.IS_BAZEL: - methods.update( + fields.update( make_non_strict = _make_non_strict, ) - return struct(**methods) + return fields -java_common = _make_java_common() +java_common = struct( + provider = JavaInfo, + compile = _compile, + compile_header = _compile_header, + run_ijar = _run_ijar, + stamp_jar = _stamp_jar, + pack_sources = _pack_sources, + default_javac_opts = _default_javac_opts, + default_javac_opts_depset = _default_javac_opts_depset, + merge = _merge, + JavaPluginInfo = JavaPluginInfo, + JavaToolchainInfo = JavaToolchainInfo, + JavaRuntimeInfo = JavaRuntimeInfo, + BootClassPathInfo = BootClassPathInfo, + JavaRuntimeClasspathInfo = JavaRuntimeClasspathInfo, + **_conditional_java_common_fields() +)