Example usage for com.google.gwt.core.ext.typeinfo JPrimitiveType INT

List of usage examples for com.google.gwt.core.ext.typeinfo JPrimitiveType INT

Introduction

In this page you can find the example usage for com.google.gwt.core.ext.typeinfo JPrimitiveType INT.

Prototype

JPrimitiveType INT

To view the source code for com.google.gwt.core.ext.typeinfo JPrimitiveType INT.

Click Source Link

Usage

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  w  w w.j  a  v  a  2s. c o m*/
    }

    // Otherwise return the fully-qualified type name
    return type.getQualifiedSourceName();
}

From source file:com.guit.rebind.jsorm.JsonSerializerUtil.java

License:Apache License

private static void printPrimitiveDeserialized(String typeName, SourceWriter writer, String fieldName,
        JPrimitiveType primitive) throws UnableToCompleteException {
    if (primitive.equals(JPrimitiveType.BOOLEAN)) {
        writer.println(fieldName + ".isBoolean().booleanValue()");
    } else if (primitive.equals(JPrimitiveType.DOUBLE)) {
        writer.println(fieldName + ".isNumber().doubleValue()");
    } else if (primitive.equals(JPrimitiveType.FLOAT)) {
        writer.println("(float)" + fieldName + ".isNumber().doubleValue()");
    } else if (primitive.equals(JPrimitiveType.LONG)) {
        writer.println("(long)" + fieldName + ".isNumber().doubleValue()");
    } else if (primitive.equals(JPrimitiveType.INT)) {
        writer.println("(int)" + fieldName + ".isNumber().doubleValue()");
    } else {/*from   ww  w.j a v  a2  s  .co  m*/
        error("The type %s is not a valid type for the place data. Found %s", primitive.getSimpleSourceName(),
                typeName);
    }
}

From source file:com.guit.rebind.jsorm.JsonSerializerUtil.java

License:Apache License

private static void printPrimitiveSerialized(String typeName, SourceWriter writer, String fieldName,
        JPrimitiveType primitive) throws UnableToCompleteException {
    if (primitive.equals(JPrimitiveType.BOOLEAN)) {
        writer.print(JSONBoolean.class.getCanonicalName() + ".getInstance(" + fieldName + ")");
    } else if (primitive.equals(JPrimitiveType.DOUBLE)) {
        writer.print("new " + JSONNumber.class.getCanonicalName() + "(" + fieldName + ")");
    } else if (primitive.equals(JPrimitiveType.FLOAT)) {
        writer.print("new " + JSONNumber.class.getCanonicalName() + "(" + fieldName + ")");
    } else if (primitive.equals(JPrimitiveType.LONG)) {
        writer.print("new " + JSONNumber.class.getCanonicalName() + "(" + fieldName + ")");
    } else if (primitive.equals(JPrimitiveType.INT)) {
        writer.print("new " + JSONNumber.class.getCanonicalName() + "(" + fieldName + ")");
    } else {//w  w w. j a va2  s  .  com
        error("The type %s is not a valid type for the place data. Found %s", primitive.getSimpleSourceName(),
                typeName);
    }
}

From source file:com.gwtmobile.persistence.rebind.GenUtils.java

License:Apache License

public String getSQLiteType(JType returnType) {
    String sqliteType = null;//from ww  w.ja  v  a 2  s .  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.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.smartgwt.rebind.BeanMethod.java

License:Open Source License

public BeanMethod(JMethod method, TypeOracle typeOracle) {
    this.method = method;

    if (couldBeCustomSetter()) {
        Matcher matcher = setterPattern.matcher(method.getName());
        if (matcher.matches()) {
            valueType = method.getParameters()[0].getType();
            setter = true;//from w  w  w.  ja  v  a 2  s . co m
            name = recapitalize(matcher.group(1));
            prefix = "set";
        }
    } else if (couldBeCustomGetter()) {
        Matcher matcher = getterPattern.matcher(method.getName());
        if (matcher.matches()) {
            valueType = method.getReturnType();
            getter = true;
            prefix = matcher.group(1);
            name = recapitalize(matcher.group(2));
        }
    }

    if (valueType != null) {
        JPrimitiveType primitiveType = valueType.isPrimitive();
        if (primitiveType == null) {
            genericType = valueType;
            classLiteral = valueType.getQualifiedSourceName() + ".class";
        } else {
            if (primitiveType == JPrimitiveType.BOOLEAN) {
                genericType = typeOracle.findType(Boolean.class.getCanonicalName());
                classLiteral = boolean.class.getCanonicalName() + ".class";
                deboxer = ".@" + genericType.getQualifiedSourceName() + "::booleanValue()()";
            } else if (primitiveType == JPrimitiveType.FLOAT) {
                genericType = typeOracle.findType(Float.class.getCanonicalName());
                classLiteral = float.class.getCanonicalName() + ".class";
                deboxer = ".@" + genericType.getQualifiedSourceName() + "::floatValue()()";
            } else if (primitiveType == JPrimitiveType.DOUBLE) {
                genericType = typeOracle.findType(Double.class.getCanonicalName());
                classLiteral = double.class.getCanonicalName() + ".class";
                deboxer = ".@" + genericType.getQualifiedSourceName() + "::doubleValue()()";
            } else if (primitiveType == JPrimitiveType.INT) {
                genericType = typeOracle.findType(Integer.class.getCanonicalName());
                classLiteral = int.class.getCanonicalName() + ".class";
                deboxer = ".@" + genericType.getQualifiedSourceName() + "::intValue()()";
            } else if (primitiveType == JPrimitiveType.LONG) {
                genericType = typeOracle.findType(Long.class.getCanonicalName());
                classLiteral = long.class.getCanonicalName() + ".class";
                deboxer = ".@" + genericType.getQualifiedSourceName() + "::longValue()()";
            }
        }
    }
}

From source file:com.smartgwt.rebind.BeanValueType.java

License:Open Source License

private void initializeBeanValueType() {
    requiresGeneration = false;/*  w  w w . j  a v a2  s. com*/

    final JPrimitiveType primitiveType = valueType.isPrimitive();
    if (primitiveType != null) {
        if (primitiveType == JPrimitiveType.BOOLEAN) {
            beanValueType = findType(PBooleanValueType.class);
            genericType = findType(Boolean.class);
        } else if (primitiveType == JPrimitiveType.FLOAT) {
            beanValueType = findType(PFloatValueType.class);
            genericType = findType(Float.class);
        } else if (primitiveType == JPrimitiveType.DOUBLE) {
            beanValueType = findType(PDoubleValueType.class);
            genericType = findType(Double.class);
        } else if (primitiveType == JPrimitiveType.INT) {
            beanValueType = findType(PIntegerValueType.class);
            genericType = findType(Integer.class);
        } else if (primitiveType == JPrimitiveType.LONG) {
            beanValueType = findType(PLongValueType.class);
            genericType = findType(Long.class);
        }
        return;
    }

    final JEnumType enumType = valueType.isEnum();
    if (enumType != null) {
        genericType = enumType;

        final JType valueEnumType = findType(ValueEnum.class);
        if (Arrays.asList(enumType.getImplementedInterfaces()).contains(valueEnumType)) {
            beanValueType = findType(ValueEnumValueType.class);
        } else {
            beanValueType = findType(EnumValueType.class);
        }
        return;
    }

    final JArrayType arrayType = valueType.isArray();
    if (arrayType != null) {
        genericType = arrayType;
        componentType = arrayType.getComponentType();
        assert componentType != null;

        componentValueType = new BeanValueType(componentType, oracle);
        assert componentValueType != null;

        if (componentType.isPrimitive() != null) {
            if (componentType == JPrimitiveType.BOOLEAN) {
                beanValueType = findType(PBooleanArrayValueType.class);
            } else if (componentType == JPrimitiveType.DOUBLE) {
                beanValueType = findType(PDoubleArrayValueType.class);
            } else if (componentType == JPrimitiveType.FLOAT) {
                beanValueType = findType(PFloatArrayValueType.class);
            } else if (componentType == JPrimitiveType.INT) {
                beanValueType = findType(PIntegerArrayValueType.class);
            } else if (componentType == JPrimitiveType.LONG) {
                beanValueType = findType(PLongArrayValueType.class);
            }
        } else if (componentType.isInterface() != null) {
            beanValueType = findType(InterfaceArrayValueType.class);

            // We have to generate for isAssignableFrom to work
            requiresGeneration = true;

            // The generic type for the subclass is the component type,
            // rather than the array type
            genericType = componentType.isInterface();
        } else if (componentType instanceof JClassType) {
            beanValueType = findType(ObjectArrayValueType.class);
            constructorTakesEmptyArray = true;
            genericType = (JClassType) componentType;
        } else {
            throw new IllegalStateException("componentType " + componentType.getQualifiedSourceName()
                    + " is not a primitive, an interface, or a class");
        }

        return;
    }

    final JClassType classType = valueType.isClass();
    if (classType != null) {
        genericType = classType;

        if (classType == findType(Integer.class)) {
            beanValueType = findType(IntegerValueType.class);
        } else if (classType == findType(Boolean.class)) {
            beanValueType = findType(BooleanValueType.class);
        } else if (classType == findType(Float.class)) {
            beanValueType = findType(FloatValueType.class);
        } else if (classType == findType(Double.class)) {
            beanValueType = findType(DoubleValueType.class);
        } else if (classType == findType(Long.class)) {
            beanValueType = findType(LongValueType.class);
        } else if (classType == findType(Number.class)) {
            beanValueType = findType(NumberValueType.class);
        } else if (classType == findType(String.class)) {
            beanValueType = findType(StringValueType.class);
        } else if (classType == findType(Date.class)) {
            beanValueType = findType(DateValueType.class);
        } else if (classType.isAssignableTo(findType(JavaScriptObject.class))) {
            beanValueType = findType(JsoValueType.class);
        } else if (classType.isAssignableTo(findType(DataSource.class))) {
            beanValueType = findType(DataSourceBaseValueType.class);
            // Need to generate, in order to get newInstance(JavaScriptObject object)
            requiresGeneration = true;
            hasSetJavaScriptObject = true;
        } else if (classType.isAssignableTo(findType(Canvas.class))) {
            beanValueType = findType(CanvasBaseValueType.class);
            // Need to generate, in order to get newInstance(JavaScriptObject object)
            requiresGeneration = true;
            hasSetJavaScriptObject = true;
        } else if (jsObjConstructor != null) {
            beanValueType = findType(JsoWrapperValueType.class);
            // Need to generate, in order to get newInstance(JavaScriptObject object)
            requiresGeneration = true;
        } else {
            beanValueType = findType(OtherValueType.class);
        }
        return;
    }

    final JClassType interfaceType = valueType.isInterface();
    if (interfaceType != null) {
        genericType = interfaceType;
        beanValueType = findType(InterfaceValueType.class);

        // Need to generate, because otherwise we can't use instanceof
        requiresGeneration = true;

        return;
    }

    System.out.println("No specific BeanValueType subclass for " + getQualifiedTypeName());
}

From source file:com.totsp.gwittir.rebind.beans.IntrospectorGenerator.java

License:Open Source License

private boolean box(JType type, SourceWriter writer) {
    if ((type.isPrimitive() != null) && (type.isPrimitive() == JPrimitiveType.INT)) {
        writer.print("new Integer( ");

        return true;
    }/* w  w  w  . j  a  v a2s  . co  m*/

    if ((type.isPrimitive() != null) && (type.isPrimitive() == JPrimitiveType.LONG)) {
        writer.print("new Long( ");

        return true;
    }

    if ((type.isPrimitive() != null) && (type.isPrimitive() == JPrimitiveType.FLOAT)) {
        writer.print("new Float( ");

        return true;
    }

    if ((type.isPrimitive() != null) && (type.isPrimitive() == JPrimitiveType.DOUBLE)) {
        writer.print("new Double( ");

        return true;
    }

    if ((type.isPrimitive() != null) && (type.isPrimitive() == JPrimitiveType.CHAR)) {
        writer.print("new Character( ");

        return true;
    }

    if ((type.isPrimitive() != null) && (type.isPrimitive() == JPrimitiveType.BYTE)) {
        writer.print("new Byte( ");

        return true;
    }

    if ((type.isPrimitive() != null) && (type.isPrimitive() == JPrimitiveType.BOOLEAN)) {
        writer.print("new Boolean( ");

        return true;
    }

    return false;
}

From source file:com.totsp.gwittir.rebind.beans.IntrospectorGenerator.java

License:Open Source License

private boolean unbox(JType type, String reference, SourceWriter writer) {
    if ((type.isPrimitive() != null) && (type.isPrimitive() == JPrimitiveType.INT)) {
        writer.print("((Integer) " + reference + ").intValue()");

        return true;
    }//from www .ja v  a  2 s  . c  om

    if ((type.isPrimitive() != null) && (type.isPrimitive() == JPrimitiveType.LONG)) {
        writer.print("((Long) " + reference + ").longValue()");

        return true;
    }

    if ((type.isPrimitive() != null) && (type.isPrimitive() == JPrimitiveType.FLOAT)) {
        writer.print("((Float) " + reference + ").floatValue()");

        return true;
    }

    if ((type.isPrimitive() != null) && (type.isPrimitive() == JPrimitiveType.DOUBLE)) {
        writer.print("((Double) " + reference + ").doubleValue()");

        return true;
    }

    if ((type.isPrimitive() != null) && (type.isPrimitive() == JPrimitiveType.CHAR)) {
        writer.print("((Character) " + reference + ").charValue()");

        return true;
    }

    if ((type.isPrimitive() != null) && (type.isPrimitive() == JPrimitiveType.BYTE)) {
        writer.print("((Byte) " + reference + ").byteValue()");

        return true;
    }

    if ((type.isPrimitive() != null) && (type.isPrimitive() == JPrimitiveType.BOOLEAN)) {
        writer.print("((Boolean) " + reference + ").booleanValue()");

        return true;
    }

    writer.print("(" + type.getQualifiedSourceName() + ") " + reference);

    return false;
}

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() ";
    }//from   www .  j  a  v a 2  s . c  o 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);
}