Skip to content

feat(extractor-java): charge inherited calls - #55

Merged
jgrodziski merged 2 commits into
mainfrom
feat/java-ancestor-attribution
Dec 1, 2026
Merged

jgrodziski merged 2 commits into
mainfrom
feat/java-ancestor-attribution

Conversation

@jgrodziski

Copy link
Copy Markdown
Contributor

Follow-up to #54: it names the member, so it builds on M24a's member.

A call to a method inherited from a library type had no edge at all. On Spring PetClinic, owners.save(owner) is inherited from JpaRepository through the corpus interface OwnerRepository; without a classpath the call has no declaring type the extractor can name, so it was dropped. The outbound report of #54 therefore saw no write into Spring Data. This PR turns that drop into a derived edge to the library ancestor, naming the member, when the corpus leaves exactly one answer.

The rule

For a call with no declaring type (dropped until now, in emitTypeLevelCall), AncestorCallLookup emits an edge when all of these hold:

  1. The receiver's type is written in the corpus: a field, a parameter, a local with an explicit type, this, super, Outer.this, Iface.super, or no receiver at all (then every enclosing class is looked through, as JLS §15.12.1 does).
  2. No corpus type among its supertypes declares a method of that name.
  3. Exactly one library type among them could answer. A library type Spoon can see (the JDK) answers only for the names it has; java.lang.Object never counts.

The edge is an invocation from an invocable and a reference otherwise, to the stub of the type the corpus wrote (JpaRepository, though CrudRepository really declares save: only the jar could tell), with member set to the method's simple name and provenance derived.

The call stays dropped when:

  • two library types could answer (counted apart, as ambiguous-ancestor);
  • a corpus type among the supertypes carries a Lombok annotation, because its generated members are written nowhere;
  • the call has no receiver and a static import of the file could supply the name (import static org.mockito.Mockito.*);
  • the receiver is a var, an untyped lambda parameter, a call's result or an array element.

A type written in the corpus (anonymous class, local class, enum constant body) is walked as corpus and is never a candidate. The rule only ever turns a drop into an edge: no existing edge changes.

The extractor's summary gains two lines, named as the Python and Ruby extractors name them: ancestor-attributed : N (derived) and ambiguous-ancestor : N (dropped).

Measured

Corpus Edges before → after Attributed Ambiguous
PetClinic, src/main/java 891 → 896 5 0
PetClinic, with tests 2 847 → 2 860 13 0
BroadleafCommerce 214 371 → 214 750 383 12
Apache Fineract 794 091 → 794 404 313 1 103
  • PetClinic: the five save / saveAndFlush sites (OwnerController:84, :168, VisitController:109, PetController:126, :199) are now edges to the JpaRepository stub. The 10 read sites are byte-identical, and the model diff is exactly those 5 lines.
  • Outbound report with a rule on org.springframework.data.jpa.repository as database and save* → write: 0 rows before, 5 database / write rows after. No model call.
  • Every diff is additions only.
  • Lombok was found by measuring. Without that condition the rule charged 2 319 generated getters on Fineract to Spring's Persistable.

Before merging

  • The absence of false attributions rests on reading samples, not on a run with a real classpath. The groups read on Broadleaf (TestCase assertions, Spring's Ordered) and Fineract (JpaRepository, Cucumber's En, SpringLiquibase) were all true.
  • Fineract's 1 103 ambiguous calls were not read one by one. An interface with two library parents stays dropped; that is the rule's main blind spot on real Spring code.
  • Reads the corpus redeclares are untouched. owners.findById(id) is still an edge to the corpus interface's own method, so it is no outbound row. Covering those needs a rule in the analyzer, not here.
  • Explain re-asks some units. A unit with such a call has one fact more, so its prompt and fingerprint change and its stored insight is asked again on the next run.
  • The shared Java fixture moved by one edge: super.post(document) in LedgerAdapter is now an edge to the LedgerClient stub. With it moved the fixture snapshot, the metrics side-car, the counts in the analyzer, CLI and insights tests, the [named, eligible] pair for Java ([21, 62]), four website tables that tests pin, and the Java explain goldens (three units' fingerprints, regenerated with the fake client).
  • The native binary and the JVM jar already disagree on Broadleaf, before this change (214 039 against 214 371 edges). Under native the rule attributes 4 sites fewer, a strict subset of the JVM's. Not investigated.

Verification

On fb8025b, which merges with main (d9b7ade) without conflict:

  • Every condition has a test that was seen red first, then green: 22 tests in AncestorAttributedCallTest, plus two on the summary's counters.
  • ./test.sh --java: 266 tests, 0 failures; the built jar and the native binary both reproduce the snapshot.
  • pnpm -r test green: CLI 2 071, analyzer 942, insights 619 (1 skipped), core 618, vocabulary 364, viz 143, navigator-ui 124, city 98, llm 96, extractors/typescript 82, scm 56, navigator 45.
  • Typecheck green. pnpm -r build green, the website included.
  • pnpm run gen:schemas changes nothing.
  • ./test.sh --csharp, --elixir, --ruby, --python, --metrics: all checks passed.
  • No model provider was called; the explain goldens were regenerated with the fake client.

🤖 Generated with Claude Code

https://claude.ai/code/session_01PKCVh1VXWEqBhGUFQftJAY

jgrodziski and others added 2 commits November 29, 2026 21:51
A call to a method a corpus type inherits from a library type has no
declaring type without the jar, so it was dropped (EdgeExtractor's
emitTypeLevelCall, on UNKNOWN_TYPE_ID). AncestorCallLookup now charges
it to the one library ancestor that could answer: an invocation of that
stub, derived, naming the method (MM-6), counted ancestor-attributed;
with two candidates it stays dropped, counted ambiguous-ancestor.

Receivers: a written field, parameter or local; this; super; the
implicit this of an unqualified call. It stays dropped when a corpus
type of the closure declares the name or carries Lombok, and for an
unqualified call a static import may bind. Only drops turn into edges.

PetClinic: the five save/saveAndFlush writes become edges to the
JpaRepository stub; the ten reads are unchanged. The Java fixture gains
LedgerAdapter's super.post; dependent counts, explain goldens (fake
client), the metrics side-car and the website tables move with it.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PKCVh1VXWEqBhGUFQftJAY
A type whose declaration is corpus source (an anonymous class, a local
class, an enum constant body) is now walked as corpus in the ancestor
lookup whatever its id, never taken for a library candidate: an
unqualified call in `new LibCallback() { ... }` under a class extending
LibBase is ambiguous. Pass 3's ids already mapped anonymous classes to
their declared ids, so no measured model changes (PetClinic, Broadleaf,
fineract byte-identical); the tests now hold without that mapping.

Iface.super.m() starts at the named interface: Spoon writes it as the
super access's target, with no type, so the call was dropped.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PKCVh1VXWEqBhGUFQftJAY
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
codegraph fb8025b Commit Preview URL

Branch Preview URL
Nov 29 2026, 10:16 PM

@jgrodziski
jgrodziski merged commit de81f6c into main Dec 1, 2026
107 of 108 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant