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

Method extract_name

codegraph-kernel/src/dart.rs:760–814  ·  view source on GitHub ↗

extractName (tree-sitter.ts:90-192) — resolveName (ctor names) → name field → the method_signature inner unwrap → identifier-ish child → ` ` (operators land here).

(&self, node: Node<'t>)

Source from the content-addressed store, hash-verified

758 /// name field → the method_signature inner unwrap → identifier-ish
759 /// child → `<anonymous>` (operators land here).
760 fn extract_name(&self, node: Node<'t>) -> String {
761 // resolveName hook (dart.ts): a typedef has no `name` field, and a
762 // legacy one writes its return type before its name (`typedef Report
763 // LegacyMaker(int n);`).
764 if node.kind() == "type_alias" {
765 if let Some(name) = type_alias_name(node) {
766 return self.text(name).to_string();
767 }
768 }
769 // resolveName hook (dart.ts:244-260): named ctor/factory → ctor name.
770 if let Some((class_name, ctor_name)) = self.ctor_info(node) {
771 if ctor_name != class_name {
772 return ctor_name;
773 }
774 }
775 // `class A = B with C;` — the mixin application's own identifier.
776 if node.kind() == "class_definition" {
777 let mut cursor = node.walk();
778 let application = node.named_children(&mut cursor).find(|c| c.kind() == "mixin_application_class");
779 if let Some(application) = application {
780 let mut ac = application.walk();
781 let id = application.named_children(&mut ac).find(|c| c.kind() == "identifier");
782 if let Some(id) = id {
783 return self.text(id).to_string();
784 }
785 }
786 }
787 if let Some(name_node) = node.child_by_field_name("name") {
788 return self.text(name_node).to_string();
789 }
790 if node.kind() == "method_signature" {
791 let mut cursor = node.walk();
792 let inner = node.named_children(&mut cursor).find(|c| {
793 matches!(
794 c.kind(),
795 "function_signature" | "getter_signature" | "setter_signature"
796 | "constructor_signature" | "factory_constructor_signature"
797 )
798 });
799 if let Some(inner) = inner {
800 let mut ic = inner.walk();
801 let id = inner.named_children(&mut ic).find(|c| c.kind() == "identifier");
802 if let Some(id) = id {
803 return self.text(id).to_string();
804 }
805 }
806 }
807 let mut cursor = node.walk();
808 for c in node.named_children(&mut cursor) {
809 if matches!(c.kind(), "identifier" | "type_identifier" | "simple_identifier" | "constant") {
810 return self.text(c).to_string();
811 }
812 }
813 "<anonymous>".to_string()
814 }
815
816 // --- the main walk (visitNode, tree-sitter.ts:936-1303) ---------------
817

Callers 5

extract_functionMethod · 0.45
extract_methodMethod · 0.45
extract_classMethod · 0.45
extract_enumMethod · 0.45
extract_type_aliasMethod · 0.45

Calls 4

type_alias_nameFunction · 0.85
ctor_infoMethod · 0.80
textMethod · 0.65
walkMethod · 0.45

Tested by

no test coverage detected