File tree Expand file tree Collapse file tree 1 file changed +42
-1
lines changed Expand file tree Collapse file tree 1 file changed +42
-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,38 @@ 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+ CppParser ,
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+ "public int sum(int x, int y) {
336+ return x + y;
337+ }" ,
338+ "foo.java" ,
339+ CppParser ,
340+ nexits,
341+ [
342+ ( exit_sum, 1 , usize ) ,
343+ ( exit_min, 0 , usize ) ,
344+ ( exit_max, 1 , usize )
345+ ] ,
346+ [ ( exit_average, 1.0 ) ] // 1 function
347+ ) ;
348+ }
308349}
You can’t perform that action at this time.
0 commit comments