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

Refactor CxxFileLinesVisitor #1602

Merged

Conversation

ivangalkin
Copy link
Contributor

@ivangalkin ivangalkin commented Nov 26, 2018

  • 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

This change is Reviewable

* 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
@ivangalkin ivangalkin added this to the 1.2.1 milestone Nov 26, 2018
@ivangalkin ivangalkin self-assigned this Nov 26, 2018
@ivangalkin ivangalkin requested review from Bertk and guwirth November 26, 2018 17:15
Copy link
Collaborator

@guwirth guwirth left a 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.

@@ -97,14 +123,14 @@ public void visitToken(Token token) {
return;
Copy link
Collaborator

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?

Copy link
Contributor Author

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)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

switch/case?

Copy link
Contributor Author

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));
}
}
Copy link
Collaborator

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?

Copy link
Contributor Author

@ivangalkin ivangalkin Nov 26, 2018

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

Copy link
Collaborator

@guwirth guwirth left a 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!

@guwirth guwirth merged commit e9ef6c9 into SonarOpenCommunity:master Nov 27, 2018
@guwirth guwirth mentioned this pull request Dec 21, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

2 participants