use of com.googlecode.aviator.AviatorEvaluatorInstance.StringSegments in project aviatorscript by killme2008.
the class AviatorEvaluatorInstanceUnitTest method testCompileStringSegments.
@Test
public void testCompileStringSegments() {
StringSegments segs = this.instance.compileStringSegments("#test");
assertTrue(segs.isEmpty());
segs = this.instance.compileStringSegments("#test#.");
assertTrue(segs.isEmpty());
segs = this.instance.compileStringSegments("#test#.#");
assertTrue(segs.isEmpty());
segs = this.instance.compileStringSegments("#test#{a}");
assertFalse(segs.isEmpty());
assertEquals("#testnull", segs.toString(AviatorEvaluator.newEnv(), null));
assertEquals("#test1", segs.toString(AviatorEvaluator.newEnv("a", 1), null));
}
use of com.googlecode.aviator.AviatorEvaluatorInstance.StringSegments in project aviatorscript by killme2008.
the class AviatorString method getLexeme.
public String getLexeme(final Map<String, Object> env, final boolean warnOnCompile) {
AviatorEvaluatorInstance engine = RuntimeUtils.getInstance(env);
if (!this.isLiteral || !this.hasInterpolation || !engine.isFeatureEnabled(Feature.StringInterpolation) || this.lexeme == null || this.lexeme.length() < 3) {
return this.lexeme;
}
StringSegments segs = null;
BaseExpression exp = (BaseExpression) (env == null ? null : env.get(Constants.EXP_VAR));
if (exp != null) {
segs = exp.getStringSegements(this.lexeme, this.lineNo);
} else {
segs = engine.compileStringSegments(this.lexeme);
if (warnOnCompile) {
warnOnCompileWithoutCaching();
}
}
assert (segs != null);
return segs.toString(env, this.lexeme);
}
use of com.googlecode.aviator.AviatorEvaluatorInstance.StringSegments in project aviatorscript by killme2008.
the class BaseExpression method getStringSegements.
public StringSegments getStringSegements(final String lexeme, final int lineNo) {
FutureTask<StringSegments> task = this.stringSegs.get(lexeme);
if (task == null) {
task = new FutureTask<>(new Callable<StringSegments>() {
@Override
public StringSegments call() throws Exception {
final StringSegments compiledSegs = BaseExpression.this.instance.compileStringSegments(lexeme, BaseExpression.this.sourceFile, lineNo);
return compiledSegs;
}
});
FutureTask<StringSegments> existsTask = this.stringSegs.putIfAbsent(lexeme, task);
if (existsTask != null) {
task = existsTask;
} else {
// first run
task.run();
}
}
try {
return task.get();
} catch (ExecutionException t) {
throw Reflector.sneakyThrow(t.getCause());
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw Reflector.sneakyThrow(e);
}
}
Aggregations