for (Map.Entry<String, Node> e : typeTransformations.entrySet()) { String name = e.getKey(); String tranformationDefinition = new CodePrinter.Builder(e.getValue()).build(); parts.add("@template " + name + " := " + tranformationDefinition + " =:");
private void setGeneratedExternsOnCompiler() { CodePrinter.Builder builder = new CodePrinter.Builder(externsRoot) .setPrettyPrint(true) .setOutputTypes(true) .setTypeRegistry(compiler.getTypeRegistry()); compiler.setExternExports(Joiner.on("\n").join( "/**", " * @fileoverview Generated externs.", " * @externs", " */", builder.build())); }
new CodePrinter.Builder(file) .setCompilerOptions(opts.getCompilerOptions()) .setTypeRegistry(compiler.getTypeRegistry()) .setCodeGeneratorFactory(factory) .setPrettyPrint(true) .setLineBreak(true) .setOutputTypes(true) .build();
protected String instrumentSource(String sourceURI, String source) { SourceFile sourceFile = SourceFile.fromCode(sourceURI, source); // com.google.javascript.jscomp.parsing.parser.SourceFile sf = new com.google.javascript.jscomp.parsing.parser.SourceFile(sourceURI, source); // LineNumberTable lineNumberTable = new LineNumberTable(sf); ParserRunner.ParseResult parsed = parse(source, sourceFile); Node jsRoot = parsed.ast; // System.out.println("jsRoot.toStringTree():\n" + jsRoot.toStringTree()); commentsHandler.processComments(parsed.comments); NodeWalker nodeWalker = new NodeWalker(); nodeWalker.visit(jsRoot, instrumenter); // System.out.println("jsRoot.toStringTree():\n" + jsRoot.toStringTree()); if (includeBranchCoverage) { instrumentBranch(jsRoot, nodeWalker, branchInstrumentor); } return new CodePrinter.Builder(jsRoot).setCompilerOptions(options).build(); }
public String generateCode(AbstractCompiler compiler, Node node) { // TODO(mknichel): Fix all the formatting problems with this code. // How does this play with goog.scope? CompilerOptions compilerOptions = new CompilerOptions(); compilerOptions.setPreferSingleQuotes(true); compilerOptions.setLineLengthThreshold(80); // We're refactoring existing code, so no need to escape values inside strings. compilerOptions.setTrustedStrings(true); return new CodePrinter.Builder(node) .setCompilerOptions(compilerOptions) .setTypeRegistry(compiler.getTypeRegistry()) .setPrettyPrint(true) .setLineBreak(true) .setOutputTypes(true) .build(); }
protected String instrumentSource(String sourceURI, String source) { SourceFile sourceFile = SourceFile.fromCode(sourceURI, source); // com.google.javascript.jscomp.parsing.parser.SourceFile sf = new com.google.javascript.jscomp.parsing.parser.SourceFile(sourceURI, source); // LineNumberTable lineNumberTable = new LineNumberTable(sf); ParserRunner.ParseResult parsed = parse(source, sourceFile); Node jsRoot = parsed.ast; // System.out.println("jsRoot.toStringTree():\n" + jsRoot.toStringTree()); commentsHandler.processComments(parsed.comments); NodeWalker nodeWalker = new NodeWalker(); nodeWalker.visit(jsRoot, instrumenter); // System.out.println("jsRoot.toStringTree():\n" + jsRoot.toStringTree()); if (includeBranchCoverage) { instrumentBranch(jsRoot, nodeWalker, branchInstrumentor); } return new CodePrinter.Builder(jsRoot).setCompilerOptions(options).build(); }
/** * Generates JavaScript source code for an AST. */ private String toSource(Node n, SourceMap sourceMap, boolean firstOutput) { CodePrinter.Builder builder = new CodePrinter.Builder(n); builder.setTypeRegistry(this.typeRegistry); builder.setCompilerOptions(options); builder.setSourceMap(sourceMap); builder.setTagAsStrict(firstOutput && options.getLanguageOut().isStrict()); return builder.build(); }
/** * Returns the generated externs. */ public String getGeneratedExterns() { CodePrinter.Builder builder = new CodePrinter.Builder(externsRoot) .setPrettyPrint(true) .setOutputTypes(true) .setTypeRegistry(compiler.getTypeIRegistry()); return builder.build(); }
/** * Generates JavaScript source code for an AST. */ private String toSource(Node n, SourceMap sourceMap, boolean firstOutput) { CodePrinter.Builder builder = new CodePrinter.Builder(n); builder.setTypeRegistry(getTypeRegistry()); builder.setCompilerOptions(options); builder.setSourceMap(sourceMap); builder.setTagAsTypeSummary(!n.isFromExterns() && options.shouldGenerateTypedExterns()); builder.setTagAsStrict(firstOutput && options.shouldEmitUseStrict()); return builder.build(); }