Skip to content

Commit

Permalink
chore: fix clippy issues
Browse files Browse the repository at this point in the history
  • Loading branch information
jpedroh committed Mar 12, 2024
1 parent e54c11c commit 0f87b97
Showing 1 changed file with 90 additions and 91 deletions.
181 changes: 90 additions & 91 deletions matching_handlers/src/java/method_declaration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,15 @@ fn extract_argument_types_from_formal_parameters(node: &CSTNode) -> Vec<String>
.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(),
}
Expand All @@ -69,13 +66,10 @@ fn extract_argument_types_from_formal_parameters(node: &CSTNode) -> Vec<String>
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() {
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 0f87b97

Please sign in to comment.