KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > polyglot > ext > jl > ast > CharLit_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>CharLit</code> represents a literal in java of
10  * <code>char</code> type.
11  */

12 public class CharLit_c extends NumLit_c implements CharLit
13 {
14     public CharLit_c(Position pos, char value) {
15     super(pos, value);
16     }
17
18     /** Get the value of the expression. */
19     public char value() {
20     return (char) longValue();
21     }
22
23     /** Set the value of the expression. */
24     public CharLit value(char value) {
25     CharLit_c n = (CharLit_c) copy();
26     n.value = value;
27     return n;
28     }
29
30     /** Type check the expression. */
31     public Node typeCheck(TypeChecker tc) throws SemanticException {
32     return type(tc.typeSystem().Char());
33     }
34
35     public String JavaDoc toString() {
36         return "'" + StringUtil.escape((char) value) + "'";
37     }
38
39     /** Write the expression to an output file. */
40     public void prettyPrint(CodeWriter w, PrettyPrinter tr) {
41         w.write("'");
42     w.write(StringUtil.escape((char) value));
43         w.write("'");
44     }
45
46     public Object JavaDoc constantValue() {
47       return new Character JavaDoc((char) value);
48     }
49 }
50
Popular Tags