MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / resolve

Function resolve

src/resolution/frameworks/play.ts:52–93  ·  view source on GitHub ↗
(ref: UnresolvedRef, context: ResolutionContext)

Source from the content-addressed store, hash-verified

50 },
51
52 resolve(ref: UnresolvedRef, context: ResolutionContext): ResolvedRef | null {
53 const m = ref.referenceName.match(/^([A-Za-z_]\w*)\.([A-Za-z_]\w*)$/);
54 if (!m) return null;
55 const [, className, methodName] = m;
56 const route = isPlayRoutesFile(ref.filePath);
57 // `import org.apache.logging.log4j.core.config.Configurator` makes a Java
58 // file's `Configurator` that library's, never a project type of the name.
59 if (!route && ref.language === 'java' && isJavaOutsideImport(className!, ref, context)) return null;
60 // A call's own language comes first: Play's `RequestAuthority` is both a
61 // Scala case class and a Java record, and each language's callers mean
62 // their own; the other language's types follow, since Play's Java API
63 // calls its Scala classes. A route file has no language of its own.
64 const kinds = route ? CONTROLLER_KINDS : OWNER_KINDS;
65 const owners = context.getNodesByName(className!).filter((n) => kinds.has(n.kind));
66 const groups = route
67 ? [owners]
68 : [owners.filter((n) => n.language === ref.language), owners.filter((n) => n.language !== ref.language)];
69 for (const group of groups) {
70 // Only a member of THAT type counts: a file can hold many classes (Java
71 // nested classes, a Scala class + its companion + siblings), and the
72 // first same-named method in the file is usually another class's. A
73 // Scala object, a companion included, holds its own members.
74 const members = new Map<string, Node>();
75 for (const cls of group) {
76 const memberQn = `${cls.qualifiedName}::${methodName}`;
77 for (const n of context.getNodesInFile(cls.filePath)) {
78 if (METHOD_KINDS.has(n.kind) && n.name === methodName && n.qualifiedName === memberQn) members.set(n.id, n);
79 }
80 }
81 if (members.size === 0) continue;
82 const found = [...members.values()];
83 // Same-named types in several packages (Scala names carry no package):
84 // the one in the caller's own file comes first.
85 const pick = (!route && found.find((n) => n.filePath === ref.filePath)) || found[0]!;
86 const result: ResolvedRef = { original: ref, targetNodeId: pick.id, confidence: 0.9, resolvedBy: 'framework' };
87 // Overloads: the one the call's arguments fit, as the generic resolver picks it.
88 return route ? result : retargetSelfOverload(result, ref, context);
89 }
90 // An inherited member isn't looked up here: the generic resolver finds it
91 // through the class's declared supertypes.
92 return null;
93 },
94
95 extract(filePath: string, content: string): { nodes: Node[]; references: UnresolvedRef[] } {
96 if (!isPlayRoutesFile(filePath)) return { nodes: [], references: [] };

Callers

nothing calls this directly

Calls 5

isPlayRoutesFileFunction · 0.90
hasMethod · 0.80
getNodesByNameMethod · 0.65
getNodesInFileMethod · 0.65
setMethod · 0.45

Tested by

no test coverage detected