-
Notifications
You must be signed in to change notification settings - Fork 362
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
Refactor CxxFileLinesVisitor #1602
Refactor CxxFileLinesVisitor #1602
Conversation
* collections for line tracking don't have not to be static * collections don't have to be sorted for each token * it's sufficient to sort / filter duplicates at file end * types of tokens must be compared rather than string values * misc refactoring
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ivangalkin thx for this PR. See some hints questions.
cxx-sensors/src/main/java/org/sonar/cxx/sensors/visitors/CxxFileLinesVisitor.java
Outdated
Show resolved
Hide resolved
cxx-sensors/src/main/java/org/sonar/cxx/sensors/visitors/CxxFileLinesVisitor.java
Outdated
Show resolved
Hide resolved
cxx-sensors/src/main/java/org/sonar/cxx/sensors/visitors/CxxFileLinesVisitor.java
Outdated
Show resolved
Hide resolved
@@ -97,14 +123,14 @@ public void visitToken(Token token) { | |||
return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is issue #1220. Could this be the reason?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if there is a connection between the metrics and the coverage data. It requires additional investigation.
if (value != null && !"{".equals(value) && !"default".equals(value) && !"case".equals(value)) { | ||
EXECUTABLE_LINES.add(astNode.getTokenLine()); | ||
final TokenType type = astNode.getToken().getType(); | ||
if (!CxxPunctuator.CURLBR_LEFT.equals(type) && !CxxKeyword.DEFAULT.equals(type) && !CxxKeyword.CASE.equals(type)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
switch/case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not worth in this case IMHO
LOG.debug(" linesOfComments: '{}'", LINES_OF_COMMENTS); | ||
LOG.debug(" executableLines: '{}'", Sets.newHashSet(executableLines)); | ||
LOG.debug(" linesOfCode: '{}'", Sets.newHashSet(linesOfCode)); | ||
LOG.debug(" linesOfComments: '{}'", Sets.newHashSet(linesOfComments)); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wondering if it would not be better to clear lists also here to safe memory. Don't know how long the visitor does life?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The lifetime of these containers was extended artificially in order to ease testing. I've rewritten tests instead
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ivangalkin thx looks perfect now!
This change is