com.google.gwt.core.ext.typeinfo.JPrimitiveType Java Examples

The following examples show how to use com.google.gwt.core.ext.typeinfo.JPrimitiveType. 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: ServiceBinderCreator.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 6 votes vote down vote up
private String typeAsString(JType type, boolean translatePrimitives) {
	StringBuilder sb = new StringBuilder();
	if (translatePrimitives && type instanceof JPrimitiveType) {
		sb.append(((JPrimitiveType) type).getQualifiedBoxedSourceName());
	} else {
		sb.append(type.getSimpleSourceName());
		if (type instanceof JParameterizedType) {
			JParameterizedType parameterizedType = (JParameterizedType) type;
			sb.append("<");
			int i = 0;
			for (JType paramType : parameterizedType.getTypeArgs()) {
				if (i++ > 0) {
					sb.append(", ");
				}
				sb.append(this.typeAsString(paramType, false));
			}
			sb.append(">");
		}
	}
	return sb.toString();
}
 
Example #2
Source File: RestServiceBinderCreator.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 6 votes vote down vote up
private String typeAsString(JType type, boolean translatePrimitives) {
	StringBuilder sb = new StringBuilder();
	if (translatePrimitives && type instanceof JPrimitiveType) {
		sb.append(((JPrimitiveType) type).getQualifiedBoxedSourceName());
	} else {
		sb.append(type.getSimpleSourceName());
		if (type instanceof JParameterizedType) {
			JParameterizedType parameterizedType = (JParameterizedType) type;
			sb.append("<");
			int i = 0;
			for (JType paramType : parameterizedType.getTypeArgs()) {
				if (i++ > 0) {
					sb.append(", ");
				}
				sb.append(this.typeAsString(paramType, false));
			}
			sb.append(">");
		}
	}
	return sb.toString();
}
 
Example #3
Source File: JTypeName.java    From gwt-jackson with Apache License 2.0 6 votes vote down vote up
private TypeName primitiveName( JPrimitiveType type, boolean boxed ) {
    if ( "boolean".equals( type.getSimpleSourceName() ) ) {
        return boxed ? BOOLEAN_NAME : TypeName.BOOLEAN;
    } else if ( "byte".equals( type.getSimpleSourceName() ) ) {
        return boxed ? BYTE_NAME : TypeName.BYTE;
    } else if ( "short".equals( type.getSimpleSourceName() ) ) {
        return boxed ? SHORT_NAME : TypeName.SHORT;
    } else if ( "int".equals( type.getSimpleSourceName() ) ) {
        return boxed ? INTEGER_NAME : TypeName.INT;
    } else if ( "long".equals( type.getSimpleSourceName() ) ) {
        return boxed ? LONG_NAME : TypeName.LONG;
    } else if ( "char".equals( type.getSimpleSourceName() ) ) {
        return boxed ? CHARACTER_NAME : TypeName.CHAR;
    } else if ( "float".equals( type.getSimpleSourceName() ) ) {
        return boxed ? FLOAT_NAME : TypeName.FLOAT;
    } else if ( "double".equals( type.getSimpleSourceName() ) ) {
        return boxed ? DOUBLE_NAME : TypeName.DOUBLE;
    } else {
        return boxed ? VOID_NAME : TypeName.VOID;
    }
}
 
Example #4
Source File: RebindConfiguration.java    From gwt-jackson with Apache License 2.0 6 votes vote down vote up
/**
 * @param clazz class to find the type
 *
 * @return the {@link JType} denoted by the class given in parameter
 */

private JType findType( Class<?> clazz ) {
    if ( clazz.isPrimitive() ) {

        return JPrimitiveType.parse( clazz.getCanonicalName() );

    } else if ( clazz.isArray() ) {

        try {
            return context.getTypeOracle().parse( clazz.getCanonicalName() );
        } catch ( TypeOracleException e ) {
            logger.log( TreeLogger.WARN, "Cannot find the array denoted by the class " + clazz.getCanonicalName() );
            return null;
        }

    } else {
        return findClassType( clazz );
    }
}
 
Example #5
Source File: ModelCreator.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 5 votes vote down vote up
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 #6
Source File: ModelCreator.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void listSetters(JMethod[] methods) {
	for (JMethod method : methods) {
		if (method.getName().startsWith("set") && method.getParameters().length == 1
			&& method.getReturnType().equals(JPrimitiveType.VOID) && method.isPublic()) {
			this.setters.put(this.extractPropertyNameFromMethod(method), method);
			this.propertyTypes.put(this.extractPropertyNameFromMethod(method), method.getParameters()[0].getType());
			this.addImport(method.getParameters()[0].getType());
		}
	}
}
 
Example #7
Source File: ModelCreator.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void listGetters(JMethod[] methods) {
	for (JMethod method : methods) {
		if (method.getName().startsWith("get") && method.getName().length() > 3
			|| method.getName().startsWith("is") && method.getName().length() > 2
			&& method.getParameters().length == 0
			&& !method.getReturnType().equals(JPrimitiveType.VOID)
			&& method.isPublic()) {

			this.getters.put(this.extractPropertyNameFromMethod(method), method);
			this.propertyTypes.put(this.extractPropertyNameFromMethod(method), method.getReturnType());
			this.addImport(method.getReturnType());
		}
	}
}
 
Example #8
Source File: ServiceBinderCreator.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void writeEndMethod(SourceWriter srcWriter, JMethod method) {
	srcWriter.println("CommandController.get().invokeCommand(commandDefinition, commandParam);");
	if (method.getReturnType().equals(JPrimitiveType.BOOLEAN)) {
		srcWriter.println("return false;");
	} else if (method.getReturnType().equals(JPrimitiveType.BYTE) || method.getReturnType().equals(JPrimitiveType.CHAR)
		|| method.getReturnType().equals(JPrimitiveType.DOUBLE) || method.getReturnType().equals(JPrimitiveType.FLOAT)
		|| method.getReturnType().equals(JPrimitiveType.INT) || method.getReturnType().equals(JPrimitiveType.LONG)
		|| method.getReturnType().equals(JPrimitiveType.SHORT)) {
		srcWriter.println("return 0;");
	} else if (!method.getReturnType().equals(JPrimitiveType.VOID)) {
		srcWriter.println("return null;");
	}
	srcWriter.outdent();
	srcWriter.println("}");
}
 
Example #9
Source File: RestServiceBinderCreator.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void writeEndMethod(SourceWriter srcWriter, JMethod method) {
	if (method.getReturnType().equals(JPrimitiveType.BOOLEAN)) {
		srcWriter.println("return false;");
	} else if (method.getReturnType().equals(JPrimitiveType.BYTE) || method.getReturnType().equals(JPrimitiveType.CHAR)
		|| method.getReturnType().equals(JPrimitiveType.DOUBLE) || method.getReturnType().equals(JPrimitiveType.FLOAT)
		|| method.getReturnType().equals(JPrimitiveType.INT) || method.getReturnType().equals(JPrimitiveType.LONG)
		|| method.getReturnType().equals(JPrimitiveType.SHORT)) {
		srcWriter.println("return 0;");
	} else if (!method.getReturnType().equals(JPrimitiveType.VOID)) {
		srcWriter.println("return null;");
	}
	srcWriter.outdent();
	srcWriter.println("}");
}
 
Example #10
Source File: PropertyProcessor.java    From gwt-jackson with Apache License 2.0 5 votes vote down vote up
private static boolean isGetterAutoDetected( RebindConfiguration configuration, PropertyAccessors propertyAccessors, BeanInfo info ) {
    if ( !propertyAccessors.getGetter().isPresent() ) {
        return false;
    }

    for ( Class<? extends Annotation> annotation : AUTO_DISCOVERY_ANNOTATIONS ) {
        if ( propertyAccessors.isAnnotationPresentOnGetter( annotation ) ) {
            return true;
        }
    }

    JMethod getter = propertyAccessors.getGetter().get();

    String methodName = getter.getName();
    JsonAutoDetect.Visibility visibility;
    if ( methodName.startsWith( "is" ) && methodName.length() > 2 && JPrimitiveType.BOOLEAN.equals( getter.getReturnType()
            .isPrimitive() ) ) {

        // getter method for a boolean
        visibility = info.getIsGetterVisibility();
        if ( Visibility.DEFAULT == visibility ) {
            visibility = configuration.getDefaultIsGetterVisibility();
        }

    } else if ( methodName.startsWith( "get" ) && methodName.length() > 3 ) {

        visibility = info.getGetterVisibility();
        if ( Visibility.DEFAULT == visibility ) {
            visibility = configuration.getDefaultGetterVisibility();
        }

    } else {
        // no annotation on method and the method does not follow naming convention
        return false;
    }
    return isAutoDetected( visibility, getter.isPrivate(), getter.isProtected(), getter.isPublic(), getter.isDefaultAccess() );
}
 
Example #11
Source File: ExtendedServiceProxyGenerator.java    From appinventor-extensions with Apache License 2.0 4 votes vote down vote up
/**
 * 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 #12
Source File: StubClassType.java    From mvp4g with Apache License 2.0 4 votes vote down vote up
@Override
public JPrimitiveType isPrimitive() {

  return null;
}
 
Example #13
Source File: CreatorUtils.java    From gwt-jackson with Apache License 2.0 3 votes vote down vote up
/**
 * 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";
}