MCPcopy Create free account
hub / github.com/codenameone/CodenameOne / collect_counts

Function collect_counts

scripts/mangle-javascript-port-identifiers.py:386–424  ·  view source on GitHub ↗
(files: list[Path], directory: Path)

Source from the content-addressed store, hash-verified

384
385
386def collect_counts(files: list[Path], directory: Path) -> tuple[Counter, frozenset[str]]:
387 counts: Counter = Counter()
388 for path in files:
389 data = path.read_text(encoding="utf-8")
390 for match in IDENTIFIER_PATTERN.finditer(data):
391 counts[match.group(0)] += 1
392 for name in EXCLUDE:
393 counts.pop(name, None)
394
395 jso_bridge_classes = _collect_jso_bridge_class_names(files)
396 jso_bridge_dispatch_ids = _load_jso_bridge_dispatch_ids(directory)
397 # Exclude every ``cn1_<jsoClass>_*`` method id so ``parseJsoBridgeMethod``
398 # keeps working against host DOM receivers. Also exclude the class name
399 # itself, both because it flows through the runtime as a plain string
400 # (the ``className`` argument of ``invokeJsoBridge`` / ``isJsoBridgeClass``
401 # / ``classes[...]`` lookup) and so runtime-built ``"cn1_" + className +
402 # "_"`` prefixes still match the unmangled method ids we just excluded.
403 # In addition, exclude every sig-based dispatch id the translator
404 # tagged as a JSO bridge method via ``jso-bridge-dispatch-ids.txt``
405 # — those ids reach ``parseJsoBridgeMethod`` for receivers whose
406 # ``__class`` resolves through ``isJsoBridgeClass`` and need to keep
407 # their original ``cn1_s_<method>_<sig>`` shape so the prefix strip
408 # recovers a real DOM member name.
409 to_exclude: set[str] = set()
410 for name in list(counts.keys()):
411 if name in jso_bridge_dispatch_ids:
412 to_exclude.add(name)
413 continue
414 for cls in jso_bridge_classes:
415 if name.startswith("cn1_" + cls + "_") or name.startswith("cn1_" + cls + "__"):
416 to_exclude.add(name)
417 break
418 if name in jso_bridge_classes:
419 to_exclude.add(name)
420 for name in to_exclude:
421 counts.pop(name, None)
422
423 preserved = frozenset(to_exclude | set(EXCLUDE) | jso_bridge_classes | jso_bridge_dispatch_ids)
424 return counts, preserved
425
426
427_IMPL_SUFFIX = "__impl"

Callers 1

mainFunction · 0.85

Calls 7

CounterClass · 0.85
groupMethod · 0.65
popMethod · 0.65
keysMethod · 0.65
addMethod · 0.65

Tested by

no test coverage detected