use of org.apache.commons.jexl3.JexlInfo in project commons-jexl by apache.
the class OptionalTest method test342.
@Test
public void test342() {
JexlBuilder builder = new JexlBuilder();
JexlUberspect uber = builder.create().getUberspect();
JexlEngine jexl = builder.uberspect(new ReferenceUberspect(uber)).safe(false).create();
JexlInfo info = new JexlInfo("test352", 1, 1);
Thing thing = new Thing();
JexlScript script;
script = jexl.createScript(info.at(53, 1), "thing.name.length()", "thing");
Object result = script.execute(null, thing);
Assert.assertNull(result);
thing.name = "foo";
result = script.execute(null, thing);
Assert.assertEquals(3, result);
try {
script = jexl.createScript(info.at(62, 1), "thing.name.size()", "thing");
result = script.execute(null, thing);
Assert.fail("should have thrown");
} catch (JexlException.Method xmethod) {
Assert.assertEquals("size", xmethod.getDetail());
Assert.assertEquals("test352@62:11 unsolvable function/method 'size'", xmethod.getMessage());
}
try {
script = jexl.createScript(info.at(71, 1), "thing.name?.size()", "thing");
result = script.execute(null, thing);
} catch (JexlException.Method xmethod) {
Assert.fail("should not have thrown");
}
thing.name = null;
script = jexl.createScript(info, "thing.names.size()", "thing");
result = script.execute(null, thing);
Assert.assertNull(result);
thing.name = "froboz";
script = jexl.createScript(info, "thing.names", "thing");
result = script.execute(null, thing);
Assert.assertNotNull(result);
script = jexl.createScript(info, "thing.names.size()", "thing");
result = script.execute(null, thing);
Assert.assertEquals(1, result);
}
use of org.apache.commons.jexl3.JexlInfo in project commons-jexl by apache.
the class JexlParser method throwAmbiguousException.
/**
* Throws Ambiguous exception.
* <p>Seeks the end of the ambiguous statement to recover.
* @param node the first token in ambiguous expression
* @throws JexlException.Ambiguous in all cases
*/
protected void throwAmbiguousException(final JexlNode node) {
final JexlInfo begin = node.jexlInfo();
final Token t = getToken(0);
final JexlInfo end = info.at(t.beginLine, t.endColumn);
final String msg = readSourceLine(source, end.getLine());
throw new JexlException.Ambiguous(begin, end, msg);
}
use of org.apache.commons.jexl3.JexlInfo in project commons-jexl by apache.
the class JexlParser method throwFeatureException.
/**
* Throws a feature exception.
* @param feature the feature code
* @param trigger the token that triggered it
* @throws JexlException.Parsing if actual error token can not be found
* @throws JexlException.Feature in all other cases
*/
protected void throwFeatureException(final int feature, Token trigger) {
Token token = trigger;
if (token == null) {
token = this.getToken(0);
if (token == null) {
throw new JexlException.Parsing(null, JexlFeatures.stringify(feature));
}
}
final JexlInfo xinfo = info.at(token.beginLine, token.beginColumn);
throwFeatureException(feature, xinfo);
}
use of org.apache.commons.jexl3.JexlInfo in project commons-jexl by apache.
the class JexlNode method jexlInfo.
/**
* Gets the associated JexlInfo instance.
*
* @return the info
*/
public JexlInfo jexlInfo() {
JexlInfo info = null;
JexlNode node = this;
while (node != null) {
if (node.jjtGetValue() instanceof JexlInfo) {
info = (JexlInfo) node.jjtGetValue();
break;
}
node = node.jjtGetParent();
}
if (lc >= 0) {
final int c = lc & 0xfff;
final int l = lc >> 0xc;
// at least an info with line/column number
return info != null ? info.at(info.getLine() + l - 1, c) : new JexlInfo(null, l, c);
}
// weird though; no jjSetFirstToken(...) ever called?
return info;
}
use of org.apache.commons.jexl3.JexlInfo in project commafeed by Athou.
the class FeedEntryFilteringService method initEngine.
private static JexlEngine initEngine() {
// classloader that prevents object creation
ClassLoader cl = new ClassLoader() {
@Override
protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException {
return null;
}
};
// uberspect that prevents access to .class and .getClass()
Uberspect uberspect = new UberspectImpl(LogFactory.getLog(JexlEngine.class)) {
@Override
public JexlPropertyGet getPropertyGet(Object obj, Object identifier, JexlInfo info) {
if ("class".equals(identifier)) {
return null;
}
return super.getPropertyGet(obj, identifier, info);
}
@Override
public JexlMethod getMethod(Object obj, String method, Object[] args, JexlInfo info) {
if ("getClass".equals(method)) {
return null;
}
return super.getMethod(obj, method, args, info);
}
};
JexlEngine engine = new JexlEngine(uberspect, null, null, null);
engine.setStrict(true);
engine.setClassLoader(cl);
return engine;
}
Aggregations