KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > polyglot > ext > jl > ast > SourceCollection_c


1 package polyglot.ext.jl.ast;
2
3 import polyglot.ast.*;
4 import polyglot.util.*;
5 import polyglot.types.*;
6 import polyglot.visit.*;
7 import java.util.*;
8
9 /**
10  * A <code>SourceCollection</code> represents a collection of source files.
11  */

12 public class SourceCollection_c extends Node_c implements SourceCollection
13 {
14     protected List sources;
15
16     public SourceCollection_c(Position pos, List sources) {
17     super(pos);
18     this.sources = TypedList.copyAndCheck(sources, SourceFile.class, true);
19     }
20
21     public String JavaDoc toString() {
22     return sources.toString();
23     }
24
25     /** Get the source files. */
26     public List sources() {
27     return this.sources;
28     }
29
30     /** Set the statements of the block. */
31     public SourceCollection sources(List sources) {
32     SourceCollection_c n = (SourceCollection_c) copy();
33     n.sources = TypedList.copyAndCheck(sources, SourceFile.class, true);
34     return n;
35     }
36
37     /** Reconstruct the collection. */
38     protected SourceCollection_c reconstruct(List sources) {
39     if (! CollectionUtil.equals(sources, this.sources)) {
40         SourceCollection_c n = (SourceCollection_c) copy();
41         n.sources = TypedList.copyAndCheck(sources, SourceFile.class, true);
42         return n;
43     }
44
45     return this;
46     }
47
48     /** Visit the children of the block. */
49     public Node visitChildren(NodeVisitor v) {
50         List sources = visitList(this.sources, v);
51     return reconstruct(sources);
52     }
53
54     /** Write the source files to an output file. */
55     public void prettyPrint(CodeWriter w, PrettyPrinter tr) {
56         for (Iterator i = sources.iterator(); i.hasNext(); ) {
57             SourceFile s = (SourceFile) i.next();
58             print(s, w, tr);
59             w.newline(0);
60         }
61     }
62 }
63
Popular Tags