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

Function scalaBaseTypeName

src/extraction/tree-sitter.ts:201–224  ·  view source on GitHub ↗

* Resolve a Scala type node to its base type NAME for name-matching — unwrapping * `generic_type` (`Monoid[Int]` → `Monoid`), taking the last segment of a * qualified `stable_type_identifier` (`cats.Functor` → `Functor`), and falling * back to a descendant `type_identifier`. Returns null for non-

(node: SyntaxNode | null, source: string)

Source from the content-addressed store, hash-verified

199 * Shared by Scala inheritance and type-reference extraction.
200 */
201function scalaBaseTypeName(node: SyntaxNode | null, source: string): string | null {
202 if (!node) return null;
203 switch (node.type) {
204 case 'type_identifier':
205 case 'identifier':
206 return getNodeText(node, source);
207 case 'generic_type':
208 // `<base> type_arguments` — the base type is the first named child.
209 return scalaBaseTypeName(node.namedChild(0), source);
210 case 'stable_type_identifier':
211 case 'stable_identifier': {
212 // Qualified `a.b.C` — match on the simple (last) segment.
213 const ids = node.namedChildren.filter(
214 (c: SyntaxNode) => c.type === 'type_identifier' || c.type === 'identifier'
215 );
216 const last = ids[ids.length - 1];
217 return last ? getNodeText(last, source) : null;
218 }
219 default: {
220 const id = node.namedChildren.find((c: SyntaxNode) => c.type === 'type_identifier');
221 return id ? getNodeText(id, source) : null;
222 }
223 }
224}
225
226/**
227 * Resolve the declared identifier inside a C declarator. A `declaration`'s

Callers 2

extractInstantiationMethod · 0.85
extractInheritanceMethod · 0.85

Calls 1

getNodeTextFunction · 0.90

Tested by

no test coverage detected