fn add_method(&mut self, method: &syn::ImplItemMethod, file: PathBuf) {
        let syn::ImplItemMethod {
            vis, attrs, sig, ..
        } = method;

        // not public
        if !matches!(vis, syn::Visibility::Public(_)) {
            return;
        }
        // not exported nor a constructor
        if !(attributes_contains(attrs, "export") || sig.ident == "new") {
            return;
        }

        let has_self = sig.receiver().is_some();
        let syn::Signature {
            ident: method_name,
            inputs,
            output,
            ..
        } = sig;

        let mut parameters = inputs.into_iter();
        if has_self {
            parameters.next();
        }
        parameters.next(); // inherit argument
        let parameters = {
            let mut params = Vec::new();
            for arg in parameters {
                if let syn::FnArg::Typed(syn::PatType { attrs, pat, ty, .. }) = arg {
                    let arg_name = {
                        if let syn::Pat::Ident(syn::PatIdent { ident, .. }) = pat.as_ref() {
                            ident.to_string()
                        } else {
                            String::new()
                        }
                    };

                    params.push((
                        arg_name,
                        get_type_name(*ty.clone())
                            .unwrap_or_else(|| Type::Named("{ERROR}".to_string())),
                        if attributes_contains(&attrs, "opt") {
                            ParameterAttribute::Opt
                        } else {
                            ParameterAttribute::None
                        },
                    ))
                }
            }
            params
        };

        let return_type = match output {
            syn::ReturnType::Default => Type::Unit,
            syn::ReturnType::Type(_, typ) => get_type_name(*typ.clone()).unwrap_or(Type::Unit),
        };
        log::trace!(
            "added method {}: parameters = {:?}, return = {:?}",
            method_name,
            parameters,
            return_type
        );
        self.methods.push(Method {
            has_self,
            name: method_name.to_string(),
            self_type: self.name.clone(),
            parameters,
            return_type,
            documentation: get_docs(&attrs),
            file,
        })
    }
/// Check that the method is exported, parse it, and add it to the class.
Check that the method is exported, parse it, and add it to the class.
Check that the method is exported parse it and add it to the class .
fn add_method(&mut self, method: &syn::ImplItemMethod, file: PathBuf) {
        let syn::ImplItemMethod {
            vis, attrs, sig, ..
        } = method;
        // not public
        if !matches!(vis, syn::Visibility::Public(_)) {
            return;
        }
        // not exported nor a constructor
        if !(attributes_contains(attrs, "export") || sig.ident == "new") {
            return;
        }
        let has_self = sig.receiver().is_some();
        let syn::Signature {
            ident: method_name,
            inputs,
            output,
            ..
        } = sig;
        let mut parameters = inputs.into_iter();
        if has_self {
            parameters.next();
        }
        parameters.next(); // inherit argument
        let parameters = {
            let mut params = Vec::new();
            for arg in parameters {
                if let syn::FnArg::Typed(syn::PatType { attrs, pat, ty, .. }) = arg {
                    let arg_name = {
                        if let syn::Pat::Ident(syn::PatIdent { ident, .. }) = pat.as_ref() {
                            ident.to_string()
                        } else {
                            String::new()
                        }
                    };
                    params.push((
                        arg_name,
                        get_type_name(*ty.clone())
                            .unwrap_or_else(|| Type::Named("{ERROR}".to_string())),
                        if attributes_contains(&attrs, "opt") {
                            ParameterAttribute::Opt
                        } else {
                            ParameterAttribute::None
                        },
                    ))
                }
            }
            params
        };
        let return_type = match output {
            syn::ReturnType::Default => Type::Unit,
            syn::ReturnType::Type(_, typ) => get_type_name(*typ.clone()).unwrap_or(Type::Unit),
        };
        log::trace!(
            "added method {}: parameters = {:?}, return = {:?}",
            method_name,
            parameters,
            return_type
        );
        self.methods.push(Method {
            has_self,
            name: method_name.to_string(),
            self_type: self.name.clone(),
            parameters,
            return_type,
            documentation: get_docs(&attrs),
            file,
        })
    }
fn add_method ( & mut self , method : & syn :: ImplItemMethod , file : PathBuf ) { let syn :: ImplItemMethod { vis , attrs , sig , .. } = method ; // not public if ! matches ! ( vis syn Visibility Public ( ) ) { return ; } // not exported nor a constructor if ! ( attributes_contains ( attrs , " " ) || sig . ident == " " ) { return ; } let has_self = sig . receiver ( ) . is_some ( ) ; let syn :: Signature { ident : method_name , inputs , output , .. } = sig ; let mut parameters = inputs . into_iter ( ) ; if has_self { parameters . next ( ) ; } parameters . next ( ) ; // inherit argument let parameters = { let mut params = Vec :: new ( ) ; for arg in parameters { if let syn :: FnArg :: Typed ( syn :: PatType { attrs , pat , ty , .. } ) = arg { let arg_name = { if let syn :: Pat :: Ident ( syn :: PatIdent { ident , .. } ) = pat . as_ref ( ) { ident . to_string ( ) } else { String :: new ( ) } } ; params . push ( ( arg_name , get_type_name ( * ty . clone ( ) ) . unwrap_or_else ( | | Type :: Named ( " " . to_string ( ) ) ) , if attributes_contains ( & attrs , " " ) { ParameterAttribute :: Opt } else { ParameterAttribute :: None } , ) ) } } params } ; let return_type = match output { syn :: ReturnType :: Default => Type :: Unit , syn :: ReturnType :: Type ( _ , typ ) => get_type_name ( * typ . clone ( ) ) . unwrap_or ( Type :: Unit ) , } ; log :: trace ! ( " " method_name parameters return_type ) ; self . methods . push ( Method { has_self , name : method_name . to_string ( ) , self_type : self . name . clone ( ) , parameters , return_type , documentation : get_docs ( & attrs ) , file , } ) }
Check that the method is exported, parse it, and add it to the class.
Check that the method is exported parse it and add it to the class .
&mut self
method
&syn::ImplItemMethod
file
PathBuf
&mut self
method
&syn::ImplItemMethod
file
PathBuf