From e7aecc54203d1c2cf5e1bfee714b0a52901f6c3f Mon Sep 17 00:00:00 2001 From: Ronald Brill Date: Tue, 4 Jun 2024 15:15:38 +0200 Subject: [PATCH] code style --- .../org/htmlunit/xpath/axes/AxesWalker.java | 40 +++- .../xpath/axes/DescendantIterator.java | 52 +++-- .../xpath/axes/UnionPathIterator.java | 28 ++- .../htmlunit/xpath/axes/WalkerFactory.java | 177 +++++++++++++----- .../org/htmlunit/xpath/compiler/Compiler.java | 3 +- .../xpath/compiler/FunctionTable.java | 12 +- .../org/htmlunit/xpath/compiler/Lexer.java | 16 +- .../xpath/functions/FuncNamespace.java | 12 +- .../xpath/xml/dtm/ref/DTMNodeIterator.java | 16 +- 9 files changed, 264 insertions(+), 92 deletions(-) diff --git a/src/main/java/org/htmlunit/xpath/axes/AxesWalker.java b/src/main/java/org/htmlunit/xpath/axes/AxesWalker.java index 9df0985..e9c765e 100644 --- a/src/main/java/org/htmlunit/xpath/axes/AxesWalker.java +++ b/src/main/java/org/htmlunit/xpath/axes/AxesWalker.java @@ -80,7 +80,9 @@ public Object clone() throws CloneNotSupportedException { AxesWalker cloneDeep(final WalkingIterator cloneOwner, final Vector cloneList) throws CloneNotSupportedException { AxesWalker clone = findClone(this, cloneList); - if (null != clone) return clone; + if (null != clone) { + return clone; + } clone = (AxesWalker) this.clone(); clone.setLocPathIterator(cloneOwner); if (null != cloneList) { @@ -88,17 +90,25 @@ AxesWalker cloneDeep(final WalkingIterator cloneOwner, final Vector cloneList.addElement(clone); } - if (wi().m_lastUsedWalker == this) cloneOwner.m_lastUsedWalker = clone; + if (wi().m_lastUsedWalker == this) { + cloneOwner.m_lastUsedWalker = clone; + } - if (null != m_nextWalker) clone.m_nextWalker = m_nextWalker.cloneDeep(cloneOwner, cloneList); + if (null != m_nextWalker) { + clone.m_nextWalker = m_nextWalker.cloneDeep(cloneOwner, cloneList); + } // If you don't check for the cloneList here, you'll go into an // recursive infinate loop. if (null != cloneList) { - if (null != m_prevWalker) clone.m_prevWalker = m_prevWalker.cloneDeep(cloneOwner, cloneList); + if (null != m_prevWalker) { + clone.m_prevWalker = m_prevWalker.cloneDeep(cloneOwner, cloneList); + } } else { - if (null != m_nextWalker) clone.m_nextWalker.m_prevWalker = clone; + if (null != m_nextWalker) { + clone.m_nextWalker.m_prevWalker = clone; + } } return clone; } @@ -116,7 +126,9 @@ static AxesWalker findClone(final AxesWalker key, final Vector clone // First, look for clone on list. final int n = cloneList.size(); for (int i = 0; i < n; i += 2) { - if (key == cloneList.elementAt(i)) return cloneList.elementAt(i + 1); + if (key == cloneList.elementAt(i)) { + return cloneList.elementAt(i + 1); + } } } return null; @@ -210,7 +222,9 @@ public void setPrevWalker(final AxesWalker walker) { * @return the next node in document order on the axes, or null. */ protected int getNextNode() { - if (m_foundLast) return DTM.NULL; + if (m_foundLast) { + return DTM.NULL; + } if (m_isFresh) { m_currentNode = m_traverser.first(m_root); @@ -223,7 +237,9 @@ else if (DTM.NULL != m_currentNode) { m_currentNode = m_traverser.next(m_root, m_currentNode); } - if (DTM.NULL == m_currentNode) this.m_foundLast = true; + if (DTM.NULL == m_currentNode) { + this.m_foundLast = true; + } return m_currentNode; } @@ -242,7 +258,9 @@ public int nextNode() { AxesWalker walker = wi().getLastUsedWalker(); while (true) { - if (null == walker) break; + if (null == walker) { + break; + } nextNode = walker.getNextNode(); @@ -356,7 +374,9 @@ 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; + } final AxesWalker walker = (AxesWalker) expr; return this.m_axis == walker.m_axis; diff --git a/src/main/java/org/htmlunit/xpath/axes/DescendantIterator.java b/src/main/java/org/htmlunit/xpath/axes/DescendantIterator.java index a2d3206..3e414da 100644 --- a/src/main/java/org/htmlunit/xpath/axes/DescendantIterator.java +++ b/src/main/java/org/htmlunit/xpath/axes/DescendantIterator.java @@ -63,7 +63,9 @@ else if (OpCodes.FROM_ROOT == stepType) { fromRoot = true; // Ugly code... will go away when AST work is done. final int nextStepPos = compiler.getNextStepPos(firstStepPos); - if (compiler.getOp(nextStepPos) == OpCodes.FROM_DESCENDANTS_OR_SELF) orSelf = true; + if (compiler.getOp(nextStepPos) == OpCodes.FROM_DESCENDANTS_OR_SELF) { + orSelf = true; + } // firstStepPos += 8; } @@ -73,21 +75,37 @@ else if (OpCodes.FROM_ROOT == stepType) { nextStepPos = compiler.getNextStepPos(nextStepPos); if (nextStepPos > 0) { final int stepOp = compiler.getOp(nextStepPos); - if (OpCodes.ENDOP != stepOp) firstStepPos = nextStepPos; - else break; + if (OpCodes.ENDOP != stepOp) { + firstStepPos = nextStepPos; + } + else { + break; + } + } + else { + break; } - else break; } // Fix for http://nagoya.apache.org/bugzilla/show_bug.cgi?id=1336 - if ((analysis & WalkerFactory.BIT_CHILD) != 0) orSelf = false; + if ((analysis & WalkerFactory.BIT_CHILD) != 0) { + orSelf = false; + } if (fromRoot) { - if (orSelf) m_axis = Axis.DESCENDANTSORSELFFROMROOT; - else m_axis = Axis.DESCENDANTSFROMROOT; + if (orSelf) { + m_axis = Axis.DESCENDANTSORSELFFROMROOT; + } + else { + m_axis = Axis.DESCENDANTSFROMROOT; + } + } + else if (orSelf) { + m_axis = Axis.DESCENDANTORSELF; + } + else { + m_axis = Axis.DESCENDANT; } - else if (orSelf) m_axis = Axis.DESCENDANTORSELF; - else m_axis = Axis.DESCENDANT; final int whatToShow = compiler.getWhatToShow(firstStepPos); @@ -96,7 +114,9 @@ else if (OpCodes.FROM_ROOT == stepType) { & (DTMFilter.SHOW_ATTRIBUTE | DTMFilter.SHOW_ELEMENT | DTMFilter.SHOW_PROCESSING_INSTRUCTION))) - || (whatToShow == DTMFilter.SHOW_ALL)) initNodeTest(whatToShow); + || (whatToShow == DTMFilter.SHOW_ALL)) { + initNodeTest(whatToShow); + } else { initNodeTest( whatToShow, compiler.getStepNS(firstStepPos), compiler.getStepLocalName(firstStepPos)); @@ -119,7 +139,9 @@ public DTMIterator cloneWithReset() throws CloneNotSupportedException { /** {@inheritDoc} */ @Override public int nextNode() { - if (m_foundLast) return DTM.NULL; + if (m_foundLast) { + return DTM.NULL; + } if (DTM.NULL == m_lastFetched) { resetProximityPositions(); @@ -190,7 +212,9 @@ public void setRoot(final int context, final Object environment) { /** {@inheritDoc} */ @Override public int asNode(final XPathContext xctxt) throws javax.xml.transform.TransformerException { - if (getPredicateCount() > 0) return super.asNode(xctxt); + if (getPredicateCount() > 0) { + return super.asNode(xctxt); + } final int current = xctxt.getCurrentNode(); @@ -236,7 +260,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 == ((DescendantIterator) expr).m_axis; } diff --git a/src/main/java/org/htmlunit/xpath/axes/UnionPathIterator.java b/src/main/java/org/htmlunit/xpath/axes/UnionPathIterator.java index 9f3bb7c..b39235e 100644 --- a/src/main/java/org/htmlunit/xpath/axes/UnionPathIterator.java +++ b/src/main/java/org/htmlunit/xpath/axes/UnionPathIterator.java @@ -212,7 +212,9 @@ protected void loadLocationPaths(final Compiler compiler, final int opPos, final final WalkingIterator iter = new WalkingIterator(compiler.getNamespaceContext()); iter.exprSetParent(this); - if (compiler.getLocationPathDepth() <= 0) iter.setIsTopLevel(true); + if (compiler.getLocationPathDepth() <= 0) { + iter.setIsTopLevel(true); + } iter.m_firstWalker = new org.htmlunit.xpath.axes.FilterExprWalker(iter); @@ -229,7 +231,9 @@ protected void loadLocationPaths(final Compiler compiler, final int opPos, final /** {@inheritDoc} */ @Override public int nextNode() { - if (m_foundLast) return DTM.NULL; + if (m_foundLast) { + return DTM.NULL; + } // Loop through the iterators getting the current fetched // node, and get the earliest occuring in document order @@ -242,7 +246,9 @@ public int nextNode() { for (int i = 0; i < n; i++) { final int node = iterators_[i].getCurrentNode(); - if (DTM.NULL == node) continue; + if (DTM.NULL == node) { + continue; + } else if (DTM.NULL == earliestNode) { iteratorUsed = i; earliestNode = node; @@ -269,7 +275,9 @@ else if (DTM.NULL == earliestNode) { incrementCurrentPos(); } - else m_foundLast = true; + else { + m_foundLast = true; + } } m_lastFetched = earliestNode; @@ -317,17 +325,23 @@ 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; + } final UnionPathIterator upi = (UnionPathIterator) expr; if (null != exprs_) { final int n = exprs_.length; - if ((null == upi.exprs_) || (upi.exprs_.length != n)) return false; + if ((null == upi.exprs_) || (upi.exprs_.length != n)) { + return false; + } for (int i = 0; i < n; i++) { - if (!exprs_[i].deepEquals(upi.exprs_[i])) return false; + if (!exprs_[i].deepEquals(upi.exprs_[i])) { + return false; + } } } else if (null != upi.exprs_) { diff --git a/src/main/java/org/htmlunit/xpath/axes/WalkerFactory.java b/src/main/java/org/htmlunit/xpath/axes/WalkerFactory.java index a79c9f9..36c7308 100644 --- a/src/main/java/org/htmlunit/xpath/axes/WalkerFactory.java +++ b/src/main/java/org/htmlunit/xpath/axes/WalkerFactory.java @@ -79,7 +79,9 @@ static AxesWalker loadWalkers( prevWalker = walker; stepOpCodePos = compiler.getNextStepPos(stepOpCodePos); - if (stepOpCodePos < 0) break; + if (stepOpCodePos < 0) { + break; + } } return firstWalker; @@ -122,7 +124,9 @@ public static DTMIterator newDTMIterator( // Is the iteration a one-step attribute pattern (i.e. select="@foo")? if (isOneStep && walksSelfOnly(analysis) && isWild(analysis) && !hasPredicate(analysis)) { - if (DEBUG_ITERATOR_CREATION) diagnoseIterator("SelfIteratorNoPredicate", analysis, compiler); + if (DEBUG_ITERATOR_CREATION) { + diagnoseIterator("SelfIteratorNoPredicate", analysis, compiler); + } // Then use a simple iteration of the attributes, with node test // and predicate testing. @@ -134,13 +138,17 @@ else if (walksChildrenOnly(analysis) && isOneStep) { // Does the pattern specify *any* child with no predicate? (i.e. // select="child::node()". if (isWild(analysis) && !hasPredicate(analysis)) { - if (DEBUG_ITERATOR_CREATION) diagnoseIterator("ChildIterator", analysis, compiler); + if (DEBUG_ITERATOR_CREATION) { + diagnoseIterator("ChildIterator", analysis, compiler); + } // Use simple child iteration without any test. iter = new ChildIterator(analysis); } else { - if (DEBUG_ITERATOR_CREATION) diagnoseIterator("ChildTestIterator", analysis, compiler); + if (DEBUG_ITERATOR_CREATION) { + diagnoseIterator("ChildTestIterator", analysis, compiler); + } // Else use simple node test iteration with predicate test. iter = new ChildTestIterator(compiler, opPos, analysis); @@ -148,7 +156,9 @@ else if (walksChildrenOnly(analysis) && isOneStep) { } // Is the iteration a one-step attribute pattern (i.e. select="@foo")? else if (isOneStep && walksAttributes(analysis)) { - if (DEBUG_ITERATOR_CREATION) diagnoseIterator("AttributeIterator", analysis, compiler); + if (DEBUG_ITERATOR_CREATION) { + diagnoseIterator("AttributeIterator", analysis, compiler); + } // Then use a simple iteration of the attributes, with node test // and predicate testing. @@ -157,16 +167,18 @@ else if (isOneStep && walksAttributes(analysis)) { else if (isOneStep && !walksFilteredList(analysis)) { if (!walksNamespaces(analysis) && (walksInDocOrder(analysis) || isSet(analysis, BIT_PARENT))) { - if (false || DEBUG_ITERATOR_CREATION) + if (false || DEBUG_ITERATOR_CREATION) { diagnoseIterator("OneStepIteratorForward", analysis, compiler); + } // Then use a simple iteration of the attributes, with node test // and predicate testing. iter = new OneStepIteratorForward(compiler, opPos, analysis); } else { - if (false || DEBUG_ITERATOR_CREATION) + if (false || DEBUG_ITERATOR_CREATION) { diagnoseIterator("OneStepIterator", analysis, compiler); + } // Then use a simple iteration of the attributes, with node test // and predicate testing. @@ -191,7 +203,9 @@ else if (isOptimizableForDescendantIterator(compiler, firstStepPos) // && walksDescendants(analysis) // && walksSubtreeOnlyFromRootOrContext(analysis) ) { - if (DEBUG_ITERATOR_CREATION) diagnoseIterator("DescendantIterator", analysis, compiler); + if (DEBUG_ITERATOR_CREATION) { + diagnoseIterator("DescendantIterator", analysis, compiler); + } iter = new DescendantIterator(compiler, opPos, analysis); } @@ -208,7 +222,9 @@ else if (isOptimizableForDescendantIterator(compiler, firstStepPos) // diagnoseIterator("MatchPatternIterator", analysis, compiler); // // return new MatchPatternIterator(compiler, opPos, analysis); - if (DEBUG_ITERATOR_CREATION) diagnoseIterator("WalkingIteratorSorted", analysis, compiler); + if (DEBUG_ITERATOR_CREATION) { + diagnoseIterator("WalkingIteratorSorted", analysis, compiler); + } iter = new WalkingIteratorSorted(compiler, opPos, analysis); } @@ -338,7 +354,9 @@ static boolean functionProximateOrContainsProximate(final Compiler compiler, int for (int p = opPos; p < endFunc; p = compiler.getNextOpPos(p)) { final int innerExprOpPos = p + 2; final boolean prox = isProximateInnerExpr(compiler, innerExprOpPos); - if (prox) return true; + if (prox) { + return true; + } } } return false; @@ -349,7 +367,9 @@ static boolean isProximateInnerExpr(final Compiler compiler, final int opPos) { final int innerExprOpPos = opPos + 2; switch (op) { case OpCodes.OP_ARGUMENT: - if (isProximateInnerExpr(compiler, innerExprOpPos)) return true; + if (isProximateInnerExpr(compiler, innerExprOpPos)) { + return true; + } break; case OpCodes.OP_VARIABLE: case OpCodes.OP_NUMBERLIT: @@ -358,7 +378,9 @@ static boolean isProximateInnerExpr(final Compiler compiler, final int opPos) { break; // OK case OpCodes.OP_FUNCTION: boolean isProx = functionProximateOrContainsProximate(compiler, opPos); - if (isProx) return true; + if (isProx) { + return true; + } break; case OpCodes.OP_GT: case OpCodes.OP_GTE: @@ -368,9 +390,13 @@ static boolean isProximateInnerExpr(final Compiler compiler, final int opPos) { final int leftPos = OpMap.getFirstChildPos(op); final int rightPos = compiler.getNextOpPos(leftPos); isProx = isProximateInnerExpr(compiler, leftPos); - if (isProx) return true; + if (isProx) { + return true; + } isProx = isProximateInnerExpr(compiler, rightPos); - if (isProx) return true; + if (isProx) { + return true; + } break; default: return true; // be conservative... @@ -410,7 +436,9 @@ public static boolean mightBeProximate( return true; // that's all she wrote! case OpCodes.OP_FUNCTION: boolean isProx = functionProximateOrContainsProximate(compiler, innerExprOpPos); - if (isProx) return true; + if (isProx) { + return true; + } break; case OpCodes.OP_GT: case OpCodes.OP_GTE: @@ -420,9 +448,13 @@ public static boolean mightBeProximate( final int leftPos = OpMap.getFirstChildPos(innerExprOpPos); final int rightPos = compiler.getNextOpPos(leftPos); isProx = isProximateInnerExpr(compiler, leftPos); - if (isProx) return true; + if (isProx) { + return true; + } isProx = isProximateInnerExpr(compiler, rightPos); - if (isProx) return true; + if (isProx) { + return true; + } break; default: return true; // be conservative... @@ -457,14 +489,19 @@ private static boolean isOptimizableForDescendantIterator( while (OpCodes.ENDOP != (stepType = compiler.getOp(stepOpCodePos))) { // The DescendantIterator can only do one node test. If there's more // than one, use another iterator. - if (nodeTestType != OpCodes.NODETYPE_NODE && nodeTestType != OpCodes.NODETYPE_ROOT) + if (nodeTestType != OpCodes.NODETYPE_NODE && nodeTestType != OpCodes.NODETYPE_ROOT) { return false; + } stepCount++; - if (stepCount > 3) return false; + if (stepCount > 3) { + return false; + } final boolean mightBeProximate = mightBeProximate(compiler, stepOpCodePos, stepType); - if (mightBeProximate) return false; + if (mightBeProximate) { + return false; + } switch (stepType) { case OpCodes.FROM_FOLLOWING: @@ -484,19 +521,27 @@ private static boolean isOptimizableForDescendantIterator( case OpCodes.MATCH_IMMEDIATE_ANCESTOR: return false; case OpCodes.FROM_ROOT: - if (1 != stepCount) return false; + if (1 != stepCount) { + return false; + } break; case OpCodes.FROM_CHILDREN: - if (!foundDS && !(foundDorDS && foundSelf)) return false; + if (!foundDS && !(foundDorDS && foundSelf)) { + return false; + } break; case OpCodes.FROM_DESCENDANTS_OR_SELF: foundDS = true; case OpCodes.FROM_DESCENDANTS: - if (3 == stepCount) return false; + if (3 == stepCount) { + return false; + } foundDorDS = true; break; case OpCodes.FROM_SELF: - if (1 != stepCount) return false; + if (1 != stepCount) { + return false; + } foundSelf = true; break; default: @@ -510,7 +555,9 @@ private static boolean isOptimizableForDescendantIterator( final int nextStepOpCodePos = compiler.getNextStepPos(stepOpCodePos); - if (nextStepOpCodePos < 0) break; + if (nextStepOpCodePos < 0) { + break; + } if (OpCodes.ENDOP != compiler.getOp(nextStepOpCodePos)) { if (compiler.countPredicates(stepOpCodePos) > 0) { @@ -546,7 +593,9 @@ private static int analyze(final Compiler compiler, int stepOpCodePos) final boolean predAnalysis = analyzePredicate(compiler, stepOpCodePos, stepType); - if (predAnalysis) analysisResult |= BIT_PREDICATE; + if (predAnalysis) { + analysisResult |= BIT_PREDICATE; + } switch (stepType) { case OpCodes.OP_VARIABLE: @@ -624,7 +673,9 @@ private static int analyze(final Compiler compiler, int stepOpCodePos) stepOpCodePos = compiler.getNextStepPos(stepOpCodePos); - if (stepOpCodePos < 0) break; + if (stepOpCodePos < 0) { + break; + } } analysisResult |= stepCount & BITS_COUNT; @@ -644,9 +695,8 @@ public static boolean isDownwardAxisOfMany(final int axis) { || (Axis.DESCENDANT == axis) || (Axis.FOLLOWING == axis) // || (Axis.FOLLOWINGSIBLING == axis) - || (Axis.PRECEDING == axis) - // || (Axis.PRECEDINGSIBLING == axis) - ; + || (Axis.PRECEDING == axis); + // || (Axis.PRECEDINGSIBLING == axis) } /** @@ -691,7 +741,9 @@ static StepPattern loadSteps(final Compiler compiler, int stepOpCodePos) prevStep = step; stepOpCodePos = compiler.getNextStepPos(stepOpCodePos); - if (stepOpCodePos < 0) break; + if (stepOpCodePos < 0) { + break; + } } int axis = Axis.SELF; @@ -752,8 +804,12 @@ static StepPattern loadSteps(final Compiler compiler, int stepOpCodePos) // wacky Xalan rules for following from an attribute. See axes108. // By these rules, following from an attribute is not strictly // inverseable. - if (Axis.PRECEDING == pat.getAxis()) pat.setAxis(Axis.PRECEDINGANDANCESTOR); - else if (Axis.DESCENDANT == pat.getAxis()) pat.setAxis(Axis.DESCENDANTORSELF); + if (Axis.PRECEDING == pat.getAxis()) { + pat.setAxis(Axis.PRECEDINGANDANCESTOR); + } + else if (Axis.DESCENDANT == pat.getAxis()) { + pat.setAxis(Axis.DESCENDANTORSELF); + } pat = attrPat; } @@ -941,8 +997,9 @@ private static AxesWalker createDefaultWalker( case OpCodes.OP_VARIABLE: case OpCodes.OP_FUNCTION: case OpCodes.OP_GROUP: - if (DEBUG_WALKER_CREATION) + if (DEBUG_WALKER_CREATION) { System.out.println("new walker: FilterExprWalker: " + analysis + ", " + compiler); + } ai = new FilterExprWalker(lpi); simpleInit = true; @@ -1008,7 +1065,9 @@ private static AxesWalker createDefaultWalker( | DTMFilter.SHOW_NAMESPACE | DTMFilter.SHOW_ELEMENT | DTMFilter.SHOW_PROCESSING_INSTRUCTION))) - || (whatToShow == DTMFilter.SHOW_ALL)) ai.initNodeTest(whatToShow); + || (whatToShow == DTMFilter.SHOW_ALL)) { + ai.initNodeTest(whatToShow); + } else { ai.initNodeTest(whatToShow, compiler.getStepNS(opPos), compiler.getStepLocalName(opPos)); } @@ -1216,15 +1275,31 @@ public static boolean canSkipSubtrees(final int analysis) { public static boolean canCrissCross(final int analysis) { // This could be done faster. Coded for clarity. - if (walksSelfOnly(analysis)) return false; - else if (walksDownOnly(analysis) && !canSkipSubtrees(analysis)) return false; - else if (walksChildrenAndExtraAndSelfOnly(analysis)) return false; - else if (walksDescendantsAndExtraAndSelfOnly(analysis)) return false; - else if (walksUpOnly(analysis)) return false; - else if (walksExtraNodesOnly(analysis)) return false; + if (walksSelfOnly(analysis)) { + return false; + } + else if (walksDownOnly(analysis) && !canSkipSubtrees(analysis)) { + return false; + } + else if (walksChildrenAndExtraAndSelfOnly(analysis)) { + return false; + } + else if (walksDescendantsAndExtraAndSelfOnly(analysis)) { + return false; + } + else if (walksUpOnly(analysis)) { + return false; + } + else if (walksExtraNodesOnly(analysis)) { + return false; + } else if (walksSubtree(analysis) - && (walksSideways(analysis) || walksUp(analysis) || canSkipSubtrees(analysis))) return true; - else return false; + && (walksSideways(analysis) || walksUp(analysis) || canSkipSubtrees(analysis))) { + return true; + } + else { + return false; + } } /** @@ -1251,7 +1326,9 @@ private static boolean isNaturalDocOrder( if (canCrissCross(analysis) || isSet(analysis, BIT_NAMESPACE) || (isSet(analysis, BIT_FOLLOWING | BIT_FOLLOWING_SIBLING) - && isSet(analysis, BIT_PRECEDING | BIT_PRECEDING_SIBLING))) return false; + && isSet(analysis, BIT_PRECEDING | BIT_PRECEDING_SIBLING))) { + return false; + } // OK, now we have to check for select="@*/axis::*" patterns, which // can also cause duplicates to happen. But select="axis*/@::*" patterns @@ -1299,12 +1376,16 @@ private static boolean isNaturalDocOrder( case OpCodes.MATCH_IMMEDIATE_ANCESTOR: case OpCodes.FROM_DESCENDANTS_OR_SELF: case OpCodes.FROM_DESCENDANTS: - if (potentialDuplicateMakingStepCount > 0) return false; + if (potentialDuplicateMakingStepCount > 0) { + return false; + } potentialDuplicateMakingStepCount++; case OpCodes.FROM_ROOT: case OpCodes.FROM_CHILDREN: case OpCodes.FROM_SELF: - if (foundWildAttribute) return false; + if (foundWildAttribute) { + return false; + } break; default: throw new RuntimeException( @@ -1315,7 +1396,9 @@ private static boolean isNaturalDocOrder( final int nextStepOpCodePos = compiler.getNextStepPos(stepOpCodePos); - if (nextStepOpCodePos < 0) break; + if (nextStepOpCodePos < 0) { + break; + } stepOpCodePos = nextStepOpCodePos; } diff --git a/src/main/java/org/htmlunit/xpath/compiler/Compiler.java b/src/main/java/org/htmlunit/xpath/compiler/Compiler.java index 1ae947b..66d45a0 100644 --- a/src/main/java/org/htmlunit/xpath/compiler/Compiler.java +++ b/src/main/java/org/htmlunit/xpath/compiler/Compiler.java @@ -611,10 +611,11 @@ public int getWhatToShow(final int opPos) { case OpCodes.FROM_DESCENDANTS_OR_SELF: return DTMFilter.SHOW_ALL; default: - if (getOp(0) == OpCodes.OP_MATCHPATTERN) + if (getOp(0) == OpCodes.OP_MATCHPATTERN) { return ~DTMFilter.SHOW_ATTRIBUTE & ~DTMFilter.SHOW_DOCUMENT & ~DTMFilter.SHOW_DOCUMENT_FRAGMENT; + } return ~DTMFilter.SHOW_ATTRIBUTE; } case OpCodes.NODETYPE_ROOT: diff --git a/src/main/java/org/htmlunit/xpath/compiler/FunctionTable.java b/src/main/java/org/htmlunit/xpath/compiler/FunctionTable.java index d5b8f78..62cbc91 100644 --- a/src/main/java/org/htmlunit/xpath/compiler/FunctionTable.java +++ b/src/main/java/org/htmlunit/xpath/compiler/FunctionTable.java @@ -224,7 +224,9 @@ String getFunctionName(final int funcID) { */ Function getFunction(final int which) throws javax.xml.transform.TransformerException { try { - if (which < NUM_BUILT_IN_FUNCS) return (Function) m_functions[which].newInstance(); + if (which < NUM_BUILT_IN_FUNCS) { + return (Function) m_functions[which].newInstance(); + } return (Function) m_functions_customer[which - NUM_BUILT_IN_FUNCS].newInstance(); } catch (IllegalAccessException | InstantiationException ex) { @@ -242,7 +244,9 @@ Function getFunction(final int which) throws javax.xml.transform.TransformerExce */ Object getFunctionID(final String key) { Object id = m_functionID_customer.get(key); - if (null == id) id = m_functionID.get(key); + if (null == id) { + id = m_functionID.get(key); + } return id; } @@ -285,7 +289,9 @@ public int installFunction(final String name, final Class func) { */ public boolean functionAvailable(final String methName) { Object tblEntry = m_functionID.get(methName); - if (null != tblEntry) return true; + if (null != tblEntry) { + return true; + } tblEntry = m_functionID_customer.get(methName); return null != tblEntry; diff --git a/src/main/java/org/htmlunit/xpath/compiler/Lexer.java b/src/main/java/org/htmlunit/xpath/compiler/Lexer.java index dfb41de..5be1947 100644 --- a/src/main/java/org/htmlunit/xpath/compiler/Lexer.java +++ b/src/main/java/org/htmlunit/xpath/compiler/Lexer.java @@ -252,7 +252,9 @@ else if (('(' == c) || ('[' == c)) { if (i > 0) { if (posOfNSSep == (i - 1)) { if (startSubstring != -1) { - if (startSubstring < (i - 1)) addToTokenQueue(pat.substring(startSubstring, i - 1)); + if (startSubstring < (i - 1)) { + addToTokenQueue(pat.substring(startSubstring, i - 1)); + } } isNum = false; @@ -476,7 +478,9 @@ private int mapNSTokens( if ((null != m_namespaceContext) && !prefix.equals("*") && !prefix.equals("xmlns")) { try { - if (prefix.length() > 0) uName = m_namespaceContext.getNamespaceForPrefix(prefix); + if (prefix.length() > 0) { + uName = m_namespaceContext.getNamespaceForPrefix(prefix); + } else { // Assume last was wildcard. This is not legal according @@ -487,7 +491,9 @@ private int mapNSTokens( final String s = pat.substring(posOfNSSep + 1, posOfScan); - if (s.length() > 0) addToTokenQueue(s); + if (s.length() > 0) { + addToTokenQueue(s); + } return -1; } @@ -508,7 +514,9 @@ private int mapNSTokens( final String s = pat.substring(posOfNSSep + 1, posOfScan); - if (s.length() > 0) addToTokenQueue(s); + if (s.length() > 0) { + addToTokenQueue(s); + } } else { m_processor.error(XPATHErrorResources.ER_PREFIX_MUST_RESOLVE, new String[] {prefix}); diff --git a/src/main/java/org/htmlunit/xpath/functions/FuncNamespace.java b/src/main/java/org/htmlunit/xpath/functions/FuncNamespace.java index b507a76..fa8cbe3 100644 --- a/src/main/java/org/htmlunit/xpath/functions/FuncNamespace.java +++ b/src/main/java/org/htmlunit/xpath/functions/FuncNamespace.java @@ -44,13 +44,19 @@ else if (t == DTM.ATTRIBUTE_NODE) { // We check for those here. Fix inspired by Davanum Srinivas. s = dtm.getNodeName(context); - if (s.startsWith("xmlns:") || s.equals("xmlns")) return XString.EMPTYSTRING; + if (s.startsWith("xmlns:") || s.equals("xmlns")) { + return XString.EMPTYSTRING; + } s = dtm.getNamespaceURI(context); } - else return XString.EMPTYSTRING; + else { + return XString.EMPTYSTRING; + } + } + else { + return XString.EMPTYSTRING; } - else return XString.EMPTYSTRING; return (null == s) ? XString.EMPTYSTRING : new XString(s); } diff --git a/src/main/java/org/htmlunit/xpath/xml/dtm/ref/DTMNodeIterator.java b/src/main/java/org/htmlunit/xpath/xml/dtm/ref/DTMNodeIterator.java index c59801d..c273b48 100644 --- a/src/main/java/org/htmlunit/xpath/xml/dtm/ref/DTMNodeIterator.java +++ b/src/main/java/org/htmlunit/xpath/xml/dtm/ref/DTMNodeIterator.java @@ -102,20 +102,28 @@ public int getWhatToShow() { /** {@inheritDoc} */ @Override public Node nextNode() throws DOMException { - if (!valid) throw new DOMException(DOMException.INVALID_STATE_ERR, ""); + if (!valid) { + throw new DOMException(DOMException.INVALID_STATE_ERR, ""); + } final int handle = dtm_iter.nextNode(); - if (handle == DTM.NULL) return null; + if (handle == DTM.NULL) { + return null; + } return dtm_iter.getDTM(handle).getNode(handle); } /** {@inheritDoc} */ @Override public Node previousNode() { - if (!valid) throw new DOMException(DOMException.INVALID_STATE_ERR, ""); + if (!valid) { + throw new DOMException(DOMException.INVALID_STATE_ERR, ""); + } final int handle = dtm_iter.previousNode(); - if (handle == DTM.NULL) return null; + if (handle == DTM.NULL) { + return null; + } return dtm_iter.getDTM(handle).getNode(handle); } }