ffi #jni_main slice 1: Java source emitter (pure fn + unit tests)

`src/ir/jni_java_emit.zig`'s `emitJavaSource` takes a
`ForeignClassDecl` with `is_main = true` and returns the `.java`
source text. AOT pipeline integration (javac + d8 + APK bundling +
manifest synthesis + RegisterNatives) lands in subsequent slices.

Emission shape per bodied method:

    @Override
    public <ret> <name>(<params>) {
        super.<name>(<args>);
        sx_<name>(<args>);
    }
    private native <ret> sx_<name>(<params>);

Declaration-only methods (no body — references inherited Java
methods that sx wants to *call*) are skipped — no override, no
native delegate.

`#extends Alias` resolves through the supplied class registry to
the parent's foreign Java path. Default parent is
`android.app.NativeActivity` when `#extends` is absent.

Type matrix: primitives (void/bool/s8..s64/u8/u16/f32/f64), `*Self`
elided as the receiver (Java's implicit `this`), `*void` as
`Object`, `*Foo` cross-class refs resolved through the class
registry.

Six unit tests cover: non-main rejection, full void onCreate(Bundle)
shape with @Override delegate, primitive params, declaration-only
skipping, `#extends Alias` resolution, default-package classes.

130/130 examples still green; zig test clean.
This commit is contained in:
agra
2026-05-20 14:16:40 +03:00
parent 6a3260ff65
commit 7ea7ad778e
3 changed files with 506 additions and 0 deletions

View File

@@ -40,6 +40,7 @@ pub const resolveAstType = type_bridge.resolveAstType;
pub const bridgeType = type_bridge.bridgeType;
pub const jni_descriptor = @import("jni_descriptor.zig");
pub const jni_java_emit = @import("jni_java_emit.zig");
pub const types_tests = @import("types.test.zig");
pub const inst_tests = @import("inst.test.zig");
@@ -50,6 +51,7 @@ pub const lower_tests = @import("lower.test.zig");
pub const type_bridge_tests = @import("type_bridge.test.zig");
pub const emit_llvm_tests = @import("emit_llvm.test.zig");
pub const jni_descriptor_tests = @import("jni_descriptor.test.zig");
pub const jni_java_emit_tests = @import("jni_java_emit.test.zig");
test {
@import("std").testing.refAllDecls(@This());