Add XPath version maker

This commit is contained in:
Clément Fournier
2020-03-22 04:32:33 +01:00
parent 0356895cc2
commit fc304bf70c
2 changed files with 86 additions and 0 deletions

View File

@@ -6,6 +6,7 @@ package net.sourceforge.pmd.lang;
import org.jaxen.Navigator;
import net.sourceforge.pmd.Rule;
import net.sourceforge.pmd.annotation.InternalApi;
import net.sourceforge.pmd.lang.xpath.Initializer;
@@ -36,16 +37,24 @@ public interface XPathHandler {
}
};
Rule newXPathRule()
/**
* Initialize. This is intended to be called by {@link Initializer} to
* perform Language specific initialization.
*
* @deprecated Jaxen support will be removed in 7.0.0
*/
@Deprecated
void initialize();
/**
* Initialize. This is intended to be called by {@link Initializer} to
* perform Language specific initialization for Saxon.
*
* @deprecated Internal API
*/
@Deprecated
void initialize(IndependentContext context);
/**

View File

@@ -0,0 +1,77 @@
/*
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.lang.rule.xpath;
import java.util.HashMap;
import java.util.Map;
/**
* Constants for XPath language version used in XPath queries.
*/
public enum XPathVersion {
/**
* XPath 1.0.
*
* @deprecated not supported anymore
*/
@Deprecated
XPATH_1_0("1.0"),
/**
* XPath 1.0 compatibility mode.
*
* @deprecated Not supported any more.
*/
@Deprecated
XPATH_1_0_COMPATIBILITY("1.0 compatibility"),
/** XPath 2.0. */
XPATH_2_0("2.0"),
/** XPath 3.1. */
XPATH_3_1("3.1");
private static final Map<String, XPathVersion> BY_NAME = new HashMap<>();
private final String version;
static {
for (XPathVersion value : values()) {
BY_NAME.put(value.getXmlName(), value);
}
}
XPathVersion(String version) {
this.version = version;
}
/**
* Returns the string used to represent the version in the XML.
*
* @return A string representation
*/
public String getXmlName() {
return version;
}
/**
* Gets an XPath version from the string used to represent
* it in the XML.
*
* @param version A version string
*
* @return An XPath version
*
* @throws IllegalArgumentException If the argument doesn't match any known version
*/
public static XPathVersion fromString(String version) {
XPathVersion v = BY_NAME.get(version);
if (v == null) {
throw new IllegalArgumentException("Version '" + version + "' is not a valid XPath version");
}
return v;
}
}