本文整理汇总了Java中groovy.lang.GroovyShell.setProperty方法的典型用法代码示例。如果您正苦于以下问题:Java GroovyShell.setProperty方法的具体用法?Java GroovyShell.setProperty怎么用?Java GroovyShell.setProperty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类groovy.lang.GroovyShell
的用法示例。
在下文中一共展示了GroovyShell.setProperty方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: run
import groovy.lang.GroovyShell; //导入方法依赖的package包/类
/**
* Standalone execution for Designer and Gradle.
*/
public void run() {
startExecution();
CompilerConfiguration compilerConfig = new CompilerConfiguration(System.getProperties());
compilerConfig.setScriptBaseClass(TestCaseScript.class.getName());
Binding binding = new Binding();
binding.setVariable("testCaseRun", this);
ClassLoader classLoader = this.getClass().getClassLoader();
GroovyShell shell = new GroovyShell(classLoader, binding, compilerConfig);
shell.setProperty("out", getLog());
setupContextClassLoader(shell);
try {
shell.run(new GroovyCodeSource(getTestCase().file()), new String[0]);
finishExecution(null);
}
catch (IOException ex) {
throw new RuntimeException(ex.getMessage(), ex);
}
}
示例2: testInvokeRawMethod
import groovy.lang.GroovyShell; //导入方法依赖的package包/类
@Test
public void testInvokeRawMethod() throws Exception {
ListMethods itf = list -> {
JsonObject combined = new JsonObject();
list.forEach(combined::mergeIn);
return combined;
};
CompilerConfiguration config = new CompilerConfiguration();
Properties props = new Properties();
props.setProperty("groovy.disabled.global.ast.transformations", "io.vertx.lang.groovy.VertxTransformation");
config.configure(props);
GroovyShell shell = new GroovyShell(config);
shell.setProperty("itf", itf);
Object o = shell.evaluate("return itf.jsonList([new io.vertx.core.json.JsonObject().put('foo', 'foo_value'), new io.vertx.core.json.JsonObject().put('bar', 'bar_value')])");
JsonObject result = (JsonObject) o;
assertEquals(result, new JsonObject().put("foo", "foo_value").put("bar", "bar_value"));
}
示例3: getShell
import groovy.lang.GroovyShell; //导入方法依赖的package包/类
private GroovyShell getShell(MessageReceivedEvent event) {
GroovyShell shell = groovyService.createShell();
shell.setProperty("message", event.getMessage());
shell.setProperty("channel", event.getChannel());
shell.setProperty("guild", event.getGuild());
shell.setProperty("member", event.getMember());
shell.setProperty("author", event.getAuthor());
return shell;
}
示例4: compile
import groovy.lang.GroovyShell; //导入方法依赖的package包/类
private void compile(String code) {
clearLog();
try {
CompilerConfiguration cc = new CompilerConfiguration();
cc.addCompilationCustomizers(
new ImportCustomizer().
addStarImports("eu.mihosoft.pow.client",
"eu.mihosoft.pow.net.api",
"eu.mihosoft.pow.lab"));
GroovyShell shell = new GroovyShell(getClass().getClassLoader(),
new Binding(), cc);
shell.setProperty("advancedApi", Main.getPOWRemoteAPI());
shell.setProperty("api", POWApi.newApi());
Script script = shell.parse(code);
Thread t = new Thread(() -> {
Object obj = script.run();
});
t.start();
} catch (Throwable ex) {
ex.printStackTrace(System.err);
}
}
示例5: createknowledgeBase
import groovy.lang.GroovyShell; //导入方法依赖的package包/类
public void createknowledgeBase(String arabicKnowledgeBase) {
//initialisation
arabicKnowledgeBase = arabicKnowledgeBase.replaceAll("،", ",");
lexemes.clear();
lexemes = Lexer.getLexemes(arabicKnowledgeBase);
cuts.initialize();
getConstants(lexemes);
getVariables(lexemes);
FromGui.insert(PrincipalWindow.interpreter, "/> ", Color.BLACK);
//construct RuleSet
String code = "";
try {
ANTLRInputStream input = new ANTLRInputStream( arabicKnowledgeBase );
ArabicPrologLexer lexer = new ArabicPrologLexer(input);
CommonTokenStream tokens = new CommonTokenStream(lexer);
ArabicPrologParser parser = new ArabicPrologParser(tokens);
ParseTree tree = parser.ruleSet();
// showTree(parser,tree);
// Walk it and attach our listener
ParseTreeWalker walker = new ParseTreeWalker();
ArabicPrologBaseListener listener = new ArabicPrologBaseListener();
walker.DEFAULT.walk(listener, tree);
code = ArabicPrologBaseListener.code.replaceAll(",\\)", "\\)")+";";
code = code.replaceAll(",;", ";");
//System.out.println(code);
}
catch (Exception e){e.printStackTrace();}
//convert String to java code with groovy
Binding binding = new Binding();
GroovyShell shell = new GroovyShell(binding);
shell.setProperty("constants", constants);
shell.setProperty("variables", variables);
shell.setProperty("cuts", cuts);
shell.setProperty("id", id);
//System.out.println(constants);
//System.out.println(variables);
Object value = shell.evaluate(
"import unification_solver.* ;"
+ "import front_end.Converter ;"
+ "RuleSet a = "+code+" return a;");
ruleSet = (RuleSet) value;
}
示例6: getQueryToSolve
import groovy.lang.GroovyShell; //导入方法依赖的package包/类
public static Object getQueryToSolve(String userQuery) {
userQuery = userQuery.replaceAll("،", ",");
lexemes.clear();
lexemes = Lexer.getLexemes(userQuery);
getConstants(lexemes);
getVariables(lexemes);
cuts.initialize();
query = userQuery;
String code = "";
try {
userQuery = userQuery.replaceAll("،", ",");
ANTLRInputStream input = new ANTLRInputStream( userQuery );
ArabicPrologLexer lexer = new ArabicPrologLexer(input);
CommonTokenStream tokens = new CommonTokenStream(lexer);
ArabicPrologParser parser = new ArabicPrologParser(tokens);
ParseTree tree = parser.query();
//showTree(parser, tree);
// Walk it and attach our listener
ParseTreeWalker walker = new ParseTreeWalker();
ArabicPrologBaseListener listener = new ArabicPrologBaseListener();
walker.DEFAULT.walk(listener, tree);
code = ArabicPrologBaseListener.code.replaceAll(",\\)", "\\)")+";";
code = code.replaceAll(",;", ";");
//System.out.println(code);
}
catch (Exception e){e.printStackTrace();}
//convert String to java code with groovy
Binding binding = new Binding();
GroovyShell shell = new GroovyShell(binding);
shell.setProperty("constants", constants);
shell.setProperty("variables", variables);
shell.setProperty("cuts", cuts);
shell.setProperty("id", id);
Object value = shell.evaluate(
"import unification_solver.* ;"
+ "import front_end.Converter ;"
+ "Object a = "+code+" return a;");
Object a = value;
return a;
}