Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/checker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ impl Checker for JavaCode {
mk_checker!(is_string, StringLiteral);
mk_checker!(is_call, MethodInvocation);
mk_checker!(is_func, MethodDeclaration);
mk_checker!(is_closure,);
mk_checker!(is_closure, LambdaExpression);
mk_checker!(
is_func_space,
Program,
Expand Down
72 changes: 72 additions & 0 deletions src/metrics/nom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -621,4 +621,76 @@ mod tests {
]
);
}

#[test]
fn java_nom() {
check_metrics!(
"class A {
public void foo(){
return;
}
public void bar(){
return;
}
}",
"foo.java",
JavaParser,
nom,
[
(functions_sum, 2, usize),
(closures_sum, 0, usize),
(total, 2, usize),
(functions_max, 1, usize),
(functions_min, 0, usize),
(closures_max, 0, usize),
(closures_min, 0, usize),
],
[
(functions_average, 0.5), // number of spaces = 4
(closures_average, 0.0),
(average, 0.5)
]
);
}

#[test]
fn java_closure_nom() {
check_metrics!(
"interface printable{
void print();
}

interface IntFunc {
int func(int n);
}

class Printer implements printable{
public void print(){System.out.println(\"Hello\");}

public static void main(String args[]){
Printer obj = new Printer();
obj.print();
IntFunc meaning = (i) -> i + 42;
int i = meaning.func(1);
}
}",
"foo.java",
JavaParser,
nom,
[
(functions_sum, 4, usize),
(closures_sum, 1, usize),
(total, 5, usize),
(functions_max, 1, usize),
(functions_min, 0, usize),
(closures_max, 1, usize),
(closures_min, 0, usize),
],
[
(functions_average, 0.5), // number of spaces = 8
(closures_average, 0.125),
(average, 0.625)
]
);
}
}