diff --git a/docs/pages/release_notes_pmd7.md b/docs/pages/release_notes_pmd7.md index 3e267577b5..e57d6c827a 100644 --- a/docs/pages/release_notes_pmd7.md +++ b/docs/pages/release_notes_pmd7.md @@ -1129,6 +1129,7 @@ The annotation `@DeprecatedUntil700` has been removed. * `hasOverriddenProperty(PropertyDescriptor)` - use {%jdoc core::lang.rule.RuleReference#isPropertyOverridden(core::properties.PropertyDescriptor) %} instead. * {%jdoc core::lang.rule.xpath.XPathRule %} * The constant `XPATH_DESCRIPTOR` has been made private and is not accessible anymore. + * The default constructor has been made package-private and is not accessible anymore. * {%jdoc core::lang.Language %} - method `getTerseName()` removed. Use {%jdoc core::lang.Language#getId() %} instead. * {%jdoc core::lang.LanguageModuleBase %} - method `getTerseName()` removed. Use {%jdoc core::lang.LanguageModuleBase#getId() %} instead. * {%jdoc core::lang.LanguageRegistry %} - the following methods have been removed: diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/InternalApiBridge.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/InternalApiBridge.java index bad7bf8168..6051910342 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/InternalApiBridge.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/InternalApiBridge.java @@ -24,4 +24,8 @@ public final class InternalApiBridge { public static String replacementIfDeprecated(Attribute attribute) { return attribute.replacementIfDeprecated(); } + + public static XPathRule newXPathRule() { + return new XPathRule(); + } } diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/XPathRule.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/XPathRule.java index dec9726fc8..4fbef8e9ae 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/XPathRule.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/XPathRule.java @@ -25,6 +25,7 @@ import net.sourceforge.pmd.properties.PropertyDescriptor; import net.sourceforge.pmd.properties.PropertyFactory; import net.sourceforge.pmd.reporting.RuleContext; import net.sourceforge.pmd.util.IteratorUtil; +import net.sourceforge.pmd.util.internal.ResourceLoader; /** @@ -51,12 +52,10 @@ public final class XPathRule extends AbstractRule { /** - * @deprecated This is now only used by the ruleset loader. When - * we have syntactic sugar for XPath rules in the XML, we won't - * need this anymore. + * This is only used by the ruleset loader. + * @see ResourceLoader#loadRuleFromClassPath(String) */ - @Deprecated - public XPathRule() { + XPathRule() { definePropertyDescriptor(XPATH_DESCRIPTOR); } diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/util/internal/ResourceLoader.java b/pmd-core/src/main/java/net/sourceforge/pmd/util/internal/ResourceLoader.java index e76576c78e..15dfa27989 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/util/internal/ResourceLoader.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/util/internal/ResourceLoader.java @@ -18,6 +18,8 @@ import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; import net.sourceforge.pmd.lang.rule.Rule; +import net.sourceforge.pmd.lang.rule.xpath.InternalApiBridge; +import net.sourceforge.pmd.lang.rule.xpath.XPathRule; /** * @apiNote Internal API @@ -129,6 +131,9 @@ public class ResourceLoader { * Load the rule from the classloader from resource loader, consistent with the ruleset */ public Rule loadRuleFromClassPath(final String clazz) throws ClassNotFoundException, IllegalAccessException, InstantiationException { + if (XPathRule.class.getName().equals(clazz)) { + return InternalApiBridge.newXPathRule(); + } return (Rule) classLoader.loadClass(clazz).newInstance(); } }