org.mozilla.javascript.optimizer.ClassCompiler Java Examples
The following examples show how to use
org.mozilla.javascript.optimizer.ClassCompiler.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Main.java From JsDroidCmd with Mozilla Public License 2.0 | 5 votes |
public Main() { reporter = new ToolErrorReporter(true); compilerEnv = new CompilerEnvirons(); compilerEnv.setErrorReporter(reporter); compiler = new ClassCompiler(compilerEnv); }
Example #2
Source File: JavaScriptClassCompiler.java From jasperreports with GNU Lesser General Public License v3.0 | 5 votes |
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; } }
Example #3
Source File: Main.java From astor with GNU General Public License v2.0 | 5 votes |
public Main() { reporter = new ToolErrorReporter(true); compilerEnv = new CompilerEnvirons(); compilerEnv.setErrorReporter(reporter); compiler = new ClassCompiler(compilerEnv); }