Java Code Examples for com.squareup.javapoet.TypeName.isBoxedPrimitive()

The following are Jave code examples for showing how to use isBoxedPrimitive() of the com.squareup.javapoet.TypeName class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: vulture   File: TypeUtils.java   View Source Code Vote up 5 votes
public static boolean isPrimitiveArray(Element element) {
    if (element.asType().getKind() != TypeKind.ARRAY) {
        return false;
    }

    ArrayType arrayType = (ArrayType) element.asType();
    TypeMirror componentType = arrayType.getComponentType();

    TypeName typeName = TypeName.get(componentType);
    return typeName.isPrimitive() || typeName.isBoxedPrimitive();
}
 
Example 2
Project: slimorm   File: SlimOrmProcessor.java   View Source Code Vote up 5 votes
private void checkIfTypeIsSupported(VariableElement variableElement) {
    final TypeName typeOfCurrentElement = ClassName.get(variableElement.asType());
    if (!typeOfCurrentElement.equals(ClassName.get(String.class)) &&
            !typeOfCurrentElement.equals(BYTE_ARRAY_TYPE) &&
            !typeOfCurrentElement.isPrimitive() &&
            !typeOfCurrentElement.isBoxedPrimitive()) {

        throwError("SlimOrm: Type " + typeOfCurrentElement + " is not supported");
    } else if ((typeOfCurrentElement.isPrimitive() || typeOfCurrentElement.isBoxedPrimitive())
            && (typeOfCurrentElement.unbox().equals(TypeName.BYTE) || typeOfCurrentElement.unbox().equals(TypeName.CHAR))) {

        throwError("SlimOrm: Type " + typeOfCurrentElement + " is not supported");
    }
}
 
Example 3
Project: auto-value-json   File: JsonGeneratorUtils.java   View Source Code Vote up 4 votes
public static boolean isSupportedType(TypeName type) {
  return type.isPrimitive() || type.isBoxedPrimitive() || SUPPORTED_TYPES.contains(type);
}
 
Example 4
Project: vulture   File: TypeUtils.java   View Source Code Vote up 4 votes
public static boolean isPrimitive(TypeName typeName) {
    return typeName.isPrimitive() || typeName.isBoxedPrimitive();
}
 
Example 5
Project: android-auto-mapper   File: Parcelables.java   View Source Code Vote up 4 votes
public static boolean isValidType(TypeName typeName) {
    return typeName.isPrimitive() || typeName.isBoxedPrimitive() || VALID_TYPES.contains(typeName);
}
 
Example 6
Project: android-auto-mapper   File: TypeUtil.java   View Source Code Vote up 4 votes
public static boolean isPrimitiveOrWrapper(TypeMirror type) {
    TypeName typeName = TypeName.get(type);

    return typeName.isPrimitive() || typeName.isBoxedPrimitive();
}
 
Example 7
Project: glimpse   File: StyleableAttributeClassCreator.java   View Source Code Vote up 4 votes
private static void createDefaultBinding(final String containingClassFieldName, final String contextFieldName, final StyleableField field, final MethodSpec.Builder builder) {
    final ResourcesWriter resWriter = ResourcesWriter.writer(containingClassFieldName, RESOURCES_FIELD_NAME);
    final PixelConverterWriter pixelWriter = PixelConverterWriter.writer(containingClassFieldName, contextFieldName);
    final TypeName typeName = field.getTypeName();
    int exceptionCount = 0;

    if (typeName.isBoxedPrimitive() || typeName.isPrimitive()) {
        final TypeName unboxedTypeName = typeName.unbox();

        if (unboxedTypeName.equals(TypeName.BOOLEAN)) {
            builder.addCode(resWriter.getBoolean(field.getName(), field.getDefaultValue()));
        } else if (unboxedTypeName.equals(TypeName.INT)) {
            // getColor(), getDimensionPixelOffset(), getDimensionPixelSize(), getInteger()
            if (field.isColorInt()) {
                builder.addCode(resWriter.getColor(field.getName(), field.getDefaultValue()));
            } else if (field.isDimension()) {
                StyleableField.DimensionUnit unit = field.getDimensionUnit();

                if (unit == null || unit == StyleableField.DimensionUnit.PX) {
                    builder.addCode(resWriter.getDimensionPixelOffset(field.getName(), field.getDefaultValue()));
                } else if (unit == StyleableField.DimensionUnit.DP) {
                    builder.addCode(resWriter.getDimensionPixelOffset(field.getName(), field.getDefaultValue()));
                    builder.addCode("\n");
                    builder.addCode(pixelWriter.convertPixelToDp(field.getName()));
                } else if (unit == StyleableField.DimensionUnit.SP) {
                    builder.addCode(resWriter.getDimensionPixelSize(field.getName(), field.getDefaultValue()));
                    builder.addCode("\n");
                    builder.addCode(pixelWriter.convertPixelToDp(field.getName()));
                }
            } else {
                builder.beginControlFlow("try");
                builder.addCode(resWriter.getColor(field.getName(), field.getDefaultValue()));
                builder.addCode("\n");
                builder.nextControlFlow("catch (Exception e$L)", exceptionCount);
                exceptionCount++;
                builder.beginControlFlow("try");
                builder.addCode(resWriter.getDimensionPixelOffset(field.getName(), field.getDefaultValue()));
                builder.addCode("\n");
                builder.nextControlFlow("catch (Exception e$L)", exceptionCount);
                builder.addCode(resWriter.getInteger(field.getName(), field.getDefaultValue()));
                builder.addCode("\n");
                builder.endControlFlow();
                builder.endControlFlow();
            }
        } else if (unboxedTypeName.equals(TypeName.FLOAT)) {
            if (field.isDimension()) {
                builder.addCode(resWriter.getDimension(field.getName(), field.getDefaultValue()));
            } else {
                builder.beginControlFlow("try");
                builder.addCode(resWriter.getDimension(field.getName(), field.getDefaultValue()));
                builder.addCode("\n");
                builder.nextControlFlow("catch (Exception e$L)", exceptionCount);
                builder.addCode(resWriter.getFraction(field.getName(), field.getDefaultValue(), 0, 1));
                builder.addCode("\n");
                builder.endControlFlow();
            }
        }
    } else if (typeName.equals(COLOR_STATE_LIST)) {
        builder.addCode(resWriter.getColorStateList(field.getName(), field.getDefaultValue()));
    } else if (typeName.equals(DRAWABLE)) {
        builder.addCode(resWriter.getDrawable(field.getName(), field.getDefaultValue()));
    } else if (typeName.equals(CHAR_SEQUENCE)) {
        builder.addCode(resWriter.getText(field.getName(), field.getDefaultValue()));
    } else if (typeName.equals(CHAR_SEQUENCE_ARRAY)) {
        builder.addCode(resWriter.getTextArray(field.getName(), field.getDefaultValue()));
    } else if (typeName.equals(STRING)) {
        builder.addCode(resWriter.getString(field.getName(), field.getDefaultValue()));
    }

    builder.addCode("\n");
}