001: /*
002: * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: * Free SoftwareFoundation, Inc.
023: * 59 Temple Place, Suite 330
024: * Boston, MA 02111-1307 USA
025: *
026: * @author Scott Ferguson
027: */
028:
029: package com.caucho.es.parser;
030:
031: import com.caucho.es.ESBase;
032: import com.caucho.es.ESId;
033:
034: import java.util.HashMap;
035:
036: /**
037: * Expr is an intermediate form representing an expression.
038: */
039: class TypeExpr extends Expr {
040: private static HashMap types;
041:
042: private static ESId CAUCHO = ESId.intern("caucho");
043: private static ESId JAVA = ESId.intern("java");
044: private static ESId PACKAGES = ESId.intern("Packages");
045:
046: private ESId id;
047:
048: protected String _typeName;
049:
050: TypeExpr(Block block, ESId id) {
051: super (block);
052:
053: this .id = id;
054:
055: Type type = (Type) types.get(id);
056: if (type != null) {
057: this .type = type.jsType;
058: _typeName = type._name;
059: javaType = type.javaClass;
060: } else {
061: this .type = TYPE_ES;
062: _typeName = "com.caucho.es.ESBase";
063: javaType = ESBase.class;
064: }
065: }
066:
067: static TypeExpr create(Block block, ESId id) {
068: if (id == CAUCHO)
069: return new JavaTypeExpr(block, "com.caucho");
070: else if (id == JAVA)
071: return new JavaTypeExpr(block, "java");
072: else if (id == PACKAGES)
073: return new JavaTypeExpr(block, "");
074: else
075: return new TypeExpr(block, id);
076: }
077:
078: String getTypeName() {
079: return _typeName;
080: }
081:
082: /**
083: * Returns a debugging string.
084: */
085: public String toString() {
086: return "TypeExpr[" + javaType + " " + type + "]";
087: }
088:
089: /**
090: * Representation of the primitive types.
091: */
092: static class Type {
093: ESId id;
094: int jsType;
095: String _name;
096: Class javaClass;
097:
098: Type(ESId id, int jsType, Class cl) {
099: this .id = id;
100: this .jsType = jsType;
101: _name = cl.getName();
102: this .javaClass = cl;
103: }
104: }
105:
106: static {
107: types = new HashMap();
108: types.put(ESId.intern("boolean"), new Type(ESId
109: .intern("boolean"), TYPE_BOOLEAN, boolean.class));
110: types.put(ESId.intern("byte"), new Type(ESId.intern("byte"),
111: TYPE_INTEGER, byte.class));
112: types.put(ESId.intern("short"), new Type(ESId.intern("short"),
113: TYPE_INTEGER, short.class));
114: types.put(ESId.intern("int"), new Type(ESId.intern("int"),
115: TYPE_INTEGER, int.class));
116: types.put(ESId.intern("long"), new Type(ESId.intern("long"),
117: TYPE_LONG, long.class));
118: types.put(ESId.intern("float"), new Type(ESId.intern("float"),
119: TYPE_NUMBER, float.class));
120: types.put(ESId.intern("double"), new Type(
121: ESId.intern("double"), TYPE_NUMBER, double.class));
122:
123: types.put(ESId.intern("String"), new Type(
124: ESId.intern("String"), TYPE_STRING, String.class));
125: }
126: }
|