Skip to content

Commit

Permalink
Issue checkstyle#13885: Migrate DescendantToken to properties macros
Browse files Browse the repository at this point in the history
  • Loading branch information
piyush kumar sadangi authored and romani committed Nov 2, 2023
1 parent 81ac4f5 commit c7ac036
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 101 deletions.
2 changes: 0 additions & 2 deletions config/checkstyle-non-main-files-suppressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -347,8 +347,6 @@
files="src[\\/]xdocs[\\/]checks[\\/]misc[\\/]avoidescapedunicodecharacters.xml.template"/>
<suppress id="propertiesMacroMustExist"
files="src[\\/]xdocs[\\/]checks[\\/]misc[\\/]commentsindentation.xml.template"/>
<suppress id="propertiesMacroMustExist"
files="src[\\/]xdocs[\\/]checks[\\/]misc[\\/]descendanttoken.xml.template"/>
<suppress id="propertiesMacroMustExist"
files="src[\\/]xdocs[\\/]checks[\\/]misc[\\/]finalparameters.xml.template"/>
<suppress id="propertiesMacroMustExist"
Expand Down
1 change: 1 addition & 0 deletions config/import-control.xml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
<allow class="com.puppycrawl.tools.checkstyle.utils.CheckUtil" local-only="true"/>
<allow class="com.puppycrawl.tools.checkstyle.utils.JavadocUtil" local-only="true"/>
<allow class="com.puppycrawl.tools.checkstyle.utils.TokenUtil" local-only="true"/>
<allow class="com.puppycrawl.tools.checkstyle.PropertyType"/>
</subpackage>

<subpackage name="utils">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.apache.maven.doxia.sink.Sink;
import org.codehaus.plexus.component.annotations.Component;

import com.puppycrawl.tools.checkstyle.PropertyType;
import com.puppycrawl.tools.checkstyle.api.AbstractCheck;
import com.puppycrawl.tools.checkstyle.api.DetailNode;
import com.puppycrawl.tools.checkstyle.checks.javadoc.AbstractJavadocCheck;
Expand All @@ -50,6 +51,12 @@
@Component(role = Macro.class, hint = "properties")
public class PropertiesMacro extends AbstractMacro {

/** Represents the relative path to the property types XML. */
private static final String PROPERTY_TYPES_XML = "property_types.xml";

/** Represents the format string for constructing URLs with two placeholders. */
private static final String URL_F = "%s#%s";

/** Reflects start of a code segment. */
private static final String CODE_START = "<code>";

Expand Down Expand Up @@ -311,20 +318,44 @@ else if (SiteUtil.JAVADOC_TOKENS.equals(propertyName)) {
}
else {
final String type = SiteUtil.getType(field, propertyName, currentModuleName, instance);
final String relativePathToPropertyTypes =
SiteUtil.getLinkToDocument(currentModuleName, "property_types.xml");
final String escapedType = type
.replace("[", ".5B")
.replace("]", ".5D");
final String url =
String.format(Locale.ROOT, "%s#%s", relativePathToPropertyTypes, escapedType);
sink.link(url);
sink.text(type);
sink.link_();
if (PropertyType.TOKEN_ARRAY.getDescription().equals(type)) {
processLinkForTokenTypes(sink);
}
else {
final String relativePathToPropertyTypes =
SiteUtil.getLinkToDocument(currentModuleName, PROPERTY_TYPES_XML);
final String escapedType = type
.replace("[", ".5B")
.replace("]", ".5D");

final String url =
String.format(Locale.ROOT, URL_F, relativePathToPropertyTypes, escapedType);

sink.link(url);
sink.text(type);
sink.link_();
}
}
sink.tableCell_();
}

/**
* Writes a formatted link for "TokenTypes" to the given sink.
*
* @param sink The output target where the link is written.
* @throws MacroExecutionException If an error occurs during the link processing.
*/
private static void processLinkForTokenTypes(Sink sink)
throws MacroExecutionException {
final String link =
SiteUtil.getLinkToDocument(currentModuleName, SiteUtil.PATH_TO_TOKEN_TYPES);

sink.text("subset of tokens ");
sink.link(link);
sink.text("TokenTypes");
sink.link_();
}

/**
* Write a link when all types of token supported.
*
Expand Down
10 changes: 2 additions & 8 deletions src/xdocs/checks/misc/descendanttoken.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,7 @@
<tr>
<td>limitedTokens</td>
<td>Specify set of tokens with limited occurrences as descendants.</td>
<td>
subset of tokens
<a href="../../apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html">TokenTypes</a>
</td>
<td>subset of tokens <a href="../../apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html">TokenTypes</a></td>
<td><code>{}</code></td>
<td>3.2</td>
</tr>
Expand Down Expand Up @@ -87,10 +84,7 @@
</tr>
<tr>
<td>sumTokenCounts</td>
<td>
Control whether the number of tokens found should be calculated
from the sum of the individual token counts.
</td>
<td>Control whether the number of tokens found should be calculated from the sum of the individual token counts.</td>
<td><a href="../../property_types.html#boolean">boolean</a></td>
<td><code>false</code></td>
<td>5.0</td>
Expand Down
85 changes: 4 additions & 81 deletions src/xdocs/checks/misc/descendanttoken.xml.template
Original file line number Diff line number Diff line change
Expand Up @@ -25,87 +25,10 @@

<subsection name="Properties" id="Properties">
<div class="wrapper">
<table>
<tr>
<th>name</th>
<th>description</th>
<th>type</th>
<th>default value</th>
<th>since</th>
</tr>
<tr>
<td>limitedTokens</td>
<td>Specify set of tokens with limited occurrences as descendants.</td>
<td>
subset of tokens
<a href="../../apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html">TokenTypes</a>
</td>
<td><code>{}</code></td>
<td>3.2</td>
</tr>
<tr>
<td>maximumDepth</td>
<td>Specify the maximum depth for descendant counts.</td>
<td><a href="../../property_types.html#int">int</a></td>
<td><code>2147483647</code></td>
<td>3.2</td>
</tr>
<tr>
<td>maximumMessage</td>
<td>Define the violation message when the maximum count is exceeded.</td>
<td><a href="../../property_types.html#String">String</a></td>
<td><code>null</code></td>
<td>3.2</td>
</tr>
<tr>
<td>maximumNumber</td>
<td>Specify a maximum count for descendants.</td>
<td><a href="../../property_types.html#int">int</a></td>
<td><code>2147483647</code></td>
<td>3.2</td>
</tr>
<tr>
<td>minimumDepth</td>
<td>Specify the minimum depth for descendant counts.</td>
<td><a href="../../property_types.html#int">int</a></td>
<td><code>0</code></td>
<td>3.2</td>
</tr>
<tr>
<td>minimumMessage</td>
<td>Define the violation message when the minimum count is not reached.</td>
<td><a href="../../property_types.html#String">String</a></td>
<td><code>null</code></td>
<td>3.2</td>
</tr>
<tr>
<td>minimumNumber</td>
<td>Specify a minimum count for descendants.</td>
<td><a href="../../property_types.html#int">int</a></td>
<td><code>0</code></td>
<td>3.2</td>
</tr>
<tr>
<td>sumTokenCounts</td>
<td>
Control whether the number of tokens found should be calculated
from the sum of the individual token counts.
</td>
<td><a href="../../property_types.html#boolean">boolean</a></td>
<td><code>false</code></td>
<td>5.0</td>
</tr>
<tr>
<td>tokens</td>
<td>tokens to check</td>
<td>set of any supported
<a href="../../apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html">
tokens</a>
</td>
<td><code>empty</code></td>
<td>3.2</td>
</tr>
</table>
<macro name="properties">
<param name="modulePath"
value="src/main/java/com/puppycrawl/tools/checkstyle/checks/DescendantTokenCheck.java"/>
</macro>
</div>
</subsection>

Expand Down

0 comments on commit c7ac036

Please sign in to comment.