devlensio 1.2.0 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/dist/graph/edges/callEdges.js +77 -3
  2. package/dist/graph/edges/callEdges.test.js +1 -1
  3. package/dist/graph/edges/callOrder.test.d.ts +1 -0
  4. package/dist/graph/edges/callOrder.test.js +227 -0
  5. package/dist/graph/edges/propEdges.js +6 -1
  6. package/dist/index.d.ts +1 -0
  7. package/dist/index.js +1 -0
  8. package/dist/parser/callFlow.d.ts +15 -0
  9. package/dist/parser/callFlow.js +302 -0
  10. package/dist/parser/callOrder.test.d.ts +1 -0
  11. package/dist/parser/callOrder.test.js +407 -0
  12. package/dist/parser/extractors/components.js +18 -28
  13. package/dist/parser/extractors/functions.d.ts +12 -3
  14. package/dist/parser/extractors/functions.js +58 -36
  15. package/dist/parser/extractors/moduleScope.js +1 -1
  16. package/dist/parser/moduleScope.test.js +5 -3
  17. package/dist/summarizer/index.js +53 -4
  18. package/dist/summarizer/prompts.js +111 -50
  19. package/dist/summarizer/prompts.test.d.ts +1 -0
  20. package/dist/summarizer/prompts.test.js +112 -0
  21. package/dist/types.d.ts +63 -0
  22. package/dist/version.d.ts +1 -0
  23. package/dist/version.js +2 -0
  24. package/extractors/go/bin/darwin-amd64/devlens_go_extractor +0 -0
  25. package/extractors/go/bin/darwin-arm64/devlens_go_extractor +0 -0
  26. package/extractors/go/bin/linux-amd64/devlens_go_extractor +0 -0
  27. package/extractors/go/bin/linux-arm64/devlens_go_extractor +0 -0
  28. package/extractors/go/bin/windows-amd64/devlens_go_extractor.exe +0 -0
  29. package/extractors/go/calls.go +89 -10
  30. package/extractors/go/nodes.go +29 -11
  31. package/extractors/go/parser.go +311 -21
  32. package/extractors/java/devlens_java_extractor.jar +0 -0
  33. package/extractors/java/src/devlens/extractor/Extractor.java +36 -10
  34. package/extractors/java/src/devlens/extractor/Parser.java +387 -0
  35. package/extractors/java/src/devlens/extractor/edges/Calls.java +66 -10
  36. package/extractors/python/devlens_extractors_python/edges/calls.py +26 -3
  37. package/extractors/python/devlens_extractors_python/parser/__init__.py +4 -3
  38. package/extractors/python/devlens_extractors_python/parser/functions.py +199 -42
  39. package/extractors/rust/bin/darwin-amd64/devlens_rust_extractor +0 -0
  40. package/extractors/rust/bin/darwin-arm64/devlens_rust_extractor +0 -0
  41. package/extractors/rust/bin/linux-amd64/devlens_rust_extractor +0 -0
  42. package/extractors/rust/bin/linux-arm64/devlens_rust_extractor +0 -0
  43. package/extractors/rust/bin/windows-amd64/devlens_rust_extractor.exe +0 -0
  44. package/extractors/rust/src/calls.rs +82 -8
  45. package/extractors/rust/src/nodes.rs +29 -0
  46. package/extractors/rust/src/parser.rs +362 -27
  47. package/package.json +77 -73
@@ -19,6 +19,9 @@ import com.github.javaparser.ast.body.VariableDeclarator;
19
19
  import com.github.javaparser.ast.nodeTypes.NodeWithMembers;
20
20
  import com.github.javaparser.ast.type.ReferenceType;
21
21
  import com.github.javaparser.ast.expr.AnnotationExpr;
22
+ import com.github.javaparser.ast.expr.CastExpr;
23
+ import com.github.javaparser.ast.expr.ConditionalExpr;
24
+ import com.github.javaparser.ast.expr.EnclosedExpr;
22
25
  import com.github.javaparser.ast.expr.Expression;
23
26
  import com.github.javaparser.ast.expr.FieldAccessExpr;
24
27
  import com.github.javaparser.ast.expr.LambdaExpr;
@@ -30,12 +33,22 @@ import com.github.javaparser.ast.expr.SingleMemberAnnotationExpr;
30
33
  import com.github.javaparser.ast.expr.StringLiteralExpr;
31
34
  import com.github.javaparser.ast.nodeTypes.NodeWithAnnotations;
32
35
  import com.github.javaparser.ast.stmt.BlockStmt;
36
+ import com.github.javaparser.ast.stmt.CatchClause;
37
+ import com.github.javaparser.ast.stmt.DoStmt;
38
+ import com.github.javaparser.ast.stmt.ForEachStmt;
39
+ import com.github.javaparser.ast.stmt.ForStmt;
40
+ import com.github.javaparser.ast.stmt.IfStmt;
41
+ import com.github.javaparser.ast.stmt.SwitchEntry;
42
+ import com.github.javaparser.ast.stmt.TryStmt;
43
+ import com.github.javaparser.ast.stmt.WhileStmt;
33
44
  import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration;
34
45
 
35
46
  import java.io.IOException;
36
47
  import java.nio.file.Files;
37
48
  import java.nio.file.Path;
38
49
  import java.util.ArrayList;
50
+ import java.util.Comparator;
51
+ import java.util.IdentityHashMap;
39
52
  import java.util.LinkedHashMap;
40
53
  import java.util.LinkedHashSet;
41
54
  import java.util.List;
@@ -81,6 +94,22 @@ public final class Parser {
81
94
  public int argCount; // argument count at the call site
82
95
  public List<String> argTypes = new ArrayList<>(); // cheap arg type tags ("String", "int", "unknown")
83
96
  public boolean hasSpread = false; // Java has no call-site spread; kept for contract parity
97
+
98
+ // ── callOrder/v1 (docs/CALL_ORDER.md) ────────────────────────────
99
+ // Metadata only: the SET of recorded calls is decided by the walk,
100
+ // these fields never add or remove a site.
101
+ public int order; // 1-based lexical rank among the owner's sites
102
+ public int col; // 0-based column of the call expression
103
+ public Integer nested; // order of the enclosing recorded call expression
104
+ public CallInfo nestedIn; // that enclosing site (re-linked when the file order is fixed)
105
+ public String scope = "inline"; // inline | callback | nested | module
106
+ public boolean awaited = false; // Java has no await — contract parity only
107
+ public String defer; // null = no evidence of detachment
108
+ public String deferDetail; // scheduler symbol ("Executors.submit", "@PostConstruct")
109
+ public boolean conc = false;
110
+ public boolean repeat = false;
111
+ public boolean maybe = false;
112
+ public boolean earlyExit = false; // Java has no `?` — contract parity only
84
113
  }
85
114
 
86
115
  public static final class MethodInfo {
@@ -169,12 +198,29 @@ public final class Parser {
169
198
  for (TypeDeclaration<?> td : cu.getTypes()) {
170
199
  pf.types.add(extractType(td, pf, null));
171
200
  }
201
+ // Field initializers and { } blocks are collected per member, so a
202
+ // file's module-scope sites arrive in member order, not source
203
+ // order — fix that up into ONE 1..N sequence for the FILE node.
204
+ orderFileCalls(pf);
172
205
  } catch (Exception e) {
173
206
  pf.errors.add(e.getMessage() == null ? e.toString() : e.getMessage());
174
207
  }
175
208
  return pf;
176
209
  }
177
210
 
211
+ /** Module-scope sites (FILE node): source order, contiguous ordinals, re-linked nesting. */
212
+ private static void orderFileCalls(ParsedFile pf) {
213
+ pf.fileCalls.sort(Comparator.comparingInt((CallInfo c) -> c.line)
214
+ .thenComparingInt(c -> c.col));
215
+ for (int i = 0; i < pf.fileCalls.size(); i++) {
216
+ CallInfo ci = pf.fileCalls.get(i);
217
+ ci.order = i + 1;
218
+ // an enclosing site always starts before its argument — hence
219
+ // already renumbered here, so `nested` stays a valid, smaller order.
220
+ ci.nested = ci.nestedIn == null ? null : ci.nestedIn.order;
221
+ }
222
+ }
223
+
178
224
  private static TypeInfo extractType(TypeDeclaration<?> td, ParsedFile pf, String outerDotted) {
179
225
  TypeInfo t = new TypeInfo();
180
226
  String simple = td.getNameAsString();
@@ -321,6 +367,9 @@ public final class Parser {
321
367
  if (body == null) {
322
368
  return calls;
323
369
  }
370
+ // pre-order walk, so an enclosing call is always numbered before the
371
+ // calls nested inside its arguments (nested === its order).
372
+ Map<MethodCallExpr, CallInfo> recorded = new IdentityHashMap<>();
324
373
  body.walk(MethodCallExpr.class, call -> {
325
374
  if (moduleScope && isNestedScope(call)) {
326
375
  return;
@@ -328,6 +377,7 @@ public final class Parser {
328
377
  CallInfo ci = new CallInfo();
329
378
  ci.methodName = call.getNameAsString();
330
379
  ci.line = lineOf(call, true);
380
+ ci.col = columnOf(call);
331
381
  Expression scope = call.getScope().orElse(null);
332
382
  if (scope != null) {
333
383
  ci.receiverName = rootName(scope);
@@ -347,11 +397,348 @@ public final class Parser {
347
397
  } catch (Throwable ignored) {
348
398
  // unresolved (external lib, local variable, dynamic) — fallback ladder
349
399
  }
400
+ ci.order = calls.size() + 1;
401
+ ci.nestedIn = enclosingRecordedCall(call, recorded);
402
+ ci.nested = ci.nestedIn == null ? null : ci.nestedIn.order;
403
+ ci.scope = moduleScope ? "module" : scopeOf(call, body);
404
+ annotateCallFlags(call, ci, body, owner);
405
+ recorded.put(call, ci);
350
406
  calls.add(ci);
351
407
  });
352
408
  return calls;
353
409
  }
354
410
 
411
+ // ── callOrder/v1 — placement + detachment flags ────────────────────
412
+ // Every annotation below is derived from AST ancestry only: no call is
413
+ // added or removed, so the recorded set stays byte-identical.
414
+
415
+ private static final Set<String> TIMER_TYPES =
416
+ Set.of("Timer", "ScheduledExecutorService", "ScheduledThreadPoolExecutor");
417
+ private static final Set<String> TIMER_MEMBERS =
418
+ Set.of("schedule", "scheduleAtFixedRate", "scheduleWithFixedDelay");
419
+ private static final Set<String> PROMISE_MEMBERS = Set.of(
420
+ "supplyAsync", "runAsync", "thenApply", "thenApplyAsync", "thenAccept",
421
+ "thenAcceptAsync", "thenRun", "thenRunAsync", "thenCompose",
422
+ "thenComposeAsync", "thenCombine", "thenCombineAsync", "applyToEither",
423
+ "applyToEitherAsync", "acceptEither", "acceptEitherAsync", "handle",
424
+ "handleAsync", "whenComplete", "whenCompleteAsync", "completeAsync",
425
+ "exceptionallyAsync");
426
+ private static final Set<String> CONC_MEMBERS = Set.of("submit", "execute", "invokeAll", "invokeAny");
427
+ private static final Set<String> CONC_TYPES = Set.of(
428
+ "Thread", "ForkJoinPool", "ForkJoinTask", "CompletableFuture", "ExecutorService",
429
+ "ScheduledExecutorService", "Executor");
430
+ /** Synchronous iteration combinators: their callback runs 0..N times. */
431
+ private static final Set<String> ITERATION_MEMBERS = Set.of(
432
+ "forEach", "forEachOrdered", "map", "mapToInt", "mapToLong", "mapToDouble",
433
+ "flatMap", "filter", "reduce", "peek", "anyMatch", "allMatch", "noneMatch",
434
+ "sorted", "removeIf");
435
+
436
+ /**
437
+ * The scheduler a call runs on, derived from the expression that received
438
+ * the closure / from the detachment API itself. `defer` may be null when
439
+ * only `conc` / `repeat` are known (ExecutorService.submit(f), stream
440
+ * forEach) — same convention as the TypeScript annotator.
441
+ */
442
+ private record Scheduler(String defer, String detail, boolean conc, boolean repeat) {}
443
+
444
+ private static void annotateCallFlags(MethodCallExpr call, CallInfo ci, Node body, MethodInfo owner) {
445
+ Node frame = nearestFunctionLike(call, body);
446
+ String defer = null;
447
+ String detail = null;
448
+ boolean conc = false;
449
+ boolean repeat = false;
450
+
451
+ // 1. Closure frame: a callback runs on whatever received it.
452
+ if (frame != null) {
453
+ Scheduler s = schedulerOfReceiver(frame, body);
454
+ if (s != null) {
455
+ defer = s.defer();
456
+ detail = s.detail();
457
+ conc = s.conc();
458
+ repeat = s.repeat();
459
+ }
460
+ }
461
+
462
+ // 2. The call site itself may be the detachment API
463
+ // (CompletableFuture.thenApply, timer.schedule, executor.submit, …).
464
+ Scheduler self = schedulerOfCall(call, ci);
465
+ if (self != null) {
466
+ if (defer == null) {
467
+ defer = self.defer();
468
+ detail = self.detail();
469
+ } else if (detail == null) {
470
+ detail = self.detail();
471
+ }
472
+ conc = conc || self.conc();
473
+ repeat = repeat || self.repeat();
474
+ }
475
+
476
+ // 3. Branch / loop / catch ancestry, bounded by the enclosing frame
477
+ // (an outer `if` decides whether the closure runs at all, not the
478
+ // calls inside it — those are the closure's own frame).
479
+ Node boundary = frame != null ? frame : body;
480
+ boolean maybe = false;
481
+ Node child = call;
482
+ Node parent = call.getParentNode().orElse(null);
483
+ while (parent != null && parent != boundary) {
484
+ if (parent instanceof ForStmt || parent instanceof ForEachStmt
485
+ || parent instanceof WhileStmt || parent instanceof DoStmt) {
486
+ repeat = true;
487
+ }
488
+ if (parent instanceof IfStmt ifs) {
489
+ boolean inBranch = child == ifs.getThenStmt()
490
+ || (ifs.getElseStmt().isPresent() && ifs.getElseStmt().get() == child);
491
+ if (inBranch) {
492
+ maybe = true;
493
+ }
494
+ }
495
+ if (parent instanceof ConditionalExpr cond) {
496
+ if (child == cond.getThenExpr() || child == cond.getElseExpr()) {
497
+ maybe = true;
498
+ }
499
+ }
500
+ if (parent instanceof SwitchEntry || parent instanceof CatchClause) {
501
+ maybe = true;
502
+ }
503
+ if (parent instanceof TryStmt ts && ts.getFinallyBlock().isPresent()
504
+ && ts.getFinallyBlock().get() == child) {
505
+ if (defer == null) {
506
+ defer = "onReturn";
507
+ }
508
+ }
509
+ child = parent;
510
+ parent = parent.getParentNode().orElse(null);
511
+ }
512
+
513
+ // 4. Commit-phase lifecycle method: the whole body runs post-render.
514
+ if (defer == null && owner != null && owner.annotations.contains("PostConstruct")) {
515
+ defer = "postRender";
516
+ detail = "@PostConstruct";
517
+ }
518
+
519
+ ci.defer = defer;
520
+ ci.deferDetail = detail;
521
+ ci.conc = conc;
522
+ ci.repeat = repeat;
523
+ ci.maybe = maybe;
524
+ }
525
+
526
+ /**
527
+ * Scheduler of a closure's receiver: `executor.submit(…)`, `new Thread(…)`,
528
+ * `items.forEach(…)`, `someLib.runLater(fn)` → unknown. Null when the
529
+ * closure is not passed to a call/creation or cannot be classified.
530
+ */
531
+ private static Scheduler schedulerOfReceiver(Node frame, Node body) {
532
+ Node receiver;
533
+ if (frame instanceof LambdaExpr lambda) {
534
+ receiver = detachingReceiver(lambda, body);
535
+ } else {
536
+ ObjectCreationExpr anonymous = anonymousCreationOf(frame, body);
537
+ receiver = anonymous == null ? null : detachingReceiver(anonymous, body);
538
+ }
539
+ if (receiver == null) {
540
+ return null;
541
+ }
542
+ if (receiver instanceof ObjectCreationExpr creation) {
543
+ String type = simpleTypeName(creation.getTypeAsString());
544
+ String display = "new " + type;
545
+ if (TIMER_TYPES.contains(type)) {
546
+ return new Scheduler("timer", display, false, false);
547
+ }
548
+ if (CONC_TYPES.contains(type)) {
549
+ return new Scheduler(null, display, true, false);
550
+ }
551
+ return new Scheduler("unknown", display, false, false);
552
+ }
553
+ MethodCallExpr mc = (MethodCallExpr) receiver;
554
+ String display = displayOf(mc);
555
+ String member = mc.getNameAsString();
556
+ String root = scopeRoot(mc);
557
+ if (isCompletionStage(root, member)) {
558
+ return new Scheduler("promise", display, isAsyncCompletion(member), false);
559
+ }
560
+ if (isTimer(root, member)) {
561
+ return new Scheduler("timer", display, false, false);
562
+ }
563
+ if (isConcurrentDispatch(root, member, display)) {
564
+ return new Scheduler(null, display, true, false);
565
+ }
566
+ if (ITERATION_MEMBERS.contains(member)) {
567
+ return new Scheduler(null, display, false, true);
568
+ }
569
+ return new Scheduler("unknown", display, false, false);
570
+ }
571
+
572
+ /** Scheduler signalled by the call site itself; null when it is no detachment API. */
573
+ private static Scheduler schedulerOfCall(MethodCallExpr call, CallInfo ci) {
574
+ String member = call.getNameAsString();
575
+ String root = scopeRoot(call);
576
+ String declaring = simpleTypeName(declaringClassOf(ci.resolvedTarget));
577
+ boolean known = false;
578
+ String defer = null;
579
+ boolean conc = false;
580
+ if (isCompletionStage(root, member) || "CompletableFuture".equals(declaring)) {
581
+ defer = "promise";
582
+ conc = isAsyncCompletion(member);
583
+ known = true;
584
+ } else if (isTimer(root, member) || TIMER_TYPES.contains(declaring)) {
585
+ defer = "timer";
586
+ known = true;
587
+ } else if (isConcurrentDispatch(root, member, ci.name) || CONC_TYPES.contains(declaring)) {
588
+ conc = true;
589
+ known = true;
590
+ }
591
+ if (!known) {
592
+ return null;
593
+ }
594
+ return new Scheduler(defer, ci.name, conc, false);
595
+ }
596
+
597
+ private static boolean isCompletionStage(String root, String member) {
598
+ return "CompletableFuture".equals(root) || PROMISE_MEMBERS.contains(member);
599
+ }
600
+
601
+ private static boolean isAsyncCompletion(String member) {
602
+ return member.endsWith("Async");
603
+ }
604
+
605
+ private static boolean isTimer(String root, String member) {
606
+ return TIMER_MEMBERS.contains(member) || TIMER_TYPES.contains(root);
607
+ }
608
+
609
+ private static boolean isConcurrentDispatch(String root, String member, String display) {
610
+ return CONC_MEMBERS.contains(member) || CONC_TYPES.contains(root)
611
+ || display.contains("parallelStream");
612
+ }
613
+
614
+ /** Nearest enclosing function-like node that is not the owner itself. */
615
+ private static Node nearestFunctionLike(Node node, Node boundary) {
616
+ Node parent = node.getParentNode().orElse(null);
617
+ while (parent != null && parent != boundary) {
618
+ if (parent instanceof LambdaExpr || parent instanceof MethodDeclaration
619
+ || parent instanceof ConstructorDeclaration) {
620
+ return parent;
621
+ }
622
+ parent = parent.getParentNode().orElse(null);
623
+ }
624
+ return null;
625
+ }
626
+
627
+ /** Anonymous class creation expression whose body contains `frame` (or null). */
628
+ private static ObjectCreationExpr anonymousCreationOf(Node frame, Node boundary) {
629
+ Node cur = frame.getParentNode().orElse(null);
630
+ while (cur != null && cur != boundary) {
631
+ if (cur instanceof ObjectCreationExpr oce && oce.getAnonymousClassBody().isPresent()) {
632
+ return oce;
633
+ }
634
+ cur = cur.getParentNode().orElse(null);
635
+ }
636
+ return null;
637
+ }
638
+
639
+ /**
640
+ * The expression that RECEIVES `fn` as an argument — the escape point of a
641
+ * closure (`executor.submit(() -> …)`, `new Thread(runnable)`, `register(fn)`).
642
+ * Null when `fn` is not passed to a call/creation (e.g. a lambda stored in a
643
+ * local variable), i.e. it stays in the owner's frame.
644
+ */
645
+ private static Node detachingReceiver(Node fn, Node boundary) {
646
+ Node child = fn;
647
+ Node parent = fn.getParentNode().orElse(null);
648
+ while (parent != null && parent != boundary) {
649
+ if (parent instanceof MethodCallExpr mc && containsIdentity(mc.getArguments(), child)) {
650
+ return mc;
651
+ }
652
+ if (parent instanceof ObjectCreationExpr oce) {
653
+ if (containsIdentity(oce.getArguments(), child)) {
654
+ return oce;
655
+ }
656
+ if (oce.getAnonymousClassBody().isPresent()
657
+ && containsIdentity(oce.getAnonymousClassBody().get(), child)) {
658
+ return oce;
659
+ }
660
+ }
661
+ if (parent instanceof EnclosedExpr || parent instanceof CastExpr) {
662
+ child = parent;
663
+ parent = parent.getParentNode().orElse(null);
664
+ continue;
665
+ }
666
+ return null;
667
+ }
668
+ return null;
669
+ }
670
+
671
+ /** Execution region of a call site (docs/CALL_ORDER.md §4.3). */
672
+ private static String scopeOf(MethodCallExpr call, Node body) {
673
+ Node frame = nearestFunctionLike(call, body);
674
+ if (frame == null) {
675
+ return "inline";
676
+ }
677
+ Scheduler detached = schedulerOfReceiver(frame, body);
678
+ if (detached != null) {
679
+ return "callback";
680
+ }
681
+ // A lambda or class body that never leaves the owner is a nested
682
+ // declaration the owner runs itself.
683
+ return "nested";
684
+ }
685
+
686
+ /** Nearest enclosing recorded call site of the same owner: bar.nested === foo.order. */
687
+ private static CallInfo enclosingRecordedCall(MethodCallExpr call, Map<MethodCallExpr, CallInfo> recorded) {
688
+ Node parent = call.getParentNode().orElse(null);
689
+ while (parent != null) {
690
+ if (parent instanceof MethodCallExpr mc) {
691
+ CallInfo enclosing = recorded.get(mc);
692
+ if (enclosing != null) {
693
+ return enclosing;
694
+ }
695
+ }
696
+ parent = parent.getParentNode().orElse(null);
697
+ }
698
+ return null;
699
+ }
700
+
701
+ private static boolean containsIdentity(List<? extends Node> nodes, Node target) {
702
+ for (Node n : nodes) {
703
+ if (n == target) {
704
+ return true;
705
+ }
706
+ }
707
+ return false;
708
+ }
709
+
710
+ /** Display string of a call as written: executor.submit, CompletableFuture.supplyAsync. */
711
+ private static String displayOf(MethodCallExpr call) {
712
+ Expression scope = call.getScope().orElse(null);
713
+ return (scope == null ? "" : scopeName(scope) + ".") + call.getNameAsString();
714
+ }
715
+
716
+ /** Root identifier of a call's receiver ("executor" for executor.submit). */
717
+ private static String scopeRoot(MethodCallExpr call) {
718
+ Expression scope = call.getScope().orElse(null);
719
+ if (scope == null) {
720
+ return "";
721
+ }
722
+ if (scope instanceof NameExpr n) {
723
+ return n.getNameAsString();
724
+ }
725
+ String root = rootName(scope);
726
+ return root == null ? "" : root;
727
+ }
728
+
729
+ /** "java.util.concurrent.CompletableFuture.thenApply" → "java.util.concurrent.CompletableFuture". */
730
+ private static String declaringClassOf(String resolvedTarget) {
731
+ if (resolvedTarget == null) {
732
+ return "";
733
+ }
734
+ int dot = resolvedTarget.lastIndexOf('.');
735
+ return dot < 0 ? resolvedTarget : resolvedTarget.substring(0, dot);
736
+ }
737
+
738
+ private static int columnOf(Node n) {
739
+ return n.getRange().map(r -> Math.max(0, r.begin.column - 1)).orElse(0);
740
+ }
741
+
355
742
  /**
356
743
  * True when the call executes inside a lambda or an anonymous/local class
357
744
  * method — i.e. not at the initializer's own init time.
@@ -42,7 +42,8 @@ public final class Calls {
42
42
  String relPath = (String) methodNode.get("filePath");
43
43
  String parentClass = (String) metadata.get("parentClass");
44
44
  String pkg = packageOf(methodNodeId, relPath);
45
- List<String> resolvedCalls = new ArrayList<>();
45
+ Map<String, Map<String, Object>> resolvedRecords = new LinkedHashMap<>();
46
+ Map<String, List<Integer>> ordersByTarget = new LinkedHashMap<>();
46
47
  List<Map<String, String>> resolvedDetails = new ArrayList<>();
47
48
 
48
49
  for (Parser.CallInfo ci : entry.getValue()) {
@@ -53,7 +54,10 @@ public final class Calls {
53
54
  edgeMeta.put("matchedBy", pick.matchedBy);
54
55
  Map<String, Object> edge = Contract.edge("CALLS", methodNodeId, pick.id, edgeMeta);
55
56
  edgesOut.add(edge);
56
- resolvedCalls.add(pick.id);
57
+ if (ci.order > 0) {
58
+ ordersByTarget.computeIfAbsent(pick.id, k -> new ArrayList<>()).add(ci.order);
59
+ }
60
+ resolvedRecords.computeIfAbsent(pick.id, k -> resolvedRecord(ci, lookup, pick.id));
57
61
  // details for OrmEdges (repo R/W classification)
58
62
  Map<String, String> detail = new LinkedHashMap<>();
59
63
  detail.put("target", pick.id);
@@ -62,9 +66,9 @@ public final class Calls {
62
66
  resolvedDetails.add(detail);
63
67
  }
64
68
  }
65
- if (!resolvedCalls.isEmpty()) {
66
- java.util.Collections.sort(resolvedCalls);
67
- metadata.put("resolvedCalls", resolvedCalls);
69
+ if (!resolvedRecords.isEmpty()) {
70
+ attachRepeatOrders(resolvedRecords, ordersByTarget);
71
+ metadata.put("resolvedCalls", new ArrayList<>(resolvedRecords.values()));
68
72
  metadata.put("resolvedCallDetails", resolvedDetails);
69
73
  }
70
74
  }
@@ -80,7 +84,8 @@ public final class Calls {
80
84
  }
81
85
  String relPath = (String) caller.get("filePath");
82
86
  String pkg = packageOf(callerId, relPath);
83
- List<String> resolvedCalls = new ArrayList<>();
87
+ Map<String, Map<String, Object>> resolvedRecords = new LinkedHashMap<>();
88
+ Map<String, List<Integer>> ordersByTarget = new LinkedHashMap<>();
84
89
  List<Map<String, String>> resolvedDetails = new ArrayList<>();
85
90
 
86
91
  for (Parser.CallInfo ci : entry.getValue()) {
@@ -95,7 +100,10 @@ public final class Calls {
95
100
  edgeMeta.put("matchedBy", pick.matchedBy);
96
101
  edgeMeta.put("scope", "module");
97
102
  edgesOut.add(Contract.edge("CALLS", callerId, pick.id, edgeMeta));
98
- resolvedCalls.add(pick.id);
103
+ if (ci.order > 0) {
104
+ ordersByTarget.computeIfAbsent(pick.id, k -> new ArrayList<>()).add(ci.order);
105
+ }
106
+ resolvedRecords.computeIfAbsent(pick.id, k -> resolvedRecord(ci, lookup, pick.id));
99
107
 
100
108
  Map<String, String> detail = new LinkedHashMap<>();
101
109
  detail.put("target", pick.id);
@@ -104,16 +112,64 @@ public final class Calls {
104
112
  resolvedDetails.add(detail);
105
113
  }
106
114
 
107
- if (!resolvedCalls.isEmpty()) {
108
- java.util.Collections.sort(resolvedCalls);
115
+ if (!resolvedRecords.isEmpty()) {
116
+ attachRepeatOrders(resolvedRecords, ordersByTarget);
109
117
  @SuppressWarnings("unchecked")
110
118
  Map<String, Object> metadata = (Map<String, Object>) caller.get("metadata");
111
- metadata.put("resolvedCalls", resolvedCalls);
119
+ metadata.put("resolvedCalls", new ArrayList<>(resolvedRecords.values()));
112
120
  metadata.put("resolvedCallDetails", resolvedDetails);
113
121
  }
114
122
  }
115
123
  }
116
124
 
125
+ /** One metadata.resolvedCalls entry, shaped exactly like ResolvedCall in
126
+ * src/types.ts. Node metadata only: nothing here depends on edge metadata. */
127
+ private static Map<String, Object> resolvedRecord(Parser.CallInfo ci, LookupMaps lookup, String targetId) {
128
+ Map<String, Object> node = lookup.nodeById.get(targetId);
129
+ String declared = node != null ? (String) node.get("name") : null;
130
+ Map<String, Object> rec = new LinkedHashMap<>();
131
+ rec.put("name", declared != null ? declared : ci.methodName);
132
+ rec.put("nodeId", targetId);
133
+ if (ci.order > 0) {
134
+ rec.put("firstOrder", ci.order);
135
+ rec.put("line", ci.line);
136
+ }
137
+ if (ci.defer != null) {
138
+ rec.put("defer", ci.defer);
139
+ }
140
+ if (ci.deferDetail != null) {
141
+ rec.put("deferDetail", ci.deferDetail);
142
+ }
143
+ if (ci.awaited) {
144
+ rec.put("awaited", true);
145
+ }
146
+ if (ci.conc) {
147
+ rec.put("conc", true);
148
+ }
149
+ if (ci.repeat) {
150
+ rec.put("repeat", true);
151
+ }
152
+ if (ci.maybe) {
153
+ rec.put("maybe", true);
154
+ }
155
+ return rec;
156
+ }
157
+
158
+ /** orders[] only when a target was reached more than once. */
159
+ private static void attachRepeatOrders(Map<String, Map<String, Object>> records,
160
+ Map<String, List<Integer>> orders) {
161
+ for (Map.Entry<String, List<Integer>> e : orders.entrySet()) {
162
+ Map<String, Object> rec = records.get(e.getKey());
163
+ if (rec == null) {
164
+ continue;
165
+ }
166
+ List<Integer> unique = e.getValue().stream().distinct().sorted().toList();
167
+ if (unique.size() > 1) {
168
+ rec.put("orders", unique);
169
+ }
170
+ }
171
+ }
172
+
117
173
  private static Overloads.Pick resolveOne(Parser.CallInfo ci, LookupMaps lookup,
118
174
  String relPath, String parentClass,
119
175
  String pkg, String methodNodeId) {
@@ -329,7 +329,11 @@ def resolve_calls(lookup: LookupMaps, registry: ThirdPartyRegistry) -> list[dict
329
329
  continue
330
330
  metadata = node["metadata"]
331
331
  sites = metadata.get("callSites") or [{"name": c} for c in metadata.get("calls", [])]
332
- resolved: list[dict] = []
332
+ # One record per target, first-seen order, shaped exactly like ResolvedCall
333
+ # in src/types.ts: name is the DECLARATION name, firstOrder the first
334
+ # position that reached it, orders carries the repeat positions.
335
+ resolved: dict[str, dict] = {}
336
+ orders_by_target: dict[str, list[int]] = {}
333
337
  for site in sites:
334
338
  called = site["name"]
335
339
  target, matched_by, chain = _resolve(called, node, lookup, registry, site)
@@ -347,7 +351,26 @@ def resolve_calls(lookup: LookupMaps, registry: ThirdPartyRegistry) -> list[dict
347
351
  edge_meta["scope"] = "module"
348
352
  edges.append({"from": node["id"], "to": target, "type": "CALLS",
349
353
  "metadata": edge_meta})
350
- resolved.append({"name": called, "nodeId": target})
351
- metadata["resolvedCalls"] = resolved
354
+
355
+ order = site.get("order")
356
+ if isinstance(order, int):
357
+ orders_by_target.setdefault(target, []).append(order)
358
+ if target not in resolved:
359
+ record = {"name": origin_name or called, "nodeId": target}
360
+ if isinstance(order, int):
361
+ record["firstOrder"] = order
362
+ line = site.get("line")
363
+ if isinstance(line, int):
364
+ record["line"] = line
365
+ for marker in ("defer", "deferDetail", "awaited", "conc", "repeat", "maybe"):
366
+ value = site.get(marker)
367
+ if value:
368
+ record[marker] = value
369
+ resolved[target] = record
370
+ for target, orders in orders_by_target.items():
371
+ unique = sorted(set(orders))
372
+ if len(unique) > 1:
373
+ resolved[target]["orders"] = unique
374
+ metadata["resolvedCalls"] = list(resolved.values())
352
375
 
353
376
  return edges
@@ -72,9 +72,10 @@ def parse_file(repo_path: str, rel_path: str) -> ParsedFile:
72
72
  file_node_["metadata"]["childNodeIds"] = [c["id"] for c in children]
73
73
 
74
74
  # Module-scope calls (executed at import time) belong to the FILE node.
75
- # _walk_scope already refuses to descend into defs/classes/lambdas, so
76
- # running it on the module body yields exactly the top-level calls.
77
- module_calls, module_sites = extract_calls_with_sites(tree.body)
75
+ # The walk already refuses to descend into defs/classes/lambdas, so
76
+ # running it on the module body yields exactly the top-level calls;
77
+ # module_scope marks their callOrder/v1 scope as "module".
78
+ module_calls, module_sites = extract_calls_with_sites(tree.body, module_scope=True)
78
79
  if module_sites:
79
80
  file_node_["metadata"]["calls"] = module_calls
80
81
  file_node_["metadata"]["callSites"] = module_sites