Skip to content

Commit

Permalink
code style
Browse files Browse the repository at this point in the history
  • Loading branch information
rbri committed Jun 4, 2024
1 parent 4c63e5d commit e7aecc5
Show file tree
Hide file tree
Showing 9 changed files with 264 additions and 92 deletions.
40 changes: 30 additions & 10 deletions src/main/java/org/htmlunit/xpath/axes/AxesWalker.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,25 +80,35 @@ public Object clone() throws CloneNotSupportedException {
AxesWalker cloneDeep(final WalkingIterator cloneOwner, final Vector<AxesWalker> 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) {
cloneList.addElement(this);
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;
}
Expand All @@ -116,7 +126,9 @@ static AxesWalker findClone(final AxesWalker key, final Vector<AxesWalker> 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;
Expand Down Expand Up @@ -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);
Expand All @@ -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;
}
Expand All @@ -242,7 +258,9 @@ public int nextNode() {
AxesWalker walker = wi().getLastUsedWalker();

while (true) {
if (null == walker) break;
if (null == walker) {
break;
}

nextNode = walker.getNextNode();

Expand Down Expand Up @@ -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;
Expand Down
52 changes: 39 additions & 13 deletions src/main/java/org/htmlunit/xpath/axes/DescendantIterator.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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);

Expand All @@ -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));
Expand All @@ -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();
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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;
}
Expand Down
28 changes: 21 additions & 7 deletions src/main/java/org/htmlunit/xpath/axes/UnionPathIterator.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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
Expand All @@ -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;
Expand All @@ -269,7 +275,9 @@ else if (DTM.NULL == earliestNode) {

incrementCurrentPos();
}
else m_foundLast = true;
else {
m_foundLast = true;
}
}

m_lastFetched = earliestNode;
Expand Down Expand Up @@ -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_) {
Expand Down
Loading

0 comments on commit e7aecc5

Please sign in to comment.