List of usage examples for com.google.gwt.core.ext.typeinfo JType getSimpleSourceName
String getSimpleSourceName();
From source file:com.didactilab.gwt.phprpc.rebind.PhpTools.java
License:Apache License
public static String typeToString(JType type, boolean phpCompatible) { String name = ""; JArrayType arrayType = type.isArray(); if (arrayType != null) { if (phpCompatible) name = "array"; else// w w w . j av a 2s .c o m name = typeToString(arrayType.getComponentType(), phpCompatible) + "[]"; } else { JClassType classType = type.isClassOrInterface(); if ((classType != null) && (classType.getEnclosingType() != null)) name = typeToString(classType.getEnclosingType(), phpCompatible) + "_"; name += filterType(type.getSimpleSourceName()); if (!phpCompatible) { JParameterizedType params = type.isParameterized(); if (params != null) { JClassType[] args = params.getTypeArgs(); name += "<"; for (int i = 0, c = args.length; i < c; i++) { name += typeToString(args[i], phpCompatible); if (i < c - 1) name += ", "; } name += ">"; } } } return name; }
From source file:com.google.appinventor.rebind.ExtendedServiceProxyGenerator.java
License:Open Source License
/** * Generate the implementation of a single method. * * @param out where to print the method to * @param method the method//w w w . j ava 2s . c o m * @param typeName type name of the containing proxy class */ private void printMethod(PrintWriter out, JMethod method, String typeName) { // Build parameter lists int i = 0; StringBuilder actualParamsBuilder = new StringBuilder(); StringBuilder formalParamsBuilder = new StringBuilder(); for (JParameter param : method.getParameters()) { if (i != 0) { actualParamsBuilder.append(", "); formalParamsBuilder.append(", "); } String paramType = param.getType().getParameterizedQualifiedSourceName(); String paramName = "p" + i++; actualParamsBuilder.append(paramName); formalParamsBuilder.append(paramType + " " + paramName); } String actualParams = actualParamsBuilder.toString(); String formalParams = formalParamsBuilder.toString(); // Information about the return type JType returnType = method.getReturnType(); boolean hasReturnValue = !returnType.getSimpleSourceName().equals("void"); JPrimitiveType primitiveReturnType = returnType.isPrimitive(); String resultType = primitiveReturnType != null ? primitiveReturnType.getQualifiedBoxedSourceName() : returnType.getParameterizedQualifiedSourceName(); String callbackType = AsyncCallback.class.getName() + "<" + resultType + ">"; // Print method out.println(" public void " + method.getName() + "(" + formalParams + (formalParams.isEmpty() ? "" : ", ") + "final " + callbackType + " callback" + ") {"); out.println(" fireStart(\"" + method.getName() + "\"" + (actualParams.isEmpty() ? "" : ", ") + actualParams + ");"); out.println(" proxy." + method.getName() + "(" + actualParams + (actualParams.isEmpty() ? "" : ", ") + "new " + callbackType + "() {"); out.println(" public void onSuccess(" + resultType + " result) {"); out.println(" " + outcome(method, "Success", "result")); out.println(" }"); out.println(" public void onFailure(Throwable caught) {"); out.println(" " + outcome(method, "Failure", "caught")); out.println(" }"); out.println(" });"); out.println(" }"); }
From source file:com.guit.rebind.jsorm.JsonSerializerUtil.java
License:Apache License
private static void makeImplName(JType pojoType, StringBuilder implName) { JArrayType array = pojoType.isArray(); if (pojoType.isPrimitive() != null) { implName.append(pojoType.getSimpleSourceName()); } else if (array != null) { implName.append("Array"); makeImplName(array.getComponentType(), implName); } else {/* ww w. j a va 2 s . c o m*/ JParameterizedType parameterized = pojoType.isParameterized(); implName.append(pojoType.getSimpleSourceName()); if (parameterized != null) { JClassType[] args = parameterized.getTypeArgs(); for (JClassType a : args) { makeImplName(a, implName); } } } }
From source file:com.gwtmobile.persistence.rebind.GenUtils.java
License:Apache License
public String getSQLiteType(JType returnType) { String sqliteType = null;// ww w.j av a 2s. c o m JPrimitiveType primitiveReturnType = returnType.isPrimitive(); if (primitiveReturnType != null) { if (primitiveReturnType == JPrimitiveType.INT) { sqliteType = "INTEGER"; } else if (primitiveReturnType == JPrimitiveType.BOOLEAN) { sqliteType = "BOOL"; } else { sqliteType = primitiveReturnType.getSimpleSourceName().toUpperCase(); } } else { String returnTypeName = returnType.getSimpleSourceName(); if (returnTypeName.equals("String")) { sqliteType = "TEXT"; } else if (isSubclassOf(returnType, "JSONValue")) { sqliteType = "JSON"; } else { sqliteType = returnTypeName.toUpperCase(); } } return sqliteType; }
From source file:com.gwtmobile.persistence.rebind.GenUtils.java
License:Apache License
public void inspectType(String typeName, List<JMethod> getters, List<JMethod> hasManyRels, List<JMethod> hasOneRels) throws UnableToCompleteException { JClassType classType = getClassType(typeName); for (JMethod method : classType.getOverridableMethods()) { if (!method.isAbstract()) { continue; }/*w w w .j a v a 2 s . c o m*/ String methodName = method.getName(); if (methodName.startsWith("get")) { String propertyName = methodName.substring(3); // getId() is reserved. if (propertyName.equals("Id")) { continue; } JType returnType = method.getReturnType(); String returnTypeName = returnType.getSimpleSourceName(); if (returnType.isPrimitive() != null && !returnTypeName.equals("long") || returnTypeName.equals("String") || returnTypeName.equals("Date") || isSubclassOf(returnType, "JSONValue")) { getters.add(method); continue; } if (returnTypeName.equals("long")) { logger.log(TreeLogger.ERROR, "GWT JSNI does not support 'long' as return type on getter '" + methodName + "'. Use 'double' instead."); throw new UnableToCompleteException(); } if (returnTypeName.startsWith("Collection")) { hasManyRels.add(method); continue; } if (isSubclassOf(returnType, "Persistable")) { hasOneRels.add(method); continue; } logger.log(TreeLogger.ERROR, "Unsupported return type '" + returnTypeName + "' on getter '" + methodName + "'."); throw new UnableToCompleteException(); } else { // TODO: check if method is a setter. ignore if so, error if not. } } }
From source file:com.gwtplatform.dispatch.rebind.RestActionGenerator.java
License:Apache License
private String getBaseName() { StringBuilder nameBuilder = new StringBuilder(actionMethod.getName()); Character firstChar = Character.toUpperCase(nameBuilder.charAt(0)); nameBuilder.setCharAt(0, firstChar); StringBuilder classNameBuilder = new StringBuilder(); classNameBuilder.append(actionMethod.getEnclosingType().getName()).append("_").append(nameBuilder); for (JType type : actionMethod.getErasedParameterTypes()) { classNameBuilder.append("_").append(type.getSimpleSourceName()); }// w ww .jav a 2s.c o m return classNameBuilder.toString(); }
From source file:com.gwtplatform.mvp.rebind.GinjectorInspector.java
License:Apache License
/** * Initializes the ginjector inspector. Finds the ginjector class given the value of the GWT configuration * property {@code gin.ginjector}./*from w ww. ja v a 2 s . com*/ * * @throws UnableToCompleteException If the ginjector property or class cannot be found, an error is logged. */ public void init() throws UnableToCompleteException { findGinjectorClassName(logger, generatorContext.getPropertyOracle()); findGinjectorClass(logger, generatorContext.getTypeOracle()); classInspector = new ClassInspector(logger, ginjectorClass); Set<JType> returnTypes = new HashSet<JType>(); for (JMethod method : classInspector.getAllMethods()) { final JType type = method.getReturnType(); if (!returnTypes.add(type)) { logger.log(TreeLogger.Type.ERROR, String.format(GINJECTOR_INVALID_METHOD, ginjectorClassName, type.getSimpleSourceName())); throw new UnableToCompleteException(); } } }
From source file:com.tyf.gwtphp.rebind.PHPRemoteServiceGenerator.java
License:Open Source License
private Collection<? extends ObjectArtifact> discoverObjects(JType type) throws ClassNotFoundException { Set<ObjectArtifact> objects = new HashSet<ObjectArtifact>(); // reduce time wasted doing duplicate discovery if (customObjectSet.contains(type)) return objects; if (isCustom(type)) { Set<JType> discoveredTypes = new HashSet<JType>(); JClassType supertype = getSuperType(type); JClassType classType;//from www .j a v a 2s.c om ObjectArtifact object; if ((classType = type.isClass()) != null) { object = new ObjectArtifact(type.getQualifiedSourceName(), type.getSimpleSourceName(), supertype != null ? supertype.getQualifiedSourceName() : null, supertype != null ? supertype.getSimpleSourceName() : null, classType.isInterface() != null, classType.isAbstract(), TypeUtil.getCRC(type)); for (JField f : classType.getFields()) { String fieldName = f.getName(); String fieldType = TypeUtil.getPHPRpcTypeName(f.getType(), discoveredTypes); object.putField(fieldName, new Field(fieldName, fieldType, TypeUtil.toPHPType(f.getType()))); } } else { object = new ObjectArtifact(type.getQualifiedSourceName(), type.getSimpleSourceName(), supertype != null ? supertype.getQualifiedSourceName() : null, supertype != null ? supertype.getSimpleSourceName() : null, false, false, TypeUtil.getCRC(type)); } objects.add(object); customObjectSet.add(type); // recursively discover the parent classes. This has to be done after the current // type is added into the customObjectSet to avoid infinite recursion if (classType != null) { if (classType.getSuperclass() != null) { objects.addAll(discoverObjects(classType.getSuperclass())); } } // recursively discover other custom objects refereced by this object for (JType t : discoveredTypes) { objects.addAll(discoverObjects(t)); } } return objects; }
From source file:com.tyf.gwtphp.rebind.TypeUtil.java
License:Open Source License
public static String toPHPType(JType type) { // TODO: more robust conversion if (type.getSimpleSourceName().equals("String")) { return "string"; }//from ww w . ja va 2s. c o m return type.getSimpleSourceName().toLowerCase(); }
From source file:fr.onevu.gwt.uibinder.elementparsers.BeanParser.java
License:Apache License
/** * Generates code to initialize all bean attributes on the given element. * Includes support for <ui:attribute /> children that will apply to * setters/* w w w .j a v a 2s . c o m*/ * * @throws UnableToCompleteException */ public void parse(XMLElement elem, String fieldName, JClassType type, UiBinderWriter writer) throws UnableToCompleteException { writer.getDesignTime().handleUIObject(writer, elem, fieldName); final Map<String, String> setterValues = new HashMap<String, String>(); final Map<String, String> localizedValues = fetchLocalizedAttributeValues(elem, writer); final Map<String, String> requiredValues = new HashMap<String, String>(); final Map<String, JType> unfilledRequiredParams = new HashMap<String, JType>(); final OwnerFieldClass ownerFieldClass = OwnerFieldClass.getFieldClass(type, writer.getLogger(), context); /* * Handle @UiFactory and @UiConstructor, but only if the user hasn't * provided an instance via @UiField(provided = true) */ JAbstractMethod creator = null; OwnerField uiField = writer.getOwnerClass().getUiField(fieldName); if ((uiField == null) || (!uiField.isProvided())) { // See if there's a factory method creator = writer.getOwnerClass().getUiFactoryMethod(type); if (creator == null) { // If not, see if there's a @UiConstructor creator = ownerFieldClass.getUiConstructor(); } if (creator != null) { for (JParameter param : creator.getParameters()) { unfilledRequiredParams.put(param.getName(), param.getType()); } } } // Work through the localized attribute values and assign them // to appropriate constructor params or setters (which had better be // ready to accept strings) for (Entry<String, String> property : localizedValues.entrySet()) { String key = property.getKey(); String value = property.getValue(); JType paramType = unfilledRequiredParams.get(key); if (paramType != null) { if (!isString(writer, paramType)) { writer.die(elem, "In %s, cannot apply message attribute to non-string " + "constructor argument %s.", paramType.getSimpleSourceName(), key); } requiredValues.put(key, value); unfilledRequiredParams.remove(key); } else { JMethod setter = ownerFieldClass.getSetter(key); JParameter[] params = setter == null ? null : setter.getParameters(); if (setter == null || !(params.length == 1) || !isString(writer, params[0].getType())) { writer.die(elem, "No method found to apply message attribute %s", key); } else { setterValues.put(key, value); } } } // Now go through the element and dispatch its attributes, remembering // that constructor arguments get first dibs for (int i = elem.getAttributeCount() - 1; i >= 0; i--) { // Backward traversal b/c we're deleting attributes from the xml element XMLAttribute attribute = elem.getAttribute(i); // Ignore xmlns attributes if (attribute.getName().startsWith("xmlns:")) { continue; } String propertyName = attribute.getLocalName(); if (setterValues.keySet().contains(propertyName) || requiredValues.containsKey(propertyName)) { writer.die(elem, "Duplicate attribute name: %s", propertyName); } if (unfilledRequiredParams.keySet().contains(propertyName)) { JType paramType = unfilledRequiredParams.get(propertyName); String value = elem.consumeAttributeWithDefault(attribute.getName(), null, paramType); if (value == null) { writer.die(elem, "Unable to parse %s as constructor argument " + "of type %s", attribute, paramType.getSimpleSourceName()); } requiredValues.put(propertyName, value); unfilledRequiredParams.remove(propertyName); } else { JMethod setter = ownerFieldClass.getSetter(propertyName); if (setter == null) { writer.die(elem, "Class %s has no appropriate set%s() method", elem.getLocalName(), initialCap(propertyName)); } String n = attribute.getName(); String value = elem.consumeAttributeWithDefault(n, null, getParamTypes(setter)); if (value == null) { writer.die(elem, "Unable to parse %s.", attribute); } setterValues.put(propertyName, value); } } if (!unfilledRequiredParams.isEmpty()) { StringBuilder b = new StringBuilder(String.format("%s missing required attribute(s):", elem)); for (String name : unfilledRequiredParams.keySet()) { b.append(" ").append(name); } writer.die(elem, b.toString()); } if (creator != null) { String[] args = makeArgsList(requiredValues, creator); if (creator instanceof JMethod) { // Factory method JMethod factoryMethod = (JMethod) creator; String initializer; if (writer.getDesignTime().isDesignTime()) { String typeName = factoryMethod.getReturnType().getQualifiedSourceName(); initializer = writer.getDesignTime().getProvidedFactory(typeName, factoryMethod.getName(), UiBinderWriter.asCommaSeparatedList(args)); } else { initializer = String.format("owner.%s(%s)", factoryMethod.getName(), UiBinderWriter.asCommaSeparatedList(args)); } writer.setFieldInitializer(fieldName, initializer); } else { // Annotated Constructor writer.setFieldInitializerAsConstructor(fieldName, args); } } for (Map.Entry<String, String> entry : setterValues.entrySet()) { String propertyName = entry.getKey(); String value = entry.getValue(); writer.addStatement("%s.set%s(%s);", fieldName, initialCap(propertyName), value); } }