File tree Expand file tree Collapse file tree 1 file changed +67
-1
lines changed Expand file tree Collapse file tree 1 file changed +67
-1
lines changed Original file line number Diff line number Diff line change @@ -172,9 +172,16 @@ impl Exit for CppCode {
172172 }
173173}
174174
175+ impl Exit for JavaCode {
176+ fn compute ( node : & Node , stats : & mut Stats ) {
177+ if matches ! ( node. object( ) . kind_id( ) . into( ) , Java :: ReturnStatement ) {
178+ stats. exit += 1 ;
179+ }
180+ }
181+ }
182+
175183impl Exit for PreprocCode { }
176184impl Exit for CcommentCode { }
177- impl Exit for JavaCode { }
178185
179186#[ cfg( test) ]
180187mod tests {
@@ -305,4 +312,63 @@ mod tests {
305312 [ ( exit_average, 0.5 ) ] // 2 functions + 2 lambdas = 4
306313 ) ;
307314 }
315+
316+ #[ test]
317+ fn java_no_exit ( ) {
318+ check_metrics ! (
319+ "int a = 42;" ,
320+ "foo.java" ,
321+ JavaParser ,
322+ nexits,
323+ [
324+ ( exit_sum, 0 , usize ) ,
325+ ( exit_min, 0 , usize ) ,
326+ ( exit_max, 0 , usize )
327+ ] ,
328+ [ ( exit_average, f64 :: NAN ) ] // 0 functions
329+ ) ;
330+ }
331+
332+ #[ test]
333+ fn java_simple_function ( ) {
334+ check_metrics ! (
335+ "class A {
336+ public int sum(int x, int y) {
337+ return x + y;
338+ }
339+ }" ,
340+ "foo.java" ,
341+ JavaParser ,
342+ nexits,
343+ [
344+ ( exit_sum, 1 , usize ) ,
345+ ( exit_min, 0 , usize ) ,
346+ ( exit_max, 1 , usize )
347+ ] ,
348+ [ ( exit_average, 1.0 ) ] // 1 exit / 1 space
349+ ) ;
350+ }
351+
352+ #[ test]
353+ fn java_split_function ( ) {
354+ check_metrics ! (
355+ "class A {
356+ public int multiply(int x, int y) {
357+ if(x == 0 || y == 0){
358+ return 0;
359+ }
360+ return x * y;
361+ }
362+ }" ,
363+ "foo.java" ,
364+ JavaParser ,
365+ nexits,
366+ [
367+ ( exit_sum, 2 , usize ) ,
368+ ( exit_min, 0 , usize ) ,
369+ ( exit_max, 2 , usize )
370+ ] ,
371+ [ ( exit_average, 2.0 ) ] // 2 exit / space 1
372+ ) ;
373+ }
308374}
You can’t perform that action at this time.
0 commit comments