1 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 ; 35 36 39 class TypeExpr extends Expr { 40 private static HashMap 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 _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 getTypeName() 82 { 83 return _typeName; 84 } 85 86 89 public String toString() 90 { 91 return "TypeExpr[" + javaType + " " + type + "]"; 92 } 93 94 97 static class Type { 98 ESId id; 99 int jsType; 100 String _name; 101 Class javaClass; 102 103 Type(ESId id, int jsType, Class 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 (); 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 .class)); 131 } 132 } 133 | Popular Tags |