KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > genimen > djeneric > tools > generator > core > nodes > ConstNode


1 package com.genimen.djeneric.tools.generator.core.nodes;
2
3 import com.genimen.djeneric.tools.generator.core.DjentelParserEngine;
4 import com.genimen.djeneric.tools.generator.core.SimpleNode;
5 import com.genimen.djeneric.tools.generator.core.util.ParseContext;
6
7 public class ConstNode extends SimpleNode
8 {
9
10   private String JavaDoc key;
11   private Object JavaDoc _constval;
12
13   public ConstNode(int i)
14   {
15     super(i);
16   }
17
18   public ConstNode(DjentelParserEngine p, int i)
19   {
20     super(p, i);
21   }
22
23   public String JavaDoc toString()
24   {
25     return getKey() + " = " + getConst();
26   }
27
28   public String JavaDoc getName()
29   {
30     return "const";
31   }
32
33   public void setKey(String JavaDoc key)
34   {
35     this.key = key;
36   }
37
38   public String JavaDoc getKey()
39   {
40     return key;
41   }
42
43   public void setString(String JavaDoc v)
44   { // Strip the quotes
45
v = v.substring(1);
46     v = v.substring(0, v.length() - 1);
47
48     _constval = v;
49   }
50
51   public void setBoolean(Boolean JavaDoc b)
52   {
53     _constval = b;
54   }
55
56   public void setChar(String JavaDoc v)
57   { // Strip the quotes
58
v = v.substring(1);
59     v = v.substring(0, v.length() - 1);
60
61     if (v.startsWith("\\"))
62     {
63       if (v.equals("\\n")) v = "\n";
64       else if (v.equals("\\t")) v = "\t";
65       else if (v.equals("\\b")) v = "\b";
66       else if (v.equals("\\r")) v = "\r";
67       else if (v.equals("\\f")) v = "\f";
68       else if (v.equals("\\\\")) v = "\\";
69       else if (v.equals("\\'")) v = "'";
70       else if (v.equals("\\\"")) v = "\"";
71     }
72     _constval = String.valueOf(v.charAt(0));
73   }
74
75   public void setInteger(Integer JavaDoc i)
76   {
77     _constval = i;
78   }
79
80   public void setFloat(Float JavaDoc f)
81   {
82     _constval = f;
83   }
84
85   public Object JavaDoc getConst()
86   {
87     return _constval;
88   }
89
90   public String JavaDoc evaluate(ParseContext context)
91   {
92     context.pushConst(getKey(), getConst());
93     return "";
94   }
95
96 }
Popular Tags