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 #13758: Add pattern array converter for auto bean #14740
Issue #13758: Add pattern array converter for auto bean #14740
Conversation
@rnveach @romani Could you please share your thoughts on this plan? I truly appreciate your opinions. Also, for #13758 (comment), which one do you think would be a better solution in our case? Update: CI is failing, but I will fix them later if we've decided the plan :). |
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.
Please read #13758 (comment)
item to disucuss
@Override | ||
public Object convert(Class type, Object value) { | ||
final String plainString = value.toString(); | ||
final String[] patternStrings = plainString.split(REGEX_SEPARATOR); |
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.
bad side effect of this is we should clearly mention that we do not allow ,
as part of regexp to match what user needs. So user can not use ,
in it Patterns, it is delimiter.
\,
will also not work, as we simply splitting for just ,
.
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, do you want me to close this PR for now? Since it might be confusing for others. We can re-open it later to further modify Pattern[]
if it is the right time. :)
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.
Let's keep it open until we come to agreement on how to fix issue.
@Lmh-java , please put in this PR all from #14764 (comment) |
6869cde
to
5b49c08
Compare
@@ -316,7 +316,8 @@ | |||
<!-- Main has an annotated field for each command line option. This is by design. --> | |||
<property name="violationSuppressXPath" | |||
value="//ClassOrInterfaceDeclaration[@SimpleName='Checker'] | |||
| //ClassOrInterfaceDeclaration[@SimpleName='Main']"/> | |||
| //ClassOrInterfaceDeclaration[@SimpleName='Main'] | |||
| //ClassOrInterfaceDeclaration[@SimpleName='ImportOrderCheck']"/> |
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.
Suppress this because PWD complains that ImportOrderCheck has too many class fields.
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 am ok with this.
/** | ||
* Complied array of patterns for property {@code groups}. | ||
*/ | ||
private Pattern[] groupsReg = EMPTY_PATTERN_ARRAY; | ||
|
||
/** | ||
* Complied array of patterns for property {@code staticGroups}. | ||
*/ | ||
private Pattern[] staticGroupsReg = EMPTY_PATTERN_ARRAY; | ||
|
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.
Add these two more fields to store the compiled regex expressions. I have to expose String[]
to users, but we also need to store the complied regex (we don't want to compile every time we want to use the regex). I am curious whether there are better solutions to this, since this change brings us more suppressions of all kinds.
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.
To next reviewers:
to avoid dealing with long discussion on what is actually a type that user should care, I am ok with this update.
I hope in some future we will agree on type system and simplify this Check
3080d29
to
7d5d4d2
Compare
String string = ""; | ||
entry.values().stream() | ||
.flatMap(List::stream) | ||
.map(Constraint::new) |
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.
Constraint::new
will not be recognized as a reference and will not be recorded. I am adding this test file to pass CI right now. I think it would be better if we could fix this false negative in a separated PR to make everything easier.
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.
Please use here File class, as you did in issue description
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.
done
final String[] expected = {}; | ||
|
||
verifyWithInlineConfigParser( | ||
getPath("InputClassFanOutComplexityLambdaNew.java"), expected); |
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 test case is not correct, but I have to add it to pass the current CI. InputClassFanOutComplexityLambdaNew.java
should NOT have 0 complexity.
See #14740 (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.
Please put comment, in code, no violations until #14787
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.
done
Line 121 in 7d5d4d2
But if I keep it, Pitest will complain about it. If this function call is removed by Pietist, nothing in our unit test will complain. After investigating it, I found that if this line is removed, sometimes there will be a few more class references counted. This is because when handling lambda expressions with a Line 398 in 7d5d4d2
Therefore, Ignoring such lambda expressions with PS: this is an issue with |
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:
7d5d4d2
to
fdf77ce
Compare
fdf77ce
to
1a4fb0f
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.
please apply review items to all cases:
src/test/java/com/puppycrawl/tools/checkstyle/checks/imports/ImportOrderCheckTest.java
Outdated
Show resolved
Hide resolved
src/test/java/com/puppycrawl/tools/checkstyle/AbstractAutomaticBeanTest.java
Outdated
Show resolved
Hide resolved
src/test/java/com/puppycrawl/tools/checkstyle/AbstractAutomaticBeanTest.java
Outdated
Show resolved
Hide resolved
src/test/java/com/puppycrawl/tools/checkstyle/AbstractAutomaticBeanTest.java
Outdated
Show resolved
Hide resolved
src/test/java/com/puppycrawl/tools/checkstyle/AbstractAutomaticBeanTest.java
Outdated
Show resolved
Hide resolved
src/test/java/com/puppycrawl/tools/checkstyle/AbstractAutomaticBeanTest.java
Outdated
Show resolved
Hide resolved
a70942d
to
9d67d78
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/AbstractAutomaticBean.java
Outdated
Show resolved
Hide resolved
9d67d78
to
a0fb82f
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
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.
Start Issue #13758.
How does this start the issue but doesn't completely resolve it? What is planned next?
src/main/java/com/puppycrawl/tools/checkstyle/AbstractAutomaticBean.java
Outdated
Show resolved
Hide resolved
src/main/java/com/puppycrawl/tools/checkstyle/AbstractAutomaticBean.java
Outdated
Show resolved
Hide resolved
@@ -371,4 +371,18 @@ public void testClearStatePackageName() throws Exception { | |||
.isTrue(); | |||
} | |||
|
|||
/** | |||
* Test [ClassName]::new expression. Such expression will be processed as a |
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.
What does this have to do with the pattern array converter? All the properties in the file are default which means it doesn't go against the converter, right?
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 has nothing to do with the converter. Please see #14740 (comment).
This is a part of the workaround for ClassFanOutCheck
until #14787
TLDR;
I have to keep the following line, otherwise the CI will fail.
Line 121 in 7d5d4d2
excludeClassesRegexps.add(CommonUtil.createPattern("^$")); |
Added this test case to kill Pitest mutation for this line. After #14787 is solved, this test case will report violations.
@@ -40,7 +40,7 @@ | |||
<a href="https://en.wikipedia.org/wiki/ASCII#Order">ASCII sort order</a>. | |||
It affects both type imports and static imports.</description> | |||
</property> | |||
<property default-value="" name="groups" type="java.util.regex.Pattern[]"> | |||
<property default-value="" name="groups" type="java.lang.String[]"> |
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.
Has it been discussed what impact this has on 3rd party tools like eclipse-cs or sonar-cs?
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 will be declared breaking compatibility, I hope eclipscs will not be actually affected.
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.
So we are not going to do any analysis or warning?
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, let move forward, and just declare breaking changes.
9c35f3e
to
8dc065a
Compare
final String plainString = value.toString(); | ||
Pattern[] patterns = new Pattern[0]; | ||
if (!CommonUtil.isBlank(plainString)) { | ||
final String[] patternStrings = plainString.split(COMMA_SEPARATOR); |
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.
Sorry I missed this before.
checkstyle/src/main/java/com/puppycrawl/tools/checkstyle/AbstractAutomaticBean.java
Line 393 in 8dc065a
value.toString().trim(), COMMA_SEPARATOR); |
checkstyle/src/main/java/com/puppycrawl/tools/checkstyle/AbstractAutomaticBean.java
Line 398 in 8dc065a
result.add(token.trim()); |
This is similar to
RelaxedStringArrayConverter
and it trims the input during the split. You are not.
You can see in testBeanConverterPatternArray
that the space remains in the regular expression. This violates your example you added in property_types.xml
as it shows the space removed.
Originally we were using RelaxedStringArrayConverter
for these type of instances, so we should continue the trimming it does. We need to implement trim in this method. I would expect spaces to be trimmed.
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.
Sorry I missed this before.
Totally no worries. This is a great catch. I was about to ask about this, but as time went by, I forgot...
Added trim. I have also updated the new converter to have the same structure with RelaxedStringArrayConverter
, so we can reduce one import to Arrays
.
I did not get a response, but I see text was updated in first post. I am more curious now. Is this PR plan to finish the issue? |
@rnveach The only thing needs to be done after this PR is #14787, but it is not relevant to #13758 (not relevant to unify pattern array.) |
aa80438
to
6bdcb72
Compare
6bdcb72
to
9f55855
Compare
Github, generate site |
Weird it failed to generated the fragment Edit: From just glancing, it looks like the code is looking at the source for |
@rnveach |
https://en.wikipedia.org/wiki/URI_fragment #14740 (comment) |
@rnveach I get it right now. So we expect the last link to be https://checkstyle-diff-reports.s3.us-east-2.amazonaws.com/9f55855_2024115508/property_types.html#Pattern.5B.5D I will open an issue for this to the main checkstyle repo. |
@Lmh-java i think we might have an issue open for it, please try to search and see if it turns up |
I didn't see an issue related to this specifically, I will try to open an issue. Edit: please see issue #14857. Not sure about my wording, please feel free to change. |
Thanks @Lmh-java ! |
For Issue #13758.
Pattern[]
with a fixed separator (in this PR)AbstractClassCouplingCheck
to use this new property type (in this PR)ImportOrderCheck
to replace use ofPattern[]
withString[]
(In this PR)Agreement on update is archived at #14764 (comment)