fn compute()

in src/metrics/npm.rs [207:246]


    fn compute(node: &Node, stats: &mut Stats) {
        use Java::*;

        // Enables the `Npm` metric if computing stats of a class space
        if Self::is_func_space(node) && stats.is_disabled() {
            stats.is_class_space = true;
        }

        match node.kind_id().into() {
            ClassBody => {
                stats.class_nm += node
                    .children()
                    .filter(|node| Self::is_func(node))
                    .map(|method| {
                        // The first child node contains the list of method modifiers
                        // There are several modifiers that may be part of a method declaration
                        // Source: https://docs.oracle.com/javase/tutorial/reflect/member/methodModifiers.html
                        if let Some(modifiers) = method.child(0) {
                            // Looks for the `public` keyword in the list of method modifiers
                            if matches!(modifiers.kind_id().into(), Modifiers)
                                && modifiers.first_child(|id| id == Public).is_some()
                            {
                                stats.class_npm += 1;
                            }
                        }
                    })
                    .count();
            }
            // All methods in an interface are implicitly public
            // Source: https://docs.oracle.com/javase/tutorial/java/IandI/interfaceDef.html
            InterfaceBody => {
                // Children nodes are filtered because Java interfaces
                // can contain methods but also constants and nested types
                // Source: https://docs.oracle.com/javase/tutorial/java/IandI/createinterface.html
                stats.interface_nm += node.children().filter(|node| Self::is_func(node)).count();
                stats.interface_npm = stats.interface_nm;
            }
            _ => {}
        }
    }