List of usage examples for com.google.gwt.core.ext.typeinfo JPrimitiveType SHORT
JPrimitiveType SHORT
To view the source code for com.google.gwt.core.ext.typeinfo JPrimitiveType SHORT.
Click Source Link
From source file:com.ekuefler.supereventbus.rebind.EventRegistrationWriter.java
License:Apache License
private String getFirstParameterType(JMethod method) { // If the parameter type is primitive, box it JType type = method.getParameterTypes()[0]; if (type.isPrimitive() != null) { if (type.isPrimitive() == JPrimitiveType.BOOLEAN) { return Boolean.class.getName(); } else if (type.isPrimitive() == JPrimitiveType.BYTE) { return Byte.class.getName(); } else if (type.isPrimitive() == JPrimitiveType.CHAR) { return Character.class.getName(); } else if (type.isPrimitive() == JPrimitiveType.DOUBLE) { return Double.class.getName(); } else if (type.isPrimitive() == JPrimitiveType.FLOAT) { return Float.class.getName(); } else if (type.isPrimitive() == JPrimitiveType.INT) { return Integer.class.getName(); } else if (type.isPrimitive() == JPrimitiveType.LONG) { return Long.class.getName(); } else if (type.isPrimitive() == JPrimitiveType.SHORT) { return Short.class.getName(); }/*from ww w . ja va 2 s . c o m*/ } // Otherwise return the fully-qualified type name return type.getQualifiedSourceName(); }
From source file:com.hiramchirino.restygwt.rebind.JsonEncoderDecoderInstanceLocator.java
License:Apache License
public JsonEncoderDecoderInstanceLocator(GeneratorContext context, TreeLogger logger) throws UnableToCompleteException { this.context = context; this.logger = logger; this.STRING_TYPE = find(String.class); this.JSON_VALUE_TYPE = find(JSONValue.class); this.DOCUMENT_TYPE = find(Document.class); this.MAP_TYPE = find(Map.class); this.SET_TYPE = find(Set.class); this.LIST_TYPE = find(List.class); builtInEncoderDecoders.put(JPrimitiveType.BOOLEAN, JSON_ENCODER_DECODER_CLASS + ".BOOLEAN"); builtInEncoderDecoders.put(JPrimitiveType.BYTE, JSON_ENCODER_DECODER_CLASS + ".BYTE"); builtInEncoderDecoders.put(JPrimitiveType.CHAR, JSON_ENCODER_DECODER_CLASS + ".CHAR"); builtInEncoderDecoders.put(JPrimitiveType.SHORT, JSON_ENCODER_DECODER_CLASS + ".SHORT"); builtInEncoderDecoders.put(JPrimitiveType.INT, JSON_ENCODER_DECODER_CLASS + ".INT"); builtInEncoderDecoders.put(JPrimitiveType.LONG, JSON_ENCODER_DECODER_CLASS + ".LONG"); builtInEncoderDecoders.put(JPrimitiveType.FLOAT, JSON_ENCODER_DECODER_CLASS + ".FLOAT"); builtInEncoderDecoders.put(JPrimitiveType.DOUBLE, JSON_ENCODER_DECODER_CLASS + ".DOUBLE"); builtInEncoderDecoders.put(find(Boolean.class), JSON_ENCODER_DECODER_CLASS + ".BOOLEAN"); builtInEncoderDecoders.put(find(Byte.class), JSON_ENCODER_DECODER_CLASS + ".BYTE"); builtInEncoderDecoders.put(find(Character.class), JSON_ENCODER_DECODER_CLASS + ".CHAR"); builtInEncoderDecoders.put(find(Short.class), JSON_ENCODER_DECODER_CLASS + ".SHORT"); builtInEncoderDecoders.put(find(Integer.class), JSON_ENCODER_DECODER_CLASS + ".INT"); builtInEncoderDecoders.put(find(Long.class), JSON_ENCODER_DECODER_CLASS + ".LONG"); builtInEncoderDecoders.put(find(Float.class), JSON_ENCODER_DECODER_CLASS + ".FLOAT"); builtInEncoderDecoders.put(find(Double.class), JSON_ENCODER_DECODER_CLASS + ".DOUBLE"); builtInEncoderDecoders.put(STRING_TYPE, JSON_ENCODER_DECODER_CLASS + ".STRING"); builtInEncoderDecoders.put(DOCUMENT_TYPE, JSON_ENCODER_DECODER_CLASS + ".DOCUMENT"); builtInEncoderDecoders.put(JSON_VALUE_TYPE, JSON_ENCODER_DECODER_CLASS + ".JSON_VALUE"); builtInEncoderDecoders.put(find(Date.class), JSON_ENCODER_DECODER_CLASS + ".DATE"); }
From source file:com.totsp.gwittir.serial.json.rebind.JSONCodecGenerator.java
License:Open Source License
public String fromType(JType type, String innerExpression) { if (type.getQualifiedSourceName().equals(String.class.getCanonicalName())) { return innerExpression + ".isString().stringValue()"; } else if (type.getQualifiedSourceName().equals(Double.class.getCanonicalName()) || ((type.isPrimitive() != null) && JPrimitiveType.DOUBLE.equals(type.isPrimitive()))) { return innerExpression + ".isNumber().doubleValue()"; } else if (type.getQualifiedSourceName().equals(Float.class.getCanonicalName()) || ((type.isPrimitive() != null) && JPrimitiveType.FLOAT.equals(type.isPrimitive()))) { return " (float) " + innerExpression + ".isNumber().doubleValue()"; } else if (type.getQualifiedSourceName().equals(Integer.class.getCanonicalName()) || ((type.isPrimitive() != null) && JPrimitiveType.INT.equals(type.isPrimitive()))) { return "Double.valueOf(" + innerExpression + ".isNumber().doubleValue()) .intValue()"; } else if (type.getQualifiedSourceName().equals(Short.class.getCanonicalName()) || ((type.isPrimitive() != null) && JPrimitiveType.SHORT.equals(type.isPrimitive()))) { return "Short.valueOf(" + innerExpression + ".isNumber().doubleValue()) .shortValue()"; } else if (type.getQualifiedSourceName().equals(Character.class.getCanonicalName()) || ((type.isPrimitive() != null) && JPrimitiveType.CHAR.equals(type.isPrimitive()))) { return "" + innerExpression + ".isString().stringValue().charAt(0)"; } else if (type.getQualifiedSourceName().equals(Long.class.getCanonicalName()) || ((type.isPrimitive() != null) && JPrimitiveType.LONG.equals(type.isPrimitive()))) { return "Double.valueOf( " + innerExpression + ".isNumber().doubleValue()).longValue()"; } else if (type.getQualifiedSourceName().equals(Boolean.class.getCanonicalName()) || ((type.isPrimitive() != null) && JPrimitiveType.BOOLEAN.equals(type.isPrimitive()))) { return innerExpression + ".isBoolean().booleanValue() "; }/* w ww. ja va2s . co m*/ BeanResolver child = findType(type); if (child != null) { this.children.add(child); return "CODEC_" + child.getType().getQualifiedSourceName().replaceAll("\\.", "_") + ".deserializeFromJSONObject(" + innerExpression + ".isObject())"; } throw new RuntimeException("" + type); }
From source file:com.totsp.gwittir.serial.json.rebind.JSONCodecGenerator.java
License:Open Source License
private String toType(JType type, String innerExpression) { //System.out.println("toType " + type); if ((type.isPrimitive() == JPrimitiveType.DOUBLE) || (type.isPrimitive() == JPrimitiveType.FLOAT) || (type.isPrimitive() == JPrimitiveType.LONG) || (type.isPrimitive() == JPrimitiveType.INT) || (type.isPrimitive() == JPrimitiveType.SHORT)) { return " new JSONNumber( (double) " + innerExpression + ")"; } else if (type.isPrimitive() == JPrimitiveType.BOOLEAN) { return " JSONBoolean.getInstance( " + innerExpression + " ) "; } else if (type.isPrimitive() == JPrimitiveType.CHAR) { return " new JSONString( Character.toString(" + innerExpression + ") )"; }//w w w. j ava 2 s.c o m StringBuilder sb = new StringBuilder(innerExpression + " == null ? JSONNull.getInstance() : "); if (type.getQualifiedSourceName().equals("java.lang.String")) { sb = sb.append(" new JSONString( " + innerExpression + " ) "); } else if (type.getQualifiedSourceName().equals("java.lang.Character")) { sb = sb.append(" new JSONString( Character.toString(" + innerExpression + ") ) "); } else if (type.isClassOrInterface() != null && type.isClassOrInterface().isAssignableTo(this.numberType)) { sb = sb.append("new JSONNumber( ((Number) " + innerExpression + ").doubleValue())"); } else if (type.getQualifiedSourceName().equals("java.lang.Boolean")) { sb.append(" JSONBoolean.getInstance( " + innerExpression + " ) "); } else { BeanResolver child = findType(type); if (child == null) { throw new RuntimeException(type + " is not introspectable!"); } this.children.add(child); sb = sb.append("CODEC_" + type.getQualifiedSourceName().replaceAll("\\.", "_") + ".serializeToJSONObject( " + innerExpression + " ) "); } return sb.toString(); }
From source file:com.totsp.gwt.freezedry.rebind.Shared.java
License:Apache License
/** * Gets the suffix needed to make a call for a particular type. For example, * the <code>int</code> class needs methods named "readInt" and "writeInt". * /* w w w. j av a2 s .c o m*/ * @param type the type in question * @return the suffix of the method to call */ static String getCallSuffix(JType type) { JParameterizedType isParameterized = type.isParameterized(); if (isParameterized != null) { return getCallSuffix(isParameterized.getRawType()); } else if (type.isPrimitive() != null) { if (type == JPrimitiveType.BOOLEAN) { return "Boolean"; } else if (type == JPrimitiveType.BYTE) { return "Byte"; } else if (type == JPrimitiveType.CHAR) { return "Char"; } else if (type == JPrimitiveType.DOUBLE) { return "Double"; } else if (type == JPrimitiveType.FLOAT) { return "Float"; } else if (type == JPrimitiveType.INT) { return "Int"; } else if (type == JPrimitiveType.LONG) { return "Long"; } else if (type == JPrimitiveType.SHORT) { return "Short"; } else { return null; } } else if (type.getQualifiedSourceName().equals("java.lang.String")) { return "String"; } else { return "Object"; } }
From source file:fr.onevu.gwt.uibinder.rebind.JClassTypeAdapter.java
License:Apache License
/** * Returns the GWT primitive type for the given java primitive type. * * @param type the java primitive type//from w ww. ja v a 2s .co m * @return the GWT primitive equivalent */ private JType adaptPrimitiveType(Class<?> type) { if (boolean.class.equals(type)) { return JPrimitiveType.BOOLEAN; } if (int.class.equals(type)) { return JPrimitiveType.INT; } if (char.class.equals(type)) { return JPrimitiveType.CHAR; } if (byte.class.equals(type)) { return JPrimitiveType.BYTE; } if (long.class.equals(type)) { return JPrimitiveType.LONG; } if (short.class.equals(type)) { return JPrimitiveType.SHORT; } if (float.class.equals(type)) { return JPrimitiveType.FLOAT; } if (double.class.equals(type)) { return JPrimitiveType.DOUBLE; } if (void.class.equals(type)) { return JPrimitiveType.VOID; } throw new IllegalArgumentException("Invalid primitive type: " + type.getName()); }
From source file:fr.onevu.gwt.uibinder.rebind.TypeOracleUtils.java
License:Apache License
/** * Check for a widening primitive conversion. See * <a href="http://java.sun.com/docs/books/jls/second_edition/html/conversions.doc.html#25214">JLS 5.1.2</a>. * /*from w w w . j av a 2s . c o m*/ * @param paramType * @param argType * @return true if assigning argType to paramType is a widening conversion */ private static boolean isWideningPrimitiveConversion(JPrimitiveType paramType, JPrimitiveType argType) { switch (paramType) { case DOUBLE: return argType != JPrimitiveType.BOOLEAN; case FLOAT: return argType != JPrimitiveType.BOOLEAN && argType != JPrimitiveType.DOUBLE; case LONG: return argType != JPrimitiveType.BOOLEAN && argType != JPrimitiveType.DOUBLE && argType != JPrimitiveType.FLOAT; case INT: return argType == JPrimitiveType.BYTE || argType == JPrimitiveType.SHORT || argType == JPrimitiveType.CHAR; case SHORT: return argType == JPrimitiveType.BYTE; default: return false; } }
From source file:fr.putnami.pwt.core.service.rebind.ServiceBinderCreator.java
License:Open Source License
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;"); }//from w ww . j a v a 2 s .c o m srcWriter.outdent(); srcWriter.println("}"); }
From source file:fr.putnami.pwt.plugin.rest.rebind.RestServiceBinderCreator.java
License:Open Source License
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;"); }/*from ww w. java 2 s. c o m*/ srcWriter.outdent(); srcWriter.println("}"); }
From source file:org.cruxframework.crux.core.rebind.rest.CruxRestProxyCreatorFromServerMetadata.java
License:Apache License
private static List<Class<?>> getAllowedType(JType jType) { List<Class<?>> result = new ArrayList<Class<?>>(); JPrimitiveType primitiveType = jType.isPrimitive(); if (primitiveType == JPrimitiveType.INT || jType.getQualifiedSourceName().equals(Integer.class.getCanonicalName())) { result.add(Integer.TYPE); result.add(Integer.class); } else if (primitiveType == JPrimitiveType.SHORT || jType.getQualifiedSourceName().equals(Short.class.getCanonicalName())) { result.add(Short.TYPE);/*from w w w .j a v a 2 s . co m*/ result.add(Short.class); } else if (primitiveType == JPrimitiveType.LONG || jType.getQualifiedSourceName().equals(Long.class.getCanonicalName())) { result.add(Long.TYPE); result.add(Long.class); } else if (primitiveType == JPrimitiveType.BYTE || jType.getQualifiedSourceName().equals(Byte.class.getCanonicalName())) { result.add(Byte.TYPE); result.add(Byte.class); } else if (primitiveType == JPrimitiveType.FLOAT || jType.getQualifiedSourceName().equals(Float.class.getCanonicalName())) { result.add(Float.TYPE); result.add(Float.class); } else if (primitiveType == JPrimitiveType.DOUBLE || jType.getQualifiedSourceName().equals(Double.class.getCanonicalName())) { result.add(Double.TYPE); result.add(Double.class); } else if (primitiveType == JPrimitiveType.BOOLEAN || jType.getQualifiedSourceName().equals(Boolean.class.getCanonicalName())) { result.add(Boolean.TYPE); result.add(Boolean.class); } else if (primitiveType == JPrimitiveType.CHAR || jType.getQualifiedSourceName().equals(Character.class.getCanonicalName())) { result.add(Character.TYPE); result.add(Character.class); } else if (jType.getQualifiedSourceName().equals(String.class.getCanonicalName())) { result.add(String.class); } else if (jType.getQualifiedSourceName().equals(Date.class.getCanonicalName())) { result.add(Date.class); } else if (jType.getQualifiedSourceName().equals(java.sql.Date.class.getCanonicalName())) { result.add(java.sql.Date.class); } else if (jType.getQualifiedSourceName().equals(BigInteger.class.getCanonicalName())) { result.add(BigInteger.class); } else if (jType.getQualifiedSourceName().equals(BigDecimal.class.getCanonicalName())) { result.add(BigDecimal.class); } return result; }