private static boolean hasArrayFields(TypeDef item) { return item.getMethods() .stream() .filter(m -> m.getReturnType() instanceof ClassRef && ((ClassRef)m.getReturnType()).getDimensions() > 0) .findAny().isPresent(); }
/** * Returns the string representation of the code that reads a primitive array property. * @param ref The reference. * @param source The type of the reference. * @param property The property to read. * @return The code. */ private static String readPrimitiveArrayProperty(String ref, TypeDef source, Property property) { StringBuilder sb = new StringBuilder(); Method getter = getterOf(source, property); sb.append("Arrays.asList(") .append(ref).append(".").append(getter.getName()).append("())") .append(".stream()").append(".collect(Collectors.toList())).toArray(new "+getter.getReturnType().toString()+"[])"); return sb.toString(); }
public static Collection<String> allGenericsOf(Method method) { Set<String> result = new HashSet<String>(allGenericsOf(method.getReturnType())); for (Property property : method.getArguments()) { result.addAll(allGenericsOf(property)); } return result; }
/** * Returns the string representation of the code that reads an object array property. * @param ref The reference. * @param source The type of the reference. * @param property The property to read. * @return The code. */ private static String readObjectArrayProperty(String ref, TypeDef source, Property property) { StringBuilder sb = new StringBuilder(); Method getter = getterOf(source, property); TypeRef getterTypeRef = getter.getReturnType(); TypeRef propertyTypeRef = property.getTypeRef(); if (propertyTypeRef instanceof ClassRef && getterTypeRef instanceof ClassRef) { String nextRef = variables.pop(); try { TypeDef propertyType = ((ClassRef) propertyTypeRef).getDefinition(); TypeDef getterType = ((ClassRef) getterTypeRef).getDefinition(); sb.append("Arrays.asList(") .append(ref).append(".").append(getter.getName()).append("())") .append(".stream().map(").append(nextRef).append(" ->").append(convertReference(nextRef, getterType, propertyType)).append(")") .append(".collect(Collectors.toList()).toArray(new " + propertyType.getFullyQualifiedName() + "[0])"); } finally { variables.push(nextRef); } return sb.toString(); } throw new IllegalArgumentException("Expected an object property and a matching object getter!!"); }
if (method.getReturnType().equals(VOID)) { return false; if (method.getName().startsWith(IS_PREFIX) && TypeUtils.isBoolean(method.getReturnType())) { return length > IS_PREFIX.length(); if (method.getName().startsWith(SHOULD_PREFIX) && TypeUtils.isBoolean(method.getReturnType())) { return length > SHOULD_PREFIX.length();
if (m.getReturnType() instanceof ClassRef) { ClassRef ref = (ClassRef) m.getReturnType(); Boolean hasSuperClass = pojo.getProperties() .stream() if (m.getReturnType().getDimensions() > 0) { sb.append(".addAllTo").append(StringUtils.capitalizeFirst(trimmedName)).append("(") .append("Arrays.asList(") .append("new ").append(generatedType.getName()).append("(") .append(ctor.getArguments().stream() .map(p -> Getter.find(((ClassRef) m.getReturnType()).getDefinition(), p, true)) .map(g -> g.getName()) .map(s -> "i."+s+"()").collect(Collectors.joining(", "))) .append("new ").append(generatedType.getName()).append("(") .append(ctor.getArguments().stream() .map(p -> Getter.find(((ClassRef) m.getReturnType()).getDefinition(), p, true)) .map(g -> g.getName()) .map(s -> "instance."+m.getName()+"()."+s+"()").collect(Collectors.joining(", ")))
/** * 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; }
if (!method.getReturnType().isAssignableFrom(property.getTypeRef())) { return false;
TypeRef returnType = m.getReturnType(); if (returnType instanceof ClassRef) { TypeDef toUnwrap = ((ClassRef)returnType).getDefinition();
TypeRef returnType = method.getReturnType(); if (method.getReturnType() instanceof ClassRef) { ClassRef ref = (ClassRef) method.getReturnType(); if (ref.getDefinition().isAnnotation()) { item.getMethods() .stream() .filter(m -> m.getReturnType() instanceof ClassRef && ((ClassRef)m.getReturnType()).getDimensions() > 0) .findAny().ifPresent(m -> { additionalImports.add(ARRAYS);
public MethodFluentImpl(Method instance){ this.withComments(instance.getComments()); this.withAnnotations(instance.getAnnotations()); this.withParameters(instance.getParameters()); this.withName(instance.getName()); this.withReturnType(instance.getReturnType()); this.withArguments(instance.getArguments()); this.withVarArgPreferred(instance.isVarArgPreferred()); this.withExceptions(instance.getExceptions()); this.withBlock(instance.getBlock()); this.withModifiers(instance.getModifiers()); 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); }
public MethodBuilder(Method instance,Boolean validationEnabled){ this.fluent = this; this.withComments(instance.getComments()); this.withAnnotations(instance.getAnnotations()); this.withParameters(instance.getParameters()); this.withName(instance.getName()); this.withReturnType(instance.getReturnType()); this.withArguments(instance.getArguments()); this.withVarArgPreferred(instance.isVarArgPreferred()); this.withExceptions(instance.getExceptions()); this.withBlock(instance.getBlock()); this.withModifiers(instance.getModifiers()); this.withAttributes(instance.getAttributes()); this.validationEnabled = validationEnabled; }
public MethodBuilder(MethodFluent<?> fluent,Method instance,Boolean validationEnabled){ this.fluent = fluent; fluent.withComments(instance.getComments()); fluent.withAnnotations(instance.getAnnotations()); fluent.withParameters(instance.getParameters()); fluent.withName(instance.getName()); fluent.withReturnType(instance.getReturnType()); fluent.withArguments(instance.getArguments()); fluent.withVarArgPreferred(instance.isVarArgPreferred()); fluent.withExceptions(instance.getExceptions()); fluent.withBlock(instance.getBlock()); fluent.withModifiers(instance.getModifiers()); fluent.withAttributes(instance.getAttributes()); this.validationEnabled = validationEnabled; } public MethodBuilder(Method instance){