Expand description
IDL4 → Java 17 source codegen (OMG IDL4-Java mapping v1.0).
Crate zerodds-idl-java — Java language bindings, cluster C5.4-a (foundation)
plus C5.4-b (bitset/bitmask, multi-inheritance, annotation bridge,
TopicType marker).
Safety classification: SAFE (std-only). A pure build-time tool —
forbid(unsafe_code), no no_std use case.
§Scope (C5.4-a)
- Block A: header layout (
package, class modifiers, FQN imports). - Block B: primitive mapping (boolean → boolean, octet → byte, …, incl. unsigned workaround per spec §6).
- Block C: struct → public class (bean pattern), enum, union →
sealed interface + case records, typedef → wrapper class,
sequence →
java.util.List<T>, array → Java array, single inheritance →extends. - Block D: Exception →
class X extends RuntimeException.
§Java version targets
The standard emit targets Java 17: unions use a sealed interface with record case types. Structs/enums/typedefs are bean
classes and thus version-neutral.
The opt-in Java-8 compat mode (JavaGenOptions::java8_compat)
avoids all Java-9+ constructs: unions are instead emitted as an
abstract class with a private constructor (pseudo-sealing) +
static final subclasses (final field + constructor + same-named
accessor). Everything else is identical in both modes.
§Scope (C5.4-b — Cluster E)
- Bitmask → wrapper class with an inner enum
FlagandEnumSet<Flag> bits(spec idl4-java-1.0 §6.3). - Bitset (≤ 64 bits cumulative) → wrapper class with
long bitsand mask/shift accessors per bitfield. > 64 bits → hard errorerror::JavaGenError::UnsupportedConstruct. - Multi-inheritance via an interface pattern: every struct that is itself
the base of another struct gets a
<Name>Interface.javacompanion. Sub-sub-classes useextends DirectBase implements GrandparentInterface, .... @value(N)on enum members → an explicitintconstructor value instead of the auto ordinal.- Annotation bridge:
@key,@id(N),@optional,@must_understand,@external,@nested,@extensibility(...)→ Java annotations underorg.zerodds.types.*(seeruntime/). - DDS Java PSM stub: every top-level
structwithout@nestedimplementsorg.omg.dds.topic.TopicType<SelfType>.
§Deliberately not in the crate
- Clusters F-H: ServiceEnvironment SPI, Time/Duration/Status/QoS/ listener codegen (C5.5).
- Reflection-based TypeRep (java-psm §8) — a stretch goal.
interface,valuetype,fixed,any,map<K,V>→ come withzerodds-rpc-java.
§Multi-file output
Java requires one .java file per top-level public class.
Therefore generate_java_files returns a Vec<JavaFile>; each
JavaFile has a package path + class name + source.
§Example
use zerodds_idl::config::ParserConfig;
use zerodds_idl_java::{generate_java_files, JavaGenOptions};
let ast = zerodds_idl::parse(
"module M { struct S { long x; }; };",
&ParserConfig::default(),
)
.expect("parse");
let files = generate_java_files(&ast, &JavaGenOptions::default()).expect("gen");
// POJO + TypeSupport (zerodds-xcdr2-java-1.0 §4).
assert_eq!(files.len(), 2);
let pojo = files.iter().find(|f| f.class_name == "S").expect("POJO");
assert!(pojo.source.contains("package m;"));
assert!(pojo.source.contains("public class S"));
assert!(files.iter().any(|f| f.class_name == "STypeSupport"));Re-exports§
pub use emitter::JavaFile;pub use error::JavaGenError;
Modules§
- emitter
- AST walker that emits Java 17 source files.
- error
- Error types for the IDL→Java codegen.
- keywords
- Java-17 keywords (incl. restricted identifiers like
record,sealed,var,yield). - rpc
- IDL service → Java RPC codegen (DDS-RPC 1.0 §7.11.2 — Java PSM).
- type_
map - Mapping of IDL primitives to Java type strings.
Structs§
- Java
GenOptions - Configuration of the Java code generator.
Functions§
- generate_
java_ files - Produces a list of Java source files from an IDL specification.
- generate_
java_ files_ with_ amqp - Convenience variant with the
emit_amqp_helpersflag enabled. - generate_
java_ files_ with_ corba_ traits - Convenience variant with the
emit_corba_traitsflag enabled.