From 0f87b9759cbec2fb3b720ee45ea41ddbe4e36d2d Mon Sep 17 00:00:00 2001 From: Joao Duarte Date: Tue, 12 Mar 2024 20:05:50 -0300 Subject: [PATCH] chore: fix clippy issues --- .../src/java/method_declaration.rs | 181 +++++++++--------- 1 file changed, 90 insertions(+), 91 deletions(-) diff --git a/matching_handlers/src/java/method_declaration.rs b/matching_handlers/src/java/method_declaration.rs index 7d1a176..3f8097d 100644 --- a/matching_handlers/src/java/method_declaration.rs +++ b/matching_handlers/src/java/method_declaration.rs @@ -48,18 +48,15 @@ fn extract_argument_types_from_formal_parameters(node: &CSTNode) -> Vec .filter(|inner_node| inner_node.kind() == "formal_parameter") .filter_map(|inner_node| match inner_node { CSTNode::Terminal(_) => None, - CSTNode::NonTerminal(non_terminal) => { - let all_children_that_are_not_an_identifier = non_terminal + CSTNode::NonTerminal(non_terminal) => Some( + non_terminal .children .iter() - .filter(|node| node.kind() != "identifier"); - - return Some( - all_children_that_are_not_an_identifier.fold(String::new(), |acc, cur| { + .filter(|node| node.kind() != "identifier") + .fold(String::new(), |acc, cur| { format!("{} {}", acc, cur.contents()) }), - ); - } + ), }) .collect(), } @@ -69,13 +66,10 @@ fn extract_argument_types_from_formal_parameters(node: &CSTNode) -> Vec mod tests { use model::{ cst_node::{NonTerminal, Terminal}, - CSTNode, Language, Point, + CSTNode, }; - use parsing::parse_string; - use std::error::Error; use crate::java::method_declaration::compute_matching_score_for_method_declaration; - use crate::java::utils::find_child_of_kind; #[test] fn it_returns_one_if_methods_have_the_same_identifier() { @@ -126,89 +120,94 @@ mod tests { #[test] fn for_matching_formal_parameters_it_takes_into_consideration_all_children_except_identifier() { - let node_a =make_method_declaration_node("ASTNodeArtifact", CSTNode::NonTerminal(NonTerminal { - kind: "formal_parameter", - children: vec![ - CSTNode::NonTerminal(NonTerminal { - kind: "modifiers", - children: vec![CSTNode::Terminal(Terminal { - kind: "final", - value: "final", - ..Default::default() - })], - ..Default::default() - }), - CSTNode::NonTerminal(NonTerminal { - kind: "generic_type", - children: vec![ - CSTNode::Terminal(Terminal { - kind: "type_identifier", - value: "ASTNode", + let node_a = make_method_declaration_node( + "ASTNodeArtifact", + CSTNode::NonTerminal(NonTerminal { + kind: "formal_parameter", + children: vec![ + CSTNode::NonTerminal(NonTerminal { + kind: "modifiers", + children: vec![CSTNode::Terminal(Terminal { + kind: "final", + value: "final", ..Default::default() - }), - CSTNode::NonTerminal(NonTerminal { - kind: "type_arguments", - children: vec![ - CSTNode::Terminal(Terminal { - kind: "<", - value: "<", - ..Default::default() - }), - CSTNode::NonTerminal(NonTerminal { - kind: "wildcard", - children: vec![CSTNode::Terminal(Terminal { - kind: "?", - value: "?", + })], + ..Default::default() + }), + CSTNode::NonTerminal(NonTerminal { + kind: "generic_type", + children: vec![ + CSTNode::Terminal(Terminal { + kind: "type_identifier", + value: "ASTNode", + ..Default::default() + }), + CSTNode::NonTerminal(NonTerminal { + kind: "type_arguments", + children: vec![ + CSTNode::Terminal(Terminal { + kind: "<", + value: "<", ..Default::default() - })], - ..Default::default() - }), - CSTNode::Terminal(Terminal { - kind: ">", - value: ">", - ..Default::default() - }), - ], - ..Default::default() - }), - ], - ..Default::default() - }), - CSTNode::Terminal(Terminal { - kind: "identifier", - value: "astnode", - ..Default::default() - }), - ], - ..Default::default() - })); - - let node_b =make_method_declaration_node("ASTNodeArtifact", CSTNode::NonTerminal(NonTerminal { - kind: "formal_parameter", - children: vec![ - CSTNode::NonTerminal(NonTerminal { - kind: "modifiers", - children: vec![CSTNode::Terminal(Terminal { - kind: "final", - value: "final", + }), + CSTNode::NonTerminal(NonTerminal { + kind: "wildcard", + children: vec![CSTNode::Terminal(Terminal { + kind: "?", + value: "?", + ..Default::default() + })], + ..Default::default() + }), + CSTNode::Terminal(Terminal { + kind: ">", + value: ">", + ..Default::default() + }), + ], + ..Default::default() + }), + ], ..Default::default() - })], - ..Default::default() - }), - CSTNode::Terminal(Terminal { - kind: "type_identifier", - value: "FileArtifact", - ..Default::default() - }), - CSTNode::Terminal(Terminal { - kind: "identifier", - value: "astnode", - ..Default::default() - }), - ], - ..Default::default() - })); + }), + CSTNode::Terminal(Terminal { + kind: "identifier", + value: "astnode", + ..Default::default() + }), + ], + ..Default::default() + }), + ); + let node_b = make_method_declaration_node( + "ASTNodeArtifact", + CSTNode::NonTerminal(NonTerminal { + kind: "formal_parameter", + children: vec![ + CSTNode::NonTerminal(NonTerminal { + kind: "modifiers", + children: vec![CSTNode::Terminal(Terminal { + kind: "final", + value: "final", + ..Default::default() + })], + ..Default::default() + }), + CSTNode::Terminal(Terminal { + kind: "type_identifier", + value: "FileArtifact", + ..Default::default() + }), + CSTNode::Terminal(Terminal { + kind: "identifier", + value: "astnode", + ..Default::default() + }), + ], + ..Default::default() + }), + ); let result = compute_matching_score_for_method_declaration(&node_a, &node_b); assert_eq!(0, result);