Issue #13626: Reuse in metadata module scrapper all methods to get data from javadoc and reflection only#13670
Issue #13626: Reuse in metadata module scrapper all methods to get data from javadoc and reflection only#13670stoyanK7 wants to merge 1 commit intocheckstyle:masterfrom stoyanK7:13626
Conversation
|
@stoyanK7 let's rebase and prepare for review :) |
src/main/java/com/puppycrawl/tools/checkstyle/meta/MetadataGeneratorUtil.java
Outdated
Show resolved
Hide resolved
src/main/java/com/puppycrawl/tools/checkstyle/meta/MetadataGeneratorUtil.java
Outdated
Show resolved
Hide resolved
src/main/java/com/puppycrawl/tools/checkstyle/meta/MetadataGeneratorUtil.java
Outdated
Show resolved
Hide resolved
src/main/java/com/puppycrawl/tools/checkstyle/meta/MetadataGeneratorUtil.java
Outdated
Show resolved
Hide resolved
src/main/java/com/puppycrawl/tools/checkstyle/meta/MetadataGeneratorUtil.java
Show resolved
Hide resolved
src/main/java/com/puppycrawl/tools/checkstyle/meta/MetadataGeneratorUtil.java
Outdated
Show resolved
Hide resolved
...resources/com/puppycrawl/tools/checkstyle/meta/checks/annotation/AnnotationLocationCheck.xml
Outdated
Show resolved
Hide resolved
src/main/java/com/puppycrawl/tools/checkstyle/meta/MetadataGeneratorUtil.java
Show resolved
Hide resolved
| import javax.xml.parsers.ParserConfigurationException; | ||
| import javax.xml.transform.TransformerException; | ||
|
|
||
| import org.apache.maven.doxia.macro.MacroExecutionException; |
There was a problem hiding this comment.
It isn't ideal that the metadata module uses the site module. I think it's better if the opposite is the case - the site module uses the metadata module. Shall we deal with this in a follow-up issue?
There was a problem hiding this comment.
We will refactor later on to move methods around to make it better design wise.
For now let's focus on functionality to unblock ability to remove properties from javadoc
There was a problem hiding this comment.
Let's collect ideas at #13699 to improve in separate PRs
|
I think PR is ready to not have commit for disablement of CIs, please remove. Please rephrase commit message, as you do not rewrite but you change a way we get data and we will do this very gradually. |
…ta from javadoc and reflection only
| * @param propertyJavadoc property javadoc. | ||
| * @return property description. | ||
| */ | ||
| private static String getPropertyDescription(String property, DetailNode propertyJavadoc) { |
There was a problem hiding this comment.
I am not sure why this method is specific for metadata.
I think there should single method that does it for xdoc and meta and meta generation just reuse it
Same for getPropertyDefaultValue
If agree please create separate issue to improve in separate PR
There was a problem hiding this comment.
I think there should be separate methods for xdoc and metadata. Or at least single method with different output depending on who/what is calling it.
Metadata gets text as-is and doesn't care about any processing.
Xdoc requires to
- convert
{@code something}to<code>something</code> - Convert links to relative ones-
https://checkstyle.org/checks/block/xxx.html->../block/xx.html, for example
There was a problem hiding this comment.
But still data creation should be single method and xdoc just do only such required formatting. If you agree just put this to separate issue that we have for design improvement as item.
romani
left a comment
There was a problem hiding this comment.
Ok to merge to unblock massive removal of javadoc content.
We will improve in separate PRs
|
@stoyanK7 , please make CI green. |
| <exclude> | ||
| com.puppycrawl.tools.checkstyle.api.AutomaticBean* | ||
| </exclude> | ||
| <exclude>com.puppycrawl.tools.checkstyle.meta.MetadataGeneratorUtil</exclude> |
There was a problem hiding this comment.
@romani should we create an issue for coverage in this class and revisit later?
There was a problem hiding this comment.
This is jacoco coverage.
The only time it makes sense if we ever move all functionality to separate project and we remote xdoc files from git completely, as we will never see how content looks like before html generations.
Before this time, all such methods should not have to work on all possible cases, code should serve our current cases of Checks and xdoc/meta. So coverage has no much meaning.
Do we need such issue ? As we do not even has plan to move it out
There was a problem hiding this comment.
If you agree, please copy my comment or part of it to description at #13426 as requirements
| /** No-argument constructor. */ | ||
| public ModuleDetails() { | ||
| // empty constructor | ||
| } |
There was a problem hiding this comment.
Compile error https://stackoverflow.com/a/5286532/1015848
We still have old code of metadata that use default ctor.
We are not rewriting metadata, we migrate it to use new method to get data that are based on reflection and javadoc
There was a problem hiding this comment.
There is usage of it in JavadocMetadataScraper
| /** No-argument constructor. */ | ||
| public ModulePropertyDetails() { | ||
| // empty constructor | ||
| } |
There was a problem hiding this comment.
Same as above, why do we need this?
There was a problem hiding this comment.
Same as above
| Lists.reverse(Arrays.asList(detailNode.getChildren())).forEach(stack::push); | ||
|
|
||
| final String childText = detailNode.getText(); | ||
| // Regular expression for detecting ANTLR tokens(for e.g. CLASS_DEF). |
There was a problem hiding this comment.
Unless I am missing something, we are not doing anything with ANTLR tokens, ANTLR is an internal detail of parser/AST implementation. Outside of these usages, these just become JavadocTokenTypes.
There was a problem hiding this comment.
Can we just use
to get a list of actual tokens and check that?| final Path templatePath = SiteUtil.getTemplatePath( | ||
| SiteUtil.removeCheckSuffix(SiteUtil.getModuleName(file)) |
There was a problem hiding this comment.
We are getting crazy with utility method usage and creation. Why can't we do a simple replace with Check as target?
| * @param moduleName module name. | ||
| * @return module type. | ||
| */ | ||
| private static ModuleType getModuleType(String moduleName) { |
There was a problem hiding this comment.
Can we reuse/repurpose https://github.com/nrmancuso/checkstyle/blob/54616f662130aa0ca5afe45f72d36cdefb78a781/src/main/java/com/puppycrawl/tools/checkstyle/meta/JavadocMetadataScraper.java#L572 ? This seems like a lot of duplication to me.
There was a problem hiding this comment.
You mean make the one in JavadocMetadataScraper public?
There was a problem hiding this comment.
I have no strong feelings either way, but we should consider some way to avoid massive copy paste
|
|
||
| final String childText = detailNode.getText(); | ||
| // Regular expression for detecting ANTLR tokens(for e.g. CLASS_DEF). | ||
| final Pattern tokenTextPattern = Pattern.compile("([A-Z_]{2,})+"); |
There was a problem hiding this comment.
Why compile this pattern repeatedly? Can we make this a field? Even better, can we just use
to get the actual tokens?| final Set<Path> templatesPaths = SiteUtil.getXdocsTemplatesFilePaths(); | ||
| for (Path templatePath: templatesPaths) { | ||
| final String content = getFileContents(templatePath); | ||
| final String propertiesMacroDefinition = "<macro name=\"properties\""; | ||
| if (content.contains(propertiesMacroDefinition)) { | ||
| result.add(templatePath); | ||
| } | ||
| } | ||
| return result; |
There was a problem hiding this comment.
psuedocode:
return SiteUtil.getXdocsTemplatesFilePaths().stream()
.map(SiteUtil::getFileContents)
.filter(c -> c.contains(p))
.collect(Collectors.toList());| } | ||
|
|
||
| /** | ||
| * Get validation type for the given property. |
There was a problem hiding this comment.
What is a validation type?
There was a problem hiding this comment.
Actual type is int[] but business logic wise it is int values from "enum"-like class of tokens. So this helps plugins to know how to validate content. Ideally it should be hinted by source code but we never end up doing it explicitly.
Only for tokens https://github.com/search?q=repo%3Acheckstyle%2Fcheckstyle+validation-type&type=code&p=1
| Set<String> properties, Map<String, DetailNode> javadocs, | ||
| String className, Object instance) | ||
| throws MacroExecutionException { | ||
| final List<ModulePropertyDetails> result = new ArrayList<>(properties.size()); |
There was a problem hiding this comment.
result -> modulePropertyDetails
|
@stoyanK7 Since we are re-writing meta, did you verify if any of your changes will break eclipse-cs or sonar? |
|
We are not rewriting, we are using different approach to get data for metadata files that we generate. No changes in files, it means it works as before. |
|
very sad that me failed to merge this, issue is still open, I hope we can come back to it. |
Resolves #13626