MCPcopy Create free account
hub / github.com/Graphify-Labs/graphify / _pascal_resolve_class

Function _pascal_resolve_class

graphify/extract.py:13029–13054  ·  view source on GitHub ↗

Resolve a Pascal class/interface name to the node ID of its defining file's class node. Pascal convention: TFooBar is defined in FooBar.pas, IFooBar in FooBar.pas. Strips the leading T/I prefix, finds the file, and returns _make_id(_file_stem(found_file), class_name). Returns None

(from_path: Path, class_name: str)

Source from the content-addressed store, hash-verified

13027
13028
13029def _pascal_resolve_class(from_path: Path, class_name: str) -> str | None:
13030 """Resolve a Pascal class/interface name to the node ID of its defining file's class node.
13031
13032 Pascal convention: TFooBar is defined in FooBar.pas, IFooBar in FooBar.pas.
13033 Strips the leading T/I prefix, finds the file, and returns
13034 _make_id(_file_stem(found_file), class_name).
13035
13036 Returns None when no matching file is found on disk (RTL, stdlib, or
13037 unconventionally-named class — caller should create a stub node).
13038 """
13039 prefix = class_name[:1]
13040 unit_name = class_name[1:] if prefix in ("T", "I") else class_name
13041
13042 root = _pascal_project_root(from_path)
13043 root_key = str(root)
13044 if root_key not in _pascal_class_stem_cache:
13045 stem_map: dict[str, str] = {}
13046 for ext in (".pas", ".pp", ".dpr", ".dpk"):
13047 for f in root.rglob("*" + ext):
13048 stem_map[f.stem.lower()] = _file_stem(f)
13049 _pascal_class_stem_cache[root_key] = stem_map
13050
13051 file_stem = _pascal_class_stem_cache[root_key].get(unit_name.lower())
13052 if file_stem:
13053 return _make_id(file_stem, class_name)
13054 return None
13055
13056
13057_PAS_TOKEN_RE = re.compile(

Callers 2

_extract_pascal_regexFunction · 0.85
walkFunction · 0.85

Calls 4

_file_stemFunction · 0.90
_make_idFunction · 0.90
_pascal_project_rootFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected