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

Method extractClass

src/extraction/tree-sitter.ts:2849–2916  ·  view source on GitHub ↗
(node: SyntaxNode, kind: NodeKind = 'class')

Source from the content-addressed store, hash-verified

2847 }
2848
2849 private extractClass(node: SyntaxNode, kind: NodeKind = 'class'): void {
2850 if (!this.extractor) return;
2851
2852 // Skip forward declarations / elaborated type references (`class Foo;`) in
2853 // languages that opt in — bodiless there means "not a definition", so it
2854 // would otherwise mint a phantom node competing with the real definition
2855 // (#1093). Languages where a bodiless class is complete (Kotlin, Scala)
2856 // leave the flag unset. Resolved once here and reused for the body walk.
2857 const resolvedBody = this.extractor.resolveBody?.(node, this.extractor.bodyField)
2858 ?? getChildByField(node, this.extractor.bodyField);
2859 if (this.extractor.skipBodilessClass && !resolvedBody) return;
2860
2861 const name = extractName(node, this.source, this.extractor);
2862 const docstring = this.docstringFor(node);
2863 const visibility = this.extractor.getVisibility?.(node);
2864 // A class expression's name is bound inside the expression alone, so the
2865 // class is never what a module exports by it, and it carries its head
2866 // (`class Widget extends Base`) as its signature: a class declaration
2867 // has none, which is how resolution tells the two apart (#2499).
2868 const expression = node.type === 'class' && CLASS_EXPRESSION_LANGUAGES.has(this.language);
2869 const isExported = expression ? false : this.extractor.isExported?.(node, this.source);
2870 const scoped = this.writtenScopeQualifiedName(node, name);
2871
2872 const classNode = this.createNode(kind, name, node, {
2873 docstring,
2874 visibility,
2875 isExported,
2876 ...(expression && resolvedBody ? { signature: classExpressionHead(this.source, node, resolvedBody) } : {}),
2877 ...this.cppBodyEnd(resolvedBody),
2878 ...(scoped !== undefined ? { qualifiedName: scoped } : {}),
2879 });
2880 if (!classNode) return;
2881 if (scoped !== undefined) this.objectPathOwners.set(classNode.id, scoped);
2882 this.openCppClassScope(classNode, resolvedBody);
2883
2884 // Extract extends/implements
2885 this.extractInheritance(node, classNode.id);
2886 this.extractCMemberTypeRefs(node, classNode);
2887
2888 // C# primary-constructor parameter dependencies (`class Svc(IRepo r, …)`).
2889 this.extractCsharpPrimaryCtorParamRefs(node, classNode.id);
2890 this.extractDartPrimaryCtorRefs(node, classNode.id);
2891
2892 // Extract decorators applied to the class (`@Foo class X {}`).
2893 this.extractDecoratorsFor(node, classNode.id);
2894
2895 // Push to stack and visit body
2896 this.nodeStack.push(classNode.id);
2897 this.extractDartNamedPrimaryCtor(node, classNode.name);
2898 const body = resolvedBody ?? node;
2899
2900 // Visit all children for methods and properties
2901 for (let i = 0; i < body.namedChildCount; i++) {
2902 const child = body.namedChild(i);
2903 if (child) {
2904 this.visitNode(child);
2905 }
2906 }

Callers 2

dispatchNodeMethod · 0.95

Calls 15

docstringForMethod · 0.95
createNodeMethod · 0.95
cppBodyEndMethod · 0.95
openCppClassScopeMethod · 0.95
extractInheritanceMethod · 0.95
extractDecoratorsForMethod · 0.95
visitNodeMethod · 0.95

Tested by

no test coverage detected