Skip to content

Codebase intelligence for AI and humans: code health scores, auto-generated docs, git analytics, dead code detection, and architectural decisions via MCP.

feat(apex): health for Apex: complexity, class cohesion, test cases and limits-in-loop perf (#4419)

Raghav Chamadiyafdeca983b7ed
diff --git a/docs/architecture/language-support.md b/docs/architecture/language-support.md
index bce92edd3..d01f64397 100644
--- a/docs/architecture/language-support.md
+++ b/docs/architecture/language-support.md
@@ -995,6 +995,14 @@ included, since `Type.forName` reaches classes by name. Ceiling: a mention in a
comment counts as a use, and a class shaped like a Visualforce controller stays
live.
+Health scores Apex methods, constructors, triggers and property accessors that
+hold code, and reports SOQL, DML, callouts, `Messaging.sendEmail`,
+`System.enqueueJob` and same-class `@future` calls inside loops. It stays quiet on
+the bulk idioms (a query in the loop header, SOQL for-loops over lists, chunked or
+literal-bound loops) and on calls that run once, such as a lazily filled cache.
+Ceiling: `while` loops, `Database.executeBatch` and `System.schedule` are not
+reported, and untested complexity needs measured coverage or a test the graph sees.
+
Each flow (`.flow-meta.xml`, or a legacy `.flow` in a `flows/` directory) is
one symbol named by its API name, linked to the Apex invocable actions,
subflows, screen components and Apex-defined types it names. Apex
diff --git a/docs/layers/LANGUAGE_SUPPORT.md b/docs/layers/LANGUAGE_SUPPORT.md
index 8b0177a71..50a2a305b 100644
--- a/docs/layers/LANGUAGE_SUPPORT.md
+++ b/docs/layers/LANGUAGE_SUPPORT.md
@@ -77,7 +77,8 @@ calls are entry paths the repository graph cannot observe.
Apex (`.cls`, `.trigger`, `.apex`) is parsed for symbols, heritage and calls,
resolved case-insensitively within each sfdx project's namespace; its dead-code
findings are review-only. Apex test coverage from the Salesforce CLI is read as a
-coverage report ([formats](TEST_INTELLIGENCE.md#supported-formats)).
+coverage report ([formats](TEST_INTELLIGENCE.md#supported-formats)). Health covers Apex
+complexity, class cohesion, and SOQL, DML and callouts inside loops.
Salesforce flows (`.flow-meta.xml`) are one symbol each, linked to the Apex
invocable actions, subflows and screen components they name.
diff --git a/packages/core/src/repowise/core/analysis/health/biomarkers/untested_complexity.py b/packages/core/src/repowise/core/analysis/health/biomarkers/untested_complexity.py
index 79d1d6598..2116c2d65 100644
--- a/packages/core/src/repowise/core/analysis/health/biomarkers/untested_complexity.py
+++ b/packages/core/src/repowise/core/analysis/health/biomarkers/untested_complexity.py
@@ -18,7 +18,15 @@ from ..crap import CRAP_THRESHOLD, coverage_tier, function_coverage, function_cr
from ..models import Severity
from .base import BiomarkerResult, FileContext
+# Apex tests reach code through platform dispatch the graph does not see, so "no
+# test found" is no evidence there. Lift when Apex test reach models dispatch.
+_UNSEEN_TEST_REACH = frozenset({"apex"})
+
_HIGH = 50.0
+
+
+def _unseen_reach(basis: str, tier: str, language: str) -> bool:
+ return basis != "measured" and tier == "none" and language in _UNSEEN_TEST_REACH
_CRITICAL = 100.0
_TIER_TEXT = {
@@ -68,6 +76,8 @@ class UntestedComplexityDetector:
result = function_crap(ccn, measured, tier)
if result.crap < CRAP_THRESHOLD:
continue
+ if _unseen_reach(result.basis, tier, ctx.language):
+ continue
is_measured = result.basis == "measured"
refactor = ccn >= CRAP_THRESHOLD
details: dict = {
diff --git a/packages/core/src/repowise/core/analysis/health/complexity/ast_utils.py b/packages/core/src/repowise/core/analysis/health/complexity/ast_utils.py
index 24d31a8fb..8bc0b3119 100644
--- a/packages/core/src/repowise/core/analysis/health/complexity/ast_utils.py
+++ b/packages/core/src/repowise/core/analysis/health/complexity/ast_utils.py
@@ -155,7 +155,7 @@ def _find_name(node: Node) -> str:
return names[-1].text.decode("utf-8", errors="replace")
# Swift: a computed property and a ``willSet`` / ``didSet`` block are named
# for the property that holds them, a subscript's body ``subscript``, and
- # ``deinit`` has no name node at all.
+ # ``deinit`` has no name node at all. An Apex accessor list is named the same way.
if node.type in _SWIFT_PROPERTY_UNITS:
return _swift_property_name(node)
if node.type == "deinit_declaration":
@@ -179,7 +179,7 @@ def _find_name(node: Node) -> str:
return "<anonymous>"
-_SWIFT_PROPERTY_UNITS = frozenset({"computed_property", "willset_didset_block"})
+_SWIFT_PROPERTY_UNITS = frozenset({"computed_property", "willset_didset_block", "accessor_list"})
def _swift_property_name(unit: Node) -> str:
@@ -188,7 +188,11 @@ def _swift_property_name(unit: Node) -> str:
return "<anonymous>"
if holder.type == "subscript_declaration":
return "subscript"
- name = holder.child_by_field_name("name")
+ # Apex keeps the property's name on its ``field_declaration``'s declarator.
+ declarator = holder.child_by_field_name("declarator")
+ name = holder.child_by_field_name("name") or (
+ declarator.child_by_field_name("name") if declarator is not None else None
+ )
text = "".join((name.text or b"").decode("utf-8", errors="replace").split()) if name else ""
return text or "<anonymous>"
diff --git a/packages/core/src/repowise/core/analysis/health/complexity/error_handling.py b/packages/core/src/repowise/core/analysis/health/complexity/error_handling.py
index a1776cb8b..248d9c533 100644
--- a/packages/core/src/repowise/core/analysis/health/complexity/error_handling.py
+++ b/packages/core/src/repowise/core/analysis/health/complexity/error_handling.py
@@ -236,7 +236,9 @@ def _eh_go_hit(node: Node) -> bool:
def _eh_java_try_ends_in_fail(catch_clause: Node, language: str) -> bool:
- """True when the enclosing Java try block's last real statement is a fail(...) call."""
+ """True when the enclosing Java or Apex try block's last real statement is a
+ ``fail(...)`` call, or Apex's ``System.assert(false, ...)``: the test expects
+ the throw, and the empty catch is where it lands."""
parent = catch_clause.parent
if parent is None or parent.type not in ("try_statement", "try_with_resources_statement"):
return False
@@ -255,7 +257,20 @@ def _eh_java_try_ends_in_fail(catch_clause: Node, language: str) -> bool:
if inv is None or inv.type != "method_invocation":
return False
name_node = inv.child_by_field_name("name")
- return name_node is not None and _eh_text(name_node) == "fail"
+ if name_node is None:
+ return False
+ if language == "apex":
+ return _eh_apex_expects_throw(inv, _eh_text(name_node).lower())
+ return _eh_text(name_node) == "fail"
+
+
+def _eh_apex_expects_throw(inv: Node, name: str) -> bool:
+ """``Assert.fail(...)`` or ``System.assert(false, ...)``, any case."""
+ if name == "fail":
+ return True
+ args = inv.child_by_field_name("arguments")
+ first = _eh_named(args)[0] if args is not None and _eh_named(args) else None
+ return name == "assert" and first is not None and _eh_text(first).lower() == "false"
# The node types ``_eh_rust_hit`` / ``_eh_go_hit`` can fire on.
@@ -324,7 +339,7 @@ def _eh_catch_visit(node: Node, language: str, hits: list[ErrorHandlingHit]) ->
block is not None
and _eh_body_is_swallowed(block, language)
and swallowed_unsuppressed
- and not (language == "java" and _eh_java_try_ends_in_fail(node, language))
+ and not (language in ("java", "apex") and _eh_java_try_ends_in_fail(node, language))
):
hits.append(ErrorHandlingHit("swallowed_catch", node.start_point[0] + 1))
if (
diff --git a/packages/core/src/repowise/core/analysis/health/complexity/languages.py b/packages/core/src/repowise/core/analysis/health/complexity/languages.py
index 22865f12f..e3fb3414e 100644
--- a/packages/core/src/repowise/core/analysis/health/complexity/languages.py
+++ b/packages/core/src/repowise/core/analysis/health/complexity/languages.py
@@ -604,6 +604,51 @@ _JAVA = LanguageNodeMap(
continue_kinds=frozenset({"continue_statement"}),
)
+
+def _apex_auto_property(node: Node) -> object:
+ """``{ get; set; }``: an accessor list with no accessor body declares state,
+ not code, so it is walked like a container and never scored."""
+ return node.type == "accessor_list" and not any(
+ c.child_by_field_name("body") is not None for c in node.named_children
+ )
+
+
+# Apex is Java-shaped. A trigger is a unit, and so is a property whose get/set
+# holds code (one unit per property); inline SOQL/SOSL and DML join ``call_kinds``.
+_APEX = LanguageNodeMap(
+ ctor_kinds=frozenset({"constructor_declaration"}),
+ fixed_signature_markers=frozenset({"override"}),
+ function_kinds=frozenset(
+ {"method_declaration", "constructor_declaration", "trigger_declaration", "accessor_list"}
+ ),
+ misread_scope=_apex_auto_property,
+ lambda_kinds=frozenset(),
+ branch_kinds=frozenset({"if_statement", "ternary_expression"}),
+ loop_kinds=frozenset(
+ {"for_statement", "enhanced_for_statement", "while_statement", "do_statement"}
+ ),
+ try_kinds=frozenset({"try_statement"}),
+ catch_kinds=frozenset({"catch_clause"}),
+ switch_kinds=frozenset({"switch_expression"}),
+ case_kinds=frozenset({"switch_rule"}),
+ boolean_operator_kinds=frozenset(),
+ boolean_operator_text_kinds=frozenset({"binary_expression"}),
+ class_kinds=frozenset({"class_declaration"}),
+ self_identifiers=frozenset({"this"}),
+ member_access_kinds=frozenset({"field_access", "method_invocation"}),
+ # A property is a ``field_declaration`` carrying an ``accessor_list``.
+ field_decl_kinds=frozenset({"field_declaration"}),
+ # A catch parameter is a ``formal_parameter`` too.
+ binding_kinds=frozenset({"variable_declarator", "formal_parameter", "enhanced_for_statement"}),
+ identifier_kinds=frozenset({"identifier"}),
+ nested_type_kinds=frozenset({"enum_declaration", "interface_declaration"}),
+ # ``Assert.*`` forms assertion runs; ``System.assert*`` counts but joins none.
+ assert_call_kinds=frozenset({"method_invocation"}),
+ call_kinds=frozenset(
+ {"method_invocation", "object_creation_expression", "query_expression", "dml_expression"}
+ ),
+)
+
_RUST = LanguageNodeMap(
trait_impl_kinds=frozenset({"impl_item"}),
scalar_type_names=frozenset(
@@ -1406,6 +1451,7 @@ LANGUAGE_MAPS: dict[str, LanguageNodeMap] = {
"jsx": _JS,
"go": _GO,
"java": _JAVA,
+ "apex": _APEX,
"rust": _RUST,
"kotlin": _KOTLIN,
"cpp": _CPP,
diff --git a/packages/core/src/repowise/core/analysis/health/complexity/perf_walk.py b/packages/core/src/repowise/core/analysis/health/complexity/perf_walk.py
index 196fa028f..41c32d667 100644
--- a/packages/core/src/repowise/core/analysis/health/complexity/perf_walk.py
+++ b/packages/core/src/repowise/core/analysis/health/complexity/perf_walk.py
@@ -611,6 +611,7 @@ class _PerfWalk:
self.do_bound = _overrides(dialect, "concurrency_bound")
self.do_loop_facts = self.do_chunked or self.do_magnitude or self.do_batch or self.do_bound
self.do_in_place = _overrides(dialect, "runs_in_place")
+ self.do_runs_once = _overrides(dialect, "runs_once_in_loop")
# Node kinds a loop, scope or call handler can apply to: one set test per node.
self.loop_probe = self.loop_kinds | (self.call_kinds if self.do_block_loop else frozenset())
self.scope_probe = self.scope_kinds | self.async_fn_kinds
@@ -978,13 +979,19 @@ class _PerfWalk:
subject=call.root_name if marker == _MEMBERSHIP else "",
)
)
- elif call.method and not (call.awaited and call.line in self.awaits_allowed):
+ elif self._is_loop_target(call):
self._record_loop_call(call, cur, nxt)
if self.do_lock_io and cur.lock_depth >= 1 and call.method:
lock_targets = self._acc(nxt.start, nxt.func)[1]
if call.method not in lock_targets:
lock_targets[call.method] = call.line
+ def _is_loop_target(self, call: _Call) -> bool:
+ """A loop-nested helper call that runs on each pass."""
+ if not call.method or (call.awaited and call.line in self.awaits_allowed):
+ return False
+ return not (self.do_runs_once and self.dialect.runs_once_in_loop(call.node))
+
def _record_loop_call(self, call: _Call, cur: _Frame, nxt: _Frame) -> None:
"""A loop-nested helper call, kept at the first line it is seen."""
targets = self._acc(nxt.start, nxt.func)[0]
diff --git a/packages/core/src/repowise/core/analysis/health/complexity/test_case.py b/packages/core/src/repowise/core/analysis/health/complexity/test_case.py
index 557c8bf19..48b74ec93 100644
--- a/packages/core/src/repowise/core/analysis/health/complexity/test_case.py
+++ b/packages/core/src/repowise/core/analysis/health/complexity/test_case.py
@@ -76,6 +76,10 @@ class TestCaseDialect:
#: qualified ``@org.junit.jupiter.api.Test`` matches the same row.
annotations: frozenset[str] = frozenset()
+ #: Lowercase modifier keywords that mark a case: Apex's legacy
+ #: ``static testMethod void t()``, read from the same ``modifiers`` subtree.
+ modifiers: frozenset[str] = frozenset()
+
#: Exact names a rule above would otherwise claim. Go's ``TestMain`` matches
#: ``TestXxx`` but is the test binary's entry point, not a case.
excluded_names: frozenset[str] = frozenset()
@@ -98,8 +102,13 @@ _JAVA = TestCaseDialect(
)
)
+# Apex: ``@IsTest`` on the method or the legacy ``testMethod`` modifier; a
+# class-level ``@IsTest`` alone marks no method.
+_APEX = TestCaseDialect(annotations=frozenset({"istest"}), modifiers=frozenset({"testmethod"}))
+
#: Keyed by ``LanguageTag``, as the sibling lexicons are.
TEST_CASE_DIALECTS: dict[str, TestCaseDialect] = {
+ "apex": _APEX,
"go": _GO,
"java": _JAVA,
"javascript": _JS_TS,
@@ -110,12 +119,16 @@ TEST_CASE_DIALECTS: dict[str, TestCaseDialect] = {
def _annotation_names(fn_node: Node) -> set[str]:
- """Lowercase last segments of the annotations on *fn_node*."""
+ """Lowercase last segments of the annotations on *fn_node*, and its
+ lowercase modifier keywords (an Apex ``modifier`` node)."""
modifiers = next((c for c in fn_node.children if c.type == _JAVA_MODIFIERS), None)
if modifiers is None:
return set()
names: set[str] = set()
for child in modifiers.children:
+ if child.type == "modifier" and child.text is not None:
+ names.add(child.text.decode("utf-8", errors="replace").lower())
+ continue
if child.type not in _JAVA_ANNOTATION_KINDS:
continue
name = child.child_by_field_name("name")
@@ -176,4 +189,5 @@ def is_test_case(fn_node: Node, name: str, language: str) -> bool:
return callee.split(".", 1)[0] in dialect.callback_callees
if _named_case(name, dialect):
return True
- return bool(dialect.annotations) and bool(dialect.annotations & _annotation_names(fn_node))
+ marks = dialect.annotations | dialect.modifiers
+ return bool(marks) and bool(marks & _annotation_names(fn_node))
diff --git a/packages/core/src/repowise/core/analysis/health/perf/dialects/__init__.py b/packages/core/src/repowise/core/analysis/health/perf/dialects/__init__.py
index 2f94c35b7..11799a3bc 100644
--- a/packages/core/src/repowise/core/analysis/health/perf/dialects/__init__.py
+++ b/packages/core/src/repowise/core/analysis/health/perf/dialects/__init__.py
@@ -14,6 +14,7 @@ No edits to the walker. A language absent here ⇒ the perf pass is silent for i
from __future__ import annotations
+from . import apex as _apex
from . import cpp as _cpp
from . import csharp as _csharp
from . import dart as _dart
@@ -42,6 +43,7 @@ _REGISTER: tuple[tuple[str, BasePerfDialect], ...] = (
("javascript", _ts_js.DIALECT),
("jsx", _ts_js.DIALECT),
("java", _java.DIALECT),
+ ("apex", _apex.DIALECT),
("go", _go.DIALECT),
("csharp", _csharp.DIALECT),
# Razor/Blazor reaches the pass as a C# buffer (its C# regions
diff --git a/packages/core/src/repowise/core/analysis/health/perf/dialects/apex.py b/packages/core/src/repowise/core/analysis/health/perf/dialects/apex.py
new file mode 100644
index 000000000..2133f0617
--- /dev/null
+++ b/packages/core/src/repowise/core/analysis/health/perf/dialects/apex.py
@@ -0,0 +1,509 @@
+"""Apex ``PerfDialect``: operations with governor limits inside a loop.
+
+Inline SOQL/SOSL and DML are statements, not calls, so the Apex node map lists
+them in ``call_kinds`` and :meth:`ApexPerfDialect.call_sink_kind` classifies
+them by node shape. The rest of the lexicon is the platform's static API
+(``Database.*``, callouts, ``Messaging.sendEmail``, ``System.enqueueJob``,
+same-class ``@future`` calls), matched case-insensitively. The Java dialect
+supplies the callee seam and the loop-source reading; only ``io_in_loop`` and
+``nested_loop_with_io`` are emitted.
+"""
+
+from __future__ import annotations
+
+import re
+from typing import TYPE_CHECKING
+
+from .iterables import upper_bound
+from .java import JavaPerfDialect
+
+if TYPE_CHECKING:
+ from tree_sitter import Node
+
+# Receiver (lowercased, ``System.`` prefix dropped) -> methods (lowercased) -> kind.
+# Ceiling: ``Database.executeBatch`` / ``System.schedule`` are out; their loops walk job types.
+_STATIC_SINKS: dict[str, dict[str, str]] = {
+ "database": dict.fromkeys(
+ (
+ "query", "querywithbinds", "countquery", "countquerywithbinds",
+ "getquerylocator", "getquerylocatorwithbinds", "insert", "update",
+ "upsert", "delete", "undelete", "merge", "emptyrecyclebin",
+ "convertlead", "insertimmediate", "updateimmediate", "deleteimmediate",
+ "insertasync", "updateasync", "deleteasync",
+ ),
+ "db",
+ ),
+ "search": dict.fromkeys(("query", "find", "suggest"), "db"),
+ "eventbus": {"publish": "db"},
+ "approval": dict.fromkeys(("process", "lock", "unlock"), "db"),
+ "system": {"enqueuejob": "db"},
+ "messaging": dict.fromkeys(("sendemail", "sendemailmessage"), "network"),
+ "webservicecallout": {"invoke": "network"},
+}
+
+_FN_KINDS: frozenset[str] = frozenset(
+ {"method_declaration", "constructor_declaration", "trigger_declaration", "accessor_list"}
+)
+_CLASS = frozenset({"class_declaration"})
+
+
+def _lower(node: Node | None) -> str:
+ return (node.text or b"").decode("utf-8", "replace").lower() if node is not None else ""
+
+
+def _ancestor(node: Node, kinds: frozenset[str]) -> Node | None:
+ cur = node.parent
+ while cur is not None and cur.type not in kinds:
+ cur = cur.parent
+ return cur
+
+
+def _declared_type(scope: Node, name: str) -> str | None:
+ """The lowercased type *scope* declares *name* with, as a local, a
+ parameter or (for a class) a field. ``None`` when nothing declares it."""
+ stack = [scope]
+ while stack:
+ cur = stack.pop()
+ if cur.type in ("local_variable_declaration", "field_declaration", "formal_parameter"):
+ names = [cur.child_by_field_name("name")] + [
+ d.child_by_field_name("name") for d in cur.children_by_field_name("declarator")
+ ]
+ if any(_lower(n) == name for n in names if n is not None):
+ return "".join(_lower(cur.child_by_field_name("type")).split())
+ continue
+ # A nested class declares its own names.
+ if cur is scope or cur.type != "class_declaration":
+ stack.extend(cur.children)
+ return None
+
+
+def _is_http(receiver: Node) -> bool:
+ """``new Http()``, or a name the enclosing method or class declares ``Http``."""
+ if receiver.type == "object_creation_expression":
+ return _lower(receiver.child_by_field_name("type")) in ("http", "system.http")
+ if receiver.type != "identifier":
+ return False
+ name = _lower(receiver)
+ for scope in (_ancestor(receiver, _FN_KINDS), _ancestor(receiver, _CLASS)):
+ if scope is None:
+ continue
+ declared = _declared_type(scope, name)
+ if declared is not None:
+ return declared in ("http", "system.http")
+ return False
+
+
+def _is_future_call(call: Node) -> bool:
+ """A call to a method of the enclosing class whose every overload is ``@future``."""
+ receiver = call.child_by_field_name("object")
+ cls = _ancestor(call, _CLASS)
+ if cls is None:
+ return False
+ if receiver is not None and _lower(receiver) != _lower(cls.child_by_field_name("name")):
+ return False
+ name = _lower(call.child_by_field_name("name"))
+ body = cls.child_by_field_name("body")
+ found = False
+ for member in body.named_children if body is not None else ():
+ if member.type != "method_declaration" or _lower(member.child_by_field_name("name")) != name:
+ continue
+ mods = next((c for c in member.children if c.type == "modifiers"), None)
+ annotations = [] if mods is None else [c for c in mods.children if c.type == "annotation"]
+ if not any(_lower(a.child_by_field_name("name")) == "future" for a in annotations):
+ return False
+ found = True
+ return found
+
+
+class ApexPerfDialect(JavaPerfDialect):
+ language = "apex"
+ markers = frozenset({"io_in_loop", "nested_loop_with_io"})
+ function_kinds = _FN_KINDS
+ int_kinds = frozenset({"int"})
+
+ # -- callee seam: inline SOQL/SOSL and DML have no callee ------------------
+
+ def callee_method_name(self, call_node: Node) -> str | None:
+ if call_node.type == "query_expression":
+ body = call_node.named_children[0] if call_node.named_children else None
+ return "SOSL" if body is not None and body.type == "sosl_query_body" else "SOQL"
+ if call_node.type == "dml_expression":
+ kind = next((c for c in call_node.children if c.type == "dml_type"), None)
+ return _lower(kind) or None
+ return super().callee_method_name(call_node)
+
+ def callee_root_name(self, call_node: Node) -> str | None:
+ if call_node.type in ("query_expression", "dml_expression"):
+ return self.callee_method_name(call_node)
+ return super().callee_root_name(call_node)
+
+ def callee_is_attribute(self, call_node: Node) -> bool:
+ if call_node.type in ("query_expression", "dml_expression"):
+ return False
+ return super().callee_is_attribute(call_node)
+
+ # -- lexicon ----------------------------------------------------------------
+
+ def call_sink_kind(
+ self, call: Node, *, awaited: bool, io_names: dict[str, str], has_db_import: bool
+ ) -> str | None:
+ kind = _sink_kind(call)
+ if kind is None or _runs_once(call):
+ return None
+ return kind
+
+ def is_literal(self, node: Node) -> bool:
+ # ``new List<String>{'a', 'b'}``: the entries sit in its initializer.
+ init = next((c for c in node.children if c.type == "array_initializer"), None)
+ return node.type == "array_creation_expression" and init is not None and bool(
+ init.named_children
+ )
+
+ def is_constant_loop(self, node: Node) -> bool:
+ """A loop whose body is no per-record work: a literal bound (``i < 6``, a
+ literal list), a walk over chunks (``i += size``, a list of lists, or
+ ``for (List<Account> chunk : [SELECT ...])``, the platform's 200-row
+ batch idiom), a retry inside a ``catch`` after a bulk call failed, and
+ ``while`` / ``do``, which walk a cursor or a chain. Ceiling: any loop
+ inside a ``catch`` and any ``while`` (a SOQL per hierarchy level) go
+ unreported."""
+ if node.type in ("while_statement", "do_statement"):
+ return True
+ holder = _ancestor(node, _SCOPES | {"catch_clause"})
+ if holder is not None and holder.type == "catch_clause":
+ return True
+ if node.type == "for_statement":
+ update = "".join(_lower(node.child_by_field_name("update")).split())
+ step = update.partition("+=")[2]
+ if (step and step != "1") or _walks_chunks(node):
+ return True
+ elif node.type == "enhanced_for_statement":
+ declared = "".join(_lower(node.child_by_field_name("type")).split())
+ if declared.startswith(("list<", "set<")) or declared.endswith("[]"):
+ return True
+ else:
+ return False
+ source = self.loop_source(node, lambda _call: None)
+ return source is not None and source.magnitude == "bounded"
+
+ def is_iteration_loop(self, node: Node) -> bool:
+ return node.type in ("for_statement", "enhanced_for_statement")
+
+ def runs_once_in_loop(self, call: Node) -> bool:
+ return _loop_ends_after(call)
+
+
+def _walks_chunks(loop: Node) -> bool:
+ """``for (i = 0; i < groups.size(); i++)`` where each entry of ``groups`` is a collection."""
+ stop = upper_bound(loop.child_by_field_name("condition"))
+ owner = stop.child_by_field_name("object") if stop is not None else None
+ if stop is None or owner is None or _lower(stop.child_by_field_name("name")) != "size":
+ return False
+ for scope in (_ancestor(loop, _FN_KINDS), _ancestor(loop, _CLASS)):
+ declared = _declared_type(scope, _lower(owner)) if scope is not None else None
+ if declared is not None:
+ return _holds_collections(declared)
+ return False
+
+
+def _holds_collections(declared: str) -> bool:
+ """``list<list<x>>``, ``x[][]``, ``map<k,list<x>>``: a container of collections."""
+ if declared.endswith("[][]"):
+ return True
+ head, _, inner = declared.partition("<")
+ if head == "map":
+ depth = 0
+ for i, char in enumerate(inner):
+ depth += char == "<"
+ depth -= char == ">"
+ if char == "," and depth == 0:
+ inner = inner[i + 1 :]
+ break
+ elif head not in ("list", "set"):
+ return False
+ return inner.startswith(("list<", "set<", "map<")) or inner.removesuffix(">").endswith("[]")
+
+
+def _sink_kind(call: Node) -> str | None:
+ if call.type in ("query_expression", "dml_expression"):
+ return "db"
+ if call.type != "method_invocation":
+ return None
+ method = _lower(call.child_by_field_name("name"))
+ receiver = call.child_by_field_name("object")
+ if receiver is None:
+ return "db" if _is_future_call(call) else None
+ owner = _lower(receiver).removeprefix("system.")
+ kind = _STATIC_SINKS.get(owner, {}).get(method)
+ if kind is not None:
+ return kind
+ if method == "send" and _is_http(receiver):
+ return "network"
+ return "db" if _is_future_call(call) else None
+
+
+# -- operations that run once, or are the bulk idiom, though written in a loop --
+
+_DATABASE = ("database", "system.database")
+_DYNAMIC_QUERIES = frozenset(
+ {
+ "query", "querywithbinds", "countquery", "countquerywithbinds",
+ "getquerylocator", "getquerylocatorwithbinds",
+ }
+)
+_LOOP_KINDS = frozenset(
+ {"for_statement", "enhanced_for_statement", "while_statement", "do_statement"}
+)
+_SCOPES = _FN_KINDS | _CLASS
+# ``' FROM ' + objName``: the object a dynamic query reads changes with a value.
+_FROM_A_VALUE = re.compile(r"\bfrom\s*'\s*\+", re.IGNORECASE)
+# Custom metadata type queries do not count against the SOQL limit.
+_FROM_METADATA = re.compile(r"\bfrom\s+\w+__mdt\b", re.IGNORECASE)
+_SPACES = re.compile(r"\s+")
+
+
+def _runs_once(call: Node) -> bool:
+ """*call* is no per-iteration governor cost: ``merge`` (three records at
+ most), a custom metadata query, a dynamic query per object type, a lazily
+ filled cache, a sink a Boolean parameter switches, DML of a per-group list,
+ a buffer flushed at a size, or a loop that ends after it. Ceiling: a
+ per-record query built with ``' FROM ' +`` is not reported."""
+ if _is_merge(call):
+ return True
+ text = _query_text(call)
+ if text and (_FROM_METADATA.search(text) or _FROM_A_VALUE.search(text)):
+ return True
+ if _cached(call) or _parameter_switched(call):
+ return True
+ target = _dml_target(call)
+ if target is not None and (_per_group_list(target) or _flushed_buffer(call, target)):
+ return True
+ return _loop_ends_after(call)
+
+
+def _database_method(call: Node) -> str | None:
+ if call.type != "method_invocation":
+ return None
+ if _lower(call.child_by_field_name("object")) not in _DATABASE:
+ return None
+ return _lower(call.child_by_field_name("name"))
+
+
+def _is_merge(call: Node) -> bool:
+ if call.type == "dml_expression":
+ kind = next((c for c in call.children if c.type == "dml_type"), None)
+ return _lower(kind) == "merge"
+ return _database_method(call) == "merge"
+
+
+def _first_argument(call: Node) -> Node | None:
+ args = call.child_by_field_name("arguments")
+ return next(iter(args.named_children), None) if args is not None else None
+
+
+def _query_text(call: Node) -> str:
+ """The SOQL a query runs: its own text, or for a dynamic query its string
+ argument plus every assignment the method makes to that name."""
+ if call.type == "query_expression":
+ return _lower(call)
+ if _database_method(call) not in _DYNAMIC_QUERIES:
+ return ""
+ arg = _first_argument(call)
+ if arg is None or arg.type != "identifier":
+ return _lower(arg)
+ name = _lower(arg)
+ scope = _ancestor(call, _FN_KINDS)
+ parts: list[str] = []
+ stack = [scope] if scope is not None else []
+ while stack:
+ cur = stack.pop()
+ if cur.type == "variable_declarator" and _lower(cur.child_by_field_name("name")) == name:
+ parts.append(_lower(cur.child_by_field_name("value")))
+ elif cur.type == "assignment_expression" and _lower(cur.child_by_field_name("left")) == name:
+ parts.append(_lower(cur.child_by_field_name("right")))
+ stack.extend(cur.children)
+ return "\n".join(parts)
+
+
+def _dml_target(call: Node) -> Node | None:
+ if call.type == "dml_expression":
+ return call.child_by_field_name("target")
+ method = _database_method(call)
+ if method is None or method in _DYNAMIC_QUERIES:
+ return None
+ return _first_argument(call)
+
+
+def _normalised(node: Node | None) -> str:
+ return _SPACES.sub("", _lower(node)).removeprefix("this.")
+
+
+def _fills(node: Node, name: str) -> bool:
+ """*node*'s subtree stores into *name*: ``x = ...`` or ``x.put(...)``."""
+ stack = [node]
+ while stack:
+ cur = stack.pop()
+ if cur.type == "assignment_expression" and _normalised(cur.child_by_field_name("left")) == name:
+ return True
+ if (
+ cur.type == "method_invocation"
+ and _normalised(cur.child_by_field_name("object")) == name
+ and _lower(cur.child_by_field_name("name")) in ("put", "putall")
+ ):
+ return True
+ stack.extend(cur.children)
+ return False
+
+
+# ``x == null`` / ``x.f == null`` / ``x.get(k) == null`` / ``!x.containsKey(k)``, and the opposites.
+_MISSING = re.compile(r"^(?:([\w.]+?)(?:\.get\(.*\))?==null|null==([\w.]+?)(?:\.get\(.*\))?|!([\w.]+?)\.containskey\(.*\))$")
+_PRESENT = re.compile(r"^(?:([\w.]+?)(?:\.get\(.*\))?!=null|null!=([\w.]+?)(?:\.get\(.*\))?|([\w.]+?)\.containskey\(.*\))$")
+
+
+def _cache_name(condition: Node | None, test: re.Pattern[str]) -> str | None:
+ found = test.match(_normalised(condition).removeprefix("(").removesuffix(")").removeprefix("this."))
+ return next((g for g in found.groups() if g), None) if found else None
+
+
+def _sole_statement(branch: Node | None) -> Node | None:
+ """The one statement of an ``if`` branch, braced or not; ``None`` otherwise."""
+ if branch is None or branch.type != "block":
+ return branch
+ inner = branch.named_children
+ return inner[0] if len(inner) == 1 else None
+
+
+def _fills_when_missing(branch: Node, call: Node) -> bool:
+ """*branch* is ``if (x == null)`` whose consequence holds *call* and fills ``x``."""
+ name = _cache_name(branch.child_by_field_name("condition"), _MISSING)
+ consequence = branch.child_by_field_name("consequence")
+ return bool(
+ name
+ and consequence is not None
+ and consequence.start_byte <= call.start_byte < consequence.end_byte
+ and _fills(consequence, name)
+ )
+
+
+def _cached(call: Node) -> bool:
+ """A lazily filled cache: *call* sits in ``if (x == null)`` (or ``x.get(k)``,
+ ``!x.containsKey(k)``) whose branch fills ``x``, or its method opens with
+ ``if (x != null) return ...;`` and fills ``x`` below."""
+ fn = _ancestor(call, _FN_KINDS)
+ cur = call.parent
+ while cur is not None and cur is not fn:
+ if cur.type == "if_statement" and _fills_when_missing(cur, call):
+ return True
+ cur = cur.parent
+ body = fn.child_by_field_name("body") if fn is not None else None
+ first = next(iter(body.named_children), None) if body is not None else None
+ if first is None or first.type != "if_statement":
+ return False
+ name = _cache_name(first.child_by_field_name("condition"), _PRESENT)
+ returns = _sole_statement(first.child_by_field_name("consequence"))
+ return bool(name) and returns is not None and returns.type == "return_statement" and _fills(body, name)
+
+
+def _parameter_switched(call: Node) -> bool:
+ """Outside any loop, under ``if (flag)`` on a Boolean parameter of its method
+ (``if (doInsert) insert rows;``): whether it runs is the caller's argument,
+ which reachability does not read. Ceiling: a caller passing ``true`` in a
+ loop is not reported."""
+ fn = _ancestor(call, _FN_KINDS)
+ params = fn.child_by_field_name("parameters") if fn is not None else None
+ if params is None:
+ return False
+ flags = {
+ _lower(p.child_by_field_name("name"))
+ for p in params.named_children
+ if _lower(p.child_by_field_name("type")) == "boolean"
+ }
+ cur = call.parent
+ switched = False
+ while cur is not None and cur is not fn:
+ if cur.type in _LOOP_KINDS:
+ return False
+ if cur.type == "if_statement":
+ condition = _normalised(cur.child_by_field_name("condition")).strip("()")
+ switched = switched or condition.removesuffix("==true") in flags
+ cur = cur.parent
+ return switched
+
+
+def _per_group_list(target: Node) -> bool:
+ """``byType.get(t)`` where ``byType`` is declared a map whose values are lists."""
+ if target.type != "method_invocation" or _lower(target.child_by_field_name("name")) != "get":
+ return False
+ owner = target.child_by_field_name("object")
+ if owner is None or owner.type != "identifier":
+ return False
+ for scope in (_ancestor(target, _FN_KINDS), _ancestor(target, _CLASS)):
+ declared = _declared_type(scope, _lower(owner)) if scope is not None else None
+ if declared is not None:
+ return declared.startswith("map<") and _holds_collections(declared)
+ return False
+
+
+def _flushed_buffer(call: Node, target: Node) -> bool:
+ """DML on ``buf`` under a branch that tests ``buf.size()`` against a batch
+ size (``== 100``, ``>= BATCH``); an emptiness test (``> 0``) is no flush."""
+ if target.type != "identifier":
+ return False
+ threshold = re.compile(re.escape(_lower(target)) + r"\.size\(\)(?:==|>=|>)(\d+|[a-z_][\w.]*)")
+ cur = call.parent
+ while cur is not None and cur.type not in _SCOPES and cur.type not in _LOOP_KINDS:
+ if cur.type == "if_statement":
+ condition = _normalised(cur.child_by_field_name("condition")).removeprefix("(").removesuffix(")")
+ found = threshold.fullmatch(condition)
+ if found and not (found[1].isdigit() and int(found[1]) < 2):
+ return True
+ cur = cur.parent
+ return False
+
+
+def _loop_ends_after(call: Node) -> bool:
+ """The loop ends right after *call*: a ``return`` or ``break`` follows it in
+ its own block, or the next exit tests a flag the ``try`` around *call* sets
+ (retry until one attempt succeeds). A ``break`` counts only when one loop
+ surrounds *call*. An exit on any other condition keeps the hit."""
+ loops = 0
+ cur = call.parent
+ while cur is not None and cur.type not in _SCOPES:
+ loops += cur.type in _LOOP_KINDS
+ cur = cur.parent
+ if not loops:
+ return False
+ exits = ("return_statement", "break_statement") if loops == 1 else ("return_statement",)
+ statement = call
+ while statement.parent is not None and statement.parent.type != "block":
+ statement = statement.parent
+ return any(s.type in exits for s in _later_siblings(statement)) or _retry_exit(call, exits)
+
+
+def _retry_exit(call: Node, exits: tuple[str, ...]) -> bool:
+ """``try { <call> } catch (...) { ok = false; } if (ok) break;``."""
+ attempt = _ancestor(call, _SCOPES | _LOOP_KINDS | {"try_statement"})
+ if attempt is None or attempt.type != "try_statement":
+ return False
+ later = next((n for n in _later_siblings(attempt) if n.type == "if_statement"), None)
+ leave = _sole_statement(later.child_by_field_name("consequence")) if later is not None else None
+ if leave is None or leave.type not in exits:
+ return False
+ flags = {
+ _normalised(n.child_by_field_name("left"))
+ for n in ApexPerfDialect._walk(attempt)
+ if n.type == "assignment_expression"
+ }
+ return _normalised(later.child_by_field_name("condition")).strip("()!") in flags
+
+
+def _later_siblings(node: Node) -> list[Node]:
+ out: list[Node] = []
+ nxt = node.next_named_sibling
+ while nxt is not None:
+ out.append(nxt)
+ nxt = nxt.next_named_sibling
+ return out
+
+
+DIALECT = ApexPerfDialect()
diff --git a/packages/core/src/repowise/core/analysis/health/perf/dialects/base.py b/packages/core/src/repowise/core/analysis/health/perf/dialects/base.py
index b104d1dab..4771e8d10 100644
--- a/packages/core/src/repowise/core/analysis/health/perf/dialects/base.py
+++ b/packages/core/src/repowise/core/analysis/health/perf/dialects/base.py
@@ -236,6 +236,11 @@ class BasePerfDialect:
has_db_import=has_db_import,
)
+ def runs_once_in_loop(self, call: Node) -> bool:
+ """*call* sits in a loop it ends (a ``return`` or ``break`` follows), so it
+ is no per-iteration call to a helper."""
+ return False
+
def defers_body(self, fn: Node) -> bool:
"""*fn*'s body runs when its result is iterated, not when it is called
(a generator, or an iterator closure that takes a ``yield`` callback)."""
diff --git a/tests/fixtures/lang_samples/apex/assertions.cls b/tests/fixtures/lang_samples/apex/assertions.cls
new file mode 100644
index 000000000..ffa1a4b27
--- /dev/null
+++ b/tests/fixtures/lang_samples/apex/assertions.cls
@@ -0,0 +1,40 @@
+// Fixtures for Apex assertion-block detection and test-case recognition.
+@IsTest
+private class Assertions {
+ @IsTest
+ static void testManyAsserts() {
+ Integer x = compute();
+ System.assertEquals(1, x);
+ System.assertNotEquals(2, x);
+ Assert.areEqual(1, x);
+ Assert.isTrue(x > 0);
+ System.assert(x != 3, 'not three');
+ }
+
+ @isTest
+ static void testFewAsserts() {
+ Integer x = compute();
+ Assert.areEqual(1, x);
+ Integer y = x + 1;
+ Assert.areEqual(2, y);
+ }
+
+ static testMethod void legacyCase() {
+ Integer x = compute();
+ System.assertEquals(1, x);
+ }
+
+ @IsTest
+ static void checksNothing() {
+ compute();
+ }
+
+ @TestSetup
+ static void makeData() {
+ insert new Account(Name = 'x');
+ }
+
+ private static Integer compute() {
+ return 1;
+ }
+}
diff --git a/tests/fixtures/lang_samples/apex/classes.cls b/tests/fixtures/lang_samples/apex/classes.cls
new file mode 100644
index 000000000..fc84cd1c4
--- /dev/null
+++ b/tests/fixtures/lang_samples/apex/classes.cls
@@ -0,0 +1,67 @@
+// Fixtures for Apex class-level (LCOM4 / god-class) walker tests. Apex reads
+// its own members bare or through `this.`; both count as member references.
+public class Classes {
+ public class Cohesive {
+ private Integer total = 0;
+ private Integer count = 0;
+
+ public void add(Integer n) {
+ total += n;
+ this.count += 1;
+ }
+
+ public Integer average() {
+ return count == 0 ? 0 : total / count;
+ }
+
+ public void reset() {
+ total = 0;
+ count = 0;
+ }
+ }
+
+ public class Splintered {
+ private Integer a = 0;
+ private Integer a2 = 0;
+ private Integer b = 0;
+ private Integer b2 = 0;
+
+ public void setA(Integer v) {
+ a = v;
+ a2 = v;
+ }
+
+ public Integer getA() {
+ return a + a2;
+ }
+
+ public void setB(Integer v) {
+ this.b = v;
+ this.b2 = v;
+ }
+
+ public Integer getB() {
+ return b + b2;
+ }
+ }
+
+ public class WithProperties {
+ public String label { get; set; }
+ public Integer size {
+ get {
+ return items.size();
+ }
+ }
+ private List<String> items = new List<String>();
+
+ public void add(String item) {
+ items.add(item);
+ }
+ }
+
+ public interface Shape {
+ Decimal area();
+ }
+
+ public enum Mode { SYNC, ASYNC }
+}
diff --git a/tests/fixtures/lang_samples/apex/nested.cls b/tests/fixtures/lang_samples/apex/nested.cls
new file mode 100644
index 000000000..fa6e094f5
--- /dev/null
+++ b/tests/fixtures/lang_samples/apex/nested.cls
@@ -0,0 +1,67 @@
+// Fixtures for Apex complexity and nesting walker tests.
+public with sharing class Nested {
+ public Integer deeplyNested(List<Integer> values) {
+ if (values != null) {
+ for (Integer v : values) {
+ if (v > 0) {
+ while (v > 10) {
+ try {
+ if (v == 50) {
+ return v;
+ }
+ } catch (MathException e) {
+ v = 0;
+ }
+ v--;
+ }
+ }
+ }
+ }
+ return 0;
+ }
+
+ public String manyBranches(Integer a, Integer b, String s) {
+ if (a > 0 && b > 0) {
+ return 'both';
+ } else if (a > 0 || b > 0) {
+ return 'one';
+ }
+ if (s == null) {
+ return 'none';
+ }
+ String t = s ?? 'x';
+ return a > b ? 'a' : 'b';
+ }
+
+ public String dispatch(Integer code) {
+ switch on code {
+ when 1 {
+ return 'one';
+ }
+ when 2, 3 {
+ return 'few';
+ }
+ when else {
+ return 'many';
+ }
+ }
+ }
+
+ public Integer shallow(Integer x) {
+ return x + 1;
+ }
+
+ public Integer total {
+ get {
+ if (cached == null) {
+ cached = 0;
+ }
+ return cached;
+ }
+ set;
+ }
+
+ public String label { get; set; }
+
+ private Integer cached;
+}
diff --git a/tests/fixtures/lang_samples/apex/perf_io_in_loop.cls b/tests/fixtures/lang_samples/apex/perf_io_in_loop.cls
new file mode 100644
index 000000000..6dec6ad85
--- /dev/null
+++ b/tests/fixtures/lang_samples/apex/perf_io_in_loop.cls
@@ -0,0 +1,144 @@
+// Fixtures for the Apex perf dialect: operations with governor limits inside
+// a loop fire io_in_loop; the bulk idioms and run-once shapes stay quiet.
+public with sharing class PerfIoInLoop {
+ // -- fire ------------------------------------------------------------------
+
+ public void soqlPerRecord(List<Contact> contacts) {
+ for (Contact c : contacts) {
+ Account a = [SELECT Id FROM Account WHERE Id = :c.AccountId];
+ }
+ }
+
+ public void dmlPerRecord(List<Account> accounts) {
+ for (Account a : accounts) {
+ update a;
+ }
+ }
+
+ public void databaseAndCallout(List<Id> ids, HttpRequest req) {
+ Http http = new Http();
+ for (Id i : ids) {
+ Database.delete(i);
+ HttpResponse res = http.send(req);
+ }
+ }
+
+ public void asyncPerRecord(List<Id> ids) {
+ for (Id i : ids) {
+ System.enqueueJob(new Worker(i));
+ notifyLater(i);
+ }
+ }
+
+ @future
+ private static void notifyLater(Id i) {
+ }
+
+ public void nested(List<Account> accounts) {
+ for (Account a : accounts) {
+ for (Contact c : a.Contacts) {
+ insert new Task(WhoId = c.Id);
+ }
+ }
+ }
+
+ // -- stay quiet --------------------------------------------------------------
+
+ public void bulk(List<Account> accounts) {
+ List<Account> changed = new List<Account>();
+ for (Account a : accounts) {
+ changed.add(a);
+ }
+ update changed;
+ List<Contact> rows = [SELECT Id FROM Contact WHERE AccountId IN :accounts];
+ }
+
+ public void queryInHeader() {
+ for (Account a : [SELECT Id FROM Account]) {
+ a.Name = 'x';
+ }
+ }
+
+ public void soqlForChunks() {
+ for (List<Account> chunk : [SELECT Id FROM Account]) {
+ update chunk;
+ }
+ }
+
+ public void literalBound(Account a) {
+ for (Integer i = 0; i < 3; i++) {
+ insert new Task(WhatId = a.Id);
+ }
+ for (String s : new List<String>{ 'a', 'b' }) {
+ insert new Task(Subject = s);
+ }
+ }
+
+ public void chunked(List<Account> rows, Integer size) {
+ for (Integer i = 0; i < rows.size(); i += size) {
+ Database.update(rows, false);
+ }
+ }
+
+ public void flushAtSize(List<Account> rows) {
+ List<Account> buffer = new List<Account>();
+ for (Account a : rows) {
+ buffer.add(a);
+ if (buffer.size() == 100) {
+ insert buffer;
+ buffer.clear();
+ }
+ }
+ }
+
+ public void cached(List<Account> rows) {
+ Map<Id, Account> byId;
+ for (Account a : rows) {
+ if (byId == null) {
+ byId = new Map<Id, Account>([SELECT Id FROM Account]);
+ }
+ }
+ }
+
+ public void firstMatch(List<Account> rows) {
+ for (Account a : rows) {
+ if (a.Name == 'x') {
+ update a;
+ break;
+ }
+ }
+ }
+
+ public void perObjectType(Map<String, Set<Id>> idsByType) {
+ for (String objectName : idsByType.keySet()) {
+ Set<Id> ids = idsByType.get(objectName);
+ List<SObject> recs = Database.query('SELECT Id FROM ' + objectName + ' WHERE Id IN :ids');
+ }
+ }
+
+ public void perGroup(Map<String, List<SObject>> byType) {
+ for (String t : byType.keySet()) {
+ insert byType.get(t);
+ }
+ }
+
+ public void customMetadata(List<String> names) {
+ for (String n : names) {
+ List<Setting__mdt> s = [SELECT Id FROM Setting__mdt WHERE DeveloperName = :n];
+ }
+ }
+
+ public void mergeAll(Account master, List<Account> dupes) {
+ for (Account d : dupes) {
+ merge master d;
+ }
+ }
+
+ // Ceiling: a hierarchy walk in a `while` is not reported.
+ public void cursor(Id startId) {
+ Id current = startId;
+ while (current != null) {
+ current = [SELECT ParentId FROM Account WHERE Id = :current].ParentId;
+ }
+ }
+}
diff --git a/tests/unit/health/golden/health_engine.json b/tests/unit/health/golden/health_engine.json
index d0ba1a4e5..3848188f5 100644
--- a/tests/unit/health/golden/health_engine.json
+++ b/tests/unit/health/golden/health_engine.json
@@ -865,39 +865,115 @@
"metrics": [
{
"file_path": "apex/AccountService.cls",
- "score": null,
- "max_ccn": null,
- "max_nesting": null,
- "nloc": 40,
+ "score": 10.0,
+ "max_ccn": 1,
+ "max_nesting": 0,
+ "nloc": 36,
"has_test_file": false,
"module": "apex",
"duplication_pct": null,
"line_coverage_pct": null,
"branch_coverage_pct": null,
- "defect_score": null,
- "maintainability_score": null,
- "performance_score": null,
- "structure_deduction": null,
- "history_deduction": null,
+ "defect_score": 10.0,
+ "maintainability_score": 10.0,
+ "performance_score": 10.0,
+ "structure_deduction": 0.0,
+ "history_deduction": 0.0,
"is_test": false,
"code_origin": "production"
},
{
"file_path": "apex/AccountTrigger.trigger",
- "score": null,
- "max_ccn": null,
- "max_nesting": null,
+ "score": 10.0,
+ "max_ccn": 1,
+ "max_nesting": 0,
"nloc": 4,
"has_test_file": false,
"module": "apex",
"duplication_pct": null,
"line_coverage_pct": null,
"branch_coverage_pct": null,
- "defect_score": null,
- "maintainability_score": null,
- "performance_score": null,
- "structure_deduction": null,
- "history_deduction": null,
+ "defect_score": 10.0,
+ "maintainability_score": 10.0,
+ "performance_score": 10.0,
+ "structure_deduction": 0.0,
+ "history_deduction": 0.0,
+ "is_test": false,
+ "code_origin": "production"
+ },
+ {
+ "file_path": "apex/assertions.cls",
+ "score": 10.0,
+ "max_ccn": 1,
+ "max_nesting": 0,
+ "nloc": 34,
+ "has_test_file": true,
+ "module": "apex",
+ "duplication_pct": null,
+ "line_coverage_pct": null,
+ "branch_coverage_pct": null,
+ "defect_score": 10.0,
+ "maintainability_score": 10.0,
+ "performance_score": 10.0,
+ "structure_deduction": 0.0,
+ "history_deduction": 0.0,
+ "is_test": true,
+ "code_origin": "test"
+ },
+ {
+ "file_path": "apex/classes.cls",
+ "score": 10.0,
+ "max_ccn": 2,
+ "max_nesting": 1,
+ "nloc": 53,
+ "has_test_file": false,
+ "module": "apex",
+ "duplication_pct": null,
+ "line_coverage_pct": null,
+ "branch_coverage_pct": null,
+ "defect_score": 10.0,
+ "maintainability_score": 10.0,
+ "performance_score": 10.0,
+ "structure_deduction": 0.0,
+ "history_deduction": 0.0,
+ "is_test": false,
+ "code_origin": "production"
+ },
+ {
+ "file_path": "apex/nested.cls",
+ "score": 8.55,
+ "max_ccn": 7,
+ "max_nesting": 5,
+ "nloc": 60,
+ "has_test_file": false,
+ "module": "apex",
+ "duplication_pct": null,
+ "line_coverage_pct": null,
+ "branch_coverage_pct": null,
+ "defect_score": 8.55,
+ "maintainability_score": 8.8,
+ "performance_score": 10.0,
+ "structure_deduction": 1.452,
+ "history_deduction": 0.0,
+ "is_test": false,
+ "code_origin": "production"
+ },
+ {
+ "file_path": "apex/perf_io_in_loop.cls",
+ "score": 10.0,
+ "max_ccn": 3,
+ "max_nesting": 2,
+ "nloc": 119,
+ "has_test_file": false,
+ "module": "apex",
+ "duplication_pct": null,
+ "line_coverage_pct": null,
+ "branch_coverage_pct": null,
+ "defect_score": 10.0,
+ "maintainability_score": 10.0,
+ "performance_score": 8.0,
+ "structure_deduction": 0.0,
+ "history_deduction": 0.0,
"is_test": false,
"code_origin": "production"
},
@@ -2176,6 +2252,211 @@
}
],
"findings": [
+ {
+ "biomarker_type": "nested_complexity",
+ "severity": "high",
+ "file_path": "apex/nested.cls",
+ "function_name": "deeplyNested",
+ "line_start": 3,
+ "line_end": 21,
+ "details": {
+ "max_nesting": 5,
+ "ccn": 7,
+ "cognitive": 20,
+ "dispatch_share": 0.0,
+ "symbol_line": 3,
+ "deepest_block": {
+ "start": 8,
+ "end": 14
+ }
+ },
+ "health_impact": 1.452,
+ "reason": "deeplyNested nests 5 levels deep",
+ "dimension": "defect",
+ "id": "finding_e2bc6665fe8f36d35f95"
+ },
+ {
+ "biomarker_type": "io_in_loop",
+ "severity": "medium",
+ "file_path": "apex/perf_io_in_loop.cls",
+ "function_name": "soqlPerRecord",
+ "line_start": 8,
+ "line_end": 8,
+ "details": {
+ "boundary_kind": "db",
+ "cross_function": false,
+ "loop_iterates": "parameter",
+ "loop_line": 7,
+ "sink_call": "SOQL",
+ "symbol_line": 6,
+ "role_owner": "apex/perf_io_in_loop.cls::PerfIoInLoop::soqlPerRecord",
+ "execution_role": "unknown",
+ "opportunity_id": "perf3_2dc2d05483e3be154222"
+ },
+ "health_impact": 0.0,
+ "reason": "a database call runs once per loop iteration (N+1 query)",
+ "dimension": "performance",
+ "id": "finding_b424265e962a4fbc7e8b"
+ },
+ {
+ "biomarker_type": "io_in_loop",
+ "severity": "medium",
+ "file_path": "apex/perf_io_in_loop.cls",
+ "function_name": "dmlPerRecord",
+ "line_start": 14,
+ "line_end": 14,
+ "details": {
+ "boundary_kind": "db",
+ "cross_function": false,
+ "loop_iterates": "parameter",
+ "loop_line": 13,
+ "sink_call": "update",
+ "symbol_line": 12,
+ "role_owner": "apex/perf_io_in_loop.cls::PerfIoInLoop::dmlPerRecord",
+ "execution_role": "unknown",
+ "opportunity_id": "perf3_7adb36b5d04725ba470e"
+ },
+ "health_impact": 0.0,
+ "reason": "a database call runs once per loop iteration (N+1 query)",
+ "dimension": "performance",
+ "id": "finding_22382e45520ab6bb7b0d"
+ },
+ {
+ "biomarker_type": "io_in_loop",
+ "severity": "medium",
+ "file_path": "apex/perf_io_in_loop.cls",
+ "function_name": "databaseAndCallout",
+ "line_start": 21,
+ "line_end": 21,
+ "details": {
+ "boundary_kind": "db",
+ "cross_function": false,
+ "loop_iterates": "parameter",
+ "loop_line": 20,
+ "sink_call": "Database.delete",
+ "symbol_line": 18,
+ "role_owner": "apex/perf_io_in_loop.cls::PerfIoInLoop::databaseAndCallout",
+ "execution_role": "unknown",
+ "opportunity_id": "perf3_8ecdf8a7dacf3c71dd27"
+ },
+ "health_impact": 0.0,
+ "reason": "a database call runs once per loop iteration (N+1 query)",
+ "dimension": "performance",
+ "id": "finding_9165427cd04cf7e4726a"
+ },
+ {
+ "biomarker_type": "io_in_loop",
+ "severity": "medium",
+ "file_path": "apex/perf_io_in_loop.cls",
+ "function_name": "databaseAndCallout",
+ "line_start": 22,
+ "line_end": 22,
+ "details": {
+ "boundary_kind": "network",
+ "cross_function": false,
+ "loop_key_unused": true,
+ "loop_iterates": "parameter",
+ "loop_line": 20,
+ "sink_call": "http.send",
+ "symbol_line": 18,
+ "role_owner": "apex/perf_io_in_loop.cls::PerfIoInLoop::databaseAndCallout",
+ "execution_role": "unknown",
+ "opportunity_id": "perf3_a850ad3bb607d14ed87e"
+ },
+ "health_impact": 0.0,
+ "reason": "a network call runs once per loop iteration (I/O call inside a loop)",
+ "dimension": "performance",
+ "id": "finding_0245fab87b55c23492c6"
+ },
+ {
+ "biomarker_type": "io_in_loop",
+ "severity": "medium",
+ "file_path": "apex/perf_io_in_loop.cls",
+ "function_name": "asyncPerRecord",
+ "line_start": 28,
+ "line_end": 28,
+ "details": {
+ "boundary_kind": "db",
+ "cross_function": false,
+ "loop_iterates": "parameter",
+ "loop_line": 27,
+ "sink_call": "System.enqueueJob",
+ "symbol_line": 26,
+ "role_owner": "apex/perf_io_in_loop.cls::PerfIoInLoop::asyncPerRecord",
+ "execution_role": "unknown",
+ "opportunity_id": "perf3_c825658c4fdf4b8ecbff"
+ },
+ "health_impact": 0.0,
+ "reason": "a database call runs once per loop iteration (N+1 query)",
+ "dimension": "performance",
+ "id": "finding_e659d96b233a265d645d"
+ },
+ {
+ "biomarker_type": "io_in_loop",
+ "severity": "medium",
+ "file_path": "apex/perf_io_in_loop.cls",
+ "function_name": "asyncPerRecord",
+ "line_start": 29,
+ "line_end": 29,
+ "details": {
+ "boundary_kind": "db",
+ "cross_function": false,
+ "loop_iterates": "parameter",
+ "loop_line": 27,
+ "sink_call": "notifyLater",
+ "symbol_line": 26,
+ "role_owner": "apex/perf_io_in_loop.cls::PerfIoInLoop::asyncPerRecord",
+ "execution_role": "unknown",
+ "opportunity_id": "perf3_c825658c4fdf4b8ecbff"
+ },
+ "health_impact": 0.0,
+ "reason": "a database call runs once per loop iteration (N+1 query)",
+ "dimension": "performance",
+ "id": "finding_55745384c52960933827"
+ },
+ {
+ "biomarker_type": "io_in_loop",
+ "severity": "medium",
+ "file_path": "apex/perf_io_in_loop.cls",
+ "function_name": "nested",
+ "line_start": 40,
+ "line_end": 40,
+ "details": {
+ "boundary_kind": "db",
+ "cross_function": false,
+ "loop_line": 39,
+ "sink_call": "insert",
+ "symbol_line": 37,
+ "role_owner": "apex/perf_io_in_loop.cls::PerfIoInLoop::nested",
+ "execution_role": "unknown",
+ "opportunity_id": "perf3_009daa9fe845b0b0a724"
+ },
+ "health_impact": 0.0,
+ "reason": "a database call runs once per loop iteration (N+1 query)",
+ "dimension": "performance",
+ "id": "finding_760a8253c79b976573d7"
+ },
+ {
+ "biomarker_type": "nested_loop_with_io",
+ "severity": "medium",
+ "file_path": "apex/perf_io_in_loop.cls",
+ "function_name": "nested",
+ "line_start": 40,
+ "line_end": 40,
+ "details": {
+ "boundary_kind": "db",
+ "loop_line": 39,
+ "sink_call": "insert",
+ "symbol_line": 37,
+ "role_owner": "apex/perf_io_in_loop.cls::PerfIoInLoop::nested",
+ "execution_role": "unknown",
+ "opportunity_id": "perf3_009daa9fe845b0b0a724"
+ },
+ "health_impact": 0.0,
+ "reason": "a database call runs inside a nested loop (O(n\u00b7m) round-trips); batch the inner query or restructure the loops",
+ "dimension": "performance",
+ "id": "finding_ad8e4f3c1ef52ec49958"
+ },
{
"biomarker_type": "nested_complexity",
"severity": "medium",
@@ -5022,27 +5303,71 @@
],
"kpis": {
"hotspot_health": null,
- "average_health": 9.59,
+ "average_health": 9.6,
"worst_performer_path": "scala/nested.scala",
"worst_performer_score": 7.77,
- "worst_test_path": null,
- "worst_test_score": null,
- "file_count": 63,
- "maintainability_average": 9.62,
+ "worst_test_path": "apex/assertions.cls",
+ "worst_test_score": 10.0,
+ "file_count": 69,
+ "maintainability_average": 9.64,
"maintainability_hotspot": null,
- "performance_average": 9.5,
+ "performance_average": 9.47,
"performance_hotspot": null,
- "structure_average": 0.41,
+ "structure_average": 0.4,
"structure_hotspot": null,
"history_average": 0.0,
"history_hotspot": null,
- "production_average": 9.59,
- "production_file_count": 63,
- "unanalysed_file_count": 6,
- "analysed_share": 0.913
+ "production_average": 9.6,
+ "production_file_count": 68,
+ "unanalysed_file_count": 4,
+ "analysed_share": 0.9452
},
"repo_function_mod_p80": null,
"suggestions": [
+ {
+ "refactoring_type": "performance_fix",
+ "file_path": "apex/perf_io_in_loop.cls",
+ "target_symbol": "apex/perf_io_in_loop.cls::nested",
+ "line_start": 40,
+ "line_end": 40,
+ "impact_delta": 0.0,
+ "effort_bucket": "S",
+ "confidence": "medium",
+ "source_biomarker": "nested_loop_with_io"
+ },
+ {
+ "refactoring_type": "performance_fix",
+ "file_path": "apex/perf_io_in_loop.cls",
+ "target_symbol": "apex/perf_io_in_loop.cls::databaseAndCallout",
+ "line_start": 21,
+ "line_end": 21,
+ "impact_delta": 0.0,
+ "effort_bucket": "S",
+ "confidence": "medium",
+ "source_biomarker": "io_in_loop"
+ },
+ {
+ "refactoring_type": "performance_fix",
+ "file_path": "apex/perf_io_in_loop.cls",
+ "target_symbol": "apex/perf_io_in_loop.cls::dmlPerRecord",
+ "line_start": 14,
+ "line_end": 14,
+ "impact_delta": 0.0,
+ "effort_bucket": "S",
+ "confidence": "medium",
+ "source_biomarker": "io_in_loop"
+ },
+ {
+ "refactoring_type": "performance_fix",
+ "file_path": "apex/perf_io_in_loop.cls",
+ "target_symbol": "apex/perf_io_in_loop.cls::soqlPerRecord",
+ "line_start": 8,
+ "line_end": 8,
+ "impact_delta": 0.0,
+ "effort_bucket": "S",
+ "confidence": "medium",
+ "source_biomarker": "io_in_loop"
+ },
{
"refactoring_type": "performance_fix",
"file_path": "csharp/PerfIoInLoop.cs",
@@ -5273,6 +5598,17 @@
"effort_bucket": "S",
"confidence": "medium",
"source_biomarker": "string_concat_in_loop"
+ },
+ {
+ "refactoring_type": "performance_fix",
+ "file_path": "apex/perf_io_in_loop.cls",
+ "target_symbol": "apex/perf_io_in_loop.cls::asyncPerRecord",
+ "line_start": 28,
+ "line_end": 28,
+ "impact_delta": 0.0,
+ "effort_bucket": "M",
+ "confidence": "medium",
+ "source_biomarker": "io_in_loop"
}
]
}
diff --git a/tests/unit/health/test_complexity_walker.py b/tests/unit/health/test_complexity_walker.py
index 430013b46..f51d39d35 100644
--- a/tests/unit/health/test_complexity_walker.py
+++ b/tests/unit/health/test_complexity_walker.py
@@ -1067,3 +1067,69 @@ def test_catch_still_nests_its_body():
assert fn.max_nesting == 1
# The nesting locator names the except clause, not the try around it.
assert fn.deepest_block == (4, 7)
+
+
+def test_apex_nesting_and_ccn():
+ results = _walk("apex/nested.cls", "apex")
+ deep = _find(results, "deeplyNested")
+ assert deep is not None
+ # if > for > if > while > catch: a try opens no level of its own.
+ assert deep.max_nesting == 5
+ many = _find(results, "manyBranches")
+ assert many is not None
+ # if + else-if + if + ternary + && + || over the base path; ``??`` is no decision.
+ assert many.ccn == 7
+ # A ``switch on`` counts once for the dispatch, not per ``when``.
+ dispatch = _find(results, "dispatch")
+ assert dispatch is not None and dispatch.ccn == 2
+ shallow = _find(results, "shallow")
+ assert shallow is not None and shallow.max_nesting == 0 and shallow.param_count == 1
+
+
+def test_apex_property_accessors_are_one_unit_named_for_the_property():
+ results = _walk("apex/nested.cls", "apex")
+ names = [r.name for r in results]
+ # ``total { get { ... } set; }`` is one unit; ``label { get; set; }`` holds
+ # no code and is none.
+ assert names.count("total") == 1
+ assert "label" not in names
+ assert _find(results, "total").ccn == 2
+
+
+def test_apex_trigger_is_a_unit():
+ source = (
+ "trigger AccountTrigger on Account (before insert) {\n"
+ " for (Account a : Trigger.new) {\n"
+ " if (a.Name == null) { a.addError('x'); }\n"
+ " }\n"
+ "}\n"
+ )
+ fn = _walk_source(source, "apex", "AccountTrigger.trigger")["AccountTrigger"]
+ assert (fn.ccn, fn.max_nesting) == (3, 2)
+
+
+def test_apex_class_cohesion():
+ classes = _walk_classes("apex/classes.cls", "apex")
+ assert classes["Cohesive"].lcom4 == 1
+ # Bare ``a`` and ``this.b`` both reach a member.
+ assert classes["Splintered"].lcom4 == 2
+ assert classes["Splintered"].method_count == 4
+ # The accessor unit is a method; the auto-property is a field only.
+ assert classes["WithProperties"].method_count == 2
+ # Interfaces and enums nested in a class are not cohesion units.
+ assert "Shape" not in classes and "Mode" not in classes
+
+
+def test_apex_assertions_and_test_cases():
+ results = _walk("apex/assertions.cls", "apex")
+ many = _find(results, "testManyAsserts")
+ assert many is not None and many.assertion_count == 5
+ # ``Assert.areEqual`` / ``Assert.isTrue`` form a run; ``System.assertEquals``
+ # counts as an assertion but, like any split ``x.assertY`` call, joins no run.
+ assert many.assertion_blocks == [(9, 10, 2)]
+ by_name = {r.name: r for r in results}
+ # ``@IsTest`` in any case, and the legacy ``testMethod`` modifier.
+ for case in ("testManyAsserts", "testFewAsserts", "legacyCase", "checksNothing"):
+ assert by_name[case].is_test_case, case
+ for helper in ("makeData", "compute"):
+ assert not by_name[helper].is_test_case, helper
diff --git a/tests/unit/health/test_error_handling.py b/tests/unit/health/test_error_handling.py
index 1b668bf32..d6d492c83 100644
--- a/tests/unit/health/test_error_handling.py
+++ b/tests/unit/health/test_error_handling.py
@@ -98,6 +98,30 @@ _FIXTURES = [
{},
"handled Java catch",
),
+ (
+ "apex",
+ b"class A { void m(){ try { go(); } catch (Exception e) { // ignore\n } } }\n",
+ {"swallowed_catch": 1},
+ "comment-only Apex catch",
+ ),
+ (
+ "apex",
+ b"class A { void m(){ try { go(); System.assert(false, 'x'); } catch (Exception e) {} } }\n",
+ {},
+ "Apex try ending in System.assert(false) -> expected exception idiom",
+ ),
+ (
+ "apex",
+ b"class A { void m(){ try { go(); Assert.fail(); } catch (Exception e) {} } }\n",
+ {},
+ "Apex try ending in Assert.fail() -> clean",
+ ),
+ (
+ "apex",
+ b"class A { void m(){ try { go(); System.assert(ok); } catch (Exception e) {} } }\n",
+ {"swallowed_catch": 1},
+ "Apex System.assert on a value is no expected-throw idiom",
+ ),
(
"kotlin",
b"fun f(){ try { go() } catch (e: Exception) {} }\n",
diff --git a/tests/unit/health/test_perf_dialects.py b/tests/unit/health/test_perf_dialects.py
index 7fdb83c0c..b7c8eedc4 100644
--- a/tests/unit/health/test_perf_dialects.py
+++ b/tests/unit/health/test_perf_dialects.py
@@ -1793,3 +1793,143 @@ def test_python_acquire_spin_vs_per_item():
assert _hits("python", spin) == []
each = "def acquire(self, items):\n for i in items:\n self.locks[i].acquire()\n"
assert _hits("python", each) == [("lock_in_loop", "")]
+
+
+# ---------------------------------------------------------------------------
+# Apex
+# ---------------------------------------------------------------------------
+
+
+def test_apex_fixture_hits():
+ fc = _walk("apex/perf_io_in_loop.cls", "apex")
+ hits = sorted((h.function, h.kind, h.detail) for h in fc.perf_hits)
+ # Every shape under "stay quiet" in the fixture is absent: the bulk idioms,
+ # the query in a loop header, run-once shapes and the ``while`` ceiling.
+ assert hits == sorted(
+ [
+ ("soqlPerRecord", "io_in_loop", "db"),
+ ("dmlPerRecord", "io_in_loop", "db"),
+ ("databaseAndCallout", "io_in_loop", "db"),
+ ("databaseAndCallout", "io_in_loop", "network"),
+ ("asyncPerRecord", "io_in_loop", "db"),
+ ("asyncPerRecord", "io_in_loop", "db"),
+ ("nested", "io_in_loop", "db"),
+ ("nested", "nested_loop_with_io", "db"),
+ ]
+ )
+ sinks = {h.sink_call for h in fc.perf_hits}
+ assert {"SOQL", "update", "Database.delete", "http.send", "System.enqueueJob", "notifyLater"} <= sinks
+
+
+def _apex_loop(body: str, params: str = "List<Id> ids") -> str:
+ return f"public class A {{\n public void m({params}) {{\n for (Id i : ids) {{\n{body}\n }}\n }}\n}}\n"
+
+
+_APEX_CASES = [
+ (_apex_loop(" Messaging.sendEmail(msgs);"), [("io_in_loop", "network")], "sendEmail"),
+ (_apex_loop(" EventBus.publish(evt);"), [("io_in_loop", "db")], "platform event"),
+ (_apex_loop(" List<List<SObject>> r = [FIND 'x' IN ALL FIELDS RETURNING Account];"),
+ [("io_in_loop", "db")], "inline SOSL"),
+ (_apex_loop(" database.countQuery(q);"), [("io_in_loop", "db")], "case-insensitive receiver"),
+ (_apex_loop(" new Http().send(req);"), [("io_in_loop", "network")], "new Http().send"),
+ (_apex_loop(" mailer.send(req);", "List<Id> ids, Mailer mailer"), [], "send on a non-Http receiver"),
+ (_apex_loop(" helper(i);"), [], "a plain same-class call is no sink"),
+ (_apex_loop(" Database.merge(master, i);"), [], "merge takes at most three records"),
+ (_apex_loop(" Database.query('SELECT Id FROM Thing__mdt');"), [], "custom metadata query"),
+ (_apex_loop(" insert rec;\n return;"), [], "return after the sink"),
+ (
+ "public class A {\n public void m(List<Id> ids) {\n for (Id a : ids) {\n"
+ " for (Id b : ids) { insert rec; break; }\n }\n }\n}\n",
+ [("io_in_loop", "db"), ("nested_loop_with_io", "db")],
+ "an inner break still runs once per outer pass",
+ ),
+ (
+ "public class A {\n public void m(List<Id> ids) {\n for (Id i : ids) {\n"
+ " if (buf.size() > 0) { insert buf; }\n }\n }\n}\n",
+ [("io_in_loop", "db")],
+ "an emptiness test is no flush threshold",
+ ),
+ (
+ "public class A {\n Map<Id, Account> cache;\n Account get(Id i) {\n"
+ " if (cache != null) { return cache; }\n cache = new Map<Id, Account>([SELECT Id FROM Account]);\n"
+ " return null;\n }\n void m(List<Id> ids) {\n for (Id i : ids) { Account a = [SELECT Id FROM Account]; }\n }\n}\n",
+ [("io_in_loop", "db")],
+ "a memoized getter's query is no sink; a plain one in a loop is",
+ ),
+ (
+ "public class A {\n static Map<String, List<Id>> byType = new Map<String, List<Id>>();\n"
+ " void m(List<String> types) {\n for (String t : types) {\n"
+ " if (byType.get(t) == null) { byType.put(t, Database.query('SELECT Id FROM Account')); }\n"
+ " }\n }\n}\n",
+ [],
+ "a map-keyed cache filled under its own null test",
+ ),
+ (
+ "public class A {\n void m(List<List<Account>> chunks) {\n"
+ " for (Integer i = 0; i < chunks.size(); i++) { update chunks[i]; }\n }\n}\n",
+ [],
+ "a counted walk over a list of lists handles a chunk per pass",
+ ),
+ (
+ "public class A {\n void m(List<Account> rows) {\n try { insert rows; } catch (Exception e) {\n"
+ " for (Account a : rows) { Database.insert(a, false); }\n }\n }\n}\n",
+ [],
+ "a per-record retry after a failed bulk call",
+ ),
+ (_apex_loop(" Database.executeBatch(new Job(i));"), [], "batch submission is left out"),
+ (
+ _apex_loop(" update rec;\n if (rec.Name == 'z') { break; }"),
+ [("io_in_loop", "db")],
+ "a guard exit on another condition keeps the hit",
+ ),
+ (
+ _apex_loop(
+ " ok = true;\n try { Database.convertLead(c); } catch (Exception e) { ok = false; }\n"
+ " if (ok) { break; }"
+ ),
+ [],
+ "retry until one attempt succeeds",
+ ),
+ (
+ _apex_loop(" buf.add(i);\n if (buf.size() > 100 || done) { update buf; }"),
+ [("io_in_loop", "db")],
+ "a size test mixed with another condition is no flush",
+ ),
+]
+
+
[email protected]("src,expected,note", _APEX_CASES, ids=[c[2] for c in _APEX_CASES])
+def test_apex_cases(src, expected, note):
+ assert _hits("apex", src) == sorted(expected), note
+
+
+def test_apex_parameter_switched_sink_is_no_bare_sink():
+ # ``if (doInsert) insert rows;`` outside a loop: the caller's argument
+ # decides, so the function is no cross-function sink target.
+ src = (
+ "public class F {\n public static List<Account> make(Integer n, Boolean doInsert) {\n"
+ " List<Account> rows = new List<Account>();\n if (doInsert) { insert rows; }\n"
+ " return rows;\n }\n public static void save(List<Account> rows) { insert rows; }\n}\n"
+ )
+ fc = walk_file("F.cls", "apex", src.encode())
+ sinks = {f.function: f.bare_sink_kind for f in fc.perf_fn_facts}
+ assert sinks.get("make") is None
+ assert sinks["save"] == "db"
+
+
+def test_apex_field_filled_when_unset_is_no_bare_sink():
+ src = (
+ "public class U {\n static void config(Settings__c s) {\n if (s.Mode__c == null) {\n"
+ " s.Mode__c = 'x';\n List<RecordType> r = [SELECT Id FROM RecordType];\n }\n }\n}\n"
+ )
+ assert walk_file("U.cls", "apex", src.encode()).perf_fn_facts == []
+
+
+def test_apex_helper_call_followed_by_return_is_no_loop_target():
+ src = (
+ "public class F {\n void m(List<Id> ids) {\n for (Id i : ids) {\n"
+ " if (i == null) { notifyAll(); return; }\n track(i);\n }\n }\n}\n"
+ )
+ fc = walk_file("F.cls", "apex", src.encode())
+ targets = {name for f in fc.perf_fn_facts for name, _line in f.loop_call_targets}
+ assert targets == {"track"}
diff --git a/tests/unit/health/test_untested_complexity.py b/tests/unit/health/test_untested_complexity.py
index b573ac296..10cdd461c 100644
--- a/tests/unit/health/test_untested_complexity.py
+++ b/tests/unit/health/test_untested_complexity.py
@@ -156,6 +156,15 @@ def test_an_untested_cc_of_five_fires_estimated_and_medium() -> None:
assert "%" not in r.reason
+def test_apex_makes_no_claim_that_no_test_reaches_it() -> None:
+ # Apex tests reach code through platform dispatch the graph does not see.
+ apex = {"file_path": "classes/Batch.cls", "language": "apex"}
+ assert BIOMARKER.detect(_ctx([_fn("execute", 1, 20, 5)], **apex)) == []
+ # A test the graph does see still prices it.
+ reached = _ctx([_fn("execute", 1, 20, 20)], function_test_hops={1: 2}, **apex)
+ assert _one(reached).details["coverage_tier"] == "reached"
+
+
def test_below_the_bar_is_silent() -> None:
assert BIOMARKER.detect(_ctx([_fn("f", 1, 20, 4)])) == []
diff --git a/tests/unit/ingestion/parser/golden/apex.json b/tests/unit/ingestion/parser/golden/apex.json
index ba4c4c1a5..14547f98c 100644
--- a/tests/unit/ingestion/parser/golden/apex.json
+++ b/tests/unit/ingestion/parser/golden/apex.json
@@ -692,5 +692,2150 @@
"local_refs": [],
"registrars": [],
"references": []
+ },
+ "apex/assertions.cls": {
+ "file_info": {
+ "path": "lang_samples/apex/assertions.cls",
+ "language": "apex",
+ "size_bytes": 890,
+ "is_test": false,
+ "is_config": false,
+ "is_api_contract": false,
+ "is_entry_point": false,
+ "is_manifest_entry": false,
+ "is_reachability_root": false
+ },
+ "symbols": [
+ {
+ "id": "lang_samples/apex/assertions.cls::Assertions",
+ "name": "Assertions",
+ "qualified_name": "lang_samples.apex.assertions.Assertions",
+ "kind": "class",
+ "signature": "class Assertions",
+ "start_line": 2,
+ "end_line": 40,
+ "docstring": null,
+ "decorators": [
+ "@IsTest\nprivate"
+ ],
+ "visibility": "private",
+ "is_async": false,
+ "complexity_estimate": 1,
+ "language": "apex",
+ "parent_name": null,
+ "is_exported_symbol": false,
+ "is_declaration": false,
+ "type_parameter_count": null,
+ "extension_receiver": null,
+ "written_receiver": null,
+ "modifiers": [
+ "private"
+ ],
+ "alias_of": null
+ },
+ {
+ "id": "lang_samples/apex/assertions.cls::Assertions::testManyAsserts",
+ "name": "testManyAsserts",
+ "qualified_name": "lang_samples.apex.assertions.Assertions.testManyAsserts",
+ "kind": "method",
+ "signature": "testManyAsserts() -> void",
+ "start_line": 4,
+ "end_line": 12,
+ "docstring": null,
+ "decorators": [
+ "@IsTest\n static"
+ ],
+ "visibility": "private",
+ "is_async": false,
+ "complexity_estimate": 1,
+ "language": "apex",
+ "parent_name": "Assertions",
+ "is_exported_symbol": false,
+ "is_declaration": false,
+ "type_parameter_count": null,
+ "extension_receiver": null,
+ "written_receiver": null,
+ "modifiers": [
+ "static"
+ ],
+ "alias_of": null
+ },
+ {
+ "id": "lang_samples/apex/assertions.cls::Assertions::testFewAsserts",
+ "name": "testFewAsserts",
+ "qualified_name": "lang_samples.apex.assertions.Assertions.testFewAsserts",
+ "kind": "method",
+ "signature": "testFewAsserts() -> void",
+ "start_line": 14,
+ "end_line": 20,
+ "docstring": null,
+ "decorators": [
+ "@isTest\n static"
+ ],
+ "visibility": "private",
+ "is_async": false,
+ "complexity_estimate": 1,
+ "language": "apex",
+ "parent_name": "Assertions",
+ "is_exported_symbol": false,
+ "is_declaration": false,
+ "type_parameter_count": null,
+ "extension_receiver": null,
+ "written_receiver": null,
+ "modifiers": [
+ "static"
+ ],
+ "alias_of": null
+ },
+ {
+ "id": "lang_samples/apex/assertions.cls::Assertions::legacyCase",
+ "name": "legacyCase",
+ "qualified_name": "lang_samples.apex.assertions.Assertions.legacyCase",
+ "kind": "method",
+ "signature": "legacyCase() -> void",
+ "start_line": 22,
+ "end_line": 25,
+ "docstring": null,
+ "decorators": [],
+ "visibility": "private",
+ "is_async": false,
+ "complexity_estimate": 1,
+ "language": "apex",
+ "parent_name": "Assertions",
+ "is_exported_symbol": false,
+ "is_declaration": false,
+ "type_parameter_count": null,
+ "extension_receiver": null,
+ "written_receiver": null,
+ "modifiers": [
+ "static",
+ "testmethod"
+ ],
+ "alias_of": null
+ },
+ {
+ "id": "lang_samples/apex/assertions.cls::Assertions::checksNothing",
+ "name": "checksNothing",
+ "qualified_name": "lang_samples.apex.assertions.Assertions.checksNothing",
+ "kind": "method",
+ "signature": "checksNothing() -> void",
+ "start_line": 27,
+ "end_line": 30,
+ "docstring": null,
+ "decorators": [
+ "@IsTest\n static"
+ ],
+ "visibility": "private",
+ "is_async": false,
+ "complexity_estimate": 1,
+ "language": "apex",
+ "parent_name": "Assertions",
+ "is_exported_symbol": false,
+ "is_declaration": false,
+ "type_parameter_count": null,
+ "extension_receiver": null,
+ "written_receiver": null,
+ "modifiers": [
+ "static"
+ ],
+ "alias_of": null
+ },
+ {
+ "id": "lang_samples/apex/assertions.cls::Assertions::makeData",
+ "name": "makeData",
+ "qualified_name": "lang_samples.apex.assertions.Assertions.makeData",
+ "kind": "method",
+ "signature": "makeData() -> void",
+ "start_line": 32,
+ "end_line": 35,
+ "docstring": null,
+ "decorators": [
+ "@TestSetup\n static"
+ ],
+ "visibility": "private",
+ "is_async": false,
+ "complexity_estimate": 1,
+ "language": "apex",
+ "parent_name": "Assertions",
+ "is_exported_symbol": false,
+ "is_declaration": false,
+ "type_parameter_count": null,
+ "extension_receiver": null,
+ "written_receiver": null,
+ "modifiers": [
+ "static"
+ ],
+ "alias_of": null
+ },
+ {
+ "id": "lang_samples/apex/assertions.cls::Assertions::compute",
+ "name": "compute",
+ "qualified_name": "lang_samples.apex.assertions.Assertions.compute",
+ "kind": "method",
+ "signature": "compute() -> Integer",
+ "start_line": 37,
+ "end_line": 39,
+ "docstring": null,
+ "decorators": [],
+ "visibility": "private",
+ "is_async": false,
+ "complexity_estimate": 1,
+ "language": "apex",
+ "parent_name": "Assertions",
+ "is_exported_symbol": false,
+ "is_declaration": false,
+ "type_parameter_count": null,
+ "extension_receiver": null,
+ "written_receiver": null,
+ "modifiers": [
+ "private",
+ "static"
+ ],
+ "alias_of": null
+ }
+ ],
+ "imports": [],
+ "exports": [],
+ "export_aliases": {},
+ "calls": [
+ {
+ "target_name": "compute",
+ "receiver_name": null,
+ "caller_symbol_id": "lang_samples/apex/assertions.cls::Assertions::testManyAsserts",
+ "line": 6,
+ "argument_count": 0,
+ "receiver_call": null,
+ "scope_name": null,
+ "edge_type": "calls",
+ "supplied_props": null,
+ "bare_name_fallback": false,
+ "spawned": false,
+ "argument_types": null,
+ "argument_names": null
+ },
+ {
+ "target_name": "assertEquals",
+ "receiver_name": "System",
+ "caller_symbol_id": "lang_samples/apex/assertions.cls::Assertions::testManyAsserts",
+ "line": 7,
+ "argument_count": 2,
+ "receiver_call": null,
+ "scope_name": null,
+ "edge_type": "calls",
+ "supplied_props": null,
+ "bare_name_fallback": false,
+ "spawned": false,
+ "argument_types": [
+ "Integer",
+ null
+ ],
+ "argument_names": [
+ null,
+ "x"
+ ]
+ },
+ {
+ "target_name": "assertNotEquals",
+ "receiver_name": "System",
+ "caller_symbol_id": "lang_samples/apex/assertions.cls::Assertions::testManyAsserts",
+ "line": 8,
+ "argument_count": 2,
+ "receiver_call": null,
+ "scope_name": null,
+ "edge_type": "calls",
+ "supplied_props": null,
+ "bare_name_fallback": false,
+ "spawned": false,
+ "argument_types": [
+ "Integer",
+ null
+ ],
+ "argument_names": [
+ null,
+ "x"
+ ]
+ },
+ {
+ "target_name": "areEqual",
+ "receiver_name": "Assert",
+ "caller_symbol_id": "lang_samples/apex/assertions.cls::Assertions::testManyAsserts",
+ "line": 9,
+ "argument_count": 2,
+ "receiver_call": null,
+ "scope_name": null,
+ "edge_type": "calls",
+ "supplied_props": null,
+ "bare_name_fallback": false,
+ "spawned": false,
+ "argument_types": [
+ "Integer",
+ null
+ ],
+ "argument_names": [
+ null,
+ "x"
+ ]
+ },
+ {
+ "target_name": "isTrue",
+ "receiver_name": "Assert",
+ "caller_symbol_id": "lang_samples/apex/assertions.cls::Assertions::testManyAsserts",
+ "line": 10,
+ "argument_count": 1,
+ "receiver_call": null,
+ "scope_name": null,
+ "edge_type": "calls",
+ "supplied_props": null,
+ "bare_name_fallback": false,
+ "spawned": false,
+ "argument_types": null,
+ "argument_names": null
+ },
+ {
+ "target_name": "assert",
+ "receiver_name": "System",
+ "caller_symbol_id": "lang_samples/apex/assertions.cls::Assertions::testManyAsserts",
+ "line": 11,
+ "argument_count": 2,
+ "receiver_call": null,
+ "scope_name": null,
+ "edge_type": "calls",
+ "supplied_props": null,
+ "bare_name_fallback": false,
+ "spawned": false,
+ "argument_types": [
+ null,
+ "String"
+ ],
+ "argument_names": null
+ },
+ {
+ "target_name": "compute",
+ "receiver_name": null,
+ "caller_symbol_id": "lang_samples/apex/assertions.cls::Assertions::testFewAsserts",
+ "line": 16,
+ "argument_count": 0,
+ "receiver_call": null,
+ "scope_name": null,
+ "edge_type": "calls",
+ "supplied_props": null,
+ "bare_name_fallback": false,
+ "spawned": false,
+ "argument_types": null,
+ "argument_names": null
+ },
+ {
+ "target_name": "areEqual",
+ "receiver_name": "Assert",
+ "caller_symbol_id": "lang_samples/apex/assertions.cls::Assertions::testFewAsserts",
+ "line": 17,
+ "argument_count": 2,
+ "receiver_call": null,
+ "scope_name": null,
+ "edge_type": "calls",
+ "supplied_props": null,
+ "bare_name_fallback": false,
+ "spawned": false,
+ "argument_types": [
+ "Integer",
+ null
+ ],
+ "argument_names": [
+ null,
+ "x"
+ ]
+ },
+ {
+ "target_name": "areEqual",
+ "receiver_name": "Assert",
+ "caller_symbol_id": "lang_samples/apex/assertions.cls::Assertions::testFewAsserts",
+ "line": 19,
+ "argument_count": 2,
+ "receiver_call": null,
+ "scope_name": null,
+ "edge_type": "calls",
+ "supplied_props": null,
+ "bare_name_fallback": false,
+ "spawned": false,
+ "argument_types": [
+ "Integer",
+ null
+ ],
+ "argument_names": [
+ null,
+ "y"
+ ]
+ },
+ {
+ "target_name": "compute",
+ "receiver_name": null,
+ "caller_symbol_id": "lang_samples/apex/assertions.cls::Assertions::legacyCase",
+ "line": 23,
+ "argument_count": 0,
+ "receiver_call": null,
+ "scope_name": null,
+ "edge_type": "calls",
+ "supplied_props": null,
+ "bare_name_fallback": false,
+ "spawned": false,
+ "argument_types": null,
+ "argument_names": null
+ },
+ {
+ "target_name": "assertEquals",
+ "receiver_name": "System",
+ "caller_symbol_id": "lang_samples/apex/assertions.cls::Assertions::legacyCase",
+ "line": 24,
+ "argument_count": 2,
+ "receiver_call": null,
+ "scope_name": null,
+ "edge_type": "calls",
+ "supplied_props": null,
+ "bare_name_fallback": false,
+ "spawned": false,
+ "argument_types": [
+ "Integer",
+ null
+ ],
+ "argument_names": [
+ null,
+ "x"
+ ]
+ },
+ {
+ "target_name": "compute",
+ "receiver_name": null,
+ "caller_symbol_id": "lang_samples/apex/assertions.cls::Assertions::checksNothing",
+ "line": 29,
+ "argument_count": 0,
+ "receiver_call": null,
+ "scope_name": null,
+ "edge_type": "calls",
+ "supplied_props": null,
+ "bare_name_fallback": false,
+ "spawned": false,
+ "argument_types": null,
+ "argument_names": null
+ },
+ {
+ "target_name": "Account",
+ "receiver_name": null,
+ "caller_symbol_id": "lang_samples/apex/assertions.cls::Assertions::makeData",
+ "line": 34,
+ "argument_count": 1,
+ "receiver_call": null,
+ "scope_name": null,
+ "edge_type": "calls",
+ "supplied_props": null,
+ "bare_name_fallback": false,
+ "spawned": false,
+ "argument_types": null,
+ "argument_names": null
+ }
+ ],
+ "heritage": [],
+ "docstring": null,
+ "parse_errors": [],
+ "content_hash": "30792ace5c3c34b05238ff4ca9b49e66033d3b2bace9fe25c66ceed02b6cb08d",
+ "type_refs": [
+ {
+ "type_name": "Account",
+ "line": 34,
+ "origin": "composite_literal"
+ }
+ ],
+ "local_refs": [],
+ "registrars": [],
+ "references": []
+ },
+ "apex/classes.cls": {
+ "file_info": {
+ "path": "lang_samples/apex/classes.cls",
+ "language": "apex",
+ "size_bytes": 1484,
+ "is_test": false,
+ "is_config": false,
+ "is_api_contract": false,
+ "is_entry_point": false,
+ "is_manifest_entry": false,
+ "is_reachability_root": false
+ },
+ "symbols": [
+ {
+ "id": "lang_samples/apex/classes.cls::Classes",
+ "name": "Classes",
+ "qualified_name": "lang_samples.apex.classes.Classes",
+ "kind": "class",
+ "signature": "class Classes",
+ "start_line": 3,
+ "end_line": 67,
+ "docstring": null,
+ "decorators": [],
+ "visibility": "public",
+ "is_async": false,
+ "complexity_estimate": 1,
+ "language": "apex",
+ "parent_name": null,
+ "is_exported_symbol": false,
+ "is_declaration": false,
+ "type_parameter_count": null,
+ "extension_receiver": null,
+ "written_receiver": null,
+ "modifiers": [
+ "public"
+ ],
+ "alias_of": null
+ },
+ {
+ "id": "lang_samples/apex/classes.cls::Classes::Cohesive",
+ "name": "Cohesive",
+ "qualified_name": "lang_samples.apex.classes.Classes.Cohesive",
+ "kind": "class",
+ "signature": "class Cohesive",
+ "start_line": 4,
+ "end_line": 21,
+ "docstring": null,
+ "decorators": [],
+ "visibility": "public",
+ "is_async": false,
+ "complexity_estimate": 1,
+ "language": "apex",
+ "parent_name": "Classes",
+ "is_exported_symbol": false,
+ "is_declaration": false,
+ "type_parameter_count": null,
+ "extension_receiver": null,
+ "written_receiver": null,
+ "modifiers": [
+ "public"
+ ],
+ "alias_of": null
+ },
+ {
+ "id": "lang_samples/apex/classes.cls::Cohesive::add",
+ "name": "add",
+ "qualified_name": "lang_samples.apex.classes.Cohesive.add",
+ "kind": "method",
+ "signature": "add(Integer n) -> void",
+ "start_line": 8,
+ "end_line": 11,
+ "docstring": null,
+ "decorators": [],
+ "visibility": "public",
+ "is_async": false,
+ "complexity_estimate": 1,
+ "language": "apex",
+ "parent_name": "Cohesive",
+ "is_exported_symbol": false,
+ "is_declaration": false,
+ "type_parameter_count": null,
+ "extension_receiver": null,
+ "written_receiver": null,
+ "modifiers": [
+ "public"
+ ],
+ "alias_of": null
+ },
+ {
+ "id": "lang_samples/apex/classes.cls::Cohesive::average",
+ "name": "average",
+ "qualified_name": "lang_samples.apex.classes.Cohesive.average",
+ "kind": "method",
+ "signature": "average() -> Integer",
+ "start_line": 13,
+ "end_line": 15,
+ "docstring": null,
+ "decorators": [],
+ "visibility": "public",
+ "is_async": false,
+ "complexity_estimate": 1,
+ "language": "apex",
+ "parent_name": "Cohesive",
+ "is_exported_symbol": false,
+ "is_declaration": false,
+ "type_parameter_count": null,
+ "extension_receiver": null,
+ "written_receiver": null,
+ "modifiers": [
+ "public"
+ ],
+ "alias_of": null
+ },
+ {
+ "id": "lang_samples/apex/classes.cls::Cohesive::reset",
+ "name": "reset",
+ "qualified_name": "lang_samples.apex.classes.Cohesive.reset",
+ "kind": "method",
+ "signature": "reset() -> void",
+ "start_line": 17,
+ "end_line": 20,
+ "docstring": null,
+ "decorators": [],
+ "visibility": "public",
+ "is_async": false,
+ "complexity_estimate": 1,
+ "language": "apex",
+ "parent_name": "Cohesive",
+ "is_exported_symbol": false,
+ "is_declaration": false,
+ "type_parameter_count": null,
+ "extension_receiver": null,
+ "written_receiver": null,
+ "modifiers": [
+ "public"
+ ],
+ "alias_of": null
+ },
+ {
+ "id": "lang_samples/apex/classes.cls::Classes::Splintered",
+ "name": "Splintered",
+ "qualified_name": "lang_samples.apex.classes.Classes.Splintered",
+ "kind": "class",
+ "signature": "class Splintered",
+ "start_line": 23,
+ "end_line": 46,
+ "docstring": null,
+ "decorators": [],
+ "visibility": "public",
+ "is_async": false,
+ "complexity_estimate": 1,
+ "language": "apex",
+ "parent_name": "Classes",
+ "is_exported_symbol": false,
+ "is_declaration": false,
+ "type_parameter_count": null,
+ "extension_receiver": null,
+ "written_receiver": null,
+ "modifiers": [
+ "public"
+ ],
+ "alias_of": null
+ },
+ {
+ "id": "lang_samples/apex/classes.cls::Splintered::setA",
+ "name": "setA",
+ "qualified_name": "lang_samples.apex.classes.Splintered.setA",
+ "kind": "method",
+ "signature": "setA(Integer v) -> void",
+ "start_line": 29,
+ "end_line": 32,
+ "docstring": null,
+ "decorators": [],
+ "visibility": "public",
+ "is_async": false,
+ "complexity_estimate": 1,
+ "language": "apex",
+ "parent_name": "Splintered",
+ "is_exported_symbol": false,
+ "is_declaration": false,
+ "type_parameter_count": null,
+ "extension_receiver": null,
+ "written_receiver": null,
+ "modifiers": [
+ "public"
+ ],
+ "alias_of": null
+ },
+ {
+ "id": "lang_samples/apex/classes.cls::Splintered::getA",
+ "name": "getA",
+ "qualified_name": "lang_samples.apex.classes.Splintered.getA",
+ "kind": "method",
+ "signature": "getA() -> Integer",
+ "start_line": 34,
+ "end_line": 36,
+ "docstring": null,
+ "decorators": [],
+ "visibility": "public",
+ "is_async": false,
+ "complexity_estimate": 1,
+ "language": "apex",
+ "parent_name": "Splintered",
+ "is_exported_symbol": false,
+ "is_declaration": false,
+ "type_parameter_count": null,
+ "extension_receiver": null,
+ "written_receiver": null,
+ "modifiers": [
+ "public"
+ ],
+ "alias_of": null
+ },
+ {
+ "id": "lang_samples/apex/classes.cls::Splintered::setB",
+ "name": "setB",
+ "qualified_name": "lang_samples.apex.classes.Splintered.setB",
+ "kind": "method",
+ "signature": "setB(Integer v) -> void",
+ "start_line": 38,
+ "end_line": 41,
+ "docstring": null,
+ "decorators": [],
+ "visibility": "public",
+ "is_async": false,
+ "complexity_estimate": 1,
+ "language": "apex",
+ "parent_name": "Splintered",
+ "is_exported_symbol": false,
+ "is_declaration": false,
+ "type_parameter_count": null,
+ "extension_receiver": null,
+ "written_receiver": null,
+ "modifiers": [
+ "public"
+ ],
+ "alias_of": null
+ },
+ {
+ "id": "lang_samples/apex/classes.cls::Splintered::getB",
+ "name": "getB",
+ "qualified_name": "lang_samples.apex.classes.Splintered.getB",
+ "kind": "method",
+ "signature": "getB() -> Integer",
+ "start_line": 43,
+ "end_line": 45,
+ "docstring": null,
+ "decorators": [],
+ "visibility": "public",
+ "is_async": false,
+ "complexity_estimate": 1,
+ "language": "apex",
+ "parent_name": "Splintered",
+ "is_exported_symbol": false,
+ "is_declaration": false,
+ "type_parameter_count": null,
+ "extension_receiver": null,
+ "written_receiver": null,
+ "modifiers": [
+ "public"
+ ],
+ "alias_of": null
+ },
+ {
+ "id": "lang_samples/apex/classes.cls::Classes::WithProperties",
+ "name": "WithProperties",
+ "qualified_name": "lang_samples.apex.classes.Classes.WithProperties",
+ "kind": "class",
+ "signature": "class WithProperties",
+ "start_line": 48,
+ "end_line": 60,
+ "docstring": null,
+ "decorators": [],
+ "visibility": "public",
+ "is_async": false,
+ "complexity_estimate": 1,
+ "language": "apex",
+ "parent_name": "Classes",
+ "is_exported_symbol": false,
+ "is_declaration": false,
+ "type_parameter_count": null,
+ "extension_receiver": null,
+ "written_receiver": null,
+ "modifiers": [
+ "public"
+ ],
+ "alias_of": null
+ },
+ {
+ "id": "lang_samples/apex/classes.cls::WithProperties::label",
+ "name": "label",
+ "qualified_name": "lang_samples.apex.classes.WithProperties.label",
+ "kind": "variable",
+ "signature": "label",
+ "start_line": 49,
+ "end_line": 49,
+ "docstring": null,
+ "decorators": [],
+ "visibility": "public",
+ "is_async": false,
+ "complexity_estimate": 1,
+ "language": "apex",
+ "parent_name": "WithProperties",
+ "is_exported_symbol": false,
+ "is_declaration": false,
+ "type_parameter_count": null,
+ "extension_receiver": null,
+ "written_receiver": null,
+ "modifiers": [
+ "public"
+ ],
+ "alias_of": null
+ },
+ {
+ "id": "lang_samples/apex/classes.cls::WithProperties::size",
+ "name": "size",
+ "qualified_name": "lang_samples.apex.classes.WithProperties.size",
+ "kind": "variable",
+ "signature": "size",
+ "start_line": 50,
+ "end_line": 54,
+ "docstring": null,
+ "decorators": [],
+ "visibility": "public",
+ "is_async": false,
+ "complexity_estimate": 1,
+ "language": "apex",
+ "parent_name": "WithProperties",
+ "is_exported_symbol": false,
+ "is_declaration": false,
+ "type_parameter_count": null,
+ "extension_receiver": null,
+ "written_receiver": null,
+ "modifiers": [
+ "public"
+ ],
+ "alias_of": null
+ },
+ {
+ "id": "lang_samples/apex/classes.cls::WithProperties::add",
+ "name": "add",
+ "qualified_name": "lang_samples.apex.classes.WithProperties.add",
+ "kind": "method",
+ "signature": "add(String item) -> void",
+ "start_line": 57,
+ "end_line": 59,
+ "docstring": null,
+ "decorators": [],
+ "visibility": "public",
+ "is_async": false,
+ "complexity_estimate": 1,
+ "language": "apex",
+ "parent_name": "WithProperties",
+ "is_exported_symbol": false,
+ "is_declaration": false,
+ "type_parameter_count": null,
+ "extension_receiver": null,
+ "written_receiver": null,
+ "modifiers": [
+ "public"
+ ],
+ "alias_of": null
+ },
+ {
+ "id": "lang_samples/apex/classes.cls::Classes::Shape",
+ "name": "Shape",
+ "qualified_name": "lang_samples.apex.classes.Classes.Shape",
+ "kind": "interface",
+ "signature": "interface Shape",
+ "start_line": 62,
+ "end_line": 64,
+ "docstring": null,
+ "decorators": [],
+ "visibility": "public",
+ "is_async": false,
+ "complexity_estimate": 1,
+ "language": "apex",
+ "parent_name": "Classes",
+ "is_exported_symbol": false,
+ "is_declaration": false,
+ "type_parameter_count": null,
+ "extension_receiver": null,
+ "written_receiver": null,
+ "modifiers": [
+ "public"
+ ],
+ "alias_of": null
+ },
+ {
+ "id": "lang_samples/apex/classes.cls::Shape::area",
+ "name": "area",
+ "qualified_name": "lang_samples.apex.classes.Shape.area",
+ "kind": "method",
+ "signature": "area() -> Decimal",
+ "start_line": 63,
+ "end_line": 63,
+ "docstring": null,
+ "decorators": [],
+ "visibility": "public",
+ "is_async": false,
+ "complexity_estimate": 1,
+ "language": "apex",
+ "parent_name": "Shape",
+ "is_exported_symbol": false,
+ "is_declaration": false,
+ "type_parameter_count": null,
+ "extension_receiver": null,
+ "written_receiver": null,
+ "modifiers": [],
+ "alias_of": null
+ },
+ {
+ "id": "lang_samples/apex/classes.cls::Classes::Mode",
+ "name": "Mode",
+ "qualified_name": "lang_samples.apex.classes.Classes.Mode",
+ "kind": "enum",
+ "signature": "enum Mode",
+ "start_line": 66,
+ "end_line": 66,
+ "docstring": null,
+ "decorators": [],
+ "visibility": "public",
+ "is_async": false,
+ "complexity_estimate": 1,
+ "language": "apex",
+ "parent_name": "Classes",
+ "is_exported_symbol": false,
+ "is_declaration": false,
+ "type_parameter_count": null,
+ "extension_receiver": null,
+ "written_receiver": null,
+ "modifiers": [
+ "public"
+ ],
+ "alias_of": null
+ }
+ ],
+ "imports": [],
+ "exports": [
+ "Classes"
+ ],
+ "export_aliases": {},
+ "calls": [
+ {
+ "target_name": "size",
+ "receiver_name": "items",
+ "caller_symbol_id": "lang_samples/apex/classes.cls::WithProperties::size",
+ "line": 52,
+ "argument_count": 0,
+ "receiver_call": null,
+ "scope_name": null,
+ "edge_type": "calls",
+ "supplied_props": null,
+ "bare_name_fallback": false,
+ "spawned": false,
+ "argument_types": null,
+ "argument_names": null
+ },
+ {
+ "target_name": "add",
+ "receiver_name": "items",
+ "caller_symbol_id": "lang_samples/apex/classes.cls::WithProperties::add",
+ "line": 58,
+ "argument_count": 1,
+ "receiver_call": null,
+ "scope_name": null,
+ "edge_type": "calls",
+ "supplied_props": null,
+ "bare_name_fallback": false,
+ "spawned": false,
+ "argument_types": null,
+ "argument_names": [
+ "item"
+ ]
+ }
+ ],
+ "heritage": [],
+ "docstring": null,
+ "parse_errors": [],
+ "content_hash": "a71e5ece2bf58ebc7cf1bb5273d5b28f488b9a7c14614188f281d2fd9c42ec6a",
+ "type_refs": [],
+ "local_refs": [],
+ "registrars": [],
+ "references": []
+ },
+ "apex/nested.cls": {
+ "file_info": {
+ "path": "lang_samples/apex/nested.cls",
+ "language": "apex",
+ "size_bytes": 1586,
+ "is_test": false,
+ "is_config": false,
+ "is_api_contract": false,
+ "is_entry_point": false,
+ "is_manifest_entry": false,
+ "is_reachability_root": false
+ },
+ "symbols": [
+ {
+ "id": "lang_samples/apex/nested.cls::Nested",
+ "name": "Nested",
+ "qualified_name": "lang_samples.apex.nested.Nested",
+ "kind": "class",
+ "signature": "class Nested",
+ "start_line": 2,
+ "end_line": 67,
+ "docstring": null,
+ "decorators": [],
+ "visibility": "public",
+ "is_async": false,
+ "complexity_estimate": 1,
+ "language": "apex",
+ "parent_name": null,
+ "is_exported_symbol": false,
+ "is_declaration": false,
+ "type_parameter_count": null,
+ "extension_receiver": null,
+ "written_receiver": null,
+ "modifiers": [
+ "public"
+ ],
+ "alias_of": null
+ },
+ {
+ "id": "lang_samples/apex/nested.cls::Nested::deeplyNested",
+ "name": "deeplyNested",
+ "qualified_name": "lang_samples.apex.nested.Nested.deeplyNested",
+ "kind": "method",
+ "signature": "deeplyNested(List<Integer> values) -> Integer",
+ "start_line": 3,
+ "end_line": 21,
+ "docstring": null,
+ "decorators": [],
+ "visibility": "public",
+ "is_async": false,
+ "complexity_estimate": 1,
+ "language": "apex",
+ "parent_name": "Nested",
+ "is_exported_symbol": false,
+ "is_declaration": false,
+ "type_parameter_count": null,
+ "extension_receiver": null,
+ "written_receiver": null,
+ "modifiers": [
+ "public"
+ ],
+ "alias_of": null
+ },
+ {
+ "id": "lang_samples/apex/nested.cls::Nested::manyBranches",
+ "name": "manyBranches",
+ "qualified_name": "lang_samples.apex.nested.Nested.manyBranches",
+ "kind": "method",
+ "signature": "manyBranches(Integer a, Integer b, String s) -> String",
+ "start_line": 23,
+ "end_line": 34,
+ "docstring": null,
+ "decorators": [],
+ "visibility": "public",
+ "is_async": false,
+ "complexity_estimate": 1,
+ "language": "apex",
+ "parent_name": "Nested",
+ "is_exported_symbol": false,
+ "is_declaration": false,
+ "type_parameter_count": null,
+ "extension_receiver": null,
+ "written_receiver": null,
+ "modifiers": [
+ "public"
+ ],
+ "alias_of": null
+ },
+ {
+ "id": "lang_samples/apex/nested.cls::Nested::dispatch",
+ "name": "dispatch",
+ "qualified_name": "lang_samples.apex.nested.Nested.dispatch",
+ "kind": "method",
+ "signature": "dispatch(Integer code) -> String",
+ "start_line": 36,
+ "end_line": 48,
+ "docstring": null,
+ "decorators": [],
+ "visibility": "public",
+ "is_async": false,
+ "complexity_estimate": 1,
+ "language": "apex",
+ "parent_name": "Nested",
+ "is_exported_symbol": false,
+ "is_declaration": false,
+ "type_parameter_count": null,
+ "extension_receiver": null,
+ "written_receiver": null,
+ "modifiers": [
+ "public"
+ ],
+ "alias_of": null
+ },
+ {
+ "id": "lang_samples/apex/nested.cls::Nested::shallow",
+ "name": "shallow",
+ "qualified_name": "lang_samples.apex.nested.Nested.shallow",
+ "kind": "method",
+ "signature": "shallow(Integer x) -> Integer",
+ "start_line": 50,
+ "end_line": 52,
+ "docstring": null,
+ "decorators": [],
+ "visibility": "public",
+ "is_async": false,
+ "complexity_estimate": 1,
+ "language": "apex",
+ "parent_name": "Nested",
+ "is_exported_symbol": false,
+ "is_declaration": false,
+ "type_parameter_count": null,
+ "extension_receiver": null,
+ "written_receiver": null,
+ "modifiers": [
+ "public"
+ ],
+ "alias_of": null
+ },
+ {
+ "id": "lang_samples/apex/nested.cls::Nested::total",
+ "name": "total",
+ "qualified_name": "lang_samples.apex.nested.Nested.total",
+ "kind": "variable",
+ "signature": "total",
+ "start_line": 54,
+ "end_line": 62,
+ "docstring": null,
+ "decorators": [],
+ "visibility": "public",
+ "is_async": false,
+ "complexity_estimate": 1,
+ "language": "apex",
+ "parent_name": "Nested",
+ "is_exported_symbol": false,
+ "is_declaration": false,
+ "type_parameter_count": null,
+ "extension_receiver": null,
+ "written_receiver": null,
+ "modifiers": [
+ "public"
+ ],
+ "alias_of": null
+ },
+ {
+ "id": "lang_samples/apex/nested.cls::Nested::label",
+ "name": "label",
+ "qualified_name": "lang_samples.apex.nested.Nested.label",
+ "kind": "variable",
+ "signature": "label",
+ "start_line": 64,
+ "end_line": 64,
+ "docstring": null,
+ "decorators": [],
+ "visibility": "public",
+ "is_async": false,
+ "complexity_estimate": 1,
+ "language": "apex",
+ "parent_name": "Nested",
+ "is_exported_symbol": false,
+ "is_declaration": false,
+ "type_parameter_count": null,
+ "extension_receiver": null,
+ "written_receiver": null,
+ "modifiers": [
+ "public"
+ ],
+ "alias_of": null
+ }
+ ],
+ "imports": [],
+ "exports": [
+ "Nested"
+ ],
+ "export_aliases": {},
+ "calls": [],
+ "heritage": [],
+ "docstring": null,
+ "parse_errors": [],
+ "content_hash": "ee158c49e5af8ec281ac45b8e9c5732c42388f32d610435fcf57fc0c1dd32113",
+ "type_refs": [],
+ "local_refs": [],
+ "registrars": [],
+ "references": []
+ },
+ "apex/perf_io_in_loop.cls": {
+ "file_info": {
+ "path": "lang_samples/apex/perf_io_in_loop.cls",
+ "language": "apex",
+ "size_bytes": 4109,
+ "is_test": false,
+ "is_config": false,
+ "is_api_contract": false,
+ "is_entry_point": false,
+ "is_manifest_entry": false,
+ "is_reachability_root": false
+ },
+ "symbols": [
+ {
+ "id": "lang_samples/apex/perf_io_in_loop.cls::PerfIoInLoop",
+ "name": "PerfIoInLoop",
+ "qualified_name": "lang_samples.apex.perf_io_in_loop.PerfIoInLoop",
+ "kind": "class",
+ "signature": "class PerfIoInLoop",
+ "start_line": 3,
+ "end_line": 144,
+ "docstring": null,
+ "decorators": [],
+ "visibility": "public",
+ "is_async": false,
+ "complexity_estimate": 1,
+ "language": "apex",
+ "parent_name": null,
+ "is_exported_symbol": false,
+ "is_declaration": false,
+ "type_parameter_count": null,
+ "extension_receiver": null,
+ "written_receiver": null,
+ "modifiers": [
+ "public"
+ ],
+ "alias_of": null
+ },
+ {
+ "id": "lang_samples/apex/perf_io_in_loop.cls::PerfIoInLoop::soqlPerRecord",
+ "name": "soqlPerRecord",
+ "qualified_name": "lang_samples.apex.perf_io_in_loop.PerfIoInLoop.soqlPerRecord",
+ "kind": "method",
+ "signature": "soqlPerRecord(List<Contact> contacts) -> void",
+ "start_line": 6,
+ "end_line": 10,
+ "docstring": null,
+ "decorators": [],
+ "visibility": "public",
+ "is_async": false,
+ "complexity_estimate": 1,
+ "language": "apex",
+ "parent_name": "PerfIoInLoop",
+ "is_exported_symbol": false,
+ "is_declaration": false,
+ "type_parameter_count": null,
+ "extension_receiver": null,
+ "written_receiver": null,
+ "modifiers": [
+ "public"
+ ],
+ "alias_of": null
+ },
+ {
+ "id": "lang_samples/apex/perf_io_in_loop.cls::PerfIoInLoop::dmlPerRecord",
+ "name": "dmlPerRecord",
+ "qualified_name": "lang_samples.apex.perf_io_in_loop.PerfIoInLoop.dmlPerRecord",
+ "kind": "method",
+ "signature": "dmlPerRecord(List<Account> accounts) -> void",
+ "start_line": 12,
+ "end_line": 16,
+ "docstring": null,
+ "decorators": [],
+ "visibility": "public",
+ "is_async": false,
+ "complexity_estimate": 1,
+ "language": "apex",
+ "parent_name": "PerfIoInLoop",
+ "is_exported_symbol": false,
+ "is_declaration": false,
+ "type_parameter_count": null,
+ "extension_receiver": null,
+ "written_receiver": null,
+ "modifiers": [
+ "public"
+ ],
+ "alias_of": null
+ },
+ {
+ "id": "lang_samples/apex/perf_io_in_loop.cls::PerfIoInLoop::databaseAndCallout",
+ "name": "databaseAndCallout",
+ "qualified_name": "lang_samples.apex.perf_io_in_loop.PerfIoInLoop.databaseAndCallout",
+ "kind": "method",
+ "signature": "databaseAndCallout(List<Id> ids, HttpRequest req) -> void",
+ "start_line": 18,
+ "end_line": 24,
+ "docstring": null,
+ "decorators": [],
+ "visibility": "public",
+ "is_async": false,
+ "complexity_estimate": 1,
+ "language": "apex",
+ "parent_name": "PerfIoInLoop",
+ "is_exported_symbol": false,
+ "is_declaration": false,
+ "type_parameter_count": null,
+ "extension_receiver": null,
+ "written_receiver": null,
+ "modifiers": [
+ "public"
+ ],
+ "alias_of": null
+ },
+ {
+ "id": "lang_samples/apex/perf_io_in_loop.cls::PerfIoInLoop::asyncPerRecord",
+ "name": "asyncPerRecord",
+ "qualified_name": "lang_samples.apex.perf_io_in_loop.PerfIoInLoop.asyncPerRecord",
+ "kind": "method",
+ "signature": "asyncPerRecord(List<Id> ids) -> void",
+ "start_line": 26,
+ "end_line": 31,
+ "docstring": null,
+ "decorators": [],
+ "visibility": "public",
+ "is_async": false,
+ "complexity_estimate": 1,
+ "language": "apex",
+ "parent_name": "PerfIoInLoop",
+ "is_exported_symbol": false,
+ "is_declaration": false,
+ "type_parameter_count": null,
+ "extension_receiver": null,
+ "written_receiver": null,
+ "modifiers": [
+ "public"
+ ],
+ "alias_of": null
+ },
+ {
+ "id": "lang_samples/apex/perf_io_in_loop.cls::PerfIoInLoop::notifyLater",
+ "name": "notifyLater",
+ "qualified_name": "lang_samples.apex.perf_io_in_loop.PerfIoInLoop.notifyLater",
+ "kind": "method",
+ "signature": "notifyLater(Id i) -> void",
+ "start_line": 33,
+ "end_line": 35,
+ "docstring": null,
+ "decorators": [
+ "@future\n private static"
+ ],
+ "visibility": "private",
+ "is_async": false,
+ "complexity_estimate": 1,
+ "language": "apex",
+ "parent_name": "PerfIoInLoop",
+ "is_exported_symbol": false,
+ "is_declaration": false,
+ "type_parameter_count": null,
+ "extension_receiver": null,
+ "written_receiver": null,
+ "modifiers": [
+ "private",
+ "static"
+ ],
+ "alias_of": null
+ },
+ {
+ "id": "lang_samples/apex/perf_io_in_loop.cls::PerfIoInLoop::nested",
+ "name": "nested",
+ "qualified_name": "lang_samples.apex.perf_io_in_loop.PerfIoInLoop.nested",
+ "kind": "method",
+ "signature": "nested(List<Account> accounts) -> void",
+ "start_line": 37,
+ "end_line": 43,
+ "docstring": null,
+ "decorators": [],
+ "visibility": "public",
+ "is_async": false,
+ "complexity_estimate": 1,
+ "language": "apex",
+ "parent_name": "PerfIoInLoop",
+ "is_exported_symbol": false,
+ "is_declaration": false,
+ "type_parameter_count": null,
+ "extension_receiver": null,
+ "written_receiver": null,
+ "modifiers": [
+ "public"
+ ],
+ "alias_of": null
+ },
+ {
+ "id": "lang_samples/apex/perf_io_in_loop.cls::PerfIoInLoop::bulk",
+ "name": "bulk",
+ "qualified_name": "lang_samples.apex.perf_io_in_loop.PerfIoInLoop.bulk",
+ "kind": "method",
+ "signature": "bulk(List<Account> accounts) -> void",
+ "start_line": 47,
+ "end_line": 54,
+ "docstring": null,
+ "decorators": [],
+ "visibility": "public",
+ "is_async": false,
+ "complexity_estimate": 1,
+ "language": "apex",
+ "parent_name": "PerfIoInLoop",
+ "is_exported_symbol": false,
+ "is_declaration": false,
+ "type_parameter_count": null,
+ "extension_receiver": null,
+ "written_receiver": null,
+ "modifiers": [
+ "public"
+ ],
+ "alias_of": null
+ },
+ {
+ "id": "lang_samples/apex/perf_io_in_loop.cls::PerfIoInLoop::queryInHeader",
+ "name": "queryInHeader",
+ "qualified_name": "lang_samples.apex.perf_io_in_loop.PerfIoInLoop.queryInHeader",
+ "kind": "method",
+ "signature": "queryInHeader() -> void",
+ "start_line": 56,
+ "end_line": 60,
+ "docstring": null,
+ "decorators": [],
+ "visibility": "public",
+ "is_async": false,
+ "complexity_estimate": 1,
+ "language": "apex",
+ "parent_name": "PerfIoInLoop",
+ "is_exported_symbol": false,
+ "is_declaration": false,
+ "type_parameter_count": null,
+ "extension_receiver": null,
+ "written_receiver": null,
+ "modifiers": [
+ "public"
+ ],
+ "alias_of": null
+ },
+ {
+ "id": "lang_samples/apex/perf_io_in_loop.cls::PerfIoInLoop::soqlForChunks",
+ "name": "soqlForChunks",
+ "qualified_name": "lang_samples.apex.perf_io_in_loop.PerfIoInLoop.soqlForChunks",
+ "kind": "method",
+ "signature": "soqlForChunks() -> void",
+ "start_line": 62,
+ "end_line": 66,
+ "docstring": null,
+ "decorators": [],
+ "visibility": "public",
+ "is_async": false,
+ "complexity_estimate": 1,
+ "language": "apex",
+ "parent_name": "PerfIoInLoop",
+ "is_exported_symbol": false,
+ "is_declaration": false,
+ "type_parameter_count": null,
+ "extension_receiver": null,
+ "written_receiver": null,
+ "modifiers": [
+ "public"
+ ],
+ "alias_of": null
+ },
+ {
+ "id": "lang_samples/apex/perf_io_in_loop.cls::PerfIoInLoop::literalBound",
+ "name": "literalBound",
+ "qualified_name": "lang_samples.apex.perf_io_in_loop.PerfIoInLoop.literalBound",
+ "kind": "method",
+ "signature": "literalBound(Account a) -> void",
+ "start_line": 68,
+ "end_line": 75,
+ "docstring": null,
+ "decorators": [],
+ "visibility": "public",
+ "is_async": false,
+ "complexity_estimate": 1,
+ "language": "apex",
+ "parent_name": "PerfIoInLoop",
+ "is_exported_symbol": false,
+ "is_declaration": false,
+ "type_parameter_count": null,
+ "extension_receiver": null,
+ "written_receiver": null,
+ "modifiers": [
+ "public"
+ ],
+ "alias_of": null
+ },
+ {
+ "id": "lang_samples/apex/perf_io_in_loop.cls::PerfIoInLoop::chunked",
+ "name": "chunked",
+ "qualified_name": "lang_samples.apex.perf_io_in_loop.PerfIoInLoop.chunked",
+ "kind": "method",
+ "signature": "chunked(List<Account> rows, Integer size) -> void",
+ "start_line": 77,
+ "end_line": 81,
+ "docstring": null,
+ "decorators": [],
+ "visibility": "public",
+ "is_async": false,
+ "complexity_estimate": 1,
+ "language": "apex",
+ "parent_name": "PerfIoInLoop",
+ "is_exported_symbol": false,
+ "is_declaration": false,
+ "type_parameter_count": null,
+ "extension_receiver": null,
+ "written_receiver": null,
+ "modifiers": [
+ "public"
+ ],
+ "alias_of": null
+ },
+ {
+ "id": "lang_samples/apex/perf_io_in_loop.cls::PerfIoInLoop::flushAtSize",
+ "name": "flushAtSize",
+ "qualified_name": "lang_samples.apex.perf_io_in_loop.PerfIoInLoop.flushAtSize",
+ "kind": "method",
+ "signature": "flushAtSize(List<Account> rows) -> void",
+ "start_line": 83,
+ "end_line": 92,
+ "docstring": null,
+ "decorators": [],
+ "visibility": "public",
+ "is_async": false,
+ "complexity_estimate": 1,
+ "language": "apex",
+ "parent_name": "PerfIoInLoop",
+ "is_exported_symbol": false,
+ "is_declaration": false,
+ "type_parameter_count": null,
+ "extension_receiver": null,
+ "written_receiver": null,
+ "modifiers": [
+ "public"
+ ],
+ "alias_of": null
+ },
+ {
+ "id": "lang_samples/apex/perf_io_in_loop.cls::PerfIoInLoop::cached",
+ "name": "cached",
+ "qualified_name": "lang_samples.apex.perf_io_in_loop.PerfIoInLoop.cached",
+ "kind": "method",
+ "signature": "cached(List<Account> rows) -> void",
+ "start_line": 94,
+ "end_line": 101,
+ "docstring": null,
+ "decorators": [],
+ "visibility": "public",
+ "is_async": false,
+ "complexity_estimate": 1,
+ "language": "apex",
+ "parent_name": "PerfIoInLoop",
+ "is_exported_symbol": false,
+ "is_declaration": false,
+ "type_parameter_count": null,
+ "extension_receiver": null,
+ "written_receiver": null,
+ "modifiers": [
+ "public"
+ ],
+ "alias_of": null
+ },
+ {
+ "id": "lang_samples/apex/perf_io_in_loop.cls::PerfIoInLoop::firstMatch",
+ "name": "firstMatch",
+ "qualified_name": "lang_samples.apex.perf_io_in_loop.PerfIoInLoop.firstMatch",
+ "kind": "method",
+ "signature": "firstMatch(List<Account> rows) -> void",
+ "start_line": 103,
+ "end_line": 110,
+ "docstring": null,
+ "decorators": [],
+ "visibility": "public",
+ "is_async": false,
+ "complexity_estimate": 1,
+ "language": "apex",
+ "parent_name": "PerfIoInLoop",
+ "is_exported_symbol": false,
+ "is_declaration": false,
+ "type_parameter_count": null,
+ "extension_receiver": null,
+ "written_receiver": null,
+ "modifiers": [
+ "public"
+ ],
+ "alias_of": null
+ },
+ {
+ "id": "lang_samples/apex/perf_io_in_loop.cls::PerfIoInLoop::perObjectType",
+ "name": "perObjectType",
+ "qualified_name": "lang_samples.apex.perf_io_in_loop.PerfIoInLoop.perObjectType",
+ "kind": "method",
+ "signature": "perObjectType(Map<String, Set<Id>> idsByType) -> void",
+ "start_line": 112,
+ "end_line": 117,
+ "docstring": null,
+ "decorators": [],
+ "visibility": "public",
+ "is_async": false,
+ "complexity_estimate": 1,
+ "language": "apex",
+ "parent_name": "PerfIoInLoop",
+ "is_exported_symbol": false,
+ "is_declaration": false,
+ "type_parameter_count": null,
+ "extension_receiver": null,
+ "written_receiver": null,
+ "modifiers": [
+ "public"
+ ],
+ "alias_of": null
+ },
+ {
+ "id": "lang_samples/apex/perf_io_in_loop.cls::PerfIoInLoop::perGroup",
+ "name": "perGroup",
+ "qualified_name": "lang_samples.apex.perf_io_in_loop.PerfIoInLoop.perGroup",
+ "kind": "method",
+ "signature": "perGroup(Map<String, List<SObject>> byType) -> void",
+ "start_line": 119,
+ "end_line": 123,
+ "docstring": null,
+ "decorators": [],
+ "visibility": "public",
+ "is_async": false,
+ "complexity_estimate": 1,
+ "language": "apex",
+ "parent_name": "PerfIoInLoop",
+ "is_exported_symbol": false,
+ "is_declaration": false,
+ "type_parameter_count": null,
+ "extension_receiver": null,
+ "written_receiver": null,
+ "modifiers": [
+ "public"
+ ],
+ "alias_of": null
+ },
+ {
+ "id": "lang_samples/apex/perf_io_in_loop.cls::PerfIoInLoop::customMetadata",
+ "name": "customMetadata",
+ "qualified_name": "lang_samples.apex.perf_io_in_loop.PerfIoInLoop.customMetadata",
+ "kind": "method",
+ "signature": "customMetadata(List<String> names) -> void",
+ "start_line": 125,
+ "end_line": 129,
+ "docstring": null,
+ "decorators": [],
+ "visibility": "public",
+ "is_async": false,
+ "complexity_estimate": 1,
+ "language": "apex",
+ "parent_name": "PerfIoInLoop",
+ "is_exported_symbol": false,
+ "is_declaration": false,
+ "type_parameter_count": null,
+ "extension_receiver": null,
+ "written_receiver": null,
+ "modifiers": [
+ "public"
+ ],
+ "alias_of": null
+ },
+ {
+ "id": "lang_samples/apex/perf_io_in_loop.cls::PerfIoInLoop::mergeAll",
+ "name": "mergeAll",
+ "qualified_name": "lang_samples.apex.perf_io_in_loop.PerfIoInLoop.mergeAll",
+ "kind": "method",
+ "signature": "mergeAll(Account master, List<Account> dupes) -> void",
+ "start_line": 131,
+ "end_line": 135,
+ "docstring": null,
+ "decorators": [],
+ "visibility": "public",
+ "is_async": false,
+ "complexity_estimate": 1,
+ "language": "apex",
+ "parent_name": "PerfIoInLoop",
+ "is_exported_symbol": false,
+ "is_declaration": false,
+ "type_parameter_count": null,
+ "extension_receiver": null,
+ "written_receiver": null,
+ "modifiers": [
+ "public"
+ ],
+ "alias_of": null
+ },
+ {
+ "id": "lang_samples/apex/perf_io_in_loop.cls::PerfIoInLoop::cursor",
+ "name": "cursor",
+ "qualified_name": "lang_samples.apex.perf_io_in_loop.PerfIoInLoop.cursor",
+ "kind": "method",
+ "signature": "cursor(Id startId) -> void",
+ "start_line": 138,
+ "end_line": 143,
+ "docstring": null,
+ "decorators": [],
+ "visibility": "public",
+ "is_async": false,
+ "complexity_estimate": 1,
+ "language": "apex",
+ "parent_name": "PerfIoInLoop",
+ "is_exported_symbol": false,
+ "is_declaration": false,
+ "type_parameter_count": null,
+ "extension_receiver": null,
+ "written_receiver": null,
+ "modifiers": [
+ "public"
+ ],
+ "alias_of": null
+ }
+ ],
+ "imports": [],
+ "exports": [
+ "PerfIoInLoop"
+ ],
+ "export_aliases": {},
+ "calls": [
+ {
+ "target_name": "delete",
+ "receiver_name": "Database",
+ "caller_symbol_id": "lang_samples/apex/perf_io_in_loop.cls::PerfIoInLoop::databaseAndCallout",
+ "line": 21,
+ "argument_count": 1,
+ "receiver_call": null,
+ "scope_name": null,
+ "edge_type": "calls",
+ "supplied_props": null,
+ "bare_name_fallback": false,
+ "spawned": false,
+ "argument_types": null,
+ "argument_names": [
+ "i"
+ ]
+ },
+ {
+ "target_name": "send",
+ "receiver_name": "http",
+ "caller_symbol_id": "lang_samples/apex/perf_io_in_loop.cls::PerfIoInLoop::databaseAndCallout",
+ "line": 22,
+ "argument_count": 1,
+ "receiver_call": null,
+ "scope_name": null,
+ "edge_type": "calls",
+ "supplied_props": null,
+ "bare_name_fallback": false,
+ "spawned": false,
+ "argument_types": null,
+ "argument_names": [
+ "req"
+ ]
+ },
+ {
+ "target_name": "enqueueJob",
+ "receiver_name": "System",
+ "caller_symbol_id": "lang_samples/apex/perf_io_in_loop.cls::PerfIoInLoop::asyncPerRecord",
+ "line": 28,
+ "argument_count": 1,
+ "receiver_call": null,
+ "scope_name": null,
+ "edge_type": "calls",
+ "supplied_props": null,
+ "bare_name_fallback": false,
+ "spawned": false,
+ "argument_types": null,
+ "argument_names": null
+ },
+ {
+ "target_name": "Worker",
+ "receiver_name": null,
+ "caller_symbol_id": "lang_samples/apex/perf_io_in_loop.cls::PerfIoInLoop::asyncPerRecord",
+ "line": 28,
+ "argument_count": 1,
+ "receiver_call": null,
+ "scope_name": null,
+ "edge_type": "calls",
+ "supplied_props": null,
+ "bare_name_fallback": false,
+ "spawned": false,
+ "argument_types": null,
+ "argument_names": [
+ "i"
+ ]
+ },
+ {
+ "target_name": "notifyLater",
+ "receiver_name": null,
+ "caller_symbol_id": "lang_samples/apex/perf_io_in_loop.cls::PerfIoInLoop::asyncPerRecord",
+ "line": 29,
+ "argument_count": 1,
+ "receiver_call": null,
+ "scope_name": null,
+ "edge_type": "calls",
+ "supplied_props": null,
+ "bare_name_fallback": false,
+ "spawned": false,
+ "argument_types": null,
+ "argument_names": [
+ "i"
+ ]
+ },
+ {
+ "target_name": "Task",
+ "receiver_name": null,
+ "caller_symbol_id": "lang_samples/apex/perf_io_in_loop.cls::PerfIoInLoop::nested",
+ "line": 40,
+ "argument_count": 1,
+ "receiver_call": null,
+ "scope_name": null,
+ "edge_type": "calls",
+ "supplied_props": null,
+ "bare_name_fallback": false,
+ "spawned": false,
+ "argument_types": null,
+ "argument_names": null
+ },
+ {
+ "target_name": "add",
+ "receiver_name": "changed",
+ "caller_symbol_id": "lang_samples/apex/perf_io_in_loop.cls::PerfIoInLoop::bulk",
+ "line": 50,
+ "argument_count": 1,
+ "receiver_call": null,
+ "scope_name": null,
+ "edge_type": "calls",
+ "supplied_props": null,
+ "bare_name_fallback": false,
+ "spawned": false,
+ "argument_types": null,
+ "argument_names": [
+ "a"
+ ]
+ },
+ {
+ "target_name": "Task",
+ "receiver_name": null,
+ "caller_symbol_id": "lang_samples/apex/perf_io_in_loop.cls::PerfIoInLoop::literalBound",
+ "line": 70,
+ "argument_count": 1,
+ "receiver_call": null,
+ "scope_name": null,
+ "edge_type": "calls",
+ "supplied_props": null,
+ "bare_name_fallback": false,
+ "spawned": false,
+ "argument_types": null,
+ "argument_names": null
+ },
+ {
+ "target_name": "Task",
+ "receiver_name": null,
+ "caller_symbol_id": "lang_samples/apex/perf_io_in_loop.cls::PerfIoInLoop::literalBound",
+ "line": 73,
+ "argument_count": 1,
+ "receiver_call": null,
+ "scope_name": null,
+ "edge_type": "calls",
+ "supplied_props": null,
+ "bare_name_fallback": false,
+ "spawned": false,
+ "argument_types": null,
+ "argument_names": null
+ },
+ {
+ "target_name": "size",
+ "receiver_name": "rows",
+ "caller_symbol_id": "lang_samples/apex/perf_io_in_loop.cls::PerfIoInLoop::chunked",
+ "line": 78,
+ "argument_count": 0,
+ "receiver_call": null,
+ "scope_name": null,
+ "edge_type": "calls",
+ "supplied_props": null,
+ "bare_name_fallback": false,
+ "spawned": false,
+ "argument_types": null,
+ "argument_names": null
+ },
+ {
+ "target_name": "update",
+ "receiver_name": "Database",
+ "caller_symbol_id": "lang_samples/apex/perf_io_in_loop.cls::PerfIoInLoop::chunked",
+ "line": 79,
+ "argument_count": 2,
+ "receiver_call": null,
+ "scope_name": null,
+ "edge_type": "calls",
+ "supplied_props": null,
+ "bare_name_fallback": false,
+ "spawned": false,
+ "argument_types": [
+ null,
+ "Boolean"
+ ],
+ "argument_names": [
+ "rows",
+ null
+ ]
+ },
+ {
+ "target_name": "add",
+ "receiver_name": "buffer",
+ "caller_symbol_id": "lang_samples/apex/perf_io_in_loop.cls::PerfIoInLoop::flushAtSize",
+ "line": 86,
+ "argument_count": 1,
+ "receiver_call": null,
+ "scope_name": null,
+ "edge_type": "calls",
+ "supplied_props": null,
+ "bare_name_fallback": false,
+ "spawned": false,
+ "argument_types": null,
+ "argument_names": [
+ "a"
+ ]
+ },
+ {
+ "target_name": "size",
+ "receiver_name": "buffer",
+ "caller_symbol_id": "lang_samples/apex/perf_io_in_loop.cls::PerfIoInLoop::flushAtSize",
+ "line": 87,
+ "argument_count": 0,
+ "receiver_call": null,
+ "scope_name": null,
+ "edge_type": "calls",
+ "supplied_props": null,
+ "bare_name_fallback": false,
+ "spawned": false,
+ "argument_types": null,
+ "argument_names": null
+ },
+ {
+ "target_name": "clear",
+ "receiver_name": "buffer",
+ "caller_symbol_id": "lang_samples/apex/perf_io_in_loop.cls::PerfIoInLoop::flushAtSize",
+ "line": 89,
+ "argument_count": 0,
+ "receiver_call": null,
+ "scope_name": null,
+ "edge_type": "calls",
+ "supplied_props": null,
+ "bare_name_fallback": false,
+ "spawned": false,
+ "argument_types": null,
+ "argument_names": null
+ },
+ {
+ "target_name": "keySet",
+ "receiver_name": "idsByType",
+ "caller_symbol_id": "lang_samples/apex/perf_io_in_loop.cls::PerfIoInLoop::perObjectType",
+ "line": 113,
+ "argument_count": 0,
+ "receiver_call": null,
+ "scope_name": null,
+ "edge_type": "calls",
+ "supplied_props": null,
+ "bare_name_fallback": false,
+ "spawned": false,
+ "argument_types": null,
+ "argument_names": null
+ },
+ {
+ "target_name": "get",
+ "receiver_name": "idsByType",
+ "caller_symbol_id": "lang_samples/apex/perf_io_in_loop.cls::PerfIoInLoop::perObjectType",
+ "line": 114,
+ "argument_count": 1,
+ "receiver_call": null,
+ "scope_name": null,
+ "edge_type": "calls",
+ "supplied_props": null,
+ "bare_name_fallback": false,
+ "spawned": false,
+ "argument_types": null,
+ "argument_names": [
+ "objectName"
+ ]
+ },
+ {
+ "target_name": "query",
+ "receiver_name": "Database",
+ "caller_symbol_id": "lang_samples/apex/perf_io_in_loop.cls::PerfIoInLoop::perObjectType",
+ "line": 115,
+ "argument_count": 1,
+ "receiver_call": null,
+ "scope_name": null,
+ "edge_type": "calls",
+ "supplied_props": null,
+ "bare_name_fallback": false,
+ "spawned": false,
+ "argument_types": null,
+ "argument_names": null
+ },
+ {
+ "target_name": "keySet",
+ "receiver_name": "byType",
+ "caller_symbol_id": "lang_samples/apex/perf_io_in_loop.cls::PerfIoInLoop::perGroup",
+ "line": 120,
+ "argument_count": 0,
+ "receiver_call": null,
+ "scope_name": null,
+ "edge_type": "calls",
+ "supplied_props": null,
+ "bare_name_fallback": false,
+ "spawned": false,
+ "argument_types": null,
+ "argument_names": null
+ },
+ {
+ "target_name": "get",
+ "receiver_name": "byType",
+ "caller_symbol_id": "lang_samples/apex/perf_io_in_loop.cls::PerfIoInLoop::perGroup",
+ "line": 121,
+ "argument_count": 1,
+ "receiver_call": null,
+ "scope_name": null,
+ "edge_type": "calls",
+ "supplied_props": null,
+ "bare_name_fallback": false,
+ "spawned": false,
+ "argument_types": null,
+ "argument_names": [
+ "t"
+ ]
+ }
+ ],
+ "heritage": [],
+ "docstring": null,
+ "parse_errors": [],
+ "content_hash": "3fe0b09443ef216137aaa2b830a7c86d1add6f89dfa78e73d9636f4a03ce3441",
+ "type_refs": [
+ {
+ "type_name": "Contact",
+ "line": 6,
+ "origin": "param_type"
+ },
+ {
+ "type_name": "Contact",
+ "line": 7,
+ "origin": "method_param"
+ },
+ {
+ "type_name": "Account",
+ "line": 8,
+ "origin": "field_type"
+ },
+ {
+ "type_name": "Account",
+ "line": 12,
+ "origin": "param_type"
+ },
+ {
+ "type_name": "Account",
+ "line": 13,
+ "origin": "method_param"
+ },
+ {
+ "type_name": "Worker",
+ "line": 28,
+ "origin": "composite_literal"
+ },
+ {
+ "type_name": "Account",
+ "line": 37,
+ "origin": "param_type"
+ },
+ {
+ "type_name": "Account",
+ "line": 38,
+ "origin": "method_param"
+ },
+ {
+ "type_name": "Contact",
+ "line": 39,
+ "origin": "method_param"
+ },
+ {
+ "type_name": "Task",
+ "line": 40,
+ "origin": "composite_literal"
+ },
+ {
+ "type_name": "Account",
+ "line": 47,
+ "origin": "param_type"
+ },
+ {
+ "type_name": "Account",
+ "line": 48,
+ "origin": "field_type"
+ },
+ {
+ "type_name": "Account",
+ "line": 49,
+ "origin": "method_param"
+ },
+ {
+ "type_name": "Contact",
+ "line": 53,
+ "origin": "field_type"
+ },
+ {
+ "type_name": "Account",
+ "line": 57,
+ "origin": "method_param"
+ },
+ {
+ "type_name": "Account",
+ "line": 63,
+ "origin": "method_param"
+ },
+ {
+ "type_name": "Account",
+ "line": 68,
+ "origin": "param_type"
+ },
+ {
+ "type_name": "Task",
+ "line": 70,
+ "origin": "composite_literal"
+ },
+ {
+ "type_name": "Task",
+ "line": 73,
+ "origin": "composite_literal"
+ },
+ {
+ "type_name": "Account",
+ "line": 77,
+ "origin": "param_type"
+ },
+ {
+ "type_name": "Account",
+ "line": 83,
+ "origin": "param_type"
+ },
+ {
+ "type_name": "Account",
+ "line": 84,
+ "origin": "field_type"
+ },
+ {
+ "type_name": "Account",
+ "line": 85,
+ "origin": "method_param"
+ },
+ {
+ "type_name": "Account",
+ "line": 94,
+ "origin": "param_type"
+ },
+ {
+ "type_name": "Account",
+ "line": 95,
+ "origin": "field_type"
+ },
+ {
+ "type_name": "Account",
+ "line": 96,
+ "origin": "method_param"
+ },
+ {
+ "type_name": "Account",
+ "line": 98,
+ "origin": "composite_literal"
+ },
+ {
+ "type_name": "Account",
+ "line": 103,
+ "origin": "param_type"
+ },
+ {
+ "type_name": "Account",
+ "line": 104,
+ "origin": "method_param"
+ },
+ {
+ "type_name": "Setting__mdt",
+ "line": 127,
+ "origin": "field_type"
+ },
+ {
+ "type_name": "Account",
+ "line": 131,
+ "origin": "param_type"
+ },
+ {
+ "type_name": "Account",
+ "line": 132,
+ "origin": "method_param"
+ }
+ ],
+ "local_refs": [],
+ "registrars": [],
+ "references": []
}
}