KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > es > parser > TypeExpr


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  * Free SoftwareFoundation, Inc.
23  * 59 Temple Place, Suite 330
24  * Boston, MA 02111-1307 USA
25  *
26  * @author Scott Ferguson
27  */

28
29 package com.caucho.es.parser;
30
31 import com.caucho.es.ESBase;
32 import com.caucho.es.ESId;
33
34 import java.util.HashMap JavaDoc;
35
36 /**
37  * Expr is an intermediate form representing an expression.
38  */

39 class TypeExpr extends Expr {
40   private static HashMap JavaDoc types;
41   
42   private static ESId CAUCHO = ESId.intern("caucho");
43   private static ESId JAVA = ESId.intern("java");
44   private static ESId PACKAGES = ESId.intern("Packages");
45
46   private ESId id;
47   
48   protected String JavaDoc _typeName;
49
50   TypeExpr(Block block, ESId id)
51   {
52     super(block);
53     
54     this.id = id;
55     
56     Type type = (Type) types.get(id);
57     if (type != null) {
58       this.type = type.jsType;
59       _typeName = type._name;
60       javaType = type.javaClass;
61     }
62     else {
63       this.type = TYPE_ES;
64       _typeName = "com.caucho.es.ESBase";
65       javaType = ESBase.class;
66     }
67   }
68
69   static TypeExpr create(Block block, ESId id)
70   {
71     if (id == CAUCHO)
72       return new JavaTypeExpr(block, "com.caucho");
73     else if (id == JAVA)
74       return new JavaTypeExpr(block, "java");
75     else if (id == PACKAGES)
76       return new JavaTypeExpr(block, "");
77     else
78       return new TypeExpr(block, id);
79   }
80
81   String JavaDoc getTypeName()
82   {
83     return _typeName;
84   }
85
86   /**
87    * Returns a debugging string.
88    */

89   public String JavaDoc toString()
90   {
91     return "TypeExpr[" + javaType + " " + type + "]";
92   }
93
94   /**
95    * Representation of the primitive types.
96    */

97   static class Type {
98     ESId id;
99     int jsType;
100     String JavaDoc _name;
101     Class JavaDoc javaClass;
102
103     Type(ESId id, int jsType, Class JavaDoc cl)
104     {
105       this.id = id;
106       this.jsType = jsType;
107       _name = cl.getName();
108       this.javaClass = cl;
109     }
110   }
111
112   static {
113     types = new HashMap JavaDoc();
114     types.put(ESId.intern("boolean"),
115               new Type(ESId.intern("boolean"), TYPE_BOOLEAN, boolean.class));
116     types.put(ESId.intern("byte"),
117               new Type(ESId.intern("byte"), TYPE_INTEGER, byte.class));
118     types.put(ESId.intern("short"),
119               new Type(ESId.intern("short"), TYPE_INTEGER, short.class));
120     types.put(ESId.intern("int"),
121               new Type(ESId.intern("int"), TYPE_INTEGER, int.class));
122     types.put(ESId.intern("long"),
123               new Type(ESId.intern("long"), TYPE_LONG, long.class));
124     types.put(ESId.intern("float"),
125               new Type(ESId.intern("float"), TYPE_NUMBER, float.class));
126     types.put(ESId.intern("double"),
127               new Type(ESId.intern("double"), TYPE_NUMBER, double.class));
128     
129     types.put(ESId.intern("String"),
130               new Type(ESId.intern("String"), TYPE_STRING, String JavaDoc.class));
131   }
132 }
133
Popular Tags