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

Method extract_name

codegraph-kernel/src/dart.rs:764–818  ·  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

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

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
walkMethod · 0.80
textMethod · 0.65

Tested by

no test coverage detected