本文整理汇总了Java中org.codehaus.janino.ClassLoaderIClassLoader类的典型用法代码示例。如果您正苦于以下问题:Java ClassLoaderIClassLoader类的具体用法?Java ClassLoaderIClassLoader怎么用?Java ClassLoaderIClassLoader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ClassLoaderIClassLoader类属于org.codehaus.janino包,在下文中一共展示了ClassLoaderIClassLoader类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: compile
import org.codehaus.janino.ClassLoaderIClassLoader; //导入依赖的package包/类
public UnaryDoubleFunction compile(String expression) throws Exception {
if (!java.util.regex.Pattern.matches(
"^[a-zA-Z0-9+\\-()/\\* \t^%\\.\\?]+$", expression)) {
throw new SecurityException();
}
String classPackage = getClass().getPackage().getName() + ".compiled";
String className = "JaninoCompiledFastexpr"
+ COMPILED_CLASS_INDEX.incrementAndGet();
String source = "package " + classPackage + ";\n"
+ "import static java.lang.Math.*;\n" + "public final class "
+ className + " implements "
+ UnaryDoubleFunction.class.getCanonicalName() + " {\n"
+ "public double evaluate(double x) {\n"
+ "return (" + expression + ");\n" + "}\n" + "}";
Scanner scanner = new Scanner(null, new ByteArrayInputStream(
source.getBytes("UTF-8")), "UTF-8");
JaninoRestrictedClassLoader cl = new JaninoRestrictedClassLoader();
UnitCompiler unitCompiler = new UnitCompiler(
new Parser(scanner).parseCompilationUnit(),
new ClassLoaderIClassLoader(cl));
ClassFile[] classFiles = unitCompiler.compileUnit(true, true, true);
Class<?> clazz = cl.defineClass(classPackage + "." + className,
classFiles[0].toByteArray());
return (UnaryDoubleFunction) clazz.newInstance();
}
示例2: JaninoClassCompiler
import org.codehaus.janino.ClassLoaderIClassLoader; //导入依赖的package包/类
public JaninoClassCompiler(ClassLoader parentClassLoader, boolean debug) {
super(debug);
this.compilationClassLoader = new ClassLoaderIClassLoader(parentClassLoader);
}
示例3: JaninoClassCompiler
import org.codehaus.janino.ClassLoaderIClassLoader; //导入依赖的package包/类
@VisibleForTesting
JaninoClassCompiler(ClassLoader parentClassLoader) {
this.compilationClassLoader = new ClassLoaderIClassLoader(parentClassLoader);
}