本文整理汇总了Java中org.mozilla.javascript.optimizer.ClassCompiler类的典型用法代码示例。如果您正苦于以下问题:Java ClassCompiler类的具体用法?Java ClassCompiler怎么用?Java ClassCompiler使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ClassCompiler类属于org.mozilla.javascript.optimizer包,在下文中一共展示了ClassCompiler类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: RhinoAdapter
import org.mozilla.javascript.optimizer.ClassCompiler; //导入依赖的package包/类
/**
* Constructor.
*
* @throws LanguageAdapterException
* In case of an initialization error
*/
public RhinoAdapter() throws LanguageAdapterException
{
super( "Rhino", getImplementationVersion(), "JavaScript", getLanguageVersion(), Arrays.asList( "js", "javascript", "rhino" ), "js", Arrays.asList( "javascript", "js", "rhino" ), "rhino" );
CompilerEnvirons compilerEnvirons = new CompilerEnvirons();
compilerEnvirons.setOptimizationLevel( getOptimizationLevel() );
classCompiler = new ClassCompiler( compilerEnvirons );
Context context = enterContext();
try
{
generatedClassLoader = context.createClassLoader( RhinoAdapter.class.getClassLoader() );
}
finally
{
Context.exit();
}
}
示例2: Main
import org.mozilla.javascript.optimizer.ClassCompiler; //导入依赖的package包/类
public Main()
{
reporter = new ToolErrorReporter(true);
compilerEnv = new CompilerEnvirons();
compilerEnv.setErrorReporter(reporter);
compiler = new ClassCompiler(compilerEnv);
}
示例3: compileScripts
import org.mozilla.javascript.optimizer.ClassCompiler; //导入依赖的package包/类
protected void compileScripts(JRCompilationUnit unit, CompilerEnvirons compilerEnv,
CompileSources compileSources, JavaScriptCompiledData compiledData)
{
List<String> scripts = compileSources.getScripts();
int scriptIndex = 0;
for (String scriptSource : scripts)
{
String scriptClassName = unit.getName() + "_" + scriptIndex;
if (log.isTraceEnabled())
{
log.trace("compiling script with name " + scriptClassName
+ "\n" + scriptSource);
}
ClassCompiler compiler = new ClassCompiler(compilerEnv);
// this should not fail since we've already separately compiled the default expression
Object[] compilationResult = compiler.compileToClassFiles(scriptSource, unit.getName(), 0, scriptClassName);
if (compilationResult.length != 2)
{
throw
new JRRuntimeException(
EXCEPTION_MESSAGE_KEY_UNEXPECTED_CLASSES_LENGTH,
new Object[]{compilationResult.length});
}
if (!scriptClassName.equals(compilationResult[0]))
{
throw
new JRRuntimeException(
EXCEPTION_MESSAGE_KEY_UNEXPECTED_CLASS_NAME,
new Object[]{compilationResult[0], scriptClassName});
}
byte[] compiledClass = (byte[]) compilationResult[1];
compiledData.addClass(scriptClassName, compiledClass);
++scriptIndex;
}
}