are input and output possible as string ?

457 views
Skip to first unread message

maty

unread,
Nov 6, 2009, 4:58:26 AM11/6/09
to Closure Compiler Discuss
are input and output possible as string values direct from java ?
(com.google.javascript.jscomp.CompilerRunner ... )


bolinfest

unread,
Nov 6, 2009, 11:26:20 AM11/6/09
to Closure Compiler Discuss
The class below shows how to do it. Ultimately, you get the string
value from compiler.toSource() rather than from a method on Result, as
you might expect.

package com.bolinfest.closure;

import com.google.javascript.jscomp.CompilationLevel;
import com.google.javascript.jscomp.Compiler;
import com.google.javascript.jscomp.CompilerOptions;
import com.google.javascript.jscomp.JSSourceFile;
import com.google.javascript.jscomp.Result;

public class Main {

public static void main(String[] args) {
Compiler compiler = new Compiler();
CompilerOptions options = new CompilerOptions();

CompilationLevel.ADVANCED_OPTIMIZATIONS.setOptionsForCompilationLevel
(options);
JSSourceFile extern = JSSourceFile.fromCode("externs.js",
"function alert(x) {}");
JSSourceFile input = JSSourceFile.fromCode("input.js",
"function hello(name) {" +
"alert('Hello, ' + name);" +
"}" +
"hello('New user');");
Result result = compiler.compile(extern, input, options);
if (result.success) {
System.out.println(compiler.toSource());

maty

unread,
Nov 10, 2009, 9:12:43 AM11/10/09
to Closure Compiler Discuss
thanks :O)
Reply all
Reply to author
Forward
0 new messages