null
if
- * there is no Jaxen Navigation for this language.
- *
- * @deprecated Support for Jaxen will be removed come 7.0.0. This isn't used
- * anymore
- */
- @Deprecated
- Navigator getNavigator();
+ static XPathHandler getHandlerForFunctionDefs(ExtensionFunctionDefinition first, ExtensionFunctionDefinition... defs) {
+ Setthrow
the
- * exception.
- *
- * @param name
- * Method name that is not supported.
- * @return A UnsupportedOperationException indicated the method is not
- * supported by the implementation class.
- */
- protected UnsupportedOperationException createUnsupportedOperationException(String name) {
- return new UnsupportedOperationException(name + " is not implemented by " + this.getClass().getName());
- }
-}
diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/saxon/AttributeAxisIterator.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/saxon/AttributeAxisIterator.java
deleted file mode 100644
index d22adb33ab..0000000000
--- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/saxon/AttributeAxisIterator.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/**
- * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
- */
-
-package net.sourceforge.pmd.lang.ast.xpath.saxon;
-
-import java.util.Iterator;
-
-import net.sourceforge.pmd.annotation.InternalApi;
-import net.sourceforge.pmd.lang.ast.xpath.Attribute;
-
-import net.sf.saxon.om.Navigator;
-import net.sf.saxon.om.SequenceIterator;
-
-/**
- * An adapter over our {@link net.sourceforge.pmd.lang.ast.xpath.AttributeAxisIterator}
- * for the Saxon model.
- */
-@Deprecated
-@InternalApi
-public class AttributeAxisIterator extends Navigator.BaseEnumeration {
-
- protected final ElementNode startNodeInfo;
- protected final Iteratortrue
if the XPath version is supported,
- * false
otherwise.
- */
- protected abstract boolean isSupportedVersion(String version);
-
- @Override
- public void setProperties(MapExample XPath 2.0: {@code //ClassOrInterfaceType[pmd-java:typeIsExactly('java.lang.String')]} + * + *
Returns true if the type of the node matches, false otherwise. + */ +public class TypeIsExactlyFunction extends BaseJavaXPathFunction { + + + protected TypeIsExactlyFunction() { + super("typeIsExactly"); } @Override - public Object call(final Context context, final List args) throws FunctionCallException { - if (args.size() != 1) { - throw new IllegalArgumentException( - "typeIsExactly function takes a single String argument with the fully qualified type name to check against."); - } - final String fullTypeName = (String) args.get(0); - final Node n = (Node) context.getNodeSet().get(0); - - return typeIsExactly(n, fullTypeName); + public SequenceType[] getArgumentTypes() { + return new SequenceType[]{SequenceType.SINGLE_STRING}; } - /** - * Example XPath 1.0: {@code //ClassOrInterfaceType[typeIsExactly('java.lang.String')]} - *
- * Example XPath 2.0: {@code //ClassOrInterfaceType[pmd-java:typeIsExactly('java.lang.String')]} - * - * @param n The node on which to check for types - * @param fullTypeName The fully qualified name of the class or any supertype - * @return True if the type of the node matches, false otherwise. - */ - public static boolean typeIsExactly(final Node n, final String fullTypeName) { - if (n instanceof TypeNode) { - return TypeHelper.isExactlyA((TypeNode) n, fullTypeName); - } else { - throw new IllegalArgumentException("typeIsExactly function may only be called on a TypeNode."); - } + + @Override + public SequenceType getResultType(SequenceType[] suppliedArgumentTypes) { + return SequenceType.SINGLE_BOOLEAN; } + + + @Override + public boolean dependsOnFocus() { + return true; + } + + @Override + public ExtensionFunctionCall makeCallExpression() { + return new ExtensionFunctionCall() { + @Override + public Sequence call(XPathContext context, Sequence[] arguments) throws XPathException { + Node contextNode = ((AstNodeWrapper) context.getContextItem()).getUnderlyingNode(); + String fullTypeName = arguments[0].head().getStringValue(); + + if (contextNode instanceof TypeNode) { + return BooleanValue.get(TypeHelper.isExactlyA((TypeNode) contextNode, fullTypeName)); + } else { + throw new IllegalArgumentException("typeIs function may only be called on a TypeNode."); + } + } + }; + } + } diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/xpath/TypeIsFunction.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/xpath/TypeIsFunction.java index 1bf3853df9..53cddd66a8 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/xpath/TypeIsFunction.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/xpath/TypeIsFunction.java @@ -4,55 +4,64 @@ package net.sourceforge.pmd.lang.java.xpath; -import java.util.List; - -import org.jaxen.Context; -import org.jaxen.Function; -import org.jaxen.FunctionCallException; -import org.jaxen.SimpleFunctionContext; -import org.jaxen.XPathFunctionContext; - -import net.sourceforge.pmd.annotation.InternalApi; import net.sourceforge.pmd.lang.ast.Node; +import net.sourceforge.pmd.lang.ast.xpath.internal.AstNodeWrapper; import net.sourceforge.pmd.lang.java.ast.TypeNode; import net.sourceforge.pmd.lang.java.typeresolution.TypeHelper; +import net.sf.saxon.expr.XPathContext; +import net.sf.saxon.lib.ExtensionFunctionCall; +import net.sf.saxon.om.Sequence; +import net.sf.saxon.trans.XPathException; +import net.sf.saxon.value.BooleanValue; +import net.sf.saxon.value.SequenceType; -@InternalApi -@Deprecated -public class TypeIsFunction implements Function { - public static void registerSelfInSimpleContext() { - ((SimpleFunctionContext) XPathFunctionContext.getInstance()).registerFunction(null, "typeIs", - new TypeIsFunction()); +/** + * XPath function {@code pmd-java:typeIs(typeName as xs:string) as xs:boolean}. + * + *
Example XPath 2.0: {@code //ClassOrInterfaceType[pmd-java:typeIs('java.lang.String')]} + * + *
Returns true if the type of the node matches, false otherwise. + */ +public class TypeIsFunction extends BaseJavaXPathFunction { + + + protected TypeIsFunction() { + super("typeIs"); } @Override - public Object call(final Context context, final List args) throws FunctionCallException { - if (args.size() != 1) { - throw new IllegalArgumentException( - "typeIs function takes a single String argument with the fully qualified type name to check against."); - } - final String fullTypeName = (String) args.get(0); - final Node n = (Node) context.getNodeSet().get(0); - - return typeIs(n, fullTypeName); + public SequenceType[] getArgumentTypes() { + return new SequenceType[]{SequenceType.SINGLE_STRING}; } - /** - * Example XPath 1.0: {@code //ClassOrInterfaceType[typeIs('java.lang.String')]} - *
- * Example XPath 2.0: {@code //ClassOrInterfaceType[pmd-java:typeIs('java.lang.String')]}
- *
- * @param n The node on which to check for types
- * @param fullTypeName The fully qualified name of the class or any supertype
- * @return True if the type of the node matches, false otherwise.
- */
- public static boolean typeIs(final Node n, final String fullTypeName) {
- if (n instanceof TypeNode) {
- return TypeHelper.isA((TypeNode) n, fullTypeName);
- } else {
- throw new IllegalArgumentException("typeIs function may only be called on a TypeNode.");
- }
+
+ @Override
+ public SequenceType getResultType(SequenceType[] suppliedArgumentTypes) {
+ return SequenceType.SINGLE_BOOLEAN;
+ }
+
+
+ @Override
+ public boolean dependsOnFocus() {
+ return true;
+ }
+
+ @Override
+ public ExtensionFunctionCall makeCallExpression() {
+ return new ExtensionFunctionCall() {
+ @Override
+ public Sequence call(XPathContext context, Sequence[] arguments) throws XPathException {
+ Node contextNode = ((AstNodeWrapper) context.getContextItem()).getUnderlyingNode();
+ String fullTypeName = arguments[0].head().getStringValue();
+
+ if (contextNode instanceof TypeNode) {
+ return BooleanValue.get(TypeHelper.isA((TypeNode) contextNode, fullTypeName));
+ } else {
+ throw new IllegalArgumentException("typeIs function may only be called on a TypeNode.");
+ }
+ }
+ };
}
}
diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/xpath/TypeOfFunction.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/xpath/TypeOfFunction.java
deleted file mode 100644
index 2fe6167146..0000000000
--- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/xpath/TypeOfFunction.java
+++ /dev/null
@@ -1,115 +0,0 @@
-/**
- * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
- */
-
-package net.sourceforge.pmd.lang.java.xpath;
-
-import java.util.Arrays;
-import java.util.List;
-import java.util.logging.Logger;
-
-import org.jaxen.Context;
-import org.jaxen.Function;
-import org.jaxen.FunctionCallException;
-import org.jaxen.SimpleFunctionContext;
-import org.jaxen.XPathFunctionContext;
-
-import net.sourceforge.pmd.PMDVersion;
-import net.sourceforge.pmd.lang.ast.Node;
-import net.sourceforge.pmd.lang.ast.xpath.Attribute;
-import net.sourceforge.pmd.lang.java.ast.TypeNode;
-
-@Deprecated
-public class TypeOfFunction implements Function {
-
- private static final Logger LOG = Logger.getLogger(TypeOfFunction.class.getName());
- private static boolean deprecationWarned = false;
-
- public static void registerSelfInSimpleContext() {
- ((SimpleFunctionContext) XPathFunctionContext.getInstance()).registerFunction(null, "typeof",
- new TypeOfFunction());
- }
-
- @Override
- public Object call(Context context, List args) throws FunctionCallException {
- nagDeprecatedFunction();
-
- String nodeTypeName = null;
- String fullTypeName = null;
- String shortTypeName = null;
- Attribute attr = null;
- for (int i = 0; i < args.size(); i++) {
- if (args.get(i) instanceof List) {
- if (attr == null) {
- attr = ((List
- * Example XPath 2.0: {@code //ClassOrInterfaceType[pmd-java:typeof(@Image, 'java.lang.String', 'String')]}
- *
- * @param n
- * @param nodeTypeName Usually the {@code @Image} attribute of the node
- * @param fullTypeName The fully qualified name of the class or any supertype
- * @param shortTypeName The simple class name, might be null
- * @return
- */
- public static boolean typeof(Node n, String nodeTypeName, String fullTypeName, String shortTypeName) {
- nagDeprecatedFunction();
-
- if (n instanceof TypeNode) {
- Class> type = ((TypeNode) n).getType();
- if (type == null) {
- return nodeTypeName != null
- && (nodeTypeName.equals(fullTypeName) || nodeTypeName.equals(shortTypeName));
- }
- if (type.getName().equals(fullTypeName)) {
- return true;
- }
- List