Repository: micronaut-projects/micronaut-core
File: management/src/main/java/io/micronaut/management/endpoint/processors/AbstractEndpointRouteBuilder.java (Java)

Code before:
    /**
     * @param beanDefinition The bean definition to process
     * @param method The executable method
     */
    @Override
    public void process(BeanDefinition<?> beanDefinition, ExecutableMethod<?, ?> method) {
        Class<?> declaringType = method.getDeclaringType();
        if (method.hasStereotype(getSupportedAnnotation())) {
            Optional<String> endPointId = resolveActiveEndPointId(declaringType);
            final Integer port = endpointDefaultConfiguration.getPort().orElse(null);
            endPointId.ifPresent(id -> registerRoute(method, id, port));
        }
    }

    /**
     * @param declaringType The type
     * @return An optional string with the endpoint id
     */
    protected Optional<String> resolveActiveEndPointId(Class<?> declaringType) {
        return endpointIds.computeIfAbsent(declaringType, aClass -> {
            Optional<? extends BeanDefinition<?>> opt = beanContext.findBeanDefinition(declaringType);
            if (opt.isPresent()) {
                BeanDefinition<?> beanDefinition = opt.get();
                if (beanDefinition.hasStereotype(Endpoint.class)) {
                    String id = beanDefinition.stringValue(Endpoint.class).orElse(null);
                    if (beanContext.containsBean(EndpointConfiguration.class, Qualifiers.byName(id))) {
                        String path = beanContext.getBean(EndpointConfiguration.class, Qualifiers.byName(id)).getPath();
                        if (StringUtils.isNotEmpty(path)) {
                            return Optional.of(path);
                        }
                    }
                    if (id == null || !ENDPOINT_ID_PATTERN.matcher(id).matches()) {
                        id = NameUtils.hyphenate(beanDefinition.getName());
                    }

                    return Optional.ofNullable(id);
                }
            }

            return Optional.empty();
        });
    }

    /**
     * @param method The {@link ExecutableMethod}
     * @param id The route id
     * @return An {@link UriTemplate}
     */
    protected UriTemplate buildUriTemplate(ExecutableMethod<?, ?> method, String id) {
        UriTemplate template = new UriTemplate(resolveUriByRouteId(id));
        for (Argument argument : method.getArguments()) {

Review comment (suggestion):
probably better to use `beanContext.getProvider` and then `isPresent()` followed by `get()`

Code after:

    /**
     * @param beanDefinition The bean definition to process
     * @param method The executable method
     */
    @Override
    public void process(BeanDefinition<?> beanDefinition, ExecutableMethod<?, ?> method) {
        Class<?> declaringType = method.getDeclaringType();
        if (method.hasStereotype(getSupportedAnnotation())) {
            Optional<String> endPointId = resolveActiveEndPointId(declaringType);
            final Integer port = endpointDefaultConfiguration.getPort().orElse(null);
            endPointId.ifPresent(id -> registerRoute(method, id, port));
        }
    }

    /**
     * @param declaringType The type
     * @return An optional string with the endpoint id
     */
    protected Optional<String> resolveActiveEndPointId(Class<?> declaringType) {
        return endpointIds.computeIfAbsent(declaringType, aClass -> {
            Optional<? extends BeanDefinition<?>> opt = beanContext.findBeanDefinition(declaringType);
            if (opt.isPresent()) {
                BeanDefinition<?> beanDefinition = opt.get();
                if (beanDefinition.hasStereotype(Endpoint.class)) {
                    String id = beanDefinition.stringValue(Endpoint.class).orElse(null);
                    final EndpointConfiguration endpointConfiguration = beanContext.getProvider(EndpointConfiguration.class, Qualifiers.byName(id))
                        .orElse(null);
                    if (endpointConfiguration != null && StringUtils.isNotEmpty(endpointConfiguration.getPath())) {
                        return Optional.of(endpointConfiguration.getPath());
                    }
                    if (id == null || !ENDPOINT_ID_PATTERN.matcher(id).matches()) {
                        id = NameUtils.hyphenate(beanDefinition.getName());
                    }

                    return Optional.ofNullable(id);
                }
            }

            return Optional.empty();
        });
    }

    /**
     * @param method The {@link ExecutableMethod}
     * @param id The route id
     * @return An {@link UriTemplate}
     */
    protected UriTemplate buildUriTemplate(ExecutableMethod<?, ?> method, String id) {
        UriTemplate template = new UriTemplate(resolveUriByRouteId(id));
        for (Argument argument : method.getArguments()) {