Skip to content

Apex: class heritage clause stops at a dot — implements Database.Batchable<sObject>, Schedulable fabricates a Database node and drops Schedulable #3277

Open

Description

@Soumyadip2003-AI

Summary

The Apex extractor's class regex matches the heritage clause with patterns that admit no dot:

cls_re = _re.compile(
    rf"^{_ANNOTATION}\s*{_ACCESS}{_SHARING}{_MOD}\s*class\s+(\w+)"
    rf"(?:\s+extends\s+(\w+))?(?:\s+implements\s+([\w,\s]+))?\s*\{{?",
    _re.IGNORECASE,
)

extends (\w+) and implements ([\w,\s]+) both stop at the first ., so a namespace-qualified base type is truncated to its namespace. Two consequences, both silent:

  1. A node is fabricated for the namespace (Database, Outer) and the heritage edge points at it — a namespace is not a type, and the real base type gets no node at all.
  2. Because the capture stops at the dot, it never reaches the comma, so every remaining interface in the list is dropped.

This is the same class of gap as #3217 (fixed for method return types in #3276), but in a different regex — that PR deliberately leaves this one alone.

Affected versions

Present in 0.9.53 / HEAD (33362d9), in graphify/extractors/apex.py.

Minimal repro

Batch.cls:

public with sharing class Batch implements Database.Batchable<sObject>, Schedulable {
    public void execute(Database.BatchableContext bc) { }
}

Child.cls:

public class Child extends Outer.BaseThing {
    public void go() { }
}
from pathlib import Path
from graphify.extract import extract_apex

for f in ("Batch.cls", "Child.cls"):
    r = extract_apex(Path(f))
    print(f, sorted(n["label"] for n in r["nodes"]))
    print("  ", [(e["relation"], e["target"]) for e in r["edges"]
                 if e["relation"] in ("extends", "implements")])

Actual:

Batch.cls ['.execute()', 'Batch', 'Database', 'Batch.cls']
   [('implements', 'database')]          # 'Database' fabricated; Schedulable lost

Child.cls ['.go()', 'Child', 'Child.cls', 'Outer']
   [('extends', 'outer')]                # 'Outer' fabricated; BaseThing never appears

Expected: the heritage target is the qualified type (Database.Batchable, Outer.BaseThing) — or at minimum its tail type name, matching the treatment Kotlin (#1793) and Scala (#1794) received — and Schedulable keeps its own implements edge.

Why it matters

implements Database.Batchable<sObject>, Schedulable is the canonical shape of every scheduled batch job in Salesforce, so this is not an edge case in a real Apex org. The fabricated Database node is also a mild hub-pollution problem: every batch class in the repo points at the same meaningless node.

Note on generics in the list

A correct fix needs to split the interface list on top-level commas only, since a generic argument can itself contain one (Map<String, Object>); splitting on every comma would shred it. Happy to open a PR if the approach sounds right.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions