-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Issue #13672: Kill mutation for FileImportControl #13760
Conversation
In explanation, I have only mentioned where it is used. And tried to understand the significance of it but i don't understand why the reason to do this. Please let me know what value this will create |
hmm, example of "file" tag https://checkstyle.org/checks/imports/importcontrol.html#ImportControl this commit when it was added and example: So pitest does not see coverage for "non-capturing group" https://stackoverflow.com/a/3513858/1015848 But we put whole regexp in non captured, this strange as it iliminates a purpose of it, as we need sibling group to make meaningful. |
@rnveach , do you remember why you used non captured group as wrapper? I don't see that wrapping non-captured whole content make all nested groups as non-captured |
pitest blocks failed due to crash of pitest execution. imports pitest has:
we need test where |
What code are you talking about? I am not following. |
* @return a grouped pattern. | ||
*/ | ||
private static String encloseInGroup(String expression) { | ||
return "(?:" + expression + ")"; |
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.
@rnveach , This code.
If we don't remember why we did this, we will remove 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.
The comment above its call says ensure that fullPackage is a self-contained regular expression
.
You had to search a bit more in the commit you found.
https://github.com/checkstyle/checkstyle/blob/master/src/main/java/com/puppycrawl/tools/checkstyle/checks/imports/PkgImportControl.java#L155-L156 was renamed from ImportControl
, and then from PkgControl
before that, and that is where the code originally came from. I did not add it.
It appears the code really came from 63e8c1d#diff-f68bc4c425df6a25439881dbcd97576b489f7d71fc7706a450e11a101f0d3e77R148-R149 .
#2999
Some things of interest:
#3438 (comment)
#3438 (comment)
#3438 (comment)
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.
Ok, thanks a lot, after reading all of this, there is no special reason of such code.
Last reason could be performance, as regexp does not need do creation of group. But as we wrap whole regexp it is does not guarantee that all nested groups will be downgraded to non-captured groups.
I am ok to remove this method.
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.
(?:.*(Panel|View|Dialog))
What happens when the regexp changes to .*(Panel|View|Dialog)
? Since this now a capturing group, will it cause any issues?
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 no code deals with group, no changes.
We do not use group, we just match, true or false.
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.
@romani To me the following lines explain why we need encloseInGroup
.
checkstyle/src/main/java/com/puppycrawl/tools/checkstyle/checks/imports/PkgImportControl.java
Lines 128 to 130 in 4d113f9
* "org.uncommon"}. Without the grouping it would be {@code "com|org.common|uncommon"} which | |
* would match {@code "com"}, {@code "org.common"}, and {@code "uncommon"}, which clearly is | |
* undesirable. Adding the group fixes this. |
Apparently we concat 2 regexps together and without the enclosing ()
we would create a very different and wrong regexp than with it. We can't rely on the users adding ()
themselves and we enclose it in a ()
in case they don't.
Unless you are saying the javadoc is out of date, and we would need proof of that.
Combination code is at:
checkstyle/src/main/java/com/puppycrawl/tools/checkstyle/checks/imports/PkgImportControl.java
Lines 98 to 101 in 4d113f9
final String parentRegex = ensureSelfContainedRegex(parent.fullPackageName, | |
parent.regex); | |
final String thisRegex = ensureSelfContainedRegex(subPackageName, regex); | |
fullPackageName = parentRegex + DOT_REGEX + thisRegex; |
Edit: I was concentrating too much on PkgImportControl
.
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.
Since this PR is only for FileImportControl
, it doesn't do any combination of 2 regexps. The field it assigns is private, so we won't be passing this field to anywhere outside this class.
So yes, it is ok that we remove 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.
If no code deals with group, no changes.
We do not use group
Or if we do not combine 2 regexps.
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.
@Kevin222004 , please investigate. Looks like we found a way to make it to work not as expected if we remove such code.
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.
@romani #13760 (comment) . I also approved this PR as I think the code removal is fine.
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.
Ok to merge
@Kevin222004 , please resolve pitest failure:
Please prepare PR for merge. |
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.
See reason above
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 seems to me we could remove name
completely, and transfer everything to patternForExactMatch
. We would just have to sanitize name that we put into patternForExactMatch
if it is not regexp
.
@Kevin222004 , please resolve a conflict. Let us know if you donot know how to resolve this survival, so mentors will look closer.
checkstyle/src/main/java/com/puppycrawl/tools/checkstyle/checks/imports/FileImportControl.java Line 89 in bbd110b
I do not think we can easily remove it. to kill mutation on |
bbd110b
to
dcc1c01
Compare
@@ -43,26 +42,8 @@ class FileImportControl extends AbstractImportControl { | |||
*/ | |||
/* package */ FileImportControl(PkgImportControl parent, String name, boolean regex) { | |||
super(parent, MismatchStrategy.DELEGATE_TO_PARENT); |
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 is the constructor. so after loading all the configuration and setup when visitToken
in ImportControl
checkstyle/src/main/java/com/puppycrawl/tools/checkstyle/checks/imports/ImportControlCheck.java
Line 237 in 83788d6
currentImportControl = root.locateFinest(packageName, fileName); |
after executing this statement
checkstyle/src/main/java/com/puppycrawl/tools/checkstyle/checks/imports/FileImportControl.java
Line 80 in 83788d6
public AbstractImportControl locateFinest(String forPkg, String forFileName) { |
after this method
checkstyle/src/main/java/com/puppycrawl/tools/checkstyle/checks/imports/FileImportControl.java
Lines 90 to 102 in 83788d6
protected boolean matchesExactly(String pkg, String fileName) { | |
final boolean result; | |
if (fileName == null) { | |
result = false; | |
} | |
else if (regex) { | |
result = patternForExactMatch.matcher(fileName).matches(); | |
} | |
else { | |
result = name.equals(fileName); | |
} | |
return result; | |
} |
where we already check that if regex is true or not so that's why replacing this
checkstyle/src/main/java/com/puppycrawl/tools/checkstyle/checks/imports/FileImportControl.java
Lines 48 to 55 in 83788d6
if (regex) { | |
this.name = encloseInGroup(name); | |
patternForExactMatch = createPatternForExactMatch(this.name); | |
} | |
else { | |
this.name = name; | |
patternForExactMatch = null; | |
} |
if as true will not make any affect.
checkstyle/src/main/java/com/puppycrawl/tools/checkstyle/checks/imports/FileImportControl.java
Line 33 in 83788d6
private final Pattern patternForExactMatch; |
The only usage of this field is at
checkstyle/src/main/java/com/puppycrawl/tools/checkstyle/checks/imports/FileImportControl.java
Lines 95 to 97 in 83788d6
else if (regex) { | |
result = patternForExactMatch.matcher(fileName).matches(); | |
} |
so we can remove this field and directly initialize that in method it will not make any issue
dcc1c01
to
903891f
Compare
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.
Items
src/main/java/com/puppycrawl/tools/checkstyle/checks/imports/FileImportControl.java
Outdated
Show resolved
Hide resolved
903891f
to
004345e
Compare
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.
Ok to merge
004345e
to
8c0b2a9
Compare
8c0b2a9
to
cfee805
Compare
Issue #13672: Kill mutation for FileImportControl
Mutation
checkstyle/config/pitest-suppressions/pitest-imports-suppressions.xml
Lines 12 to 19 in ccc12eb
Explaination
This constructor
checkstyle/src/main/java/com/puppycrawl/tools/checkstyle/checks/imports/FileImportControl.java
Lines 44 to 49 in ccc12eb
is used called only at line 185
checkstyle/src/main/java/com/puppycrawl/tools/checkstyle/checks/imports/ImportControlLoader.java
Lines 181 to 186 in ccc12eb
so this elseif statment will execute in case
where we have file know encloseInGroup is used to non-capture the group I have done some research at
https://stackoverflow.com/questions/3512471/what-is-a-non-capturing-group-in-regular-expressions