public TypeRef apply(TypeRef type) { if (type instanceof ClassRef) { ClassRef classRef = (ClassRef) type; if (TypeUtils.isOptional(classRef)) { return classRef.getArguments().get(0); } if (TypeUtils.isOptionalInt(classRef)) { return new TypeDefBuilder().withPackageName("java.lang").withName("Integer").build().toReference(); } if (TypeUtils.isOptionalLong(classRef)) { return new TypeDefBuilder().withPackageName("java.lang").withName("Long").build().toReference(); } if (TypeUtils.isOptionalDouble(classRef)) { return new TypeDefBuilder().withPackageName("java.lang").withName("Double").build().toReference(); } } return type; } };
public static JSONSchemaProps from(TypeRef typeRef) { //1. Handle Collections and Arrays if (typeRef.getDimensions() > 0 || TypeUtils.isCollection(typeRef)) { return new JSONSchemaPropsBuilder() .withType("array") .withNewItems() .withSchema(from(TypeAs.combine(TypeAs.UNWRAP_ARRAY_OF, TypeAs.UNWRAP_COLLECTION_OF).apply(typeRef))) .and() .build(); //2. Handle Standard Types } else if (TYPE_MAP.containsKey(typeRef)) { return new JSONSchemaPropsBuilder() .withType(TYPE_MAP.get(typeRef)) .build(); //3. Handle Optionals } else if (TypeUtils.isOptional(typeRef)) { return from(TypeAs.UNWRAP_OPTIONAL_OF.apply(typeRef)); //4. Handle complex types } else if (typeRef instanceof ClassRef) { ClassRef classRef = (ClassRef) typeRef; TypeDef def = classRef.getDefinition(); return from(def); } return null; } }
public Method apply(final Property property) { String prefix = "has"; String methodName = prefix + property.getNameCapitalized(); List<Statement> statements = new ArrayList<Statement>(); if (isPrimitive(property.getTypeRef())) { statements.add(new StringStatement("return true;")); } else if (isList(property.getTypeRef()) || isSet(property.getTypeRef())) { statements.add(new StringStatement("return " + property.getName() + " != null && !" + property.getName() + ".isEmpty();")); } else if (isOptional(property.getTypeRef())|| isOptionalInt(property.getTypeRef()) || isOptionalLong(property.getTypeRef()) || isOptionalDouble(property.getTypeRef())) { statements.add(new StringStatement("return " + property.getName() + " != null && " + property.getName() + ".isPresent();")); } else { statements.add(new StringStatement("return this." + property.getName() + " != null;")); } return new MethodBuilder() .withModifiers(TypeUtils.modifiersToInt(Modifier.PUBLIC)) .withName(methodName) .withReturnType(BOOLEAN_REF) .withArguments() .withNewBlock() .withStatements(statements) .endBlock() .build(); } });
isOptional(baseType) ? "return withNew" + methodNameBase + "Like(get" + methodNameBase + "() != null && get"+methodNameBase+"().isPresent() ? get" + methodNameBase + "().get() : new " + builderType.getName() + "().build());" : "return withNew" + methodNameBase + "Like(get" + methodNameBase + "() != null ? get" + methodNameBase + "(): new " + builderType.getName() + "().build());";
boolean isMap = TypeUtils.isMap(toAdd.getTypeRef()); boolean isAbstract = isAbstract(unwrapped); boolean isOptional = TypeUtils.isOptional(toAdd.getTypeRef()) || TypeUtils.isOptionalInt(toAdd.getTypeRef()) || TypeUtils.isOptionalDouble(toAdd.getTypeRef())
String methodName = prefix + methodNameBase + suffix; String statement = isOptional(property.getTypeRef()) ? "return withNew" + methodNameBase + "Like(get" + methodNameBase + "() != null && get"+methodNameBase+"().isPresent() ? get" + methodNameBase + "().get(): item);" : "return withNew" + methodNameBase + "Like(get" + methodNameBase + "() != null ? get" + methodNameBase + "(): item);";
boolean isList = TypeUtils.isList(typeRef); boolean isMap = TypeUtils.isMap(typeRef); boolean isOptional = TypeUtils.isOptional(typeRef); boolean isOptionalInt = TypeUtils.isOptionalInt(typeRef); boolean isOptionalDouble = TypeUtils.isOptionalDouble(typeRef);
String methodName = prefix + methodNameBase; String statement = isOptional(property.getTypeRef()) ? "return withNew" + methodNameBase + "Like(get" + methodNameBase + "() != null ? get" + methodNameBase + "().orElse(null) : null);" : "return withNew" + methodNameBase + "Like(get" + methodNameBase + "());";
final boolean isMap = TypeUtils.isMap(property.getTypeRef()); final boolean isAbstract = isAbstract(unwrapped); boolean isOptional = TypeUtils.isOptional(property.getTypeRef()) || TypeUtils.isOptionalInt(property.getTypeRef()) || TypeUtils.isOptionalDouble(property.getTypeRef())
boolean isList = isList(property.getTypeRef()); boolean isSet = isSet(property.getTypeRef()); boolean isOptional = isOptional(property.getTypeRef()) || isOptionalDouble(property.getTypeRef()) || isOptionalInt(property.getTypeRef()) || isOptionalLong(property.getTypeRef());
if (TypeUtils.isOptional(classRef)) { ClassRef optionalRef = Optionals.OPTIONAL.toReference(builderType); return new PropertyBuilder(property).withTypeRef(optionalRef)