KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > polyglot > ext > jl > ast > Branch_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  * A <code>Branch</code> is an immutable representation of a branch
11  * statment in Java (a break or continue).
12  */

13 public class Branch_c extends Stmt_c implements Branch
14 {
15     protected Branch.Kind kind;
16     protected String JavaDoc label;
17
18     public Branch_c(Position pos, Branch.Kind kind, String JavaDoc label) {
19     super(pos);
20     this.kind = kind;
21     this.label = label;
22     }
23
24     /** Get the kind of the branch. */
25     public Branch.Kind kind() {
26     return this.kind;
27     }
28
29     /** Set the kind of the branch. */
30     public Branch kind(Branch.Kind kind) {
31     Branch_c n = (Branch_c) copy();
32     n.kind = kind;
33     return n;
34     }
35
36     /** Get the target label of the branch. */
37     public String JavaDoc label() {
38     return this.label;
39     }
40
41     /** Set the target label of the branch. */
42     public Branch label(String JavaDoc label) {
43     Branch_c n = (Branch_c) copy();
44     n.label = label;
45     return n;
46     }
47
48     public String JavaDoc toString() {
49     return kind.toString() + (label != null ? " " + label : "");
50     }
51
52     /** Write the expression to an output file. */
53     public void prettyPrint(CodeWriter w, PrettyPrinter tr) {
54     w.write(kind.toString());
55     if (label != null) {
56         w.write(" " + label);
57     }
58     w.write(";");
59     }
60
61     /**
62      * Return the first (sub)term performed when evaluating this
63      * term.
64      */

65     public Term entry() {
66         return this;
67     }
68
69     public List acceptCFG(CFGBuilder v, List succs) {
70         v.visitBranchTarget(this);
71         return Collections.EMPTY_LIST;
72     }
73 }
74
Popular Tags