sb.append(COMA); if (varArg.getTypeRef().getDimensions() == 1) { sb.append(varArg.getTypeRef().withDimensions(0)).append(VARARG).append(SPACE); } else { sb.append(varArg.getTypeRef()).append(SPACE);
public TypeRefFluentImpl(TypeRef instance){ this.withAttributes(instance.getAttributes()); }
/** * Returns the string representation of the code that given a reference of the specified type, reads the specified property. * @param ref The reference. * @param source The type of the reference. * @param property The property to read. * @return The code. */ private static String readProperty(String ref, TypeDef source, Property property) { TypeRef propertyTypeRef = property.getTypeRef(); Method getter = getterOf(source, property); if (getter == null) { return "null"; } TypeRef getterTypeRef = getter.getReturnType(); if (propertyTypeRef.getDimensions() == getterTypeRef.getDimensions() && propertyTypeRef.isAssignableFrom(getterTypeRef)) { return readObjectProperty(ref, source, property); } if (property.getTypeRef().getDimensions() > 0) { return readArrayProperty(ref, source, property); } if (property.getTypeRef() instanceof ClassRef && ((ClassRef)getterTypeRef).getDefinition().isAnnotation()) { return readAnnotationProperty(ref + "."+getter.getName()+"()", ((ClassRef) getterTypeRef).getDefinition(), property); } return readObjectProperty(ref, source, property); }
if (m.getReturnType().getDimensions() > 0) { sb.append(".addAllTo").append(StringUtils.capitalizeFirst(trimmedName)).append("(") .append("Arrays.asList(")
/** * Checks if {@link ClassRef} is buildable. * @param ref The reference. * @return True if buildable repository contains the ref or builder for the reference is present. */ public static boolean isBuildable(ClassRef ref) { if (BuilderContextManager.getContext().getBuildableRepository().isBuildable(ref)) { return true; } String builderFQCN = ref.getDefinition().getFullyQualifiedName() + "Builder"; TypeDef builder = BuilderContextManager.getContext().getDefinitionRepository().getDefinition(builderFQCN); if (builder == null) { return false; } return builder.getMethods() .stream() .filter(m -> "build".equals(m.getName())) .filter(m -> m.getReturnType().isAssignableFrom(ref)) .count() > 0; }
Property item = new PropertyBuilder(property) .withName("items") .withTypeRef(unwrapped.withDimensions(1)) .build();
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; } }
if (!method.getReturnType().isAssignableFrom(property.getTypeRef())) { return false;
.withTypeRef(unwrapped.withDimensions(1)) .build();
return targetRef.withDimensions(dimensions + targetRef.getDimensions());
private static Set<TypeRef> findTypeArguments(Set<ClassRef> interfaces) { if (interfaces.size() < 2) { return Collections.<TypeRef>emptySet(); } //1st pass find all generics Set<TypeRef> allGenerics = new LinkedHashSet<TypeRef>(); for (ClassRef clazz : interfaces) { allGenerics.addAll(clazz.getArguments()); } //2nd pass collect common generics Set<TypeRef> common = new LinkedHashSet<TypeRef>(allGenerics); for (ClassRef clazz : interfaces) { Set<TypeRef> ownGenerics = new LinkedHashSet<TypeRef>(); ownGenerics.addAll(clazz.getArguments()); common.remove(clazz); common.retainAll(ownGenerics); } Set<TypeRef> result = new LinkedHashSet<TypeRef>(); for (TypeRef type : common) { Boolean isGeneric = type.getAttributes().containsKey(IS_GENERIC) ? (Boolean) type.getAttributes().get(IS_GENERIC) : false; if (!isGeneric) { result.add(type); } } return result; }
typeRef = typeRef.withDimensions(typeRef.getDimensions() + 1);
TypeDef toUnwrap = ((ClassRef)returnType).getDefinition(); methods.add(new MethodBuilder(m).withReturnType(Generics.UNWRAP.apply(toUnwrap).toInternalReference()).build()); } else if (returnType.getAttributes().containsKey(ORIGINAL_REF)) { methods.add(new MethodBuilder(m).withReturnType((TypeRef) returnType.getAttributes().get(ORIGINAL_REF)).build()); } else { methods.add(new MethodBuilder(m).withReturnType(returnType).build());