Issue #13399: Implement module properties macro#13407
Conversation
|
@stoyanK7 , please share some hints of this PR status and challenges that you facing. |
|
@stoyanK7 let's get to reviewable state |
|
@stoyanK7 , please keep fixing CI failures - https://ci.appveyor.com/project/Checkstyle/checkstyle/builds/47874621/job/t52fqlfkkwhbsbsm#L310 to be ready for merge at any time. |
| result = '"' + value.toString().replace("\n", "\\n").replace("\t", "\\t") | ||
| .replace("\r", "\\r").replace("\f", "\\f") + '"'; |
There was a problem hiding this comment.
Please share an example of a check that requires this replacement. Also, is it safe to just always assume that we need to do \ -> \\?
There was a problem hiding this comment.
This method and others I have taken as-is from XdocsPagesTest - getProperties, fixCapturedProperties, getType, getDefaultValue, getPatternArrayPropertyValue, getStringArrayPropertyValue, getIntArrayPropertyValue, getFieldClass, subtractTokens.
To answer your question - running the code from XdocsPagesTest, JavadocStyle.endOfSentenceFormat pops up

Also, is it safe to just always assume that we need to do \ -> \
I think so. Makes value readable:
Value before
([.?!][
<])|([.?!]$)
Value after
([.?!][ \t\n\r\f<])|([.?!]$)
| final Object instance = SiteUtil.getModuleInstance(moduleName); | ||
| final Class<?> clss = instance.getClass(); |
There was a problem hiding this comment.
Can we do final AbstractCheck checkInstance = (AbstractCheck) SiteUtil.getModuleInstance(moduleName); and do checkInstance.getClass() in called methods to reduce the number of parameters and casts?
There was a problem hiding this comment.
It's not certain that it's always an AbstractCheck. For example filters.
|
Resolving comments right now, will move to ready for review when done. |
|
Moving back to ready for review even though CI will fail. Moved quite a bit of stuff around. |
| * Property {@code allowSamelineSingleParameterlessAnnotation} - Allow single parameterless | ||
| * Property {@code allowSamelineParameterizedAnnotation} - Allow one and only parameterized | ||
| * annotation to be located on the same line as target element. | ||
| * Type is {@code boolean}. | ||
| * Default value is {@code true}. | ||
| * Default value is {@code false}. | ||
| * </li> | ||
| * <li> | ||
| * Property {@code allowSamelineParameterizedAnnotation} - Allow one and only parameterized | ||
| * Property {@code allowSamelineSingleParameterlessAnnotation} - Allow single parameterless | ||
| * annotation to be located on the same line as target element. | ||
| * Type is {@code boolean}. | ||
| * Default value is {@code false}. | ||
| * Default value is {@code true}. |
There was a problem hiding this comment.
The reason why the metadata file and the javadoc are changed is because of the order of the properties. Properties didn't have any order until now(or do they?) so it's impossible to match their order. The order now follows the order of the setters in the module class.
There was a problem hiding this comment.
XDocs Order:
XdocsJavaDocsTest took XDoc as it is (order and all) and made sure it was in the correct format as the Javadoc.
JavadocMetadataScraper just took what was in Javadoc and placed it into meta file in the same order as the Javadoc since it uses an array list.
It seems to me, javadoc should be ordered just like xdoc, which is alphabetical order by TreeSet.
There was a problem hiding this comment.
Looks like your issue is at:
You switch over from the TreeSet to a LinkedHashSet. You shouldn't use hash sorting as different VMs can possibly create different hashes. Even if we were guaranteed hashes, we want alpha ordering here.
There was a problem hiding this comment.
You're right, getProperties uses TreeSet and then I used LinkedHashSet in this subsequent method for some reason. Changed to TreeSet.
But still. Until now, xdoc does not seem to follow alphabetical order. The only ordering asserted is whether tokens/javadocTokens is last:
Take https://checkstyle.org/checks/annotation/annotationusestyle.html for example
- elementStyle
- closingParens
- trailingArrayComma
There was a problem hiding this comment.
The only ordering asserted is whether tokens/javadocTokens is last
This was intentional as that was the ordering of tokens when I built the test.
Take https://checkstyle.org/checks/annotation/annotationusestyle.html for example
elementStyle
closingParens
trailingArrayComma
I could have sworn we ordered properties. It looks like we just ensure all properties are listed, and the order in XDoc is the order they should be in, regardless if it is alpha or random.
I recommend creating a new issue for this and this being done first. It won't be easy to review if there is a bunch of property changes like this.
There was a problem hiding this comment.
I recommend creating a new issue for this and this being done first. It won't be easy to review if there is a bunch of property changes like this.
I second this.
There was a problem hiding this comment.
Can we implement alphabet ordering now, but do not migrate numerous checks for now. So we can do:
1)migration to macroses in smaller batches
2)make massive updates for ordering first and then separate PRs wave to use macroses.
We will see later on what is less on effort.
|
|
||
| /** | ||
| * Sets whether we should apply the check to public members. | ||
| * Setter to control whether we should apply the check to public members. |
There was a problem hiding this comment.
Changed so we can match what's already in the documentation:
https://checkstyle.org/checks/naming/constantname.html#Properties
| name | description |
|---|---|
| applyToPublic | Controls whether to apply the check to public member. |
| applyToProtected | Controls whether to apply the check to protected member. |
There was a problem hiding this comment.
This was a limitation since Checkstyle does not support multi-file.
| * @param moduleName the module name. | ||
| */ | ||
| public static void setModuleName(String moduleName) { | ||
| ClassAndPropertiesSettersJavadocScraper.moduleName = moduleName; |
There was a problem hiding this comment.
we can get name of class from file name, do we need this setter ?
May be it is same question as making Module as stateless that I raised above.
| private static boolean isInCodeLiteral; | ||
| /** Variable that tells if we are in an HTML_ELEMENT token. */ | ||
| private static boolean isInHtmlElement; | ||
| /** Variable that tells if we are in an HREF attribute. */ | ||
| private static boolean isInHrefAttribute; |
There was a problem hiding this comment.
IDEA inspections:
https://app.circleci.com/pipelines/github/checkstyle/checkstyle/20544/workflows/29b03a15-8b8d-485a-bd8a-2bd63d1b2aa4/jobs/373704/artifacts
Static field <code>isInHrefAttribute</code> may not be initialized during class initialization #loc
...
Initialize it with false and checkstyle complains it is initialized to default value. Place it back in method and method becomes too complex. I am stuck with this one.
There was a problem hiding this comment.
https://sonarcloud.io/project/issues?resolved=false&types=CODE_SMELL&sinceLeakPeriod=true&pullRequest=13407&id=org.checkstyle%3Acheckstyle
Regarding the Sonarqube code smells - the first 2 ones with the brackets are not applicable because line length would become more than 100
Regarding the 2 methods that are too complex getDescriptionFromJavadoc and getDefaultValue, I don't think there's anything to gain from splitting them.
There was a problem hiding this comment.
for Inspecton: put @noisnpection StaticVariableInitialization look at more example in our code on how to do this.
There was a problem hiding this comment.
For Sonar: I agree, we can merge with violations and I suppress them in Sonar UI after merge.
romani
left a comment
There was a problem hiding this comment.
Ok to merge.
Thanks a lot for your hard work on this
nrmancuso
left a comment
There was a problem hiding this comment.
This is good for now, let's merge this and improve later.
Resolves #13399
Creates
PropertiesMacrowhich is responsible for creating the table with 5 properties - name, description, type, default value, since. Lots of code has been taken fromXdocsPagesTestas it already does what we want to.The way the macro works is:
Call
ClassAndPropertiesSettersJavadocScraperto scrape all the setter javadocs of parent classes - for exampleAbstractNameCheckwhich holds properties such asapplyToPublic,applyToProtected. Properties that are not specified in checks classes but are inherited. This step is done only once when the macro is executed for the first time.Process the module given to the macro - gather the class and setters javadocs from the file
Write the header row - name, description, type, default value, since
Get a set of the properties via the class property descriptors
Filter this set of properties - remove ones that are not supposed to be documented and add ones that are supposed to be -
tokens,fileExtensions, etc..Iterate trough this set of properties and write the 5 columns
XdocsPagesTestXdocsPagesTest@since xxxfrom class javadoc@since xxxversion from property setter Javadoc