/** * Given a list of {@link ParameterGroupDeclaration}, introspect it and finds all the considered parameters with an associated * {@link ValueProvider} * * @param parameterGroups parameter groups to introspect * @return a Map containing all the {@link ParameterGroupDeclaration} with their correspondent {@link ValueProvider} */ private Map<ParameterGroupDeclaration, OfValues> introspectParameterGroups(List<ParameterGroupDeclaration> parameterGroups) { Map<ParameterGroupDeclaration, OfValues> optionResolverEnabledParameters = new HashMap<>(); parameterGroups .forEach(paramGroup -> paramGroup.getModelProperty(ParameterGroupModelProperty.class) .ifPresent(modelProperty -> { AnnotatedElement container = modelProperty.getDescriptor().getContainer(); if (container != null) { OfValues annotation = container.getAnnotation(OfValues.class); if (annotation != null) { optionResolverEnabledParameters.put(paramGroup, annotation); } } })); return optionResolverEnabledParameters; }
private Optional<MetadataKeyIdModelProperty> findMetadataKeyIdInGroups( ComponentDeclaration<? extends ComponentDeclaration> component, String categoryName) { return component.getParameterGroups().stream() .map(group -> group.getModelProperty(ParameterGroupModelProperty.class).orElse(null)) .filter(Objects::nonNull) .filter(group -> group.getDescriptor().getAnnotatedContainer().isAnnotatedWith(MetadataKeyId.class)) .map(group -> new MetadataKeyIdModelProperty(group.getDescriptor().getMetadataType(), group.getDescriptor().getName(), categoryName)) .findFirst(); }
private Optional<Pair<MetadataKeyId, MetadataType>> locateMetadataKeyId( ComponentDeclaration<? extends ComponentDeclaration> component) { Optional<Pair<MetadataKeyId, MetadataType>> keyId = component.getAllParameters().stream() .map((declaration) -> new ImmutablePair<>(declaration, getAnnotatedElement(declaration))) .filter(p -> p.getRight().isPresent() && p.getRight().get().isAnnotationPresent(MetadataKeyId.class)) .map(p -> (Pair<MetadataKeyId, MetadataType>) new ImmutablePair<>(p.getRight().get().getAnnotation(MetadataKeyId.class), p.getLeft().getType())) .findFirst(); if (!keyId.isPresent()) { for (ParameterGroupDeclaration group : component.getParameterGroups()) { keyId = group.getModelProperty(ParameterGroupModelProperty.class) .map(ParameterGroupModelProperty::getDescriptor) .filter(g -> g.getAnnotatedContainer().isAnnotatedWith(MetadataKeyId.class)) .map(g -> new ImmutablePair<>(g.getContainer().getAnnotation(MetadataKeyId.class), g.getType().asMetadataType())); if (keyId.isPresent()) { break; } } } return keyId; }
/** * Given a list of {@link ParameterGroupDeclaration}, introspect it and finds all the considered parameters with an associated * {@link ValueProvider} * * @param parameterGroups parameter groups to introspect * @return a Map containing all the {@link ParameterGroupDeclaration} with their correspondent {@link ValueProvider} */ private Map<ParameterGroupDeclaration, OfValues> introspectParameterGroups(List<ParameterGroupDeclaration> parameterGroups) { Map<ParameterGroupDeclaration, OfValues> optionResolverEnabledParameters = new HashMap<>(); parameterGroups .forEach(paramGroup -> paramGroup.getModelProperty(ParameterGroupModelProperty.class) .ifPresent(modelProperty -> { AnnotatedElement container = modelProperty.getDescriptor().getContainer(); if (container != null) { OfValues annotation = container.getAnnotation(OfValues.class); if (annotation != null) { optionResolverEnabledParameters.put(paramGroup, annotation); } } })); return optionResolverEnabledParameters; }
private Optional<MetadataKeyIdModelProperty> findMetadataKeyIdInGroups( ComponentDeclaration<? extends ComponentDeclaration> component, String categoryName) { return component.getParameterGroups().stream() .map(group -> group.getModelProperty(ParameterGroupModelProperty.class).orElse(null)) .filter(Objects::nonNull) .filter(group -> group.getDescriptor().getAnnotatedContainer().isAnnotatedWith(MetadataKeyId.class)) .map(group -> new MetadataKeyIdModelProperty(group.getDescriptor().getMetadataType(), group.getDescriptor().getName(), categoryName)) .findFirst(); }
private Optional<Pair<MetadataKeyId, MetadataType>> locateMetadataKeyId( ComponentDeclaration<? extends ComponentDeclaration> component) { Optional<Pair<MetadataKeyId, MetadataType>> keyId = component.getAllParameters().stream() .map((declaration) -> new ImmutablePair<>(declaration, getAnnotatedElement(declaration))) .filter(p -> p.getRight().isPresent() && p.getRight().get().isAnnotationPresent(MetadataKeyId.class)) .map(p -> (Pair<MetadataKeyId, MetadataType>) new ImmutablePair<>(p.getRight().get().getAnnotation(MetadataKeyId.class), p.getLeft().getType())) .findFirst(); if (!keyId.isPresent()) { for (ParameterGroupDeclaration group : component.getParameterGroups()) { keyId = group.getModelProperty(ParameterGroupModelProperty.class) .map(ParameterGroupModelProperty::getDescriptor) .filter(g -> g.getAnnotatedContainer().isAnnotatedWith(MetadataKeyId.class)) .map(g -> new ImmutablePair<>(g.getContainer().getAnnotation(MetadataKeyId.class), g.getType().asMetadataType())); if (keyId.isPresent()) { break; } } } return keyId; }