Skip to content

Issue #17310: Added new Notes Macro#17311

Merged
romani merged 1 commit into
checkstyle:masterfrom
SteLeo1602:notesMacro
Jul 14, 2025
Merged

Issue #17310: Added new Notes Macro#17311
romani merged 1 commit into
checkstyle:masterfrom
SteLeo1602:notesMacro

Conversation

@SteLeo1602

@SteLeo1602 SteLeo1602 commented Jul 3, 2025

Copy link
Copy Markdown
Contributor

Issue: #17310

Comment on lines +75 to +104
/**
* Assigns values to each instance variable.
*
* @param moduleName name of module.
* @return set of property names.
* @throws MacroExecutionException if the module could not be retrieved.
*/
private static Set<String> getPropertyNames(String moduleName)
throws MacroExecutionException {
final Object instance = SiteUtil.getModuleInstance(moduleName);
final Class<?> clss = instance.getClass();

return SiteUtil.getPropertiesForDocumentation(clss, instance);
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#17278 will be merged soon. DescriptionMacro.java also has this method. We should move it to a common place from where both of these files can access this method.

Should we move it to JavadocMetadataScraper class or create a new common Parent class which will have these methods @romani ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moving to common should be delayed.
We will do unification with JavadocMetadataScraper, and reduction of doing the same, only after macroses fully cover our code base, and functionally we will be satisfied.
There will be a lot of surprises as move forward with migrations, so this implementation might change.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SteLeo1602 , please create issue to move all potentially same methods to some common utility class to reuse between macroses.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SteLeo1602 , please respond on above comment

@SteLeo1602 SteLeo1602 Jul 12, 2025

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done: #17371

@romani

romani commented Jul 6, 2025

Copy link
Copy Markdown
Member

@SteLeo1602 , please rebase.

✔ ~/java/github/romani/checkstyle [SteLeo1602/notesMacro L|✔] 
$ mvn clean test
...
[INFO] Running com.puppycrawl.tools.checkstyle.internal.XdocsJavaDocsTest
[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 2.048 s <<< FAILURE! -- in com.puppycrawl.tools.checkstyle.internal.XdocsJavaDocsTest
[ERROR] com.puppycrawl.tools.checkstyle.internal.XdocsJavaDocsTest.testAllCheckSectionJavaDocs -- Time elapsed: 2.046 s <<< ERROR!
java.lang.Error: Error was thrown while processing src/main/java/com/puppycrawl/tools/checkstyle/checks/blocks/EmptyCatchBlockCheck.java
	at com.puppycrawl.tools.checkstyle.Checker.processFiles(Checker.java:320)
	at com.puppycrawl.tools.checkstyle.Checker.process(Checker.java:226)
	at com.puppycrawl.tools.checkstyle.internal.XdocsJavaDocsTest.assertCheckSection(XdocsJavaDocsTest.java:178)
	at com.puppycrawl.tools.checkstyle.internal.XdocsJavaDocsTest.testAllCheckSectionJavaDocs(XdocsJavaDocsTest.java:151)
	at java.base/java.lang.reflect.Method.invoke(Method.java:569)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
Caused by: EmptyCatchBlock's class-level JavaDoc
diff (-expected +actual):
    @@ -1,4 +1,4 @@
    -<div>Checks for empty catch blocks. By default, check allows empty catch block with any comment inside.</div><div>Checks for empty catch blocks. By default, check allows empty catch block with any comment inside.</div> Notes:
    +<div>Checks for empty catch blocks. By default, check allows empty catch block with any comment inside.</div> Notes:
     <p>
     There are two options to make validation more precise: <b>exceptionVariableName</b> and <b>commentFormat</b>. If both options are specified - they are applied by <b>any of them is matching</b>.
     </p>
	at com.puppycrawl.tools.checkstyle.internal.XdocsJavaDocsTest$JavaDocCapture.visitClass(XdocsJavaDocsTest.java:638)
	at com.puppycrawl.tools.checkstyle.internal.XdocsJavaDocsTest$JavaDocCapture.visitToken(XdocsJavaDocsTest.java:586)
	at com.puppycrawl.tools.checkstyle.TreeWalker.notifyVisit(TreeWalker.java:393)
	at com.puppycrawl.tools.checkstyle.TreeWalker.processIter(TreeWalker.java:466)
	at com.puppycrawl.tools.checkstyle.TreeWalker.walk(TreeWalker.java:331)
	at com.puppycrawl.tools.checkstyle.TreeWalker.processFiltered(TreeWalker.java:215)
	at com.puppycrawl.tools.checkstyle.api.AbstractFileSetCheck.process(AbstractFileSetCheck.java:101)
	at com.puppycrawl.tools.checkstyle.Checker.processFile(Checker.java:340)
	at com.puppycrawl.tools.checkstyle.Checker.processFiles(Checker.java:299)
	at com.puppycrawl.tools.checkstyle.Checker.process(Checker.java:226)
	at com.puppycrawl.tools.checkstyle.internal.XdocsJavaDocsTest.assertCheckSection(XdocsJavaDocsTest.java:178)
	at com.puppycrawl.tools.checkstyle.internal.XdocsJavaDocsTest.testAllCheckSectionJavaDocs(XdocsJavaDocsTest.java:151)
	at [[Reflective call: 4 frames collapsed (https://goo.gl/aH3UyP)]].(:0)
	at [[Testing framework: 28 frames collapsed (https://goo.gl/aH3UyP)]].(:0)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
	at [[Testing framework: 9 frames collapsed (https://goo.gl/aH3UyP)]].(:0)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
	at [[Testing framework: 26 frames collapsed (https://goo.gl/aH3UyP)]].(:0)
	at org.apache.maven.surefire.junitplatform.LazyLauncher.execute(LazyLauncher.java:56)
	at org.apache.maven.surefire.junitplatform.JUnitPlatformProvider.execute(JUnitPlatformProvider.java:194)
	at org.apache.maven.surefire.junitplatform.JUnitPlatformProvider.invokeAllTests(JUnitPlatformProvider.java:150)
	at org.apache.maven.surefire.junitplatform.JUnitPlatformProvider.invoke(JUnitPlatformProvider.java:124)
	at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:385)
	at org.apache.maven.surefire.booter.ForkedBooter.execute(ForkedBooter.java:162)
	at org.apache.maven.surefire.booter.ForkedBooter.run(ForkedBooter.java:507)
	at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:495)

....
^C✘-INT ~/java/github/romani/checkstyle [SteLeo1602/notesMacro L|✚ 1] 
06:41 $ 
✘-INT ~/java/github/romani/checkstyle [SteLeo1602/notesMacro L|✚ 1] 
06:45 $ git diff
diff --git a/src/site/xdoc/checks/blocks/emptycatchblock.xml b/src/site/xdoc/checks/blocks/emptycatchblock.xml
index 8356df7eef..b00a65a7d8 100644
--- a/src/site/xdoc/checks/blocks/emptycatchblock.xml
+++ b/src/site/xdoc/checks/blocks/emptycatchblock.xml
@@ -16,9 +16,15 @@
       </subsection>
 
       <subsection name="Notes" id="Notes">
+        <div>
+          Checks for empty catch blocks.
+          By default, check allows empty catch block with any comment inside.
+        </div>
+
+Notes:
         <p>
           There are two options to make validation more precise: <b>exceptionVariableName</b> and
-          <b>commentFormat</b>.
+        <b>commentFormat</b>.
           If both options are specified - they are applied by <b>any of them is matching</b>.
         </p>
       </subsection>

macros is breathing , but polishing is required.

@SteLeo1602 SteLeo1602 force-pushed the notesMacro branch 2 times, most recently from fa37ce7 to a1d0bca Compare July 9, 2025 04:22
@SteLeo1602

Copy link
Copy Markdown
Contributor Author

GitHub, generate website

Comment thread src/main/java/com/puppycrawl/tools/checkstyle/site/NotesMacro.java Outdated
Comment thread src/main/java/com/puppycrawl/tools/checkstyle/site/NotesMacro.java Outdated

@romani romani left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Items

Comment thread src/main/java/com/puppycrawl/tools/checkstyle/site/NotesMacro.java Outdated

@romani romani left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Items

Comment thread src/main/java/com/puppycrawl/tools/checkstyle/site/NotesMacro.java Outdated
Comment thread src/main/java/com/puppycrawl/tools/checkstyle/site/NotesMacro.java Outdated
@SteLeo1602 SteLeo1602 force-pushed the notesMacro branch 2 times, most recently from 7354a09 to 3db3e20 Compare July 11, 2025 06:56
Comment thread src/main/java/com/puppycrawl/tools/checkstyle/site/NotesMacro.java
Comment thread src/main/java/com/puppycrawl/tools/checkstyle/site/NotesMacro.java
Comment thread src/main/java/com/puppycrawl/tools/checkstyle/site/NotesMacro.java Outdated
Comment thread src/main/java/com/puppycrawl/tools/checkstyle/site/NotesMacro.java
Comment on lines +103 to +110
if (NotesMacro.getNotesStartIndex(moduleJavadoc) > -1) {
descriptionEndIndex += NotesMacro.getNotesStartIndex(moduleJavadoc);
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a good way to use common methods. We shouldn't use method directly from other Macro. Instead we should have a common class for all Macros to use the util methods v

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, the common util development is in progress in #17377

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can still see it's usage. For now just copy paste the common methods in macros. We'll move them toa common place as part of the issue you linked.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved

@romani romani left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets merge this, we can improve in followup PRs.
There two PRs already open that are based on this PR

Comment on lines +130 to +136
/**
* Gets the start index of the Notes section.
*
* @param moduleJavadoc javadoc of module.
* @return start index.
*/
public static int getNotesStartIndex(DetailNode moduleJavadoc) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we have this method inside description macro?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To check if there is Notes section in module's javadoc

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (NotesMacro.getNotesStartIndex(moduleJavadoc) > -1) {
descriptionEndIndex += NotesMacro.getNotesStartIndex(moduleJavadoc);
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have used NotesMacro's static method.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will be the util's soon

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please follow this:#17311 (comment)

Do not use NotesMacro inside Description Macro. You have copy pasted the method in the Macro, just use it instead of using NotesMacro's public static method

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved

@Zopsss Zopsss left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@romani romani merged commit 6f07680 into checkstyle:master Jul 14, 2025
117 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants