@@ -519,30 +519,25 @@ impl Loc for JavaCode {
519519 add_cloc_lines ( stats, start, end) ;
520520 }
521521 AssertStatement
522- | AssignmentExpression
523522 | BreakStatement
524- | BinaryExpression
525- | CastExpression
526523 | ContinueStatement
527524 | DoStatement
528- | Declaration
529525 | EnhancedForStatement
526+ | ExpressionStatement
530527 | IfStatement
531- | InstanceofExpression
532- | LambdaExpression
533528 | LocalVariableDeclaration
534- | MethodInvocation
535- | ParenthesizedExpression
536- | PrimaryExpression
537529 | ReturnStatement
538- | Statement
539530 | SwitchStatement
540- | TernaryExpression
541531 | ThrowStatement
542532 | TryStatement
543- | UpdateExpression
544- | UnaryExpression => {
533+ | WhileStatement => {
545534 stats. logical_lines += 1 ;
535+ println ! ( "+1" ) ;
536+ }
537+ ForStatement => {
538+ // handle binary check + increment
539+ stats. logical_lines += 2 ;
540+ println ! ( "+2" ) ;
546541 }
547542 _ => {
548543 check_comment_ends_on_code_line ( stats, start) ;
@@ -1601,6 +1596,20 @@ mod tests {
16011596 ) ;
16021597 }
16031598
1599+ #[ test]
1600+ fn java_update_expression_lloc ( ) {
1601+ check_metrics ! (
1602+ "int i = 10;
1603+ i++;" ,
1604+ "foo.java" ,
1605+ JavaParser ,
1606+ loc,
1607+ [
1608+ ( lloc, 2 , usize ) , // The number of statements is 2
1609+ ]
1610+ ) ;
1611+ }
1612+
16041613 #[ test]
16051614 fn java_for_lloc ( ) {
16061615 check_metrics ! (
@@ -1638,30 +1647,96 @@ mod tests {
16381647 check_metrics ! (
16391648 "
16401649 int i=0; // +1
1641- while(i < 10) { // +2 paren exp + binary
1650+ while(i < 10) { // +1
16421651 i++; // +1
16431652 System.out.println(i); // +1
16441653 }" ,
16451654 "foo.java" ,
16461655 JavaParser ,
16471656 loc,
16481657 [
1649- ( lloc, 5 , usize ) , // The number of statements is 5
1658+ ( lloc, 4 , usize ) , // The number of statements is 4
1659+ ]
1660+ ) ;
1661+ }
1662+
1663+ #[ test]
1664+ fn java_do_while_lloc ( ) {
1665+ check_metrics ! (
1666+ "
1667+ int i=0; // +1
1668+ do { // +1
1669+ i++; // +1
1670+ System.out.println(i); // +1
1671+ } while(i < 10)" ,
1672+ "foo.java" ,
1673+ JavaParser ,
1674+ loc,
1675+ [
1676+ ( lloc, 4 , usize ) , // The number of statements is 4
16501677 ]
16511678 ) ;
16521679 }
16531680
16541681 #[ test]
1655- fn java_multi_lloc ( ) {
1682+ fn java_switch_lloc ( ) {
1683+ check_metrics ! (
1684+ "switch(grade) { // +1
1685+ case 'A' :
1686+ System.out.println(\" Pass with distinction\" ); // +1
1687+ break; // +1
1688+ case 'B' :
1689+ case 'C' :
1690+ System.out.println(\" Pass\" ); // +1
1691+ break; // +1
1692+ case 'D' :
1693+ System.out.println(\" At risk\" ); // +1
1694+ case 'F' :
1695+ System.out.println(\" Fail\" ); // +1
1696+ break; // +1
1697+ default :
1698+ System.out.println(\" Invalid grade\" ); // +1
1699+ }" ,
1700+ "foo.java" ,
1701+ JavaParser ,
1702+ loc,
1703+ [
1704+ ( lloc, 9 , usize ) , // The number of statements is 6
1705+ ]
1706+ ) ;
1707+ }
1708+
1709+ #[ test]
1710+ fn java_continue_lloc ( ) {
16561711 check_metrics ! (
16571712 "int max = 10; // +1
16581713
16591714 for (int i = 0; i < max; i++) { // +3
1660- System.out.println(i); // +1
1715+ if(i % 2 == 0) { continue;} + 2
1716+ System.out.println(i); // +1
16611717 }" ,
16621718 "foo.java" ,
16631719 JavaParser ,
16641720 loc,
1721+ [
1722+ ( lloc, 7 , usize ) , // The number of statements is 7
1723+ ]
1724+ ) ;
1725+ }
1726+
1727+ #[ test]
1728+ fn java_try_lloc ( ) {
1729+ check_metrics ! (
1730+ "try { // +1
1731+ int[] myNumbers = {1, 2, 3}; // +1
1732+ System.out.println(myNumbers[10]); // +1
1733+ } catch (Exception e) {
1734+ System.out.println(e.getMessage()); // +1
1735+ throw e; // +1
1736+ }" ,
1737+ "foo.java" ,
1738+ JavaParser ,
1739+ loc,
16651740 [
16661741 ( lloc, 5 , usize ) , // The number of statements is 5
16671742 ]
@@ -1690,37 +1765,26 @@ mod tests {
16901765 ) ;
16911766 }
16921767
1693- // copy in 1 line at a time
1694- //
1695- //
1696- //
1697- //
1698- //
1699- //
1700- //
1701- //
1702- //
1703- //
17041768 #[ test]
17051769 fn java_expressions_lloc ( ) {
17061770 check_metrics ! (
1707- "int x = 10; // +1
1708- x=+90; // +2 var + unary
1709- int y = x * 2; // +2 var + binary
1710- IntFunction double = (n) -> n*2; // +3 var + lambda + binary
1711- int y2 = double(x); // +2 var + paren expression
1712- System.out.println(\" double \" + x + \" = \" + y2); // +4 method + binary x 3
1713- String message = (x % 2) == 0 ? \" Evenly done.\" : \" Oddly done.\" ; // +5 lloc : 1 var assignment + ternary + binary + param exp + binary
1714- Object done = (Runnable) () -> { System.out.println(\" Done!\" ); }; // +4 var + cast + lamda + method invoc
1715- String s = \" string\" ; // +1
1716- boolean isS = (s instanceof String); // +3 var assignment + paren exp + instanceof
1717- done.run(); // +1 method invoc
1771+ "int x = 10; // +1 local var declaration
1772+ x=+90; // +1 expression statement
1773+ int y = x * 2; // +1 local var declaration
1774+ IntFunction double = (n) -> n*2; // +1 local var declaration
1775+ int y2 = double(x); // +1 local var declaration
1776+ System.out.println(\" double \" + x + \" = \" + y2); // +1 expression statement
1777+ String message = (x % 2) == 0 ? \" Evenly done.\" : \" Oddly done.\" ; // +1 local var declaration
1778+ Object done = (Runnable) () -> { System.out.println(\" Done!\" ); }; // +2 local var declaration + expression statement
1779+ String s = \" string\" ; // +1 local var declaration
1780+ boolean isS = (s instanceof String); // +1 local var declaration
1781+ done.run(); // +1 expression statement
17181782 " ,
17191783 "foo.java" ,
17201784 JavaParser ,
17211785 loc,
17221786 [
1723- ( lloc, 28 , usize ) , // The number of statements is 28
1787+ ( lloc, 12 , usize ) , // The number of statements is 12
17241788 ]
17251789 ) ;
17261790 }
@@ -1778,7 +1842,7 @@ mod tests {
17781842
17791843 class HelloWorldApp {
17801844 public void main(String[] args) {
1781- String message = args.length == 0 ? \" Hello empty world\" : \" Hello world\" ; // +3 lloc : 1 var assignment + ternary + binary exp
1845+ String message = args.length == 0 ? \" Hello empty world\" : \" Hello world\" ; // +1 lloc : 1 var assignment
17821846 System.out.println(message); // Display the string. +1 lloc
17831847 }
17841848 }" ,
@@ -1788,7 +1852,7 @@ mod tests {
17881852 [
17891853 ( sloc, 12 , usize ) , // The number of lines is 12
17901854 ( ploc, 7 , usize ) , // The number of code lines is 7
1791- ( lloc, 4 , usize ) , // The number of statements is 4
1855+ ( lloc, 2 , usize ) , // The number of statements is 2
17921856 ( cloc, 6 , usize ) , // The number of comments is 6
17931857 ( blank, 1 , usize ) // The number of blank lines is 1
17941858 ]
0 commit comments