#![allow(clippy::wildcard_imports, clippy::enum_glob_use)]
#![allow(
clippy::cast_precision_loss,
clippy::cast_possible_truncation,
clippy::cast_sign_loss
)]
use super::*;
fn go_count_declaration_names(declaration: &Node, code: &[u8]) -> (usize, usize) {
use Go as G;
let mut names = declaration
.children()
.filter(|c| matches!(c.kind_id().into(), G::FieldIdentifier))
.peekable();
if names.peek().is_none() {
let Some(name) = go_embedded_field_name(declaration) else {
return (0, 0);
};
return (
1,
usize::from(name.utf8_text(code).is_some_and(go_is_exported)),
);
}
let mut declared = 0usize;
let mut exported = 0usize;
for name in names {
declared += 1;
if name.utf8_text(code).is_some_and(go_is_exported) {
exported += 1;
}
}
(declared, exported)
}
impl Npa for GoCode {
fn compute<'a>(
node: &Node<'a>,
code: &'a [u8],
_ancestors: Ancestors<'a, '_>,
stats: &mut Stats,
) {
use Go as G;
if !matches!(node.kind_id().into(), G::StructType) {
return;
}
let Some(body) = node
.children()
.find(|c| matches!(c.kind_id().into(), G::FieldDeclarationList))
else {
return;
};
let mut total = 0usize;
let mut public = 0usize;
for declaration in body
.children()
.filter(|c| matches!(c.kind_id().into(), G::FieldDeclaration))
{
let (declared, exported) = go_count_declaration_names(&declaration, code);
total += declared;
public += exported;
}
stats.class_na += total;
stats.class_npa += public;
}
}