com.github.javaparser.resolution.types.ResolvedPrimitiveType Java Examples

The following examples show how to use com.github.javaparser.resolution.types.ResolvedPrimitiveType. 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: PrimitiveTypeDescription.java    From apigcc with MIT License 5 votes vote down vote up
public PrimitiveTypeDescription(ResolvedPrimitiveType resolvedPrimitiveType){
    type = resolvedPrimitiveType.describe();
    switch (resolvedPrimitiveType){
        case BYTE:
            value = (byte) 0;
            break;
        case SHORT:
            value = (short) 0;
            break;
        case INT:
            value = 0;
            break;
        case LONG:
            value = 0L;
            break;
        case FLOAT:
            value = 0f;
            break;
        case DOUBLE:
            value = 0d;
            break;
        case CHAR:
            value = (char)0;
            break;
        case BOOLEAN:
            value = false;
            break;
    }
}
 
Example #2
Source File: SchemaResolver.java    From flow with Apache License 2.0 5 votes vote down vote up
private boolean isNumberType(ResolvedType type) {
    if (type.isPrimitive()) {
        ResolvedPrimitiveType resolvedPrimitiveType = type.asPrimitive();
        return resolvedPrimitiveType != ResolvedPrimitiveType.BOOLEAN
                && resolvedPrimitiveType != ResolvedPrimitiveType.CHAR;
    } else {
        return isTypeOf(type, Number.class);
    }
}
 
Example #3
Source File: SchemaResolver.java    From flow with Apache License 2.0 5 votes vote down vote up
private boolean isBooleanType(ResolvedType type) {
    if (type.isPrimitive()) {
        return type.asPrimitive() == ResolvedPrimitiveType.BOOLEAN;
    } else {
        return isTypeOf(type, Boolean.class);
    }
}
 
Example #4
Source File: SchemaResolver.java    From flow with Apache License 2.0 5 votes vote down vote up
private boolean isStringType(ResolvedType type) {
    if (type.isPrimitive()) {
        return type.asPrimitive() == ResolvedPrimitiveType.CHAR;
    } else {
        return isTypeOf(type, String.class, Character.class);
    }
}
 
Example #5
Source File: SchemaResolverTest.java    From flow with Apache License 2.0 5 votes vote down vote up
@Test
public void should_ReturnNotNullableNumberSchema_When_GivenTypeIsAPrimitiveInt() {
    ResolvedType numberType = mockPrimitiveTypeOf(
            ResolvedPrimitiveType.INT);

    Schema schema = schemaResolver.parseResolvedTypeToSchema(numberType);
    Assert.assertTrue(schema instanceof NumberSchema);
    Assert.assertNull(schema.getNullable());
    Assert.assertTrue(schemaResolver.getFoundTypes().isEmpty());
}
 
Example #6
Source File: SchemaResolverTest.java    From flow with Apache License 2.0 5 votes vote down vote up
@Test
public void should_ReturnNotNullableBoolean_When_GivenTypeIsAPrimitiveBoolean() {
    ResolvedType resolvedType = mockPrimitiveTypeOf(
            ResolvedPrimitiveType.BOOLEAN);

    Schema schema = schemaResolver.parseResolvedTypeToSchema(resolvedType);

    Assert.assertTrue(schema instanceof BooleanSchema);
    Assert.assertNull(schema.getNullable());
    Assert.assertTrue(schemaResolver.getFoundTypes().isEmpty());
}
 
Example #7
Source File: SchemaResolverTest.java    From flow with Apache License 2.0 5 votes vote down vote up
private ResolvedType mockPrimitiveTypeOf(
        ResolvedPrimitiveType primitiveType) {
    ResolvedType numberType = mock(ResolvedType.class);

    when(numberType.isPrimitive()).thenReturn(true);
    when(numberType.asPrimitive()).thenReturn(primitiveType);
    return numberType;
}