KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > polyglot > ext > coffer > ast > ThrowConstraintNode_c


1 package polyglot.ext.coffer.ast;
2
3 import polyglot.ast.*;
4 import polyglot.visit.*;
5 import polyglot.ext.jl.ast.*;
6 import polyglot.ext.coffer.types.*;
7 import polyglot.types.*;
8 import polyglot.util.*;
9
10 /**
11  * An AST node for an exception throw declaration annotated with a key set.
12  */

13 public class ThrowConstraintNode_c extends Node_c implements ThrowConstraintNode
14 {
15     TypeNode tn;
16     KeySetNode keys;
17     ThrowConstraint constraint;
18
19     public ThrowConstraintNode_c(Position pos,
20                                  TypeNode tn, KeySetNode keys) {
21         super(pos);
22         this.tn = tn;
23         this.keys = keys;
24     }
25
26     public TypeNode type() { return tn; }
27     public KeySetNode keys() { return keys; }
28
29     public Node buildTypes(TypeBuilder tb) throws SemanticException {
30         CofferTypeSystem ts = (CofferTypeSystem) tb.typeSystem();
31         ThrowConstraint constraint = ts.throwConstraint(position(),
32                                                         tn.type(),
33                                                         keys != null ? keys.keys() : null);
34         return constraint(constraint);
35     }
36
37     public Node disambiguate(AmbiguityRemover ar) throws SemanticException {
38         if (ar.kind() == AmbiguityRemover.SIGNATURES) {
39             CofferTypeSystem ts = (CofferTypeSystem) ar.typeSystem();
40             ThrowConstraint constraint = ts.throwConstraint(position(),
41                                                             tn.type(),
42                                                             keys != null ? keys.keys() : null);
43             return constraint(constraint);
44         }
45
46         return this;
47     }
48
49     public ThrowConstraint constraint() {
50         return constraint;
51     }
52
53     public ThrowConstraintNode constraint(ThrowConstraint constraint) {
54     ThrowConstraintNode_c n = (ThrowConstraintNode_c) copy();
55     n.constraint = constraint;
56     return n;
57     }
58
59     public ThrowConstraintNode keys(KeySetNode keys) {
60     ThrowConstraintNode_c n = (ThrowConstraintNode_c) copy();
61     n.keys = keys;
62     return n;
63     }
64
65     public ThrowConstraintNode type(TypeNode tn) {
66     ThrowConstraintNode_c n = (ThrowConstraintNode_c) copy();
67     n.tn = tn;
68     return n;
69     }
70
71     public Node visitChildren(NodeVisitor v) {
72         TypeNode tn = (TypeNode) visitChild(this.tn, v);
73         KeySetNode keys = (KeySetNode) visitChild(this.keys, v);
74     return reconstruct(tn, keys);
75     }
76
77     protected ThrowConstraintNode_c reconstruct(TypeNode tn, KeySetNode keys) {
78       if (tn != this.tn || keys != this.keys) {
79           ThrowConstraintNode_c n = (ThrowConstraintNode_c) copy();
80           n.tn = tn;
81           n.keys = keys;
82           return n;
83       }
84
85       return this;
86     }
87
88     public void prettyPrint(CodeWriter w, PrettyPrinter pp) {
89         print(tn, w, pp);
90         if (keys != null)
91             print(keys, w, pp);
92     }
93
94     public void translate(CodeWriter w, Translator tr) {
95         print(tn, w, tr);
96     }
97 }
98
Popular Tags