Skip to content

codeanalyzer-java: L1 v2 tree emission #180

Description

@sinha108

Plan (optional)

Design spec: https://github.com/codellm-devkit/codeanalyzer-java/blob/main/docs/design/specs/schema-v2-l3-l4-design.md

Problem

The analyzer emits the legacy v1 tree (combinedJsonObject.add("symbol_table", …), CodeAnalyzer.java) with JType is_* booleans, per-callable code, and flat start_line/end_line. Canonical schema v2 requires an additive CPG tree: an envelope, per-module source blob, byte-offset spans, can:// ids, structured decorators, nested metrics/refs, and body call nodes.

Scope boundary

L1 tree emission only — no call_graph edges (that is the L2 issue), no dataflow. Keep the JavaParser compute guts; rewrite only the emission layer. The v1 emitter is kept behind a flag as a superset oracle during transition. Pure structural emission — no analysis-engine changes.

Goals

  • Envelope {schema_version:"2.0.0", language:"java", max_level, analyzer{name,version}, application{id,kind,symbol_table}}
  • module{id, kind:"module", span, source, package, imports, types, functions, content_hash}; byte offsets on every span
  • type.kind ∈ {class,interface,enum,record,annotation} + nesting{parent?,is_local?} (D4); base_types/interfaces; structured decorators:[{name,args,span}] (D2)
  • callable{id, kind, signature, span, parameters, return_type, error_channel, modifiers, decorators, metrics{cyclomatic}, refs{types,fields}, body{}} (D1, D3); thrown_exceptions → error_channel
  • body call nodes {kind:"call", span, callee:null, arguments:[local-id]} (callee backfilled at L2)
  • can://java/<app>/<file>/<type>/<sig> id construction from signatureOf() (D8)
  • v1 emitter behind a flag (superset oracle)

Caveats and known risks

  • Span byte offsets depend on JavaParser token positions; degrade gracefully where absent.
  • symbol_table keys must be relative (never absolute or ..-prefixed).
  • Callable kinds: method, constructor, initializer (static/instance init blocks), lambda; is_variadic for varargs.

Definition of done

  • L1 gate: output validates against the SDK Application; symbol_table non-empty, relative keys; a known module has source and the get_method_body slice = module.source[span.bytes]; call nodes carry callee:null; can:// ids stable across two runs; re-run reuses cache.
  • Monotonicity holds for L1; determinism -j N byte-identical to -j 1.

Metadata

Metadata

Assignees

Labels

breakingBreaking ChangeenhancementNew feature or requestjavaPull requests that update java code

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions