Skip to content

Commit 5e60512

Browse files
committed
Adds exit metrics
1 parent 0cc9bcd commit 5e60512

File tree

1 file changed

+42
-1
lines changed

1 file changed

+42
-1
lines changed

src/metrics/exit.rs

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff 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+
175183
impl Exit for PreprocCode {}
176184
impl Exit for CcommentCode {}
177-
impl Exit for JavaCode {}
178185

179186
#[cfg(test)]
180187
mod 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
}

0 commit comments

Comments
 (0)