protected Collection findBuildMethods()

in aws-wafv2-commons/src/main/java/com/amazonaws/mapstruct/builder/AWSSDKBuilderProvider.java [24:56]


    protected Collection<ExecutableElement> findBuildMethods(TypeElement builderElement, TypeElement typeElement) {
        if (shouldIgnore(builderElement)) {
            return Collections.emptyList();
        }

        List<ExecutableElement> builderMethods = ElementFilter.methodsIn(builderElement.getEnclosedElements());
        List<ExecutableElement> buildMethods = new ArrayList<>();
        for (ExecutableElement buildMethod : builderMethods) {
            if (isBuildMethod(buildMethod, typeElement)) {
                buildMethods.add(buildMethod);
            }
        }

        if (buildMethods.isEmpty()) {
            Optional<? extends Element> builderImpl = typeElement.getEnclosedElements().stream()
                    .filter(e -> e.getSimpleName().toString().equals(BUILDER_IMPL_CLASS_NAME))
                    .findFirst();

            builderMethods = ElementFilter.methodsIn(builderImpl.get().getEnclosedElements());
            buildMethods = builderMethods.stream()
                    .filter(m -> isBuildMethod(m, typeElement))
                    .collect(Collectors.toList());
        }

        if (buildMethods.isEmpty()) {
            return findBuildMethods(
                    getTypeElement(builderElement.getSuperclass()),
                    typeElement
            );
        }

        return buildMethods;
    }