-
-
Notifications
You must be signed in to change notification settings - Fork 356
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
fix: fix qodana warning with proper call to Array.toString() #4536
fix: fix qodana warning with proper call to Array.toString() #4536
Conversation
The following has changed in the code: Replaced str.toString() with Arrays.toString(str).
@MartinWitt where can I see the list of all Qodana warnings? We have a tool that can automatically repair such types of warnings - Sorald. You can see the list of rules it handles as of now here. EDIT: I guess you have already contributed to it ASSERT-KTH/sorald#368 :) |
Do you want a list of all we have or all qodana has? |
@MartinWitt Both would be good. I will see if we can fix any violations using Sorald. |
For all we have, see here https://github.com/INRIA/spoon/pull/4481/files (we disabled this view in a recent PR) or run |
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.
Delete the new line and then we can merge.
@@ -7,6 +7,7 @@ | |||
*/ | |||
package spoon.support.sniper.internal; | |||
|
|||
|
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.
You accidentally added this new line.
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.
Yes, I still have problems of added newlines while sniper printing. I removed it.
@@ -720,7 +721,7 @@ private void onCharSequence(CharType type, StringBuilder buff, Consumer<SourceFr | |||
} | |||
// nothing has matched, best effort token | |||
if (longestMatcher == null) { | |||
consumer.accept(new TokenSourceFragment(str.toString(), TokenType.CODE_SNIPPET)); | |||
consumer.accept(new TokenSourceFragment(Arrays.toString(str), TokenType.CODE_SNIPPET)); |
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.
very confusing to have an array named str, charArray
is better?
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.
Yes, I renamed it
214c44c
to
aa4f970
Compare
longestMatcher = strMatcher.getLonger(longestMatcher); | ||
} | ||
} | ||
// nothing has matched, best effort token | ||
if (longestMatcher == null) { | ||
consumer.accept(new TokenSourceFragment(str.toString(), TokenType.CODE_SNIPPET)); | ||
consumer.accept(new TokenSourceFragment(Arrays.toString(charArray), TokenType.CODE_SNIPPET)); |
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.
this looks like this best-effort token never worked. I guess we don't have any single test here :)?
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.
Looking at the coverage, there should exist a testcase for this line https://coveralls.io/builds/45751341/source?filename=src%2Fmain%2Fjava%2Fspoon%2Fsupport%2Fsniper%2Finternal%2FElementSourceFragment.java#L724. But I have not found a way in the UI to find it.
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.
Looking at the coverage, there should exist a testcase for this line coveralls.io/builds/45751341/source?filename=src%2Fmain%2Fjava%2Fspoon%2Fsupport%2Fsniper%2Finternal%2FElementSourceFragment.java#L724. But I have not found a way in the UI to find it.
argh, this is #4541
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.
anyway, I'd be in favor in writing an assertion on the content of this token. Otherwise, we fix broken code by something which may be buggy as well
would you be able to add such an assertion?
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.
After some debugging, I found the testcase
public void testPrintLocalVariableDeclaration2() { |
0,
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 believe the current input token is simply wrong.
Agree, that's why we need a new test or a new assertion to assert the actual correct content. Would you write this?
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 can only trigger this line with joint declarations but currently the sniper is not able to work with them, see #3386. It looks like either this token was never relevant or is needed in a future version and we can't great asserts for the value currently.
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.
If we are unable to specify this line, then the best option is to simply remove it. Could you give it a try?
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.
It looks like the token is for some strange reasons important for the sniper printing and removing it adds unwanted whitespaces. So we more or less have to keep it and fix this after fixing the linked problem.
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.
ack, then let's revert this last commit and proceed with the change, it's not harmful. we replace code we don't understand by code we still don't understand but less confusing.
Thanks @MartinWitt |
Change Log
The following bad smells are refactored:
ArraysToString
array.toString()
is not the best way to print an array. UseArrays.toString(array)
instead.The following has changed in the code:
ArraysToString
str.toString()
withArrays.toString(str)
.