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

Function kotlinClassHeaderCode

src/extraction/languages/kotlin.ts:173–193  ·  view source on GitHub ↗

* The code a class, object or enum header holds, in source order: each * constructor parameter's default value (`c: Clock = SystemClock()`), the * arguments of the superclass constructor it calls (`: Base(load())`), and the * expression after `by` it delegates an interface to (`I by Impl()`). The

(node: SyntaxNode)

Source from the content-addressed store, hash-verified

171 * and annotations around it are left alone, as they are for a property.
172 */
173function kotlinClassHeaderCode(node: SyntaxNode): SyntaxNode[] {
174 const out: SyntaxNode[] = [];
175 for (const child of node.namedChildren) {
176 if (child?.type === 'primary_constructor') {
177 for (const param of child.namedChildren) {
178 const value = param?.type === 'class_parameter' ? namedChildAfter(param, '=') : null;
179 if (value) out.push(value);
180 }
181 } else if (child?.type === 'delegation_specifier') {
182 const spec = child.namedChild(0);
183 if (spec?.type === 'constructor_invocation') {
184 const args = spec.namedChildren.find((c) => c.type === 'value_arguments');
185 if (args) out.push(args);
186 } else if (spec?.type === 'explicit_delegation') {
187 const delegate = namedChildAfter(spec, 'by');
188 if (delegate) out.push(delegate);
189 }
190 }
191 }
192 return out;
193}
194
195/** Check if a node matches the `fun interface` misparse pattern */
196function isFunInterfaceNode(node: SyntaxNode): boolean {

Callers

nothing calls this directly

Calls 2

namedChildAfterFunction · 0.85
pushMethod · 0.80

Tested by

no test coverage detected