Skip to content

Commit 7b9d158

Browse files
authored
Java nom metrics (#823)
* Closure to checker for nom * Adds a simpler test * Removed debug statement
1 parent d24a558 commit 7b9d158

File tree

2 files changed

+73
-1
lines changed

2 files changed

+73
-1
lines changed

src/checker.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ impl Checker for JavaCode {
208208
mk_checker!(is_string, StringLiteral);
209209
mk_checker!(is_call, MethodInvocation);
210210
mk_checker!(is_func, MethodDeclaration);
211-
mk_checker!(is_closure,);
211+
mk_checker!(is_closure, LambdaExpression);
212212
mk_checker!(
213213
is_func_space,
214214
Program,

src/metrics/nom.rs

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -621,4 +621,76 @@ mod tests {
621621
]
622622
);
623623
}
624+
625+
#[test]
626+
fn java_nom() {
627+
check_metrics!(
628+
"class A {
629+
public void foo(){
630+
return;
631+
}
632+
public void bar(){
633+
return;
634+
}
635+
}",
636+
"foo.java",
637+
JavaParser,
638+
nom,
639+
[
640+
(functions_sum, 2, usize),
641+
(closures_sum, 0, usize),
642+
(total, 2, usize),
643+
(functions_max, 1, usize),
644+
(functions_min, 0, usize),
645+
(closures_max, 0, usize),
646+
(closures_min, 0, usize),
647+
],
648+
[
649+
(functions_average, 0.5), // number of spaces = 4
650+
(closures_average, 0.0),
651+
(average, 0.5)
652+
]
653+
);
654+
}
655+
656+
#[test]
657+
fn java_closure_nom() {
658+
check_metrics!(
659+
"interface printable{
660+
void print();
661+
}
662+
663+
interface IntFunc {
664+
int func(int n);
665+
}
666+
667+
class Printer implements printable{
668+
public void print(){System.out.println(\"Hello\");}
669+
670+
public static void main(String args[]){
671+
Printer obj = new Printer();
672+
obj.print();
673+
IntFunc meaning = (i) -> i + 42;
674+
int i = meaning.func(1);
675+
}
676+
}",
677+
"foo.java",
678+
JavaParser,
679+
nom,
680+
[
681+
(functions_sum, 4, usize),
682+
(closures_sum, 1, usize),
683+
(total, 5, usize),
684+
(functions_max, 1, usize),
685+
(functions_min, 0, usize),
686+
(closures_max, 1, usize),
687+
(closures_min, 0, usize),
688+
],
689+
[
690+
(functions_average, 0.5), // number of spaces = 8
691+
(closures_average, 0.125),
692+
(average, 0.625)
693+
]
694+
);
695+
}
624696
}

0 commit comments

Comments
 (0)