Java Code Examples for com.google.gwt.core.ext.typeinfo.JType#isPrimitive()
The following examples show how to use
com.google.gwt.core.ext.typeinfo.JType#isPrimitive() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JTypeName.java From gwt-jackson with Apache License 2.0 | 6 votes |
/** * @param boxed true if the primitive should be boxed. Useful when use in a parameterized type. * @param type the type * * @return the {@link TypeName} */ public TypeName typeName( boolean boxed, JType type ) { if ( null != type.isPrimitive() ) { return primitiveName( type.isPrimitive(), boxed ); } else if ( null != type.isParameterized() ) { return parameterizedName( type.isParameterized() ); } else if ( null != type.isGenericType() ) { return genericName( type.isGenericType() ); } else if ( null != type.isArray() ) { return arrayName( type.isArray() ); } else if ( null != type.isTypeParameter() ) { return typeVariableName( type.isTypeParameter() ); } else if ( null != type.isWildcard() ) { return wildcardName( type.isWildcard() ); } else { return className( type.isClassOrInterface() ); } }
Example 2
Source File: JTypeName.java From gwt-jackson with Apache License 2.0 | 6 votes |
/** * @param boxed true if the primitive should be boxed. Useful when use in a parameterized type. * @param type type to convert * * @return the raw {@link TypeName} without parameter */ public TypeName rawName( boolean boxed, JType type ) { if ( null != type.isPrimitive() ) { return primitiveName( type.isPrimitive(), boxed ); } else if ( null != type.isParameterized() ) { return className( type.isParameterized().getRawType() ); } else if ( null != type.isGenericType() ) { return className( type.isGenericType().getRawType() ); } else if ( null != type.isArray() ) { return arrayName( type.isArray() ); } else if ( null != type.isTypeParameter() ) { return typeVariableName( type.isTypeParameter() ); } else { return className( type.isClassOrInterface() ); } }
Example 3
Source File: ModelCreator.java From putnami-web-toolkit with GNU Lesser General Public License v3.0 | 5 votes |
private void generateInternalSet(TreeLogger logger, SourceWriter srcWriter) { srcWriter.println("protected <P> void internalSet(%s bean, String fieldName, P value){", this.beanType.getSimpleSourceName()); srcWriter.indent(); for (String propertyName : this.propertyTypes.keySet()) { JType propertyType = this.propertyTypes.get(propertyName); JPrimitiveType primitiveType = propertyType.isPrimitive(); JMethod setter = this.setters.get(propertyName); if (setter != null) { if (primitiveType != null) { srcWriter.println( "if(\"%s\".equals(fieldName)){ bean.%s((%s) PrimitiveUtils.asPrimitive((%s)value)); }", propertyName, setter.getName(), propertyType.getSimpleSourceName(), primitiveType.getQualifiedBoxedSourceName()); } else { srcWriter.println("if(\"%s\".equals(fieldName)){ bean.%s((%s) value); }", propertyName, setter.getName(), propertyType.getSimpleSourceName()); } } else if (this.publicFields.containsKey(propertyName)) { if (primitiveType != null) { srcWriter .println("if(\"%s\".equals(fieldName)){ bean.%s = PrimitiveUtils.asPrimitive((%s) value); }", propertyName, propertyName, primitiveType.getQualifiedBoxedSourceName()); } else { srcWriter .println("if(\"%s\".equals(fieldName)){ bean.%s = (%s) value; }", propertyName, propertyName, propertyType.getSimpleSourceName()); } } } srcWriter.outdent(); srcWriter.println("}"); }
Example 4
Source File: ModelCreator.java From putnami-web-toolkit with GNU Lesser General Public License v3.0 | 5 votes |
private SourceWriter getSourceWriter(PrintWriter printWriter, GeneratorContext ctx) { String packageName = this.proxyModelQualifiedName.indexOf('.') == -1 ? "" : this.proxyModelQualifiedName.substring(0, this.proxyModelQualifiedName.lastIndexOf('.')); String className = this.proxyModelQualifiedName.indexOf('.') == -1 ? this.proxyModelQualifiedName : this.proxyModelQualifiedName .substring(this.proxyModelQualifiedName.lastIndexOf('.') + 1, this.proxyModelQualifiedName.length()); ClassSourceFileComposerFactory composerFactory = new ClassSourceFileComposerFactory(packageName, className); composerFactory.addImport(Map.class.getName()); composerFactory.addImport(Maps.class.getName()); composerFactory.addImport(GWT.class.getName()); composerFactory.addImport(Model.class.getName()); composerFactory.addImport(AbstractModel.class.getName()); composerFactory.addImport(ModelCollection.class.getName()); composerFactory.addImport(PropertyDescription.class.getName()); composerFactory.addImport(PrimitiveUtils.class.getName()); composerFactory.addImport(this.beanType.getQualifiedSourceName()); composerFactory.addImport("fr.putnami.pwt.core.editor.client.validator.*"); for (JType jType : this.imports) { if (jType.isPrimitive() != null) { continue; } composerFactory.addImport(jType.getQualifiedSourceName()); } for (String submodel : this.subModels.values()) { composerFactory.addImport(submodel); } composerFactory .setSuperclass(AbstractModel.class.getSimpleName() + "<" + this.beanType.getSimpleSourceName() + ">"); return composerFactory.createSourceWriter(ctx, printWriter); }
Example 5
Source File: ServiceBinderCreator.java From putnami-web-toolkit with GNU Lesser General Public License v3.0 | 5 votes |
private SourceWriter getSourceWriter(PrintWriter printWriter, GeneratorContext ctx) { String packageName = this.handlerType.getPackage().getName(); String className = this.proxyModelQualifiedName.indexOf('.') == -1 ? this.proxyModelQualifiedName : this.proxyModelQualifiedName.substring( this.proxyModelQualifiedName.lastIndexOf('.') + 1, this.proxyModelQualifiedName.length()); ClassSourceFileComposerFactory composerFactory = new ClassSourceFileComposerFactory(packageName, className); composerFactory.addImport(AsyncCallback.class.getName()); composerFactory.addImport(AbstractServiceBinder.class.getName()); composerFactory.addImport(Arrays.class.getName()); composerFactory.addImport(Lists.class.getName()); composerFactory.addImport(CommandDefinition.class.getName()); composerFactory.addImport(CommandParam.class.getName()); composerFactory.addImport(CallbackAdapter.class.getName()); composerFactory.addImport(CommandController.class.getName()); composerFactory.addImport(this.serviceType.getQualifiedSourceName()); composerFactory.addImport(this.serviceBinderType.getQualifiedSourceName()); for (JType jType : this.imports) { if (jType.isPrimitive() != null) { continue; } composerFactory.addImport(jType.getQualifiedSourceName()); } composerFactory.setSuperclass(AbstractServiceBinder.class.getSimpleName() + "<" + this.handlerType.getSimpleSourceName() + ", " + this.serviceType.getSimpleSourceName() + ">"); composerFactory.addImplementedInterface(this.serviceType.getSimpleSourceName()); composerFactory.addImplementedInterface(this.serviceBinderType.getSimpleSourceName()); return composerFactory.createSourceWriter(ctx, printWriter); }
Example 6
Source File: RestServiceBinderCreator.java From putnami-web-toolkit with GNU Lesser General Public License v3.0 | 5 votes |
private SourceWriter getSourceWriter(PrintWriter printWriter, GeneratorContext ctx) { String packageName = this.handlerType.getPackage().getName(); String className = this.proxyModelQualifiedName.indexOf('.') == -1 ? this.proxyModelQualifiedName : this.proxyModelQualifiedName.substring( this.proxyModelQualifiedName.lastIndexOf('.') + 1, this.proxyModelQualifiedName.length()); ClassSourceFileComposerFactory composerFactory = new ClassSourceFileComposerFactory(packageName, className); composerFactory.addImport(AbstractServiceBinder.class.getName()); composerFactory.addImport(Arrays.class.getName()); composerFactory.addImport(Lists.class.getName()); composerFactory.addImport(MethodCallbackAdapter.class.getName()); composerFactory.addImport(Method.class.getName()); composerFactory.addImport(CompositeMethodCallback.class.getName()); composerFactory.addImport(CallbackAdapter.class.getName()); composerFactory.addImport(REST.class.getName()); composerFactory.addImport(GWT.class.getName()); composerFactory.addImport(this.serviceType.getQualifiedSourceName()); composerFactory.addImport(this.serviceBinderType.getQualifiedSourceName()); for (JType jType : this.imports) { if (jType.isPrimitive() != null) { continue; } composerFactory.addImport(jType.getQualifiedSourceName()); } composerFactory.setSuperclass(AbstractServiceBinder.class.getSimpleName() + "<" + this.handlerType.getSimpleSourceName() + ", " + this.serviceType.getSimpleSourceName() + ">"); composerFactory.addImplementedInterface(this.serviceType.getSimpleSourceName()); composerFactory.addImplementedInterface(this.serviceBinderType.getSimpleSourceName()); return composerFactory.createSourceWriter(ctx, printWriter); }
Example 7
Source File: ExtendedServiceProxyGenerator.java From appinventor-extensions with Apache License 2.0 | 4 votes |
/** * Generate the implementation of a single method. * * @param out where to print the method to * @param method the method * @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(" }"); }
Example 8
Source File: ModelCreator.java From putnami-web-toolkit with GNU Lesser General Public License v3.0 | 4 votes |
private void generateStaticInitializer(TreeLogger logger, SourceWriter srcWriter) { srcWriter.println("protected static final Map<String, PropertyDescription> PROPERTIES = Maps.newHashMap();"); srcWriter.println("static{"); srcWriter.indent(); for (String propertyName : this.propertyTypes.keySet()) { JType propertyType = this.propertyTypes.get(propertyName); String simplePropertyTypeName = propertyType.getSimpleSourceName(); String modelName = this.subModels.get(propertyType); if (modelName != null) { modelName += ".INSTANCE"; } try { if (propertyType.isPrimitive() == null) { Class<?> propertyClass = Class.forName(propertyType.getQualifiedSourceName()); if (Collection.class.isAssignableFrom(propertyClass)) { JParameterizedType parametrizedType = propertyType.isParameterized(); JType subType = propertyType; if (parametrizedType != null) { subType = parametrizedType.getTypeArgs()[0]; String submodelName = this.subModels.get(subType); if (submodelName != null) { submodelName += ".INSTANCE"; } else { submodelName = subType.getSimpleSourceName() + ".class"; } modelName = String.format("new ModelCollection<%s>(%s.class, %s)", subType.getSimpleSourceName(), propertyType.getSimpleSourceName(), submodelName); } else { logger.branch(Type.WARN, String.format( "Property [%s] on bean %s is a raw collection type. You cannot use it on editors.", propertyName, this.beanType.getQualifiedSourceName())); modelName = "new ModelCollection((Model) null)"; } } } } catch (ClassNotFoundException e) { logger.branch(Type.WARN, String.format( "%s class not found.", propertyType.getQualifiedSourceName())); } Boolean getter = this.getters.containsKey(propertyName); Boolean setter = this.setters.containsKey(propertyName); srcWriter.print("PROPERTIES.put(\"%s\", newPropertyDescription(\"%s\", %s.class, %s, %s, %s", propertyName, propertyName, simplePropertyTypeName, modelName, getter, setter); this.generateValidators(srcWriter, propertyName); srcWriter.println("));"); } srcWriter.outdent(); srcWriter.println("}"); srcWriter.println("protected Map<String, PropertyDescription> getProperties(){"); srcWriter.println(" return PROPERTIES;"); srcWriter.println("}"); }
Example 9
Source File: CreatorUtils.java From gwt-jackson with Apache License 2.0 | 3 votes |
/** * Returns the default value of the given type. * <ul> * <li>{@link Object} : null</li> * <li>char : '\u0000'</li> * <li>boolean : false</li> * <li>other primitive : 0</li> * </ul> * * @param type type to find the default value * @return the default value of the type. */ public static String getDefaultValueForType( JType type ) { JPrimitiveType primitiveType = type.isPrimitive(); if ( null != primitiveType ) { return primitiveType.getUninitializedFieldExpression(); } return "null"; }