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

Function _resolve_java_member_calls

graphify/extract.py:8978–9383  ·  view source on GitHub ↗

Resolve Java member calls against the receiver's declared type. Explicit type receivers, ``this`` and ``super`` are exact. Fields declared on the caller's class plus method parameters and explicit locals are inferred from the extractor's method-scoped type table. A missing or ambiguous

(
    per_file: list[dict],
    all_nodes: list[dict],
    all_edges: list[dict],
)

Source from the content-addressed store, hash-verified

8976
8977
8978def _resolve_java_member_calls(
8979 per_file: list[dict],
8980 all_nodes: list[dict],
8981 all_edges: list[dict],
8982) -> None:
8983 """Resolve Java member calls against the receiver's declared type.
8984
8985 Explicit type receivers, ``this`` and ``super`` are exact. Fields declared on the
8986 caller's class plus method parameters and explicit locals are inferred from
8987 the extractor's method-scoped type table. A missing or ambiguous receiver
8988 type is skipped rather than falling back to a bare method-name match.
8989
8990 A bare `m()` or `field.m()` the caller's file could not bind names a member
8991 the class inherits from a supertype in another file: the nearest supertype
8992 declaring it is the target, and a tie on one level binds nothing.
8993
8994 A receiver that is itself a call (`builder().size(3).build()`), a `new T()`
8995 or a cast is typed step by step from the declared return types the
8996 extractor put on method nodes (`_java_ret`). A class-qualified static
8997 field (`Service.INSTANCE.get()`, and `Service.INSTANCE.other().m()`) is
8998 the same walk: the field's declared type on that class, including one
8999 inherited from a superclass, types the next step. A local, parameter, or
9000 field that shadows the class name is not that class. An instance field
9001 accessed as `Type.field` is not.
9002 """
9003 def key(label: str) -> str:
9004 return str(label).strip().removeprefix(".").removesuffix("()")
9005
9006 contained = {edge.get("target") for edge in all_edges
9007 if edge.get("relation") == "contains"}
9008 node_by_id = {node.get("id"): node for node in all_nodes}
9009
9010 type_def_nids: dict[str, list[str]] = {}
9011 for node in all_nodes:
9012 if (
9013 node.get("source_file")
9014 and node.get("id") in contained
9015 and _is_type_like_definition(node)
9016 ):
9017 type_def_nids.setdefault(key(node.get("label", "")), []).append(node["id"])
9018
9019 method_index: dict[tuple[str, str], set[str]] = {}
9020 enclosing_type: dict[str, str] = {}
9021 for edge in all_edges:
9022 if edge.get("relation") != "method":
9023 continue
9024 owner, method = edge.get("source"), edge.get("target")
9025 method_node = node_by_id.get(method)
9026 if method_node is None:
9027 continue
9028 enclosing_type.setdefault(method, owner)
9029 method_index.setdefault((owner, key(method_node.get("label", ""))), set()).add(method)
9030
9031 def _one(hits: set[str] | list[str], argc: object) -> str | None:
9032 """The single method ``hits`` name, else None. Several overloads of one
9033 class are one method when the call's argument count fits exactly one
9034 (#5251); two that both fit, or overloads in different classes, stay
9035 ambiguous, as the same-name rule has always treated them."""

Callers

nothing calls this directly

Calls 13

_is_type_like_definitionFunction · 0.90
_chain_typeFunction · 0.85
_method_on_type_or_basesFunction · 0.85
_jvm_basesFunction · 0.85
_inherited_field_typeFunction · 0.85
_type_namedFunction · 0.85
keyFunction · 0.70
_inherited_methodFunction · 0.70
_emitFunction · 0.70
getMethod · 0.45

Tested by

no test coverage detected