use of groovy.lang.GroovyShell in project groovy-core by groovy.
the class GroovyMain method processSockets.
/**
* Process Sockets.
*/
private void processSockets() throws CompilationFailedException, IOException, URISyntaxException {
GroovyShell groovy = new GroovyShell(conf);
new GroovySocketServer(groovy, getScriptSource(isScriptFile, script), autoOutput, port);
}
use of groovy.lang.GroovyShell in project groovy-core by groovy.
the class SeansBug method testBug.
public void testBug() throws Exception {
String code = "for (i in 1..10) \n{\n println(i)\n}";
GroovyShell shell = new GroovyShell();
shell.evaluate(code);
}
use of groovy.lang.GroovyShell in project groovy-core by groovy.
the class InspectorTest method testClassPropsGroovy.
public void testClassPropsGroovy() {
Object testObject = new GroovyShell().evaluate("class Test {def meth1(a,b){}}\nreturn new Test()");
Inspector insp = new Inspector(testObject);
String[] classProps = insp.getClassProps();
assertEquals("package n/a", classProps[Inspector.CLASS_PACKAGE_IDX]);
assertEquals("public class Test", classProps[Inspector.CLASS_CLASS_IDX]);
assertEquals("implements GroovyObject ", classProps[Inspector.CLASS_INTERFACE_IDX]);
assertEquals("extends Object", classProps[Inspector.CLASS_SUPERCLASS_IDX]);
assertEquals("is Primitive: false, is Array: false, is Groovy: true", classProps[Inspector.CLASS_OTHER_IDX]);
}
use of groovy.lang.GroovyShell in project groovy-core by groovy.
the class Eval method xyz.
/**
* Evaluates the specified String expression and makes the first three parameters available inside
* the script bound to variables named 'x', 'y', and 'z' respectively, returning the result. For
* example, this code executes without failure:
* <pre>
* assert 10 == Eval.xyz(2, 4, 2, ' x * y + z')
* </pre>
* @param expression the Groovy expression to evaluate
* @return the result of the expression
* @throws CompilationFailedException if expression is not valid Groovy
*/
public static Object xyz(final Object x, final Object y, final Object z, final String expression) throws CompilationFailedException {
Binding b = new Binding();
b.setVariable("x", x);
b.setVariable("y", y);
b.setVariable("z", z);
GroovyShell sh = new GroovyShell(b);
return sh.evaluate(expression);
}
use of groovy.lang.GroovyShell in project groovy-core by groovy.
the class Eval method me.
/**
* Evaluates the specified String expression and makes the parameter available inside
* the script, returning the result. For example, this code binds the 'x' variable:
* <pre>
* assert 10 == Eval.me('x', 2, ' x * 4 + 2')
* </pre>
* @param expression the Groovy expression to evaluate
* @return the result of the expression
* @throws CompilationFailedException if expression is not valid Groovy
*/
public static Object me(final String symbol, final Object object, final String expression) throws CompilationFailedException {
Binding b = new Binding();
b.setVariable(symbol, object);
GroovyShell sh = new GroovyShell(b);
return sh.evaluate(expression);
}
Aggregations