public static boolean has(TypeDef clazz, Property property) { for (Method method : clazz.getMethods()) { if (isApplicable(method, property)) { return true; } } return false; }
/** * Check if method exists on the specified type. * @param typeDef The type. * @param method The method name. * @return True if method is found, false otherwise. */ public static boolean hasMethod(TypeDef typeDef, String method) { return unrollHierarchy(typeDef) .stream() .flatMap(h -> h.getMethods().stream()) .filter(m -> method.equals(m.getName())) .findAny() .isPresent(); }
private static boolean hasArrayFields(TypeDef item) { return item.getMethods() .stream() .filter(m -> m.getReturnType() instanceof ClassRef && ((ClassRef)m.getReturnType()).getDimensions() > 0) .findAny().isPresent(); }
private static final Method getterOf(TypeDef source, Property property) { Method result = source.getMethods().stream() .filter(m -> m.isPublic() && m.getArguments().size() == 0 && Getter.propertyNameSafe(m).equals(property.getName())) .findFirst() .orElse(null); return result; }
public static Set<String> allGenericsOf(TypeDef clazz) { Set<String> result = new HashSet<String>(); for (TypeParamDef paramDef : clazz.getParameters()) { result.add(paramDef.getName()); } for (Property property : clazz.getProperties()) { result.addAll(allGenericsOf(property)); } for (Method method : clazz.getMethods()) { result.addAll(allGenericsOf(method)); } return result; }
/** * Checks that a factory method with the required number of arguments is found. * @param arguments */ private void checkFactoryMethodArguments(int arguments) { for (Method m : typeDef.getMethods()) { int a = m.getArguments() != null ? m.getArguments().size() : 0; if (m.getName().equals(staticFactoryMethod) && a == arguments && m.isStatic()) { return; } } throw new IllegalArgumentException("No static method found on " + typeDef.getName() + " with name " + staticFactoryMethod + " and " + arguments + " arguments."); } }
public static boolean hasOrInherits(TypeDef clazz, Property property) { TypeDef current = clazz; //Iterate parent objects and check for properties with setters but not ctor arguments. while (current!= null && !current.equals(TypeDef.OBJECT)) { for (Method method : current.getMethods()) { if (isApplicable(method, property)) { return true; } } if (!current.getExtendsList().isEmpty()) { String fqn = current.getExtendsList().iterator().next().getDefinition().getFullyQualifiedName(); current = DefinitionRepository.getRepository().getDefinition(fqn); } else { current = null; } } return false; } }
sb.append("return new ").append(pojoBuilder.getName()).append("()"); for (Method m : source.getMethods()) { String trimmedName = StringUtils.deCapitalizeFirst(m.getName().replaceAll("^get", "").replaceAll("^is", "")); if (m.getReturnType() instanceof ClassRef) {
/** * 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; }
while (current!= null && !current.equals(TypeDef.OBJECT)) { for (Method method : current.getMethods()) { if (isApplicable(method, property, true, false)) { return method; for (Method method : current.getMethods()) { if (isApplicable(method, property, false, false)) { return method; for (Method method : current.getMethods()) { if (isApplicable(method, property, false, true)) { return method;
public TypeDef apply(TypeDef... items) { if (items == null || items.length == 0) { throw new IllegalArgumentException("Items cannot be empty."); } else if (items.length == 1) { return items[0]; } else if (items.length == 2) { TypeDef mergedType = TYPES.apply(new TypeDef[]{items[0], items[1]}); TypeDefBuilder builder = new TypeDefBuilder(mergedType); for (Method constructor : items[1].getConstructors()) { builder = builder.addToConstructors(constructor); } for (Method method : items[1].getMethods()) { builder = builder.addToMethods(method); } for (Property property : items[1].getProperties()) { builder = builder.addToProperties(property); } return builder.build(); } else { TypeDef[] rest = new TypeDef[items.length - 1]; System.arraycopy(items, 1, rest, 0, rest.length); CLASSES.apply(new TypeDef[]{items[0], CLASSES.apply(rest)}); } return null; } };
for (Method m : current.getMethods()) { TypeRef returnType = m.getReturnType(); if (returnType instanceof ClassRef) { for (Method m : current.getMethods()) { methods.add(new MethodBuilder(m).withReturnType(current.toUnboundedReference()).build());
for (Method method : t.getMethods()) { for (Method method : superClass.getMethods()) { if (Getter.is(method)) { for (Method m : getters) { item.getMethods() .stream() .filter(m -> m.getReturnType() instanceof ClassRef && ((ClassRef)m.getReturnType()).getDimensions() > 0)
public TypeDefFluentImpl(TypeDef instance){ this.withKind(instance.getKind()); this.withPackageName(instance.getPackageName()); this.withName(instance.getName()); this.withComments(instance.getComments()); this.withAnnotations(instance.getAnnotations()); this.withExtendsList(instance.getExtendsList()); this.withImplementsList(instance.getImplementsList()); this.withParameters(instance.getParameters()); this.withProperties(instance.getProperties()); this.withConstructors(instance.getConstructors()); this.withMethods(instance.getMethods()); this.withOuterType(instance.getOuterType()); this.withInnerTypes(instance.getInnerTypes()); this.withModifiers(instance.getModifiers()); this.withAttributes(instance.getAttributes()); }
public TypeDefBuilder(TypeDef instance,Boolean validationEnabled){ this.fluent = this; this.withKind(instance.getKind()); this.withPackageName(instance.getPackageName()); this.withName(instance.getName()); this.withComments(instance.getComments()); this.withAnnotations(instance.getAnnotations()); this.withExtendsList(instance.getExtendsList()); this.withImplementsList(instance.getImplementsList()); this.withParameters(instance.getParameters()); this.withProperties(instance.getProperties()); this.withConstructors(instance.getConstructors()); this.withMethods(instance.getMethods()); this.withOuterType(instance.getOuterType()); this.withInnerTypes(instance.getInnerTypes()); this.withModifiers(instance.getModifiers()); this.withAttributes(instance.getAttributes()); this.validationEnabled = validationEnabled; }
public TypeDefBuilder(TypeDefFluent<?> fluent,TypeDef instance,Boolean validationEnabled){ this.fluent = fluent; fluent.withKind(instance.getKind()); fluent.withPackageName(instance.getPackageName()); fluent.withName(instance.getName()); fluent.withComments(instance.getComments()); fluent.withAnnotations(instance.getAnnotations()); fluent.withExtendsList(instance.getExtendsList()); fluent.withImplementsList(instance.getImplementsList()); fluent.withParameters(instance.getParameters()); fluent.withProperties(instance.getProperties()); fluent.withConstructors(instance.getConstructors()); fluent.withMethods(instance.getMethods()); fluent.withOuterType(instance.getOuterType()); fluent.withInnerTypes(instance.getInnerTypes()); fluent.withModifiers(instance.getModifiers()); fluent.withAttributes(instance.getAttributes()); this.validationEnabled = validationEnabled; } public TypeDefBuilder(TypeDef instance){