1 16 package com.google.gwt.user.rebind.rpc; 17 18 import com.google.gwt.core.ext.BadPropertyValueException; 19 import com.google.gwt.core.ext.PropertyOracle; 20 import com.google.gwt.core.ext.TreeLogger; 21 import com.google.gwt.core.ext.typeinfo.JClassType; 22 import com.google.gwt.core.ext.typeinfo.JParameterizedType; 23 import com.google.gwt.core.ext.typeinfo.JPrimitiveType; 24 import com.google.gwt.core.ext.typeinfo.JType; 25 26 import java.util.Locale ; 27 28 class Shared { 29 30 34 static final String RPC_PROP_ENFORCE_TYPE_VERSIONING = "gwt.enforceRPCTypeVersioning"; 35 36 42 static String capitalize(String name) { 43 return name.substring(0, 1).toUpperCase(Locale.US) + name.substring(1); 44 } 45 46 53 static String getCallSuffix(JType type) { 54 JParameterizedType isParameterized = type.isParameterized(); 55 if (isParameterized != null) { 56 return getCallSuffix(isParameterized.getRawType()); 57 } else if (type.isPrimitive() != null) { 58 if (type == JPrimitiveType.BOOLEAN) { 59 return "Boolean"; 60 } else if (type == JPrimitiveType.BYTE) { 61 return "Byte"; 62 } else if (type == JPrimitiveType.CHAR) { 63 return "Char"; 64 } else if (type == JPrimitiveType.DOUBLE) { 65 return "Double"; 66 } else if (type == JPrimitiveType.FLOAT) { 67 return "Float"; 68 } else if (type == JPrimitiveType.INT) { 69 return "Int"; 70 } else if (type == JPrimitiveType.LONG) { 71 return "Long"; 72 } else if (type == JPrimitiveType.SHORT) { 73 return "Short"; 74 } else { 75 return null; 76 } 77 } else if (type.getQualifiedSourceName().equals("java.lang.String")) { 78 return "String"; 79 } else { 80 return "Object"; 81 } 82 } 83 84 88 static boolean shouldEnforceTypeVersioning(TreeLogger logger, PropertyOracle propertyOracle) { 89 try { 90 String propVal = propertyOracle.getPropertyValue(logger, 91 RPC_PROP_ENFORCE_TYPE_VERSIONING); 92 if (propVal.equals("false")) { 93 return false; 94 } 95 } catch (BadPropertyValueException e) { 96 } 99 return true; 101 } 102 103 122 static String [] synthesizeTopLevelClassName(JClassType type, String suffix) { 123 String className = type.getName(); 127 128 className += suffix; 131 132 className = className.replace('.', '_'); 135 136 String packageName = type.getPackage().getName(); 137 return new String []{packageName, className}; 138 } 139 140 149 static boolean typeNeedsCast(JType type) { 150 return type.isPrimitive() == null 151 && !type.getQualifiedSourceName().equals("java.lang.String") 152 && !type.getQualifiedSourceName().equals("java.lang.Object"); 153 } 154 } 155 | Popular Tags |