KickJava   Java API By Example, From Geeks To Geeks.

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


1 package polyglot.ext.jl.ast;
2
3 import polyglot.ast.*;
4 import polyglot.types.*;
5 import polyglot.visit.*;
6 import polyglot.util.*;
7 import java.util.*;
8
9 /**
10  * Am immutable representation of a Java statement with a label. A labeled
11  * statement contains the statement being labelled and a string label.
12  */

13 public class Labeled_c extends Stmt_c implements Labeled
14 {
15     protected String JavaDoc label;
16     protected Stmt statement;
17
18     public Labeled_c(Position pos, String JavaDoc label, Stmt statement) {
19     super(pos);
20     this.label = label;
21     this.statement = statement;
22     }
23
24     /** Get the label of the statement. */
25     public String JavaDoc label() {
26     return this.label;
27     }
28
29     /** Set the label of the statement. */
30     public Labeled label(String JavaDoc label) {
31     Labeled_c n = (Labeled_c) copy();
32     n.label = label;
33     return n;
34     }
35
36     /** Get the sub-statement of the statement. */
37     public Stmt statement() {
38     return this.statement;
39     }
40
41     /** Set the sub-statement of the statement. */
42     public Labeled statement(Stmt statement) {
43     Labeled_c n = (Labeled_c) copy();
44     n.statement = statement;
45     return n;
46     }
47
48     /** Reconstruct the statement. */
49     protected Labeled_c reconstruct(Stmt statement) {
50     if (statement != this.statement) {
51         Labeled_c n = (Labeled_c) copy();
52         n.statement = statement;
53         return n;
54     }
55
56     return this;
57     }
58
59     /** Visit the children of the statement. */
60     public Node visitChildren(NodeVisitor v) {
61     Stmt statement = (Stmt) visitChild(this.statement, v);
62     return reconstruct(statement);
63     }
64
65     public String JavaDoc toString() {
66     return label + ": " + statement;
67     }
68
69     /** Write the statement to an output file. */
70     public void prettyPrint(CodeWriter w, PrettyPrinter tr) {
71     w.write(label + ": ");
72     print(statement, w, tr);
73     }
74
75     public Term entry() {
76         return statement.entry();
77     }
78
79     public List acceptCFG(CFGBuilder v, List succs) {
80         v.push(this).visitCFG(statement, this);
81         return succs;
82     }
83 }
84
Popular Tags