Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
rbri committed Dec 8, 2023
1 parent 0c39261 commit 1277bb8
Show file tree
Hide file tree
Showing 144 changed files with 1,577 additions and 1,515 deletions.
9 changes: 9 additions & 0 deletions checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@

<module name="TreeWalker">


<!-- Checks for Naming Conventions. -->
<!-- See http://checkstyle.sf.net/config_naming.html -->
<module name="LocalFinalVariableName"/>

<!-- Checks for imports -->
<!-- See http://checkstyle.sf.net/config_imports.html -->
<module name="AvoidStarImport"/>
Expand All @@ -35,6 +40,10 @@
<module name="UnnecessarySemicolonInEnumeration"/>
<module name="UnnecessarySemicolonInTryWithResources"/>

<module name="FinalLocalVariable">
<property name="tokens" value="VARIABLE_DEF,PARAMETER_DEF"/>
<property name="validateEnhancedForLoopVariable" value="true"/>
</module>
<module name="MissingOverride"/>
</module>
</module>
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@
<configuration>
<java>
<googleJavaFormat>
<version>1.7</version>
<version>1.8</version>
</googleJavaFormat>
</java>
</configuration>
Expand Down
44 changes: 25 additions & 19 deletions src/main/java/org/htmlunit/xpath/XPathAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ public class XPathAPI {
* @return The first node found that matches the XPath, or null.
* @throws TransformerException in case of error
*/
public static Node selectSingleNode(Node contextNode, String str) throws TransformerException {
public static Node selectSingleNode(final Node contextNode, final String str)
throws TransformerException {
return selectSingleNode(contextNode, str, contextNode);
}

Expand All @@ -65,11 +66,12 @@ public static Node selectSingleNode(Node contextNode, String str) throws Transfo
* @return The first node found that matches the XPath, or null.
* @throws TransformerException in case of error
*/
public static Node selectSingleNode(Node contextNode, String str, Node namespaceNode)
public static Node selectSingleNode(
final Node contextNode, final String str, final Node namespaceNode)
throws TransformerException {

// Have the XObject return its result as a NodeSetDTM.
NodeIterator nl = selectNodeIterator(contextNode, str, namespaceNode);
final NodeIterator nl = selectNodeIterator(contextNode, str, namespaceNode);

// Return the first node, or null
return nl.nextNode();
Expand All @@ -84,7 +86,7 @@ public static Node selectSingleNode(Node contextNode, String str, Node namespace
* @return A NodeIterator, should never be null.
* @throws TransformerException in case of error
*/
public static NodeIterator selectNodeIterator(Node contextNode, String str)
public static NodeIterator selectNodeIterator(final Node contextNode, final String str)
throws TransformerException {
return selectNodeIterator(contextNode, str, contextNode);
}
Expand All @@ -99,11 +101,12 @@ public static NodeIterator selectNodeIterator(Node contextNode, String str)
* @return A NodeIterator, should never be null.
* @throws TransformerException in case of error
*/
public static NodeIterator selectNodeIterator(Node contextNode, String str, Node namespaceNode)
public static NodeIterator selectNodeIterator(
final Node contextNode, final String str, final Node namespaceNode)
throws TransformerException {

// Execute the XPath, and have it return the result
XObject list = eval(contextNode, str, namespaceNode);
final XObject list = eval(contextNode, str, namespaceNode);

// Have the XObject return its result as a NodeSetDTM.
return list.nodeset();
Expand All @@ -118,7 +121,8 @@ public static NodeIterator selectNodeIterator(Node contextNode, String str, Node
* @return A NodeIterator, should never be null.
* @throws TransformerException in case of error
*/
public static NodeList selectNodeList(Node contextNode, String str) throws TransformerException {
public static NodeList selectNodeList(final Node contextNode, final String str)
throws TransformerException {
return selectNodeList(contextNode, str, contextNode);
}

Expand All @@ -132,11 +136,12 @@ public static NodeList selectNodeList(Node contextNode, String str) throws Trans
* @return A NodeIterator, should never be null.
* @throws TransformerException in case of error
*/
public static NodeList selectNodeList(Node contextNode, String str, Node namespaceNode)
public static NodeList selectNodeList(
final Node contextNode, final String str, final Node namespaceNode)
throws TransformerException {

// Execute the XPath, and have it return the result
XObject list = eval(contextNode, str, namespaceNode);
final XObject list = eval(contextNode, str, namespaceNode);

// Return a NodeList.
return list.nodelist();
Expand All @@ -156,7 +161,7 @@ public static NodeList selectNodeList(Node contextNode, String str, Node namespa
* @see org.htmlunit.xpath.objects.XString
* @throws TransformerException in case of error
*/
public static XObject eval(Node contextNode, String str) throws TransformerException {
public static XObject eval(final Node contextNode, final String str) throws TransformerException {
return eval(contextNode, str, contextNode);
}

Expand All @@ -177,7 +182,7 @@ public static XObject eval(Node contextNode, String str) throws TransformerExcep
* @see org.htmlunit.xpath.objects.XString
* @throws TransformerException in case of error
*/
public static XObject eval(Node contextNode, String str, Node namespaceNode)
public static XObject eval(final Node contextNode, final String str, final Node namespaceNode)
throws TransformerException {

// Since we don't have a XML Parser involved here, install some default support
Expand All @@ -187,24 +192,24 @@ public static XObject eval(Node contextNode, String str, Node namespaceNode)
// XPathContext should be done away with.)
// Create an XPathContext that doesn't support pushing and popping of
// variable resolution scopes. Sufficient for simple XPath 1.0 expressions.
XPathContext xpathSupport = new XPathContext(false);
final XPathContext xpathSupport = new XPathContext(false);

// Create an object to resolve namespace prefixes.
// XPath namespaces are resolved from the input context node's document element
// if it is a root node, or else the current context node (for lack of a better
// resolution space, given the simplicity of this sample code).
PrefixResolverDefault prefixResolver =
final PrefixResolverDefault prefixResolver =
new PrefixResolverDefault(
(namespaceNode.getNodeType() == Node.DOCUMENT_NODE)
? ((Document) namespaceNode).getDocumentElement()
: namespaceNode);

// Create the XPath object.
XPath xpath = new XPath(str, prefixResolver, XPath.SELECT, null);
final XPath xpath = new XPath(str, prefixResolver, XPath.SELECT, null);

// Execute the XPath, and have it return the result
// return xpath.execute(xpathSupport, contextNode, prefixResolver);
int ctxtNode = xpathSupport.getDTMHandleFromNode(contextNode);
final int ctxtNode = xpathSupport.getDTMHandleFromNode(contextNode);

return xpath.execute(xpathSupport, ctxtNode, prefixResolver);
}
Expand All @@ -227,7 +232,8 @@ public static XObject eval(Node contextNode, String str, Node namespaceNode)
* @see org.htmlunit.xpath.objects.XString
* @throws TransformerException in case of error
*/
public static XObject eval(Node contextNode, String str, PrefixResolver prefixResolver)
public static XObject eval(
final Node contextNode, final String str, final PrefixResolver prefixResolver)
throws TransformerException {

// Since we don't have a XML Parser involved here, install some default support
Expand All @@ -236,14 +242,14 @@ public static XObject eval(Node contextNode, String str, PrefixResolver prefixRe
// because XPathContext is weak in a number of areas... perhaps
// XPathContext should be done away with.)
// Create the XPath object.
XPath xpath = new XPath(str, prefixResolver, XPath.SELECT, null);
final XPath xpath = new XPath(str, prefixResolver, XPath.SELECT, null);

// Create an XPathContext that doesn't support pushing and popping of
// variable resolution scopes. Sufficient for simple XPath 1.0 expressions.
XPathContext xpathSupport = new XPathContext(false);
final XPathContext xpathSupport = new XPathContext(false);

// Execute the XPath, and have it return the result
int ctxtNode = xpathSupport.getDTMHandleFromNode(contextNode);
final int ctxtNode = xpathSupport.getDTMHandleFromNode(contextNode);

return xpath.execute(xpathSupport, ctxtNode, prefixResolver);
}
Expand Down
27 changes: 15 additions & 12 deletions src/main/java/org/htmlunit/xpath/XPathContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,22 @@ public DTMManager getDTMManager() {
/** {@inheritDoc} */
@Override
public DTM getDTM(
javax.xml.transform.Source source, boolean unique, boolean incremental, boolean doIndexing) {
final javax.xml.transform.Source source,
final boolean unique,
final boolean incremental,
final boolean doIndexing) {
return m_dtmManager.getDTM(source, unique, incremental, doIndexing);
}

/** {@inheritDoc} */
@Override
public DTM getDTM(int nodeHandle) {
public DTM getDTM(final int nodeHandle) {
return m_dtmManager.getDTM(nodeHandle);
}

/** {@inheritDoc} */
@Override
public int getDTMHandleFromNode(org.w3c.dom.Node node) {
public int getDTMHandleFromNode(final org.w3c.dom.Node node) {
return m_dtmManager.getDTMHandleFromNode(node);
}

Expand All @@ -81,7 +84,7 @@ public XPathContext() {
* @param recursiveVarContext A <code>boolean</code> value indicating whether the XPath context
* needs to support pushing of scopes for variable resolution
*/
public XPathContext(boolean recursiveVarContext) {
public XPathContext(final boolean recursiveVarContext) {
m_prefixResolvers.push(null);
m_currentNodes.push(DTM.NULL);
}
Expand Down Expand Up @@ -129,7 +132,7 @@ public final ErrorListener getErrorListener() {
*
* @param listener A non-null ErrorListener reference.
*/
public void setErrorListener(ErrorListener listener) throws IllegalArgumentException {
public void setErrorListener(final ErrorListener listener) throws IllegalArgumentException {
if (listener == null)
throw new IllegalArgumentException(
XPATHMessages.createXPATHMessage(XPATHErrorResources.ER_NULL_ERROR_HANDLER, null));
Expand Down Expand Up @@ -158,7 +161,7 @@ public final URIResolver getURIResolver() {
* @param resolver the URIResolver to be associated with this execution context, may be null to
* clear an already set resolver.
*/
public void setURIResolver(URIResolver resolver) {
public void setURIResolver(final URIResolver resolver) {
m_uriResolver = resolver;
}

Expand Down Expand Up @@ -190,7 +193,7 @@ public final int getCurrentNode() {
*
* @param cn the <a href="http://www.w3.org/TR/xslt#dt-current-node">current node</a>.
*/
public final void pushCurrentNodeAndExpression(int cn) {
public final void pushCurrentNodeAndExpression(final int cn) {
m_currentNodes.push(cn);
}

Expand All @@ -204,7 +207,7 @@ public final void popCurrentNodeAndExpression() {
*
* @param n the <a href="http://www.w3.org/TR/xslt#dt-current-node">current node</a>.
*/
public final void pushCurrentNode(int n) {
public final void pushCurrentNode(final int n) {
m_currentNodes.push(n);
}

Expand All @@ -219,7 +222,7 @@ public final int getPredicatePos() {
return m_predicatePos.peek();
}

public final void pushPredicatePos(int n) {
public final void pushPredicatePos(final int n) {
m_predicatePos.push(n);
}

Expand All @@ -243,7 +246,7 @@ public final PrefixResolver getNamespaceContext() {
*
* @param pr the prefix resolver to be used for resolving prefixes to namespace URLs.
*/
public final void setNamespaceContext(PrefixResolver pr) {
public final void setNamespaceContext(final PrefixResolver pr) {
m_prefixResolvers.pop();
m_prefixResolvers.push(pr);
}
Expand All @@ -253,7 +256,7 @@ public final void setNamespaceContext(PrefixResolver pr) {
*
* @param pr the prefix resolver to be used for resolving prefixes to namespace URLs.
*/
public final void pushNamespaceContext(PrefixResolver pr) {
public final void pushNamespaceContext(final PrefixResolver pr) {
m_prefixResolvers.push(pr);
}

Expand All @@ -274,7 +277,7 @@ public final void popNamespaceContext() {
*
* @param iter A sub-context AxesWalker.
*/
public final void pushSubContextList(SubContextList iter) {
public final void pushSubContextList(final SubContextList iter) {
m_axesIteratorStack.push(iter);
}

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/htmlunit/xpath/XPathException.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class XPathException extends TransformerException {
*
* @param message The error message.
*/
public XPathException(String message, SourceLocator ex) {
public XPathException(final String message, final SourceLocator ex) {
super(message);
this.setLocator(ex);
}
Expand All @@ -43,14 +43,14 @@ public XPathException(String message, SourceLocator ex) {
*
* @param message The error message.
*/
public XPathException(String message) {
public XPathException(final String message) {
super(message);
}

/** {@inheritDoc} */
@Override
public String getMessage() {
String lastMessage = super.getMessage();
final String lastMessage = super.getMessage();
return (null != lastMessage) ? lastMessage : "";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class XPathProcessorException extends XPathException {
*
* @param message The error message.
*/
public XPathProcessorException(String message) {
public XPathProcessorException(final String message) {
super(message);
}
}
4 changes: 2 additions & 2 deletions src/main/java/org/htmlunit/xpath/XPathVisitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public boolean visitStep() {
* @param pred The predicate object.
* @return true if the sub expressions should be traversed.
*/
public boolean visitPredicate(Expression pred) {
public boolean visitPredicate(final Expression pred) {
return true;
}

Expand Down Expand Up @@ -96,7 +96,7 @@ public boolean visitUnaryOperation() {
* @param func The function reference object.
* @return true if the sub expressions should be traversed.
*/
public boolean visitFunction(Function func) {
public boolean visitFunction(final Function func) {
return true;
}

Expand Down
Loading

0 comments on commit 1277bb8

Please sign in to comment.