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

Method ctor_callee

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

dartCtorCallee (dart.ts) — the type a misparsed generic constructor call names, from the `<` that opens its type arguments inside `rel`: `X` in `X `, or `p.X` with its import prefix. The callee is all of `rel` before the `<`, under an `await` or a prefix operator too, and the `<` is written against it.

(&self, rel: Node<'t>, lt: Node<'t>)

Source from the content-addressed store, hash-verified

1717 /// `rel` before the `<`, under an `await` or a prefix operator too, and
1718 /// the `<` is written against it.
1719 fn ctor_callee(&self, rel: Node<'t>, lt: Node<'t>) -> Option<(Node<'t>, Node<'t>)> {
1720 let before = lt.prev_named_sibling()?;
1721 if before.end_byte() != lt.start_byte() {
1722 return None;
1723 }
1724 // `await Future<void>.delayed(d)` and `await p.Box<int>.named(…)` put
1725 // the callee under the `await`.
1726 let mut last = before;
1727 if is_prefixed(before.kind()) {
1728 if rel.named_child(0)? != before {
1729 return None;
1730 }
1731 while is_prefixed(last.kind()) {
1732 last = last.named_child(last.named_child_count().checked_sub(1)?)?;
1733 }
1734 }
1735 let (head, type_name) = if last.kind() == "selector" {
1736 // `p.X<T>.named(…)`: the import prefix, then the type.
1737 let accessor = last.named_child(0)?;
1738 if last.named_child_count() != 1 || accessor.kind() != "unconditional_assignable_selector" {
1739 return None;
1740 }
1741 let mut ac = accessor.walk();
1742 let type_name = accessor.named_children(&mut ac).find(|c| c.kind() == "identifier")?;
1743 (last.prev_named_sibling()?, type_name)
1744 } else {
1745 (last, last)
1746 };
1747 if head.kind() != "identifier" {
1748 return None;
1749 }
1750 // Written as it is, the callee is all of `rel` before the `<`.
1751 if last == before && rel.named_child(0)? != head {
1752 return None;
1753 }
1754 if !is_upper_camel(self.text(type_name)) {
1755 return None;
1756 }
1757 Some((head, type_name))
1758 }
1759
1760 /// dartCtorTypeArgsStart (dart.ts) — the `<` of a relational expression
1761 /// that opens a misparsed call's type arguments: its only operator.

Callers 2

misparsed_ctorMethod · 0.80
misparsed_ctor_inMethod · 0.80

Calls 4

is_prefixedFunction · 0.85
is_upper_camelFunction · 0.85
textMethod · 0.65
walkMethod · 0.45

Tested by

no test coverage detected