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

Method ctor_info

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

dartCtorInfo (dart.ts:61-70).

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

Source from the content-addressed store, hash-verified

544
545 /// dartCtorInfo (dart.ts:61-70).
546 fn ctor_info(&self, node: Node<'t>) -> Option<(String, String)> {
547 let ctor = self.constructor_signature(node)?;
548 // The names before the parameters: a redirecting factory names its
549 // target after them (`factory Foo() = _Impl.named;`).
550 let mut cursor = ctor.walk();
551 let ids: Vec<Node<'t>> = ctor
552 .named_children(&mut cursor)
553 .take_while(|c| c.kind() != "formal_parameter_list")
554 .filter(|c| c.kind() == "identifier")
555 .collect();
556 let class_name = self.enclosing_type_name(node)?;
557 // Dart 3.13's concise constructors leave the class out: `new()`,
558 // `new named()`, `const new()`, `factory()` and `factory make()`
559 // declare what `Foo()`, `Foo.named()`, `const Foo()`, `factory Foo()`
560 // and `factory Foo.make()` do (#3270).
561 let factory = matches!(
562 ctor.kind(),
563 "factory_constructor_signature" | "redirecting_factory_constructor_signature"
564 );
565 let concise = if factory {
566 ids.first().map(|n| self.text(*n)) != Some(class_name)
567 } else {
568 let mut nc = ctor.walk();
569 let has_new = ctor.children(&mut nc).any(|c| c.kind() == "new");
570 has_new
571 };
572 if concise {
573 let ctor_name = ids.first().map(|n| self.text(*n)).unwrap_or(class_name);
574 return Some((class_name.to_string(), ctor_name.to_string()));
575 }
576 let first = ids.first()?;
577 if self.text(*first) != class_name {
578 return None; // misparsed method, not a ctor
579 }
580 let ctor_name = ids.get(1).map(|n| self.text(*n)).unwrap_or(class_name);
581 Some((class_name.to_string(), ctor_name.to_string()))
582 }
583
584 /// extractDartReturnType (dart.ts:80-92).
585 fn return_type_of(&self, node: Node<'t>) -> Option<String> {

Callers 3

return_type_ofMethod · 0.80
is_misparsed_functionMethod · 0.80
extract_nameMethod · 0.80

Calls 9

walkMethod · 0.80
enclosing_type_nameMethod · 0.80
mapMethod · 0.80
childrenMethod · 0.80
textMethod · 0.65
getMethod · 0.65
constructor_signatureMethod · 0.45
collectMethod · 0.45
firstMethod · 0.45

Tested by

no test coverage detected