use of org.apache.commons.jexl3.internal.Script in project nexus-public by sonatype.
the class DatastoreCselToSqlTest method refTest.
@Test
public void refTest() {
final ASTJexlScript script = jexlEngine.parseExpression("a == dog.name");
script.childrenAccept(underTest, builder);
assertThat(builder.getQueryString(), is("a_alias = prop.name"));
assertThat(builder.getQueryParameters().size(), is(0));
}
use of org.apache.commons.jexl3.internal.Script in project nexus-public by sonatype.
the class DatastoreCselToSqlTest method likeTest.
@Test
public void likeTest() {
final ASTJexlScript script = jexlEngine.parseExpression("a =^ \"woof\"");
script.childrenAccept(underTest, builder);
assertThat(builder.getQueryString(), is("a_alias like :param_0"));
assertThat(builder.getQueryParameters().size(), is(1));
assertThat(builder.getQueryParameters().get("param_0"), is("woof%"));
}
use of org.apache.commons.jexl3.internal.Script in project nexus-public by sonatype.
the class DatastoreCselToSqlTest method parensTest.
@Test
public void parensTest() {
final ASTJexlScript script = jexlEngine.parseExpression("a==\"woof\" && (b==\"meow\" || b==\"purr\")");
script.childrenAccept(underTest, builder);
assertThat(builder.getQueryString(), is("a_alias = :param_0 and (b_alias = :param_1 or b_alias = :param_2)"));
assertThat(builder.getQueryParameters().size(), is(3));
assertThat(builder.getQueryParameters().get("param_0"), is("woof"));
assertThat(builder.getQueryParameters().get("param_1"), is("meow"));
assertThat(builder.getQueryParameters().get("param_2"), is("purr"));
}
use of org.apache.commons.jexl3.internal.Script in project commons-jexl by apache.
the class Interpreter method visit.
@Override
protected Object visit(final ASTJexlScript script, final Object data) {
if (script instanceof ASTJexlLambda && !((ASTJexlLambda) script).isTopLevel()) {
return new Closure(this, (ASTJexlLambda) script);
}
block = new LexicalFrame(frame, block).defineArgs();
try {
final int numChildren = script.jjtGetNumChildren();
Object result = null;
for (int i = 0; i < numChildren; i++) {
final JexlNode child = script.jjtGetChild(i);
result = child.jjtAccept(this, data);
cancelCheck(child);
}
return result;
} finally {
block = block.pop();
}
}
use of org.apache.commons.jexl3.internal.Script in project commons-jexl by apache.
the class Closure method setCaptured.
/**
* Sets the captured index of a given symbol, ie the target index of a parent
* captured symbol in this closure's frame.
* <p>This is meant to allow a locally defined function to "see" and call
* itself as a local (captured) variable;
* in other words, this allows recursive call of a function.
* @param symbol the symbol index (in the caller of this closure)
* @param value the value to set in the local frame
*/
public void setCaptured(final int symbol, final Object value) {
if (script instanceof ASTJexlLambda) {
final ASTJexlLambda lambda = (ASTJexlLambda) script;
final Scope scope = lambda.getScope();
if (scope != null) {
final Integer reg = scope.getCaptured(symbol);
if (reg != null) {
frame.set(reg, value);
}
}
}
}
Aggregations