KickJava   Java API By Example, From Geeks To Geeks.

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


1 package polyglot.ext.jl.ast;
2
3 import polyglot.ast.ClassLit;
4 import polyglot.ast.Expr;
5 import polyglot.ast.Node;
6 import polyglot.ast.TypeNode;
7 import polyglot.types.SemanticException;
8 import polyglot.util.CodeWriter;
9 import polyglot.util.Position;
10 import polyglot.visit.NodeVisitor;
11 import polyglot.visit.PrettyPrinter;
12 import polyglot.visit.TypeChecker;
13
14 /**
15  * A <code>ClassLit</code> represents a class literal expression.
16  * A class literal expressions is an expression consisting of the
17  * name of a class, interface, array, or primitive type followed by a period (.)
18  * and the token class.
19  */

20 public class ClassLit_c extends Lit_c implements ClassLit
21 {
22   protected TypeNode typeNode;
23
24   public ClassLit_c(Position pos, TypeNode typeNode) {
25     super(pos);
26     this.typeNode = typeNode;
27   }
28
29   public TypeNode typeNode() {
30     return this.typeNode;
31   }
32
33   public ClassLit typeNode(TypeNode typeNode) {
34       if (this.typeNode == typeNode) {
35           return this;
36       }
37     ClassLit_c n = (ClassLit_c) copy();
38     n.typeNode = typeNode;
39     return n;
40   }
41     
42   /**
43    * Cannot return the correct object (except for maybe
44    * some of the primitive arrays), so we just return null here.
45    */

46   public Object JavaDoc objValue() {
47     return null;
48   }
49
50   public Node visitChildren(NodeVisitor v) {
51     TypeNode tn = (TypeNode)visitChild(this.typeNode, v);
52     return this.typeNode(tn);
53   }
54
55   /** Type check the expression. */
56   public Node typeCheck(TypeChecker tc) throws SemanticException {
57     return type(tc.typeSystem().Class());
58   }
59
60   public String JavaDoc toString() {
61     return typeNode.toString() + ".class";
62   }
63
64   /** Write the expression to an output file. */
65   public void prettyPrint(CodeWriter w, PrettyPrinter tr)
66   {
67     w.begin(0);
68     print(typeNode, w, tr);
69     w.write(".class");
70     w.end();
71   }
72
73   /**
74    * According to the JLS 2nd Ed, sec 15.28, a class literal
75    * is not a compile time constant.
76    */

77   public boolean isConstant() {
78     return false;
79   }
80
81   public Object JavaDoc constantValue() {
82     return null;
83   }
84 }
85
Popular Tags