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

Method cpp_written_class_parts

codegraph-kernel/src/ccpp/mod.rs:721–750  ·  view source on GitHub ↗

cppWrittenClassParts (languages/c-cpp.ts): the `::` segments of a class, struct or union name written with a scope, the scope's template arguments dropped (`["SkipList", "Node"]` for `struct SkipList ::Node`). None for a plain name and for a specialization, whose innermost name has template arguments.

(&self, node: Node)

Source from the content-addressed store, hash-verified

719 /// Comparator>::Node`). None for a plain name and for a specialization,
720 /// whose innermost name has template arguments.
721 fn cpp_written_class_parts(&self, node: Node) -> Option<Vec<String>> {
722 if !matches!(node.kind(), "class_specifier" | "struct_specifier" | "union_specifier") {
723 return None;
724 }
725 let written = node.child_by_field_name("name")?;
726 if written.kind() != "qualified_identifier" {
727 return None;
728 }
729 let mut innermost = Some(written);
730 while let Some(n) = innermost.filter(|n| n.kind() == "qualified_identifier") {
731 innermost = n.child_by_field_name("name");
732 }
733 if innermost.map(|n| n.kind()) != Some("type_identifier") {
734 return None;
735 }
736 let parts: Vec<String> = strip_cpp_template_args(self.text(written))
737 .split("::")
738 .map(|p| p.trim().to_string())
739 .filter(|p| !p.is_empty())
740 .collect();
741 let identifier = |p: &String| {
742 let mut chars = p.chars();
743 chars.next().is_some_and(|c| c.is_ascii_alphabetic() || c == '_')
744 && chars.all(|c| c.is_ascii_alphanumeric() || c == '_')
745 };
746 if parts.is_empty() || !parts.iter().all(identifier) {
747 return None;
748 }
749 Some(parts)
750 }
751
752 /// writtenScopeQualifiedName (tree-sitter.ts): a class whose name is
753 /// written in a scope is qualified like an out-of-line method under it.

Callers 2

extract_name_rawMethod · 0.80

Calls 6

strip_cpp_template_argsFunction · 0.85
mapMethod · 0.80
nextMethod · 0.80
textMethod · 0.65
allMethod · 0.65
collectMethod · 0.45

Tested by

no test coverage detected