KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > polyglot > ext > jl > ast > AmbPrefix_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
8 /**
9  * An <code>AmbPrefix</code> is an ambiguous AST node composed of dot-separated
10  * list of identifiers that must resolve to a prefix.
11  */

12 public class AmbPrefix_c extends Node_c implements AmbPrefix
13 {
14     protected Prefix prefix;
15     protected String JavaDoc name;
16
17     public AmbPrefix_c(Position pos, Prefix prefix, String JavaDoc name) {
18     super(pos);
19     this.prefix = prefix;
20     this.name = name;
21     }
22
23     /** Get the name of the prefix. */
24     public String JavaDoc name() {
25     return this.name;
26     }
27
28     /** Set the name of the prefix. */
29     public AmbPrefix name(String JavaDoc name) {
30     AmbPrefix_c n = (AmbPrefix_c) copy();
31     n.name = name;
32     return n;
33     }
34
35     /** Get the prefix of the prefix. */
36     public Prefix prefix() {
37     return this.prefix;
38     }
39
40     /** Set the prefix of the prefix. */
41     public AmbPrefix prefix(Prefix prefix) {
42     AmbPrefix_c n = (AmbPrefix_c) copy();
43     n.prefix = prefix;
44     return n;
45     }
46
47     /** Reconstruct the prefix. */
48     protected AmbPrefix_c reconstruct(Prefix prefix) {
49     if (prefix != this.prefix) {
50         AmbPrefix_c n = (AmbPrefix_c) copy();
51         n.prefix = prefix;
52         return n;
53     }
54
55     return this;
56     }
57
58     /** Visit the children of the prefix. */
59     public Node visitChildren(NodeVisitor v) {
60     Prefix prefix = (Prefix) visitChild(this.prefix, v);
61     return reconstruct(prefix);
62     }
63
64     /** Disambiguate the prefix. */
65     public Node disambiguate(AmbiguityRemover ar) throws SemanticException {
66     return ar.nodeFactory().disamb().disambiguate(this, ar, position(), prefix, name);
67     }
68
69     /** Type check the prefix. */
70     public Node typeCheck(TypeChecker tc) throws SemanticException {
71     throw new InternalCompilerError(position(),
72         "Cannot type check ambiguous node " + this + ".");
73     }
74
75     /** Check exceptions thrown by the prefix. */
76     public Node exceptionCheck(ExceptionChecker ec) throws SemanticException {
77     throw new InternalCompilerError(position(),
78         "Cannot exception check ambiguous node " + this + ".");
79     }
80
81     /** Write the prefix to an output file. */
82     public void prettyPrint(CodeWriter w, PrettyPrinter tr) {
83     if (prefix != null) {
84             print(prefix, w, tr);
85             w.write(".");
86         }
87                 
88         w.write(name);
89     }
90
91     public void translate(CodeWriter w, Translator tr) {
92     throw new InternalCompilerError(position(),
93         "Cannot translate ambiguous node " + this + ".");
94     }
95
96     public String JavaDoc toString() {
97     return (prefix == null
98         ? name
99         : prefix.toString() + "." + name) + "{amb}";
100     }
101 }
102
Popular Tags