#![allow(clippy::wildcard_imports, clippy::enum_glob_use)]
#![allow(
clippy::cast_precision_loss,
clippy::cast_possible_truncation,
clippy::cast_sign_loss
)]
use super::*;
impl Npa for GoCode {
fn compute<'a>(node: &Node<'a>, code: &'a [u8], 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 mut names = declaration
.children()
.filter(|c| matches!(c.kind_id().into(), G::FieldIdentifier))
.peekable();
if names.peek().is_some() {
for name in names {
total += 1;
if name.utf8_text(code).is_some_and(go_is_exported) {
public += 1;
}
}
} else if let Some(name) = go_embedded_field_name(&declaration) {
total += 1;
if name.utf8_text(code).is_some_and(go_is_exported) {
public += 1;
}
}
}
if total == 0 {
return;
}
if stats.is_disabled() {
stats.is_class_space = true;
}
stats.class_na += total;
stats.class_npa += public;
}
}