KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > polyglot > frontend > PrettyPrintPass


1 package polyglot.frontend;
2
3 import polyglot.ast.*;
4 import polyglot.frontend.*;
5 import polyglot.types.*;
6 import polyglot.util.*;
7 import polyglot.visit.*;
8 import polyglot.types.Package;
9
10 import java.io.*;
11 import java.util.*;
12
13 /** An output pass generates output code from the processed AST. */
14 public class PrettyPrintPass extends AbstractPass
15 {
16     protected Job job;
17     protected PrettyPrinter pp;
18     protected CodeWriter w;
19
20     /**
21      * Create a PrettyPrinter. The output of the visitor is a collection of files
22      * whose names are added to the collection <code>outputFiles</code>.
23      */

24     public PrettyPrintPass(Pass.ID id, Job job, CodeWriter w, PrettyPrinter pp) {
25     super(id);
26         this.job = job;
27         this.pp = pp;
28         this.w = w;
29     }
30
31     public boolean run() {
32         Node ast = job.ast();
33
34         if (ast == null) {
35             w.write("<<<< null AST >>>>");
36         }
37         else {
38             pp.printAst(ast, w);
39         }
40
41         return true;
42     }
43 }
44
Popular Tags