Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blanks are not counted correctly in Java #73

Closed
ptupitsyn opened this issue May 2, 2019 · 4 comments
Closed

Blanks are not counted correctly in Java #73

ptupitsyn opened this issue May 2, 2019 · 4 comments
Labels
bug Something isn't working

Comments

@ptupitsyn
Copy link

Describe the bug
In some cases blank lines are not counted correctly in Java files.
I've simplified the example somewhat, but could not pinpoint problematic lines.

To Reproduce

  1. Download file AbstractSACParser.zip
  2. Extract
  3. Scc

Expected behavior

───────────────────────────────────────────────────────────────────────────────
Language                 Files     Lines     Code  Comments   Blanks Complexity
───────────────────────────────────────────────────────────────────────────────
Java                         1       139      103        16        20          8

Actual behavior

───────────────────────────────────────────────────────────────────────────────
Language                 Files     Lines     Code  Comments   Blanks Complexity
───────────────────────────────────────────────────────────────────────────────
Java                         1       139      119        15        5          8

Desktop

  • Windows 10
@boyter boyter added the bug Something isn't working label May 2, 2019
@boyter
Copy link
Owner

boyter commented May 2, 2019

Does not appear to be related to #72 as the file is UTF-8 encoded.

@boyter
Copy link
Owner

boyter commented May 5, 2019

Issue is the following line,

if (c == '\\' || (c == '\"')) {

The " is being picked up as the start of a string which is throwing out the count. Because scc counts blank lines as being code if inside a string unlike tokei this is why the count is incorrect.

In this case we could check for \ before the string since this should only occur inside a char. However not all languages work like that. I think this is acceptable for the moment as a quick fix though and to create a new issue to evaluate how this works in other languages. It should work for most of the common languages though which is a good short term win.

@boyter
Copy link
Owner

boyter commented May 5, 2019

Fix for this case exists on branch #75

$ go run main.go examples/regressions/java/AbstractSACParser.java
───────────────────────────────────────────────────────────────────────────────
Language                 Files     Lines     Code  Comments   Blanks Complexity
───────────────────────────────────────────────────────────────────────────────
Java                         1       139      103        16       20         55
───────────────────────────────────────────────────────────────────────────────
Total                        1       139      103        16       20         55
───────────────────────────────────────────────────────────────────────────────
Estimated Cost to Develop $2,483
Estimated Schedule Effort 1.570432 months
Estimated People Required 0.187331
───────────────────────────────────────────────────────────────────────────────

NB complexity goes up because it spends time in the code state now which triggers that logic.

@boyter
Copy link
Owner

boyter commented May 9, 2019

Merged into master.

This will still need work to make it more flexible, so no release till that is done in #76

That said closing down because if you build from master its all fine now and will make it into the next release.

@boyter boyter closed this as completed May 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants