Update some usages early

This commit is contained in:
Clément Fournier
2020-04-08 21:59:41 +02:00
parent 5067c79eb2
commit 1de1d1c66d
4 changed files with 50 additions and 21 deletions

View File

@@ -405,10 +405,11 @@ public class RuleDocGenerator {
lines.addAll(EscapeUtils.escapeLines(toLines(stripIndentation(rule.getDescription()))));
lines.add("");
if (rule instanceof XPathRule || rule instanceof RuleReference && ((RuleReference) rule).getRule() instanceof XPathRule) {
XPathRule xpathRule = asXPathRule(rule);
if (xpathRule != null) {
lines.add("**This rule is defined by the following XPath expression:**");
lines.add("``` xpath");
lines.addAll(toLines(StringUtils.stripToEmpty(rule.getProperty(XPathRule.XPATH_DESCRIPTOR))));
lines.addAll(toLines(StringUtils.stripToEmpty(xpathRule.getXPathExpression())));
lines.add("```");
} else {
lines.add("**This rule is defined by the following Java class:** "
@@ -502,6 +503,15 @@ public class RuleDocGenerator {
}
}
private XPathRule asXPathRule(Rule rule) {
if (rule instanceof XPathRule) {
return (XPathRule) rule;
} else if (rule instanceof RuleReference && ((RuleReference) rule).getRule() instanceof XPathRule) {
return (XPathRule) ((RuleReference) rule).getRule();
}
return null;
}
private static boolean isDeprecated(PropertyDescriptor<?> propertyDescriptor) {
return propertyDescriptor.description() != null
&& propertyDescriptor.description().toLowerCase(Locale.ROOT).startsWith(DEPRECATED_RULE_PROPERTY_MARKER);