Use existing function registry

This commit is contained in:
Clément Fournier
2021-08-08 15:06:59 +02:00
parent 55c005a39e
commit 482268def8
3 changed files with 11 additions and 27 deletions

View File

@@ -5,7 +5,6 @@
package net.sourceforge.pmd.lang.ast.xpath;
import net.sourceforge.pmd.annotation.InternalApi;
import net.sourceforge.pmd.lang.ast.xpath.internal.CoreXPathFunctions;
import net.sourceforge.pmd.lang.ast.xpath.internal.FileNameXPathFunction;
import net.sf.saxon.sxpath.IndependentContext;
@@ -22,7 +21,7 @@ public class DefaultASTXPathHandler extends AbstractASTXPathHandler {
@Override
public void initialize(IndependentContext context) {
context.declareNamespace("pmd", "java:" + CoreXPathFunctions.class.getName());
// override if needed
}
}

View File

@@ -1,25 +0,0 @@
/*
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.lang.ast.xpath.internal;
import net.sourceforge.pmd.lang.ast.Node;
import net.sourceforge.pmd.lang.ast.xpath.saxon.ElementNode;
import net.sf.saxon.expr.XPathContext;
/**
* @author Clément Fournier
*/
public final class CoreXPathFunctions {
private CoreXPathFunctions() {
// util class
}
public static String fileName(final XPathContext context) {
Node ctxNode = ((ElementNode) context.getContextItem()).getUnderlyingNode();
return FileNameXPathFunction.getFileName(ctxNode);
}
}

View File

@@ -5,6 +5,11 @@
package net.sourceforge.pmd.lang.xpath;
import net.sourceforge.pmd.annotation.InternalApi;
import net.sourceforge.pmd.lang.ast.Node;
import net.sourceforge.pmd.lang.ast.xpath.internal.FileNameXPathFunction;
import net.sourceforge.pmd.lang.ast.xpath.saxon.ElementNode;
import net.sf.saxon.expr.XPathContext;
@InternalApi
@@ -37,4 +42,9 @@ public final class PMDFunctions {
String pattern5, String pattern6) {
return MatchesFunction.matches(s, pattern1, pattern2, pattern3, pattern4, pattern5, pattern6);
}
public static String fileName(final XPathContext context) {
Node ctxNode = ((ElementNode) context.getContextItem()).getUnderlyingNode();
return FileNameXPathFunction.getFileName(ctxNode);
}
}