41
41
42
42
/**
43
43
* Processes all location path steps (like descendant::*, ancestor::XXX).
44
- *
44
+ * <p>
45
45
* The results of the first evaluation of the expression are cached for the
46
46
* lifetime of the object and only reloaded if the context sequence (as passed
47
47
* to the {@link #eval(Sequence, Item)} method) has changed.
@@ -63,7 +63,7 @@ public class LocationStep extends Step {
63
63
//private int parentDeps = Dependency.UNKNOWN_DEPENDENCY;
64
64
private boolean preloadedData = false ;
65
65
protected boolean optimized = false ;
66
- // private boolean inUpdate = false;
66
+ // private boolean inUpdate = false;
67
67
private boolean useDirectChildSelect = false ;
68
68
private boolean applyPredicate = true ;
69
69
@@ -84,36 +84,36 @@ public LocationStep(final XQueryContext context, final int axis) {
84
84
* Creates a new instance.
85
85
*
86
86
* @param context the XQuery context
87
- * @param axis the axis of the location step
88
- * @param test a node test on the axis
87
+ * @param axis the axis of the location step
88
+ * @param test a node test on the axis
89
89
*/
90
- public LocationStep (final XQueryContext context , final int axis , final NodeTest test ) {
90
+ public LocationStep (final XQueryContext context , final int axis , final NodeTest test ) {
91
91
super (context , axis , test );
92
92
}
93
93
94
94
@ Override
95
95
public int getDependencies () {
96
- int deps = Dependency .CONTEXT_SET ;
96
+ int dependencies = Dependency .CONTEXT_SET ;
97
97
98
98
// self axis has an obvious dependency on the context item
99
99
// likewise we depend on the context item if this is a single path step (outside a predicate)
100
- if (!this . inPredicate &&
101
- (this . axis == Constants .SELF_AXIS ||
100
+ if (!inPredicate &&
101
+ (axis == Constants .SELF_AXIS ||
102
102
(parent != null && parent .getSubExpressionCount () > 0 && parent .getSubExpression (0 ) == this ))) {
103
- deps = deps | Dependency .CONTEXT_ITEM ;
103
+ dependencies = dependencies | Dependency .CONTEXT_ITEM ;
104
104
}
105
105
106
106
// TODO : normally, we should call this one...
107
107
// int deps = super.getDependencies(); ???
108
- for (final Predicate pred : predicates ) {
109
- deps |= pred .getDependencies ();
108
+ for (final Predicate predicate : predicates ) {
109
+ dependencies |= predicate .getDependencies ();
110
110
}
111
111
112
112
// TODO : should we remove the CONTEXT_ITEM dependency returned by the
113
113
// predicates ? See the comment above.
114
114
// consider nested predicates however...
115
115
116
- return deps ;
116
+ return dependencies ;
117
117
}
118
118
119
119
/**
@@ -147,10 +147,10 @@ private boolean hasPreloadedData() {
147
147
* @param nodes a <code>NodeSet</code> value
148
148
*/
149
149
public void setPreloadedData (final DocumentSet docs , final NodeSet nodes ) {
150
- this . preloadedData = true ;
151
- this . currentDocs = docs ;
152
- this . currentSet = nodes ;
153
- this . optimized = true ;
150
+ preloadedData = true ;
151
+ currentDocs = docs ;
152
+ currentSet = nodes ;
153
+ optimized = true ;
154
154
}
155
155
156
156
/**
@@ -165,12 +165,9 @@ private Sequence applyPredicate(Sequence outerSequence, final Sequence contextSe
165
165
if (contextSequence == null ) {
166
166
return Sequence .EMPTY_SEQUENCE ;
167
167
}
168
- if (predicates .size () == 0
169
- || !applyPredicate
170
- || (!(contextSequence instanceof VirtualNodeSet ) && contextSequence
171
- .isEmpty ()))
172
- // Nothing to apply
173
- {
168
+ if (predicates .size () == 0 || !applyPredicate || (
169
+ !(contextSequence instanceof VirtualNodeSet ) && contextSequence .isEmpty ())) {
170
+ // Nothing to apply
174
171
return contextSequence ;
175
172
}
176
173
Sequence result ;
@@ -183,9 +180,8 @@ private Sequence applyPredicate(Sequence outerSequence, final Sequence contextSe
183
180
//
184
181
// If the predicate is known to return a node set, no special treatment
185
182
// is required.
186
- if (abbreviatedStep
187
- && (pred .getExecutionMode () != Predicate .ExecutionMode .NODE || !contextSequence
188
- .isPersistentSet ())) {
183
+ if (abbreviatedStep && (
184
+ pred .getExecutionMode () != Predicate .ExecutionMode .NODE || !contextSequence .isPersistentSet ())) {
189
185
result = new ValueSequence ();
190
186
((ValueSequence ) result ).keepUnOrdered (unordered );
191
187
if (contextSequence .isPersistentSet ()) {
@@ -222,9 +218,9 @@ private Sequence processPredicate(Sequence outerSequence, final Sequence context
222
218
for (final Iterator <Predicate > i = predicates .iterator (); i .hasNext ()
223
219
&& (result instanceof VirtualNodeSet || !result .isEmpty ()); ) {
224
220
// TODO : log and/or profile ?
225
- final Predicate pred = i .next ();
226
- pred .setContextDocSet (getContextDocSet ());
227
- result = pred .evalPredicate (outerSequence , result , axis );
221
+ final Predicate predicate = i .next ();
222
+ predicate .setContextDocSet (getContextDocSet ());
223
+ result = predicate .evalPredicate (outerSequence , result , axis );
228
224
// subsequent predicates operate on the result of the previous one
229
225
outerSequence = null ;
230
226
context .setContextSequencePosition (0 , null );
@@ -234,7 +230,7 @@ private Sequence processPredicate(Sequence outerSequence, final Sequence context
234
230
235
231
@ Override
236
232
public void analyze (final AnalyzeContextInfo contextInfo ) throws XPathException {
237
- this . parent = contextInfo .getParent ();
233
+ parent = contextInfo .getParent ();
238
234
239
235
unordered = (contextInfo .getFlags () & UNORDERED ) > 0 ;
240
236
@@ -248,16 +244,18 @@ public void analyze(final AnalyzeContextInfo contextInfo) throws XPathException
248
244
if ((contextInfo .getFlags () & USE_TREE_TRAVERSAL ) > 0 ) {
249
245
useDirectChildSelect = true ;
250
246
}
247
+
251
248
// Mark ".", which is expanded as self::node() by the parser
252
249
// even though it may *also* be relevant with atomic sequences
253
- if (this .axis == Constants .SELF_AXIS
254
- && this .test .getType () == Type .NODE ) {
250
+ // JL: may be unnecessary since ContextItemExpression will add the DOT_TEST flag by itself
251
+ // JL: literal self::node() might still need this
252
+ if (axis == Constants .SELF_AXIS && test .getType () == Type .NODE ) {
255
253
contextInfo .addFlag (DOT_TEST );
256
254
}
257
255
258
- //Change axis from descendant-or-self to descendant for '//'
259
- if (this . axis == Constants .DESCENDANT_SELF_AXIS && isAbbreviated ()) {
260
- this . axis = Constants .DESCENDANT_AXIS ;
256
+ // Change axis from descendant-or-self to descendant for '//'
257
+ if (axis == Constants .DESCENDANT_SELF_AXIS && isAbbreviated ()) {
258
+ axis = Constants .DESCENDANT_AXIS ;
261
259
}
262
260
263
261
final Expression contextStep ;
@@ -320,8 +318,8 @@ public void analyze(final AnalyzeContextInfo contextInfo) throws XPathException
320
318
staticReturnType = Type .EMPTY ;
321
319
}
322
320
break ;
323
- // case Constants.PARENT_AXIS:
324
- // case Constants.ATTRIBUTE_AXIS:
321
+ // case Constants.PARENT_AXIS:
322
+ // case Constants.ATTRIBUTE_AXIS:
325
323
default :
326
324
}
327
325
@@ -385,7 +383,6 @@ public Sequence eval(Sequence contextSequence, final Item contextItem)
385
383
386
384
try {
387
385
switch (axis ) {
388
-
389
386
case Constants .DESCENDANT_AXIS :
390
387
case Constants .DESCENDANT_SELF_AXIS :
391
388
result = getDescendants (context , contextSequence );
@@ -486,16 +483,15 @@ private boolean needsComputation() {
486
483
if (nodeTestType == null ) {
487
484
nodeTestType = test .getType ();
488
485
}
489
- if (nodeTestType != Type .NODE
490
- && nodeTestType != Type .ELEMENT
491
- && nodeTestType != Type .PROCESSING_INSTRUCTION ) {
486
+ if (nodeTestType != Type .NODE &&
487
+ nodeTestType != Type .ELEMENT &&
488
+ nodeTestType != Type .PROCESSING_INSTRUCTION ) {
492
489
if (context .getProfiler ().isEnabled ()) {
493
490
context .getProfiler ().message (this , Profiler .OPTIMIZATIONS ,
494
491
"OPTIMIZATION" , "avoid useless computations" );
495
492
}
496
493
return false ;
497
494
}
498
-
499
495
}
500
496
return true ;
501
497
}
@@ -556,7 +552,7 @@ private Sequence getSelf(final XQueryContext context, final Sequence contextSequ
556
552
} else {
557
553
final NewArrayNodeSet results = new NewArrayNodeSet ();
558
554
for (final NodeProxy p : contextSet ) {
559
- if (test .matches (p )) {
555
+ if (test .matches (p )) {
560
556
results .add (p );
561
557
}
562
558
}
@@ -601,10 +597,8 @@ protected Sequence getAttributes(final XQueryContext context, final Sequence con
601
597
if (hasPreloadedData ()) {
602
598
final DocumentSet docs = getDocumentSet (contextSet );
603
599
synchronized (context ) {
604
- if (currentSet == null
605
- || currentDocs == null
606
- || (!optimized && !(docs == currentDocs || docs
607
- .equalDocs (currentDocs )))) {
600
+ if (currentSet == null || currentDocs == null || (
601
+ !optimized && !(docs == currentDocs || docs .equalDocs (currentDocs )))) {
608
602
final StructuralIndex index = context .getBroker ().getStructuralIndex ();
609
603
if (context .getProfiler ().isEnabled ()) {
610
604
context .getProfiler ().message (
@@ -691,10 +685,8 @@ private Sequence getChildren(final XQueryContext context, final Sequence context
691
685
synchronized (context ) {
692
686
// TODO : understand why this one is different from the other
693
687
// ones
694
- if (currentSet == null
695
- || currentDocs == null
696
- || (!optimized && !(docs == currentDocs || docs
697
- .equalDocs (currentDocs )))) {
688
+ if (currentSet == null || currentDocs == null || (
689
+ !optimized && !(docs == currentDocs || docs .equalDocs (currentDocs )))) {
698
690
final StructuralIndex index = context .getBroker ().getStructuralIndex ();
699
691
if (context .getProfiler ().isEnabled ()) {
700
692
context .getProfiler ().message (
@@ -735,15 +727,14 @@ private Sequence getChildren(final XQueryContext context, final Sequence context
735
727
private Sequence getDescendants (final XQueryContext context , final Sequence contextSequence ) throws XPathException {
736
728
if (!contextSequence .isPersistentSet ()) {
737
729
final MemoryNodeSet nodes = contextSequence .toMemNodeSet ();
738
- return nodes .getDescendants (axis == Constants .DESCENDANT_SELF_AXIS ,
739
- test );
730
+ return nodes .getDescendants (axis == Constants .DESCENDANT_SELF_AXIS , test );
740
731
}
741
732
742
733
final NodeSet contextSet = contextSequence .toNodeSet ();
743
734
// TODO : understand this. I guess comments should be treated in a
744
735
// similar way ? -pb
745
- if ((!hasPreloadedData () && test .isWildcardTest ())
746
- || test .getType () == Type .PROCESSING_INSTRUCTION ) {
736
+ if ((!hasPreloadedData () && test .isWildcardTest ()) ||
737
+ test .getType () == Type .PROCESSING_INSTRUCTION ) {
747
738
// test is one out of *, text(), node() including
748
739
// processing-instruction(targetname)
749
740
final VirtualNodeSet vset = new VirtualNodeSet (context .getBroker (), axis , test , contextId , contextSet );
@@ -754,10 +745,8 @@ private Sequence getDescendants(final XQueryContext context, final Sequence cont
754
745
synchronized (context ) {
755
746
// TODO : understand why this one is different from the other
756
747
// ones
757
- if (currentSet == null
758
- || currentDocs == null
759
- || (!optimized && !(docs == currentDocs || docs
760
- .equalDocs (currentDocs )))) {
748
+ if (currentSet == null || currentDocs == null || (
749
+ !optimized && !(docs == currentDocs || docs .equalDocs (currentDocs )))) {
761
750
final StructuralIndex index = context .getBroker ().getStructuralIndex ();
762
751
if (context .getProfiler ().isEnabled ()) {
763
752
context .getProfiler ().message (
@@ -774,11 +763,11 @@ private Sequence getDescendants(final XQueryContext context, final Sequence cont
774
763
775
764
switch (axis ) {
776
765
case Constants .DESCENDANT_SELF_AXIS :
777
- return currentSet .selectAncestorDescendant (contextSet , NodeSet . DESCENDANT , true , contextId ,
778
- true );
766
+ return currentSet .selectAncestorDescendant (
767
+ contextSet , NodeSet . DESCENDANT , true , contextId , true );
779
768
case Constants .DESCENDANT_AXIS :
780
- return currentSet .selectAncestorDescendant (contextSet , NodeSet . DESCENDANT , false , contextId ,
781
- true );
769
+ return currentSet .selectAncestorDescendant (
770
+ contextSet , NodeSet . DESCENDANT , false , contextId , true );
782
771
default :
783
772
throw new IllegalArgumentException ("Unsupported axis specified" );
784
773
}
@@ -910,11 +899,9 @@ protected Sequence getSiblings(final XQueryContext context, final Sequence conte
910
899
/**
911
900
* Get the preceding or following axis nodes
912
901
*
913
- * @param context the xquery context
902
+ * @param context the xquery context
914
903
* @param contextSequence the context sequence
915
- *
916
904
* @return the nodes from the preceding or following axis
917
- *
918
905
* @throws XPathException if an error occurs
919
906
*/
920
907
private Sequence getPrecedingOrFollowing (final XQueryContext context , final Sequence contextSequence )
@@ -1034,11 +1021,9 @@ private int computeLimit() throws XPathException {
1034
1021
/**
1035
1022
* Get the ancestor axis nodes
1036
1023
*
1037
- * @param context the xquery context
1024
+ * @param context the xquery context
1038
1025
* @param contextSequence the context sequence
1039
- *
1040
1026
* @return the ancestor nodes
1041
- *
1042
1027
* @throws XPathException if an error occurs
1043
1028
*/
1044
1029
protected Sequence getAncestors (final XQueryContext context , final Sequence contextSequence ) throws XPathException {
@@ -1138,11 +1123,9 @@ protected Sequence getAncestors(final XQueryContext context, final Sequence cont
1138
1123
/**
1139
1124
* Get the parent axis nodes
1140
1125
*
1141
- * @param context the xquery context
1126
+ * @param context the xquery context
1142
1127
* @param contextSequence the context sequence
1143
- *
1144
1128
* @return the parent nodes
1145
- *
1146
1129
* @throws XPathException if an error occurs
1147
1130
*/
1148
1131
protected Sequence getParents (final XQueryContext context , final Sequence contextSequence ) throws XPathException {
@@ -1164,7 +1147,8 @@ protected Sequence getParents(final XQueryContext context, final Sequence contex
1164
1147
} else if (hasPreloadedData ()) {
1165
1148
final DocumentSet docs = getDocumentSet (contextSet );
1166
1149
synchronized (context ) {
1167
- if (currentSet == null || currentDocs == null || (!optimized && !(docs == currentDocs || docs .equalDocs (currentDocs )))) {
1150
+ if (currentSet == null || currentDocs == null ||
1151
+ (!optimized && !(docs == currentDocs || docs .equalDocs (currentDocs )))) {
1168
1152
final StructuralIndex index = context .getBroker ().getStructuralIndex ();
1169
1153
if (context .getProfiler ().isEnabled ()) {
1170
1154
context .getProfiler ().message (
@@ -1311,7 +1295,7 @@ private class FollowingSiblingFilter extends AbstractFilterBase {
1311
1295
boolean sibling = false ;
1312
1296
1313
1297
FollowingSiblingFilter (final NodeTest test , final NodeProxy start , final NodeSet result ,
1314
- final int contextId , final int limit ) {
1298
+ final int contextId , final int limit ) {
1315
1299
super (test , result , contextId , limit );
1316
1300
this .start = start ;
1317
1301
this .level = start .getNodeId ().getTreeLevel ();
@@ -1363,7 +1347,7 @@ private class PrecedingSiblingFilter extends AbstractFilterBase {
1363
1347
final NodeProxy referenceNode ;
1364
1348
1365
1349
PrecedingSiblingFilter (final NodeTest test , final NodeProxy start , final NodeProxy referenceNode ,
1366
- final NodeSet result , final int contextId ) {
1350
+ final NodeSet result , final int contextId ) {
1367
1351
super (test , result , contextId , -1 );
1368
1352
this .level = start .getNodeId ().getTreeLevel ();
1369
1353
this .referenceNode = referenceNode ;
@@ -1411,7 +1395,7 @@ private class FollowingFilter extends AbstractFilterBase {
1411
1395
boolean isAfter = false ;
1412
1396
1413
1397
FollowingFilter (final NodeTest test , final NodeProxy root , final NodeProxy referenceNode , final NodeSet result ,
1414
- final int contextId , final int limit ) {
1398
+ final int contextId , final int limit ) {
1415
1399
super (test , result , contextId , limit );
1416
1400
this .root = root ;
1417
1401
this .referenceNode = referenceNode ;
@@ -1460,7 +1444,7 @@ private class PrecedingFilter extends AbstractFilterBase {
1460
1444
final NodeProxy referenceNode ;
1461
1445
1462
1446
PrecedingFilter (final NodeTest test , final NodeProxy root , final NodeProxy referenceNode , final NodeSet result ,
1463
- final int contextId ) {
1447
+ final int contextId ) {
1464
1448
super (test , result , contextId , -1 );
1465
1449
this .root = root ;
1466
1450
this .referenceNode = referenceNode ;
0 commit comments