Skip to content

Commit

Permalink
[reactor] Remove unecessary additional interface function in preparat…
Browse files Browse the repository at this point in the history
…ion for de-composition of interfaces
  • Loading branch information
adamretter committed Oct 8, 2023
1 parent 7a47e1e commit bfa7afa
Show file tree
Hide file tree
Showing 70 changed files with 140 additions and 158 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ private static final class IteratorItem extends OrderedLinkedList.Node {
public IteratorItem(final NodeProxy proxy, final PathExpr expr) {
this.proxy = proxy;
try {
final Sequence seq = expr.eval(proxy);
final Sequence seq = expr.eval(proxy, null);
final StringBuilder buf = new StringBuilder();
final OrderedLinkedList strings = new OrderedLinkedList();
Item item;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,12 @@ public void doRewrite(final HttpServletRequest request, final HttpServletRespons
final ContextItemDeclaration cid = call.getContext().getContextItemDeclartion();
final Sequence contextSequence;
if (cid != null) {
contextSequence = cid.eval(null);
contextSequence = cid.eval(null, null);
} else {
contextSequence = null;
}

final Sequence result = call.eval(contextSequence);
final Sequence result = call.eval(contextSequence, null);
if (LOG.isDebugEnabled()) {
LOG.debug("Found: {}", result.getItemCount());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,13 @@ protected void runScript(Subject subject, String scriptURI, String script, QName
final Sequence contextSequence;
final ContextItemDeclaration cid = context.getContextItemDeclartion();
if(cid != null) {
contextSequence = cid.eval(null);
contextSequence = cid.eval(null, null);
} else {
contextSequence = NodeSet.EMPTY_SET;
}

call.analyze(new AnalyzeContextInfo());
call.eval(contextSequence);
call.eval(contextSequence, null);
}
} catch(final XPathException e) {
//XXX: log
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,6 @@ public int getContextId() {
return contextId;
}

@Override
public Sequence eval(Sequence contextSequence) throws XPathException {
return eval(contextSequence, null);
}

@Override
public void resetState(boolean postOptimization) {
contextDocSet = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public Sequence eval(Sequence contextSequence, final Item contextItem) throws XP
if (contextItem != null) {
contextSequence = contextItem.toSequence();
}
contextSequence = leftExpr.eval(contextSequence);
contextSequence = leftExpr.eval(contextSequence, null);

final FunctionReference fref;
if (fcall != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ public void setArguments(final List<Expression> arguments) throws XPathException

@Override
public Sequence eval(Sequence contextSequence, Item contextItem) throws XPathException {
return castExpression.eval(contextSequence);
return castExpression.eval(contextSequence, null);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.io.Writer;

import org.exist.source.Source;
import org.exist.xquery.value.Item;
import org.exist.xquery.value.Sequence;
import org.xmldb.api.base.CompiledExpression;

Expand Down Expand Up @@ -51,12 +52,14 @@ public interface CompiledXQuery extends CompiledExpression {
* sequence as context.
*
* @param contextSequence the context sequence
* @param contextItem a single item, taken from context. This defines the item,
* the expression should work on.
*
* @return the result.
*
* @throws XPathException if an error occurs during evaluation.
*/
public Sequence eval(Sequence contextSequence) throws XPathException;
public Sequence eval(Sequence contextSequence, Item contextItem) throws XPathException;

/**
* Is the compiled expression still valid? Returns false if, for example,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,6 @@ public Sequence eval(Sequence contextSequence, Item contextItem) throws XPathExc
}
}

public Sequence eval(Sequence contextSequence) throws XPathException {
return eval(contextSequence, null);
}

public void setPrimaryAxis(int axis) {
expression.setPrimaryAxis(axis);
}
Expand Down
28 changes: 8 additions & 20 deletions exist-core/src/main/java/org/exist/xquery/Expression.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import org.exist.xquery.value.Item;
import org.exist.xquery.value.Sequence;

import javax.annotation.Nullable;

/**
* Base interface implemented by all classes which are part
* of an XQuery/XPath expression. The main method is
Expand Down Expand Up @@ -101,12 +103,12 @@ public interface Expression {

/**
* Statically analyze the expression and its subexpressions.
*
*
* During the static analysis phase, the query engine can detect
* unknown variables and some type errors.
*
* @param contextInfo the context infomation.
*
*
* @throws XPathException if an error occurs during the analysis.
*/
public void analyze(AnalyzeContextInfo contextInfo) throws XPathException;
Expand Down Expand Up @@ -134,29 +136,15 @@ public interface Expression {
* The context sequence might be a node set, a sequence of atomic values or a single
* node or atomic value.
*
* @param contextSequence the current context sequence.
* @param contextItem a single item, taken from context. This defines the item,
* the expression should work on.
*
* @return the result sequence.
*
* @throws XPathException if an error occurs during evaluation.
*/
public Sequence eval(Sequence contextSequence, Item contextItem) throws XPathException;

/**
* Evaluate the expression represented by this object.
*
* An overloaded method which just passes the context sequence depending on the
* expression context.
*
* @param contextSequence the current context sequence.
* @param contextSequence the current context sequence, or null if there is no context sequence.
* @param contextItem a single item, taken from context, or null if there is no context item.
* This defines the item, the expression should work on.
*
* @return the result sequence.
*
* @throws XPathException if an error occurs during evaluation.
*/
public Sequence eval(Sequence contextSequence) throws XPathException;
public Sequence eval(@Nullable Sequence contextSequence, @Nullable Item contextItem) throws XPathException;

public void setPrimaryAxis(int axis);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ public boolean isVarDeclared(QName qname) {
}
decl.analyze(declContextInfo);

decl.eval(getContext().getContextItem());
decl.eval(getContext().getContextItem(), null);
var = mStaticVariables.get(qname);
}
if (var == null) {
Expand Down
2 changes: 1 addition & 1 deletion exist-core/src/main/java/org/exist/xquery/ForExpr.java
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ private void processItem(LocalVariable var, Item contextItem, Sequence in, Seque
//Reset the context position
context.setContextSequencePosition(0, null);

resultSequence.addAll(returnExpr.eval(null));
resultSequence.addAll(returnExpr.eval(null, null));

// free resources
var.destroy(context, resultSequence);
Expand Down
16 changes: 8 additions & 8 deletions exist-core/src/main/java/org/exist/xquery/GeneralComparison.java
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ public NodeSet preSelect( Sequence contextSequence, boolean useContext ) throws
LOG.trace("Using QName index on type {}", Type.getTypeName(indexType));
}

final Sequence rightSeq = getRight().eval( contextSequence );
final Sequence rightSeq = getRight().eval(contextSequence, null);

// if the right hand sequence has more than one item, we need to merge them
// into preselectResult
Expand Down Expand Up @@ -469,15 +469,15 @@ public Sequence eval( Sequence contextSequence, Item contextItem ) throws XPathE
if( ( !Dependency.dependsOn( rightOpDeps, Dependency.CONTEXT_ITEM ) ) ) {
result = quickNodeSetCompare( contextSequence );
} else {
final NodeSet nodes = ( NodeSet )getLeft().eval( contextSequence );
final NodeSet nodes = ( NodeSet )getLeft().eval(contextSequence, null);
result = nodeSetCompare( nodes, contextSequence );
}
} else {
result = genericCompare( contextSequence, contextItem );
}
} else {
contextStep.setPreloadedData( preselectResult.getDocumentSet(), preselectResult );
result = getLeft().eval( contextSequence ).toNodeSet();
result = getLeft().eval(contextSequence, null).toNodeSet();
// the expression can be called multiple times, so we need to clear the previous preselectResult
preselectResult = null;
}
Expand Down Expand Up @@ -627,7 +627,7 @@ protected Sequence nodeSetCompare( NodeSet nodes, Sequence contextSequence ) thr
final AtomicValue lv = item.atomize();

do {
final Sequence rs = getRight().eval( context.getNode().toSequence() );
final Sequence rs = getRight().eval(context.getNode().toSequence(), null);

for( final SequenceIterator i2 = Atomize.atomize(rs).iterate(); i2.hasNext(); ) {
final AtomicValue rv = i2.nextItem().atomize();
Expand All @@ -642,7 +642,7 @@ protected Sequence nodeSetCompare( NodeSet nodes, Sequence contextSequence ) thr

for( final NodeProxy item : nodes ) {
final AtomicValue lv = item.atomize();
final Sequence rs = getRight().eval( contextSequence );
final Sequence rs = getRight().eval(contextSequence, null);

for( final SequenceIterator i2 = Atomize.atomize(rs).iterate(); i2.hasNext(); ) {
final AtomicValue rv = i2.nextItem().atomize();
Expand Down Expand Up @@ -687,7 +687,7 @@ protected Sequence quickNodeSetCompare( Sequence contextSequence ) throws XPathE
final long start = System.currentTimeMillis();

//get the NodeSet on the left
final Sequence leftSeq = getLeft().eval( contextSequence );
final Sequence leftSeq = getLeft().eval(contextSequence, null);

if( !leftSeq.isPersistentSet() ) {
return( genericCompare( leftSeq, contextSequence, null ) );
Expand All @@ -704,7 +704,7 @@ protected Sequence quickNodeSetCompare( Sequence contextSequence ) throws XPathE
}

//get the Sequence on the right
final Sequence rightSeq = getRight().eval( contextSequence );
final Sequence rightSeq = getRight().eval(contextSequence, null);

//nothing on the right, so nothing to do
if( rightSeq.isEmpty() ) {
Expand Down Expand Up @@ -1260,7 +1260,7 @@ protected Collator getCollator( Sequence contextSequence ) throws XPathException
String collationURI;

if( collationArg instanceof Expression ) {
collationURI = ( ( Expression )collationArg ).eval( contextSequence ).getStringValue();
collationURI = ( ( Expression )collationArg ).eval(contextSequence, null).getStringValue();
} else if( collationArg instanceof StringValue ) {
collationURI = ( ( StringValue )collationArg ).getStringValue();
} else {
Expand Down
4 changes: 2 additions & 2 deletions exist-core/src/main/java/org/exist/xquery/GroupByClause.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public Sequence eval(Sequence contextSequence, Item contextItem) throws XPathExc
final List<Sequence> groupingValues = new ArrayList<>();
final List<AtomicValue> groupingKeys = new ArrayList<>();
for (GroupSpec spec: groupSpecs) {
final Sequence groupingSeq = spec.getGroupExpression().eval(null);
final Sequence groupingSeq = spec.getGroupExpression().eval(null, null);
if (groupingSeq.getItemCount() > 1) {
throw new XPathException(this, ErrorCodes.XPTY0004, "Grouping variable " + spec.getKeyVarName() + " " +
"evaluates to more than one item");
Expand Down Expand Up @@ -164,7 +164,7 @@ public Sequence postEval(final Sequence seq) throws XPathException {
final LocalVariable var = data.variables.get(entry.getKey());
var.setValue(entry.getValue());
}
final Sequence r = returnExpr.eval(null);
final Sequence r = returnExpr.eval(null, null);
result.addAll(r);
}
} finally {
Expand Down
4 changes: 2 additions & 2 deletions exist-core/src/main/java/org/exist/xquery/Lookup.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public Sequence eval(Sequence contextSequence, Item contextItem) throws XPathExc
} else if (contextExpression == null) {
leftSeq = contextSequence;
} else {
leftSeq = contextExpression.eval(contextSequence);
leftSeq = contextExpression.eval(contextSequence, null);
}
final int contextType = leftSeq.getItemType();

Expand All @@ -96,7 +96,7 @@ public Sequence eval(Sequence contextSequence, Item contextItem) throws XPathExc
"expression to the left of a lookup operator needs to be a sequence of maps or arrays");
}
if (keyExpression != null) {
keys = keyExpression.eval(contextSequence);
keys = keyExpression.eval(contextSequence, null);
if (keys.isEmpty()) {
return Sequence.EMPTY_SEQUENCE;
}
Expand Down
4 changes: 2 additions & 2 deletions exist-core/src/main/java/org/exist/xquery/OpSimpleMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ public void analyze(AnalyzeContextInfo contextInfo) throws XPathException {
public Sequence eval(Sequence contextSequence, Item contextItem) throws XPathException {
if (contextItem != null)
{contextSequence = contextItem.toSequence();}
final Sequence leftSeq = left.eval(contextSequence);
final Sequence leftSeq = left.eval(contextSequence, null);
if (leftSeq.isEmpty())
{return Sequence.EMPTY_SEQUENCE;}

final ValueSequence result = new ValueSequence();
int pos = 0;
for (final SequenceIterator i = leftSeq.iterate(); i.hasNext(); pos++) {
context.setContextSequencePosition(pos, leftSeq);
final Sequence rightSeq = right.eval(i.nextItem().toSequence());
final Sequence rightSeq = right.eval(i.nextItem().toSequence(), null);
result.addAll(rightSeq);
}
return result;
Expand Down
2 changes: 1 addition & 1 deletion exist-core/src/main/java/org/exist/xquery/PathExpr.java
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ public Sequence eval(Sequence contextSequence, final Item contextItem) throws XP
result = exprResult;
} else {
try {
result = expr.eval(currentContext);
result = expr.eval(currentContext, null);
} catch (XPathException ex){
// enrich exception when information is available
if (ex.getLine() < 1 || ex.getColumn() < 1) {
Expand Down
8 changes: 4 additions & 4 deletions exist-core/src/main/java/org/exist/xquery/Predicate.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ private AnalyzeContextInfo createContext(final AnalyzeContextInfo contextInfo) {

public Sequence preprocess() throws XPathException {
final Expression inner = steps.size() == 1 ? getSubExpression(0) : this;
return inner.eval(null);
return inner.eval(null, null);
}

public Sequence evalPredicate(final Sequence outerSequence,
Expand Down Expand Up @@ -193,7 +193,7 @@ public Sequence evalPredicate(final Sequence outerSequence,
// if not, do not pass the context sequence to avoid cardinality errors
context.setContextSequencePosition(0, contextSequence);
innerSeq = inner.eval(Dependency.dependsOn(inner.getDependencies(), Dependency.CONTEXT_ITEM)
? contextSequence : null);
? contextSequence : null, null);
}

// We must check for empty sequences here to avoid an NPE
Expand Down Expand Up @@ -239,7 +239,7 @@ private Tuple2<ExecutionMode, Sequence> recomputeExecutionMode(final Sequence co
// computation should now be better
!((inner instanceof GeneralComparison) &&
((GeneralComparison) inner).invalidNodeEvaluation)) {
innerSeq = inner.eval(contextSequence);
innerSeq = inner.eval(contextSequence, null);
// Only if we have an actual *singleton* of numeric items
if (innerSeq.hasOne()
&& Type.subTypeOfUnion(innerSeq.getItemType(), Type.NUMBER)) {
Expand All @@ -255,7 +255,7 @@ private Tuple2<ExecutionMode, Sequence> recomputeExecutionMode(final Sequence co
* WARNING : this sequence will be evaluated with
* preloadable nodesets !
*/
innerSeq = inner.eval(contextSequence);
innerSeq = inner.eval(contextSequence, null);
// Try to promote a boolean evaluation to a nodeset one
// We are now sure of the inner sequence return type
if (Type.subTypeOf(innerSeq.getItemType(), Type.NODE)
Expand Down
2 changes: 1 addition & 1 deletion exist-core/src/main/java/org/exist/xquery/SimpleStep.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public Sequence eval(Sequence contextSequence, Item contextItem) throws XPathExc
{contextSequence = contextItem.toSequence();}

Sequence result = Sequence.EMPTY_SEQUENCE;
final Sequence set = expression.eval(contextSequence);
final Sequence set = expression.eval(contextSequence, null);

if (!set.isEmpty()) {
if (set.isPersistentSet()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public void analyze(final AnalyzeContextInfo contextInfo) throws XPathException

@Override
public String eval(final Sequence contextSequence) throws XPathException {
final Sequence result = expression.eval(contextSequence);
final Sequence result = expression.eval(contextSequence, null);

final StringBuilder out = new StringBuilder();
boolean gotOne = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,10 @@ public Sequence eval(Sequence contextSequence, Item contextItem) throws XPathExc

if (contextItem != null)
{contextSequence = contextItem.toSequence();}
final Sequence opSeq = operand.eval(contextSequence);
final Sequence opSeq = operand.eval(contextSequence, null);
Sequence result = null;
if (opSeq.isEmpty()) {
result = defaultClause.returnClause.eval(contextSequence);
result = defaultClause.returnClause.eval(contextSequence, null);
} else {
if (opSeq.hasMany()) {
throw new XPathException(this, ErrorCodes.XPTY0004, "Cardinality error in switch operand ", opSeq);
Expand All @@ -106,13 +106,13 @@ public Sequence eval(Sequence contextSequence, Item contextItem) throws XPathExc
}
final AtomicValue caseVal = caseSeq.isEmpty() ? AtomicValue.EMPTY_VALUE : caseSeq.itemAt(0).atomize();
if (FunDeepEqual.deepEquals(caseVal, opVal, defaultCollator)) {
return next.returnClause.eval(contextSequence);
return next.returnClause.eval(contextSequence, null);
}
}
}
}
if (result == null) {
result = defaultClause.returnClause.eval(contextSequence);
result = defaultClause.returnClause.eval(contextSequence, null);
}

return result;
Expand Down
Loading

0 comments on commit bfa7afa

Please sign in to comment.