From 78811a100898cdba6180dc87e1ee5306f891fed8 Mon Sep 17 00:00:00 2001 From: Ronald Brill Date: Sat, 27 Jul 2024 19:33:27 +0200 Subject: [PATCH] code style --- .../java/org/htmlunit/xpath/NodeSetDTM.java | 47 +++++--- .../java/org/htmlunit/xpath/XPathContext.java | 11 +- .../htmlunit/xpath/axes/LocPathIterator.java | 31 +++-- .../org/htmlunit/xpath/axes/NodeSequence.java | 41 +++++-- .../htmlunit/xpath/axes/OneStepIterator.java | 44 +++++-- .../xpath/axes/OneStepIteratorForward.java | 4 +- .../xpath/axes/PredicatedNodeTest.java | 56 ++++++--- .../xpath/axes/ReverseAxesWalker.java | 20 +++- .../xpath/axes/SelfIteratorNoPredicate.java | 4 +- .../xpath/axes/UnionChildIterator.java | 8 +- .../htmlunit/xpath/axes/WalkingIterator.java | 12 +- .../htmlunit/xpath/operations/Operation.java | 8 +- .../xpath/operations/UnaryOperation.java | 8 +- .../xpath/patterns/FunctionPattern.java | 4 +- .../org/htmlunit/xpath/patterns/NodeTest.java | 110 +++++++++++++----- .../htmlunit/xpath/patterns/StepPattern.java | 4 +- .../htmlunit/xpath/patterns/UnionPattern.java | 28 +++-- .../org/htmlunit/xpath/res/XPATHMessages.java | 12 +- .../xpath/xml/dtm/ref/DTMNodeProxy.java | 4 +- 19 files changed, 330 insertions(+), 126 deletions(-) diff --git a/src/main/java/org/htmlunit/xpath/NodeSetDTM.java b/src/main/java/org/htmlunit/xpath/NodeSetDTM.java index 355e1be..6b5fa65 100644 --- a/src/main/java/org/htmlunit/xpath/NodeSetDTM.java +++ b/src/main/java/org/htmlunit/xpath/NodeSetDTM.java @@ -153,9 +153,10 @@ public int nextNode() { @Override public int previousNode() { - if (!m_cacheNodes) - throw new RuntimeException( - XPATHMessages.createXPATHMessage(XPATHErrorResources.ER_NODESETDTM_CANNOT_ITERATE, null)); + if (!m_cacheNodes) { + throw new RuntimeException( + XPATHMessages.createXPATHMessage(XPATHErrorResources.ER_NODESETDTM_CANNOT_ITERATE, null)); + } if ((m_next - 1) > 0) { m_next--; @@ -179,12 +180,17 @@ public boolean isFresh() { @Override public void runTo(final int index) { - if (!m_cacheNodes) - throw new RuntimeException( - XPATHMessages.createXPATHMessage(XPATHErrorResources.ER_NODESETDTM_CANNOT_INDEX, null)); + if (!m_cacheNodes) { + throw new RuntimeException( + XPATHMessages.createXPATHMessage(XPATHErrorResources.ER_NODESETDTM_CANNOT_INDEX, null)); + } - if ((index >= 0) && (m_next < m_firstFree)) m_next = index; - else m_next = m_firstFree - 1; + if ((index >= 0) && (m_next < m_firstFree)) { + m_next = index; + } + else { + m_next = m_firstFree - 1; + } } /** {@inheritDoc} */ @@ -282,7 +288,9 @@ public void addNodeInDocOrder(final int node, final boolean test, final XPathCon } } - if (!foundit) addElement(node); + if (!foundit) { + addElement(node); + } } // checkDups(); @@ -348,9 +356,10 @@ public int getCurrentPos() { @Override public void setCurrentPos(final int i) { - if (!m_cacheNodes) - throw new RuntimeException( - XPATHMessages.createXPATHMessage(XPATHErrorResources.ER_NODESETDTM_CANNOT_INDEX, null)); + if (!m_cacheNodes) { + throw new RuntimeException( + XPATHMessages.createXPATHMessage(XPATHErrorResources.ER_NODESETDTM_CANNOT_INDEX, null)); + } m_next = i; } @@ -359,8 +368,9 @@ public void setCurrentPos(final int i) { @Override public int getCurrentNode() { - if (!m_cacheNodes) - throw new RuntimeException("This NodeSetDTM can not do indexing or counting functions!"); + if (!m_cacheNodes) { + throw new RuntimeException("This NodeSetDTM can not do indexing or counting functions!"); + } final int saved = m_next; // because nextNode always increments @@ -386,10 +396,11 @@ public int getCurrentNode() { @Override public void setShouldCacheNodes(final boolean b) { - if (!isFresh()) - throw new RuntimeException( - XPATHMessages.createXPATHMessage( - XPATHErrorResources.ER_CANNOT_CALL_SETSHOULDCACHENODE, null)); + if (!isFresh()) { + throw new RuntimeException( + XPATHMessages.createXPATHMessage( + XPATHErrorResources.ER_CANNOT_CALL_SETSHOULDCACHENODE, null)); + } m_cacheNodes = b; } diff --git a/src/main/java/org/htmlunit/xpath/XPathContext.java b/src/main/java/org/htmlunit/xpath/XPathContext.java index 52f5e96..43858e6 100644 --- a/src/main/java/org/htmlunit/xpath/XPathContext.java +++ b/src/main/java/org/htmlunit/xpath/XPathContext.java @@ -119,7 +119,9 @@ public void reset() { * @return A non-null ErrorListener reference. */ public final ErrorListener getErrorListener() { - if (null != m_errorListener) return m_errorListener; + if (null != m_errorListener) { + return m_errorListener; + } if (null == m_defaultErrorListener) { m_defaultErrorListener = new org.htmlunit.xpath.xml.utils.DefaultErrorHandler(); @@ -133,9 +135,10 @@ public final ErrorListener getErrorListener() { * @param listener A non-null ErrorListener reference. */ public void setErrorListener(final ErrorListener listener) throws IllegalArgumentException { - if (listener == null) - throw new IllegalArgumentException( - XPATHMessages.createXPATHMessage(XPATHErrorResources.ER_NULL_ERROR_HANDLER, null)); + if (listener == null) { + throw new IllegalArgumentException( + XPATHMessages.createXPATHMessage(XPATHErrorResources.ER_NULL_ERROR_HANDLER, null)); + } m_errorListener = listener; } diff --git a/src/main/java/org/htmlunit/xpath/axes/LocPathIterator.java b/src/main/java/org/htmlunit/xpath/axes/LocPathIterator.java index eef4b40..fa6698f 100644 --- a/src/main/java/org/htmlunit/xpath/axes/LocPathIterator.java +++ b/src/main/java/org/htmlunit/xpath/axes/LocPathIterator.java @@ -172,7 +172,9 @@ public void setRoot(final int context, final Object environment) { m_currentContextNode = context; // only if top level? // Yech, shouldn't have to do this. -sb - if (null == m_prefixResolver) m_prefixResolver = xctxt.getNamespaceContext(); + if (null == m_prefixResolver) { + m_prefixResolver = xctxt.getNamespaceContext(); + } m_lastFetched = DTM.NULL; m_foundLast = false; @@ -225,11 +227,15 @@ public int getLength() { // If we have already calculated the length, and the current predicate // is the first predicate, then return the length. We don't cache // the anything but the length of the list to the first predicate. - if (-1 != m_length && isPredicateTest && m_predicateIndex < 1) return m_length; + if (-1 != m_length && isPredicateTest && m_predicateIndex < 1) { + return m_length; + } // I'm a bit worried about this one, since it doesn't have the // checks found above. I suspect it's fine. -sb - if (m_foundLast) return m_pos; + if (m_foundLast) { + return m_pos; + } // Create a clone, and count from the current position to the end // of the list, not taking into account the current predicate and @@ -260,7 +266,9 @@ public int getLength() { pos++; } - if (isPredicateTest && m_predicateIndex < 1) m_length = pos; + if (isPredicateTest && m_predicateIndex < 1) { + m_length = pos; + } return pos; } @@ -357,7 +365,9 @@ protected int returnNextNode(final int nextNode) { m_lastFetched = nextNode; - if (DTM.NULL == nextNode) m_foundLast = true; + if (DTM.NULL == nextNode) { + m_foundLast = true; + } return nextNode; } @@ -372,15 +382,20 @@ public int getCurrentNode() { @Override public void runTo(final int index) { - if (m_foundLast || ((index >= 0) && (index <= getCurrentPos()))) return; + if (m_foundLast || ((index >= 0) && (index <= getCurrentPos()))) { + return; + } if (-1 == index) { - while (DTM.NULL != nextNode()) + while (DTM.NULL != nextNode()) { ; } + } else { while (DTM.NULL != nextNode()) { - if (getCurrentPos() >= index) break; + if (getCurrentPos() >= index) { + break; + } } } } diff --git a/src/main/java/org/htmlunit/xpath/axes/NodeSequence.java b/src/main/java/org/htmlunit/xpath/axes/NodeSequence.java index b64110f..b7c7f38 100644 --- a/src/main/java/org/htmlunit/xpath/axes/NodeSequence.java +++ b/src/main/java/org/htmlunit/xpath/axes/NodeSequence.java @@ -184,12 +184,16 @@ public void setRoot(final int nodeHandle, final Object environment) { m_dtmMgr = xctxt.getDTMManager(); m_iter.setRoot(nodeHandle, environment); if (!m_iter.isDocOrdered()) { - if (!hasCache()) setShouldCacheNodes(true); + if (!hasCache()) { + setShouldCacheNodes(true); + } runTo(-1); m_next = 0; } } - else assertion(false, "Can not setRoot on a non-iterated NodeSequence!"); + else { + assertion(false, "Can not setRoot on a non-iterated NodeSequence!"); + } } /** {@inheritDoc} */ @@ -236,7 +240,9 @@ else if (cacheComplete() || (-1 != m_last) || (null == m_iter)) { } } - if (null == m_iter) return DTM.NULL; + if (null == m_iter) { + return DTM.NULL; + } final int next = m_iter.nextNode(); if (DTM.NULL != next) { @@ -247,10 +253,14 @@ else if (cacheComplete() || (-1 != m_last) || (null == m_iter)) { } else { final int insertIndex = addNodeInDocOrder(next); - if (insertIndex >= 0) m_next++; + if (insertIndex >= 0) { + m_next++; + } } } - else m_next++; + else { + m_next++; + } } else { // We have exhausted the iterator, and if there is a cache @@ -285,7 +295,9 @@ public int previousNode() { /** {@inheritDoc} */ @Override public void detach() { - if (null != m_iter) m_iter.detach(); + if (null != m_iter) { + m_iter.detach(); + } super.detach(); } @@ -321,7 +333,9 @@ public void setShouldCacheNodes(final boolean b) { setVector(new NodeVector()); } } - else setVector(null); + else { + setVector(null); + } } /** {@inheritDoc} */ @@ -335,8 +349,9 @@ public int getCurrentPos() { public void runTo(final int index) { if (-1 == index) { final int pos = m_next; - while (DTM.NULL != nextNode()) + while (DTM.NULL != nextNode()) { ; + } m_next = pos; } else if (m_next == index) { @@ -345,13 +360,15 @@ else if (hasCache() && m_next < getVector().size()) { m_next = index; } else if ((null == getVector()) && (index < m_next)) { - while ((m_next >= index) && DTM.NULL != previousNode()) + while ((m_next >= index) && DTM.NULL != previousNode()) { ; } + } else { - while ((m_next < index) && DTM.NULL != nextNode()) + while ((m_next < index) && DTM.NULL != nextNode()) { ; } + } } /** {@inheritDoc} */ @@ -414,7 +431,9 @@ public DTMIterator cloneWithReset() throws CloneNotSupportedException { @Override public Object clone() throws CloneNotSupportedException { final NodeSequence clone = (NodeSequence) super.clone(); - if (null != m_iter) clone.m_iter = (DTMIterator) m_iter.clone(); + if (null != m_iter) { + clone.m_iter = (DTMIterator) m_iter.clone(); + } return clone; } diff --git a/src/main/java/org/htmlunit/xpath/axes/OneStepIterator.java b/src/main/java/org/htmlunit/xpath/axes/OneStepIterator.java index a2fc0f7..41dbdb4 100644 --- a/src/main/java/org/htmlunit/xpath/axes/OneStepIterator.java +++ b/src/main/java/org/htmlunit/xpath/axes/OneStepIterator.java @@ -57,14 +57,18 @@ public class OneStepIterator extends ChildTestIterator { @Override public void setRoot(final int context, final Object environment) { super.setRoot(context, environment); - if (m_axis > -1) m_iterator = m_cdtm.getAxisIterator(m_axis); + if (m_axis > -1) { + m_iterator = m_cdtm.getAxisIterator(m_axis); + } m_iterator.setStartNode(m_context); } /** {@inheritDoc} */ @Override public void detach() { - if (m_axis > -1) m_iterator = null; + if (m_axis > -1) { + m_iterator = null; + } // Always call the superclass detach last! super.detach(); @@ -108,12 +112,16 @@ public boolean isReverseAxes() { /** {@inheritDoc} */ @Override protected int getProximityPosition(final int predicateIndex) { - if (!isReverseAxes()) return super.getProximityPosition(predicateIndex); + if (!isReverseAxes()) { + return super.getProximityPosition(predicateIndex); + } // A negative predicate index seems to occur with // (preceding-sibling::*|following-sibling::*)/ancestor::*[position()]/*[position()] // -sb - if (predicateIndex < 0) return -1; + if (predicateIndex < 0) { + return -1; + } if (m_proximityPositions[predicateIndex] <= 0) { final XPathContext xctxt = getXPathContext(); @@ -151,7 +159,9 @@ protected int getProximityPosition(final int predicateIndex) { /** {@inheritDoc} */ @Override public int getLength() { - if (!isReverseAxes()) return super.getLength(); + if (!isReverseAxes()) { + return super.getLength(); + } // Tell if this is being called from within a predicate. final boolean isPredicateTest = this == m_execContext.getSubContextList(); @@ -159,7 +169,9 @@ public int getLength() { // If we have already calculated the length, and the current predicate // is the first predicate, then return the length. We don't cache // the anything but the length of the list to the first predicate. - if (-1 != m_length && isPredicateTest && m_predicateIndex < 1) return m_length; + if (-1 != m_length && isPredicateTest && m_predicateIndex < 1) { + return m_length; + } int count = 0; @@ -183,7 +195,9 @@ public int getLength() { finally { xctxt.popCurrentNode(); } - if (isPredicateTest && m_predicateIndex < 1) m_length = count; + if (isPredicateTest && m_predicateIndex < 1) { + m_length = count; + } return count; } @@ -191,8 +205,12 @@ public int getLength() { /** {@inheritDoc} */ @Override protected void countProximityPosition(final int i) { - if (!isReverseAxes()) super.countProximityPosition(i); - else if (i < m_proximityPositions.length) m_proximityPositions[i]--; + if (!isReverseAxes()) { + super.countProximityPosition(i); + } + else if (i < m_proximityPositions.length) { + m_proximityPositions[i]--; + } } /** {@inheritDoc} */ @@ -200,7 +218,9 @@ protected void countProximityPosition(final int i) { public void reset() { super.reset(); - if (null != m_iterator) m_iterator.reset(); + if (null != m_iterator) { + m_iterator.reset(); + } } /** {@inheritDoc} */ @@ -212,7 +232,9 @@ public int getAxis() { /** {@inheritDoc} */ @Override public boolean deepEquals(final Expression expr) { - if (!super.deepEquals(expr)) return false; + if (!super.deepEquals(expr)) { + return false; + } return m_axis == ((OneStepIterator) expr).m_axis; } diff --git a/src/main/java/org/htmlunit/xpath/axes/OneStepIteratorForward.java b/src/main/java/org/htmlunit/xpath/axes/OneStepIteratorForward.java index f8a6efd..8910e9e 100644 --- a/src/main/java/org/htmlunit/xpath/axes/OneStepIteratorForward.java +++ b/src/main/java/org/htmlunit/xpath/axes/OneStepIteratorForward.java @@ -73,7 +73,9 @@ public int getAxis() { /** {@inheritDoc} */ @Override public boolean deepEquals(final Expression expr) { - if (!super.deepEquals(expr)) return false; + if (!super.deepEquals(expr)) { + return false; + } return m_axis == ((OneStepIteratorForward) expr).m_axis; } diff --git a/src/main/java/org/htmlunit/xpath/axes/PredicatedNodeTest.java b/src/main/java/org/htmlunit/xpath/axes/PredicatedNodeTest.java index 4d2dcaf..9dded15 100644 --- a/src/main/java/org/htmlunit/xpath/axes/PredicatedNodeTest.java +++ b/src/main/java/org/htmlunit/xpath/axes/PredicatedNodeTest.java @@ -60,7 +60,9 @@ public Object clone() throws CloneNotSupportedException { this.m_proximityPositions.length); } - if (clone.m_lpi == this) clone.m_lpi = (LocPathIterator) clone; + if (clone.m_lpi == this) { + clone.m_lpi = (LocPathIterator) clone; + } return clone; } @@ -74,7 +76,9 @@ public Object clone() throws CloneNotSupportedException { * @return the number of predicates that this walker has. */ public int getPredicateCount() { - if (-1 == m_predCount) return (null == predicates_) ? 0 : predicates_.length; + if (-1 == m_predCount) { + return (null == predicates_) ? 0 : predicates_.length; + } return m_predCount; } @@ -92,7 +96,9 @@ public void setPredicateCount(final int count) { System.arraycopy(predicates_, 0, newPredicates, 0, count); predicates_ = newPredicates; } - else predicates_ = null; + else { + predicates_ = null; + } } /** @@ -160,7 +166,9 @@ protected int getProximityPosition(final int predicateIndex) { public void resetProximityPositions() { final int nPredicates = getPredicateCount(); if (nPredicates > 0) { - if (null == m_proximityPositions) m_proximityPositions = new int[nPredicates]; + if (null == m_proximityPositions) { + m_proximityPositions = new int[nPredicates]; + } for (int i = 0; i < nPredicates; i++) { try { @@ -192,7 +200,9 @@ protected void countProximityPosition(final int i) { // Note that in the case of a UnionChildIterator, this may be a // static object and so m_proximityPositions may indeed be null! final int[] pp = m_proximityPositions; - if ((null != pp) && (i < pp.length)) pp[i]++; + if ((null != pp) && (i < pp.length)) { + pp[i]++; + } } /** @@ -217,7 +227,9 @@ boolean executePredicates(final int context, final XPathContext xctxt) final int nPredicates = getPredicateCount(); // System.out.println("nPredicates: "+nPredicates); - if (nPredicates == 0) return true; + if (nPredicates == 0) { + return true; + } try { m_predicateIndex = 0; @@ -270,7 +282,9 @@ else if (DEBUG_PREDICATECOUNTING) { m_foundLast = true; } } - else if (!pred.bool()) return false; + else if (!pred.bool()) { + return false; + } countProximityPosition(++m_predicateIndex); } @@ -324,7 +338,9 @@ public short acceptNode(final int n) { if (getPredicateCount() > 0) { countProximityPosition(0); - if (!executePredicates(n, xctxt)) return DTMIterator.FILTER_SKIP; + if (!executePredicates(n, xctxt)) { + return DTMIterator.FILTER_SKIP; + } } return DTMIterator.FILTER_ACCEPT; @@ -350,7 +366,9 @@ public short acceptNode(final int n) { */ public void setLocPathIterator(final LocPathIterator li) { m_lpi = li; - if (this != li) li.exprSetParent(this); + if (this != li) { + li.exprSetParent(this); + } } /** {@inheritDoc} */ @@ -358,7 +376,9 @@ public void setLocPathIterator(final LocPathIterator li) { public boolean canTraverseOutsideSubtree() { final int n = getPredicateCount(); for (int i = 0; i < n; i++) { - if (getPredicate(i).canTraverseOutsideSubtree()) return true; + if (getPredicate(i).canTraverseOutsideSubtree()) { + return true; + } } return false; } @@ -382,18 +402,26 @@ public void callPredicateVisitors(final XPathVisitor visitor) { /** {@inheritDoc} */ @Override public boolean deepEquals(final Expression expr) { - if (!super.deepEquals(expr)) return false; + if (!super.deepEquals(expr)) { + return false; + } final PredicatedNodeTest pnt = (PredicatedNodeTest) expr; if (null != predicates_) { final int n = predicates_.length; - if ((null == pnt.predicates_) || (pnt.predicates_.length != n)) return false; + if ((null == pnt.predicates_) || (pnt.predicates_.length != n)) { + return false; + } for (int i = 0; i < n; i++) { - if (!predicates_[i].deepEquals(pnt.predicates_[i])) return false; + if (!predicates_[i].deepEquals(pnt.predicates_[i])) { + return false; + } } } - else if (null != pnt.predicates_) return false; + else if (null != pnt.predicates_) { + return false; + } return true; } diff --git a/src/main/java/org/htmlunit/xpath/axes/ReverseAxesWalker.java b/src/main/java/org/htmlunit/xpath/axes/ReverseAxesWalker.java index 838174d..340f70c 100644 --- a/src/main/java/org/htmlunit/xpath/axes/ReverseAxesWalker.java +++ b/src/main/java/org/htmlunit/xpath/axes/ReverseAxesWalker.java @@ -55,13 +55,19 @@ public void detach() { /** {@inheritDoc} */ @Override protected int getNextNode() { - if (m_foundLast) return DTM.NULL; + if (m_foundLast) { + return DTM.NULL; + } final int next = m_iterator.next(); - if (m_isFresh) m_isFresh = false; + if (m_isFresh) { + m_isFresh = false; + } - if (DTM.NULL == next) this.m_foundLast = true; + if (DTM.NULL == next) { + this.m_foundLast = true; + } return next; } @@ -78,7 +84,9 @@ protected int getProximityPosition(final int predicateIndex) { // A negative predicate index seems to occur with // (preceding-sibling::*|following-sibling::*)/ancestor::*[position()]/*[position()] // -sb - if (predicateIndex < 0) return -1; + if (predicateIndex < 0) { + return -1; + } int count = m_proximityPositions[predicateIndex]; @@ -119,7 +127,9 @@ protected int getProximityPosition(final int predicateIndex) { /** {@inheritDoc} */ @Override protected void countProximityPosition(final int i) { - if (i < m_proximityPositions.length) m_proximityPositions[i]--; + if (i < m_proximityPositions.length) { + m_proximityPositions[i]--; + } } /** {@inheritDoc} */ diff --git a/src/main/java/org/htmlunit/xpath/axes/SelfIteratorNoPredicate.java b/src/main/java/org/htmlunit/xpath/axes/SelfIteratorNoPredicate.java index fde5d54..22f7c35 100644 --- a/src/main/java/org/htmlunit/xpath/axes/SelfIteratorNoPredicate.java +++ b/src/main/java/org/htmlunit/xpath/axes/SelfIteratorNoPredicate.java @@ -41,7 +41,9 @@ public class SelfIteratorNoPredicate extends LocPathIterator { /** {@inheritDoc} */ @Override public int nextNode() { - if (m_foundLast) return DTM.NULL; + if (m_foundLast) { + return DTM.NULL; + } final int next; diff --git a/src/main/java/org/htmlunit/xpath/axes/UnionChildIterator.java b/src/main/java/org/htmlunit/xpath/axes/UnionChildIterator.java index a5b7912..9f2b5dc 100644 --- a/src/main/java/org/htmlunit/xpath/axes/UnionChildIterator.java +++ b/src/main/java/org/htmlunit/xpath/axes/UnionChildIterator.java @@ -78,9 +78,13 @@ public short acceptNode(final int n) { if (score != NodeTest.SCORE_NONE) { // Note that we are assuming there are no positional predicates! if (pnt.getPredicateCount() > 0) { - if (pnt.executePredicates(n, xctxt)) return DTMIterator.FILTER_ACCEPT; + if (pnt.executePredicates(n, xctxt)) { + return DTMIterator.FILTER_ACCEPT; + } } - else return DTMIterator.FILTER_ACCEPT; + else { + return DTMIterator.FILTER_ACCEPT; + } } } } diff --git a/src/main/java/org/htmlunit/xpath/axes/WalkingIterator.java b/src/main/java/org/htmlunit/xpath/axes/WalkingIterator.java index 0c2dec5..707b272 100644 --- a/src/main/java/org/htmlunit/xpath/axes/WalkingIterator.java +++ b/src/main/java/org/htmlunit/xpath/axes/WalkingIterator.java @@ -116,7 +116,9 @@ public void setRoot(final int context, final Object environment) { /** {@inheritDoc} */ @Override public int nextNode() { - if (m_foundLast) return DTM.NULL; + if (m_foundLast) { + return DTM.NULL; + } // If the variable stack position is not -1, we'll have to // set our position in the variable stack, so our variable access @@ -192,12 +194,16 @@ public void callVisitors(final XPathVisitor visitor) { /** {@inheritDoc} */ @Override public boolean deepEquals(final Expression expr) { - if (!super.deepEquals(expr)) return false; + if (!super.deepEquals(expr)) { + return false; + } AxesWalker walker1 = m_firstWalker; AxesWalker walker2 = ((WalkingIterator) expr).m_firstWalker; while ((null != walker1) && (null != walker2)) { - if (!walker1.deepEquals(walker2)) return false; + if (!walker1.deepEquals(walker2)) { + return false; + } walker1 = walker1.getNextWalker(); walker2 = walker2.getNextWalker(); } diff --git a/src/main/java/org/htmlunit/xpath/operations/Operation.java b/src/main/java/org/htmlunit/xpath/operations/Operation.java index 52a293f..9fd6880 100644 --- a/src/main/java/org/htmlunit/xpath/operations/Operation.java +++ b/src/main/java/org/htmlunit/xpath/operations/Operation.java @@ -44,7 +44,9 @@ public class Operation extends Expression { public boolean canTraverseOutsideSubtree() { if ((null != m_left && m_left.canTraverseOutsideSubtree()) - || (null != m_right && m_right.canTraverseOutsideSubtree())) return true; + || (null != m_right && m_right.canTraverseOutsideSubtree())) { + return true; + } return false; } @@ -102,7 +104,9 @@ public void callVisitors(final XPathVisitor visitor) { public boolean deepEquals(final Expression expr) { if (!isSameClass(expr) || !m_left.deepEquals(((Operation) expr).m_left) - || !m_right.deepEquals(((Operation) expr).m_right)) return false; + || !m_right.deepEquals(((Operation) expr).m_right)) { + return false; + } return true; } diff --git a/src/main/java/org/htmlunit/xpath/operations/UnaryOperation.java b/src/main/java/org/htmlunit/xpath/operations/UnaryOperation.java index 40ce411..8acd644 100644 --- a/src/main/java/org/htmlunit/xpath/operations/UnaryOperation.java +++ b/src/main/java/org/htmlunit/xpath/operations/UnaryOperation.java @@ -36,7 +36,9 @@ public abstract class UnaryOperation extends Expression { @Override public boolean canTraverseOutsideSubtree() { - if (null != m_right && m_right.canTraverseOutsideSubtree()) return true; + if (null != m_right && m_right.canTraverseOutsideSubtree()) { + return true; + } return false; } @@ -78,7 +80,9 @@ public void callVisitors(final XPathVisitor visitor) { /** {@inheritDoc} */ @Override public boolean deepEquals(final Expression expr) { - if (!isSameClass(expr) || !m_right.deepEquals(((UnaryOperation) expr).m_right)) return false; + if (!isSameClass(expr) || !m_right.deepEquals(((UnaryOperation) expr).m_right)) { + return false; + } return true; } diff --git a/src/main/java/org/htmlunit/xpath/patterns/FunctionPattern.java b/src/main/java/org/htmlunit/xpath/patterns/FunctionPattern.java index 130af52..5788682 100644 --- a/src/main/java/org/htmlunit/xpath/patterns/FunctionPattern.java +++ b/src/main/java/org/htmlunit/xpath/patterns/FunctionPattern.java @@ -46,7 +46,9 @@ public final void calcScore() { m_score = SCORE_OTHER; - if (null == m_targetString) calcTargetString(); + if (null == m_targetString) { + calcTargetString(); + } } /** diff --git a/src/main/java/org/htmlunit/xpath/patterns/NodeTest.java b/src/main/java/org/htmlunit/xpath/patterns/NodeTest.java index 098da77..5d336e3 100644 --- a/src/main/java/org/htmlunit/xpath/patterns/NodeTest.java +++ b/src/main/java/org/htmlunit/xpath/patterns/NodeTest.java @@ -191,23 +191,39 @@ public NodeTest(final int whatToShow) { /** {@inheritDoc} */ @Override public boolean deepEquals(final Expression expr) { - if (!isSameClass(expr)) return false; + if (!isSameClass(expr)) { + return false; + } final NodeTest nt = (NodeTest) expr; if (null != nt.m_name) { - if (null == m_name) return false; - else if (!nt.m_name.equals(m_name)) return false; + if (null == m_name) { + return false; + } + else if (!nt.m_name.equals(m_name)) { + return false; + } + } + else if (null != m_name) { + return false; } - else if (null != m_name) return false; if (null != nt.m_namespace) { - if (null == m_namespace) return false; - else if (!nt.m_namespace.equals(m_namespace)) return false; + if (null == m_namespace) { + return false; + } + else if (!nt.m_namespace.equals(m_namespace)) { + return false; + } + } + else if (null != m_namespace) { + return false; } - else if (null != m_namespace) return false; - if (m_whatToShow != nt.m_whatToShow) return false; + if (m_whatToShow != nt.m_whatToShow) { + return false; + } return m_isTotallyWild == nt.m_isTotallyWild; } @@ -274,11 +290,18 @@ public void setStaticScore(final XNumber score) { /** Static calc of match score. */ protected void calcScore() { - if ((m_namespace == null) && (m_name == null)) m_score = SCORE_NODETEST; - else if (((m_namespace == WILD) || (m_namespace == null)) && (m_name == WILD)) - m_score = SCORE_NODETEST; - else if ((m_namespace != WILD) && (m_name == WILD)) m_score = SCORE_NSWILD; - else m_score = SCORE_QNAME; + if ((m_namespace == null) && (m_name == null)) { + m_score = SCORE_NODETEST; + } + else if (((m_namespace == WILD) || (m_namespace == null)) && (m_name == WILD)) { + m_score = SCORE_NODETEST; + } + else if ((m_namespace != WILD) && (m_name == WILD)) { + m_score = SCORE_NSWILD; + } + else { + m_score = SCORE_QNAME; + } m_isTotallyWild = m_namespace == null && m_name == WILD; } @@ -294,32 +317,57 @@ else if (((m_namespace == WILD) || (m_namespace == null)) && (m_name == WILD)) */ public static int getNodeTypeTest(final int whatToShow) { // %REVIEW% Is there a better way? - if (0 != (whatToShow & DTMFilter.SHOW_ELEMENT)) return DTM.ELEMENT_NODE; + if (0 != (whatToShow & DTMFilter.SHOW_ELEMENT)) { + return DTM.ELEMENT_NODE; + } - if (0 != (whatToShow & DTMFilter.SHOW_ATTRIBUTE)) return DTM.ATTRIBUTE_NODE; + if (0 != (whatToShow & DTMFilter.SHOW_ATTRIBUTE)) { + return DTM.ATTRIBUTE_NODE; + } - if (0 != (whatToShow & DTMFilter.SHOW_TEXT)) return DTM.TEXT_NODE; + if (0 != (whatToShow & DTMFilter.SHOW_TEXT)) { + return DTM.TEXT_NODE; + } - if (0 != (whatToShow & DTMFilter.SHOW_DOCUMENT)) return DTM.DOCUMENT_NODE; + if (0 != (whatToShow & DTMFilter.SHOW_DOCUMENT)) { + return DTM.DOCUMENT_NODE; + } - if (0 != (whatToShow & DTMFilter.SHOW_DOCUMENT_FRAGMENT)) return DTM.DOCUMENT_FRAGMENT_NODE; + if (0 != (whatToShow & DTMFilter.SHOW_DOCUMENT_FRAGMENT)) { + return DTM.DOCUMENT_FRAGMENT_NODE; + } - if (0 != (whatToShow & DTMFilter.SHOW_NAMESPACE)) return DTM.NAMESPACE_NODE; + if (0 != (whatToShow & DTMFilter.SHOW_NAMESPACE)) { + return DTM.NAMESPACE_NODE; + } - if (0 != (whatToShow & DTMFilter.SHOW_COMMENT)) return DTM.COMMENT_NODE; + if (0 != (whatToShow & DTMFilter.SHOW_COMMENT)) { + return DTM.COMMENT_NODE; + } - if (0 != (whatToShow & DTMFilter.SHOW_PROCESSING_INSTRUCTION)) - return DTM.PROCESSING_INSTRUCTION_NODE; + if (0 != (whatToShow & DTMFilter.SHOW_PROCESSING_INSTRUCTION)) { + return DTM.PROCESSING_INSTRUCTION_NODE; + } - if (0 != (whatToShow & DTMFilter.SHOW_DOCUMENT_TYPE)) return DTM.DOCUMENT_TYPE_NODE; + if (0 != (whatToShow & DTMFilter.SHOW_DOCUMENT_TYPE)) { + return DTM.DOCUMENT_TYPE_NODE; + } - if (0 != (whatToShow & DTMFilter.SHOW_ENTITY)) return DTM.ENTITY_NODE; + if (0 != (whatToShow & DTMFilter.SHOW_ENTITY)) { + return DTM.ENTITY_NODE; + } - if (0 != (whatToShow & DTMFilter.SHOW_ENTITY_REFERENCE)) return DTM.ENTITY_REFERENCE_NODE; + if (0 != (whatToShow & DTMFilter.SHOW_ENTITY_REFERENCE)) { + return DTM.ENTITY_REFERENCE_NODE; + } - if (0 != (whatToShow & DTMFilter.SHOW_NOTATION)) return DTM.NOTATION_NODE; + if (0 != (whatToShow & DTMFilter.SHOW_NOTATION)) { + return DTM.NOTATION_NODE; + } - if (0 != (whatToShow & DTMFilter.SHOW_CDATA_SECTION)) return DTM.CDATA_SECTION_NODE; + if (0 != (whatToShow & DTMFilter.SHOW_CDATA_SECTION)) { + return DTM.CDATA_SECTION_NODE; + } return 0; } @@ -357,7 +405,9 @@ public XObject execute(final XPathContext xctxt, final int context) final DTM dtm = xctxt.getDTM(context); final short nodeType = dtm.getNodeType(context); - if (m_whatToShow == DTMFilter.SHOW_ALL) return m_score; + if (m_whatToShow == DTMFilter.SHOW_ALL) { + return m_score; + } final int nodeBit = m_whatToShow & (0x00000001 << (nodeType - 1)); @@ -409,7 +459,9 @@ public XObject execute( final XPathContext xctxt, final int context, final DTM dtm, final int expType) throws javax.xml.transform.TransformerException { - if (m_whatToShow == DTMFilter.SHOW_ALL) return m_score; + if (m_whatToShow == DTMFilter.SHOW_ALL) { + return m_score; + } final int nodeBit = m_whatToShow & (0x00000001 << ((dtm.getNodeType(context)) - 1)); diff --git a/src/main/java/org/htmlunit/xpath/patterns/StepPattern.java b/src/main/java/org/htmlunit/xpath/patterns/StepPattern.java index b07ffea..ed1f2df 100644 --- a/src/main/java/org/htmlunit/xpath/patterns/StepPattern.java +++ b/src/main/java/org/htmlunit/xpath/patterns/StepPattern.java @@ -421,7 +421,9 @@ else if (!pred.boolWithSideEffects()) { xctxt.popSubContextList(); } - if (pass) pos++; + if (pass) { + pos++; + } if (!findLast && child == context) { return pos; diff --git a/src/main/java/org/htmlunit/xpath/patterns/UnionPattern.java b/src/main/java/org/htmlunit/xpath/patterns/UnionPattern.java index 07ba1cf..6fb5268 100644 --- a/src/main/java/org/htmlunit/xpath/patterns/UnionPattern.java +++ b/src/main/java/org/htmlunit/xpath/patterns/UnionPattern.java @@ -39,7 +39,9 @@ public class UnionPattern extends Expression { public boolean canTraverseOutsideSubtree() { if (null != patterns_) { for (final StepPattern pattern : patterns_) { - if (pattern.canTraverseOutsideSubtree()) return true; + if (pattern.canTraverseOutsideSubtree()) { + return true; + } } } return false; @@ -68,8 +70,12 @@ public XObject execute(final XPathContext xctxt) throws javax.xml.transform.Tran final XObject score = pattern.execute(xctxt); if (score != NodeTest.SCORE_NONE) { - if (null == bestScore) bestScore = score; - else if (score.num() > bestScore.num()) bestScore = score; + if (null == bestScore) { + bestScore = score; + } + else if (score.num() > bestScore.num()) { + bestScore = score; + } } } @@ -94,19 +100,27 @@ public void callVisitors(final XPathVisitor visitor) { /** {@inheritDoc} */ @Override public boolean deepEquals(final Expression expr) { - if (!isSameClass(expr)) return false; + if (!isSameClass(expr)) { + return false; + } final UnionPattern up = (UnionPattern) expr; if (null != patterns_) { final int n = patterns_.length; - if ((null == up.patterns_) || (up.patterns_.length != n)) return false; + if ((null == up.patterns_) || (up.patterns_.length != n)) { + return false; + } for (int i = 0; i < n; i++) { - if (!patterns_[i].deepEquals(up.patterns_[i])) return false; + if (!patterns_[i].deepEquals(up.patterns_[i])) { + return false; + } } } - else if (up.patterns_ != null) return false; + else if (up.patterns_ != null) { + return false; + } return true; } diff --git a/src/main/java/org/htmlunit/xpath/res/XPATHMessages.java b/src/main/java/org/htmlunit/xpath/res/XPATHMessages.java index 464b7e4..6bfbb4d 100644 --- a/src/main/java/org/htmlunit/xpath/res/XPATHMessages.java +++ b/src/main/java/org/htmlunit/xpath/res/XPATHMessages.java @@ -34,7 +34,9 @@ public class XPATHMessages { */ public static String createXPATHMessage( final String msgKey, final Object[] args) { // throws Exception - if (XPATHBundle == null) XPATHBundle = new XPATHErrorResources(); + if (XPATHBundle == null) { + XPATHBundle = new XPATHErrorResources(); + } if (XPATHBundle != null) { return createXPATHMsg(XPATHBundle, msgKey, args); @@ -58,7 +60,9 @@ private static String createXPATHMsg( boolean throwex = false; String msg = null; - if (msgKey != null) msg = fResourceBundle.getString(msgKey); + if (msgKey != null) { + msg = fResourceBundle.getString(msgKey); + } if (msg == null) { msg = fResourceBundle.getString(XPATHErrorResources.BAD_CODE); @@ -73,7 +77,9 @@ private static String createXPATHMsg( final int n = args.length; for (int i = 0; i < n; i++) { - if (null == args[i]) args[i] = ""; + if (null == args[i]) { + args[i] = ""; + } } fmsg = java.text.MessageFormat.format(msg, args); diff --git a/src/main/java/org/htmlunit/xpath/xml/dtm/ref/DTMNodeProxy.java b/src/main/java/org/htmlunit/xpath/xml/dtm/ref/DTMNodeProxy.java index 936371e..33a6de9 100644 --- a/src/main/java/org/htmlunit/xpath/xml/dtm/ref/DTMNodeProxy.java +++ b/src/main/java/org/htmlunit/xpath/xml/dtm/ref/DTMNodeProxy.java @@ -523,9 +523,7 @@ private void traverseChildren( final String localname, final boolean isNamespaceURIWildCard, final boolean isLocalNameWildCard) { - if (tempNode == null) { - } - else { + if (tempNode != null) { if (tempNode.getNodeType() == DTM.ELEMENT_NODE && (isLocalNameWildCard || tempNode.getLocalName().equals(localname))) { final String nsURI = tempNode.getNamespaceURI();