本文整理匯總了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;
}