private void establishOrder(ParameterizedDeclaration declaration) { addMissingParameterOrders(declaration.getAllParameters()); int minGroupOrder = addMissingParameterOrders(declaration.getParameterGroups()); updateGeneralGroupOrder(declaration, minGroupOrder); }
private void document(ParameterizedDeclaration<?> declaration, List<XmlExtensionElementDocumentation> elements) { elements.stream().filter(e -> e.getName().equals(declaration.getName())).findAny() .ifPresent(e -> { declaration.setDescription(e.getDescription()); declaration.getAllParameters() .forEach(param -> e.getParameters().stream().filter(p -> p.getName().equals(param.getName())).findAny() .ifPresent(p -> param.setDescription(p.getDescription()))); }); } }.walk(declaration);
public static ParameterGroupDeclaration mockParameters(ParameterizedDeclaration declaration, String groupName, ParameterDeclaration... parameters) { ParameterGroupDeclaration group = mock(ParameterGroupDeclaration.class); when(group.getName()).thenReturn(groupName); when(declaration.getParameterGroups()).thenReturn(asList(group)); when(declaration.getParameterGroup(groupName)).thenReturn(group); List<ParameterDeclaration> params = new ArrayList<>(asList(parameters)); when(group.getParameters()).thenReturn(params); when(declaration.getAllParameters()).thenReturn(params); return group; }
private void enrichMetadataKeyParameters(ParameterizedDeclaration<?> declaration, TypeKeysResolver typeKeysResolver) { declaration.getAllParameters() .forEach(paramDeclaration -> paramDeclaration.getModelProperty(ExtensionParameterDescriptorModelProperty.class) .ifPresent(modelProperty -> parseMetadataKeyAnnotations(modelProperty.getExtensionParameter(), paramDeclaration, typeKeysResolver))); }
private void updateGeneralGroupOrder(ParameterizedDeclaration declaration, int minGroupOrder) { Optional<ParameterGroupDeclaration> general = declaration.getParameterGroups().stream() .filter(pg -> ((ParameterGroupDeclaration) pg).getName().equals(DEFAULT_GROUP_NAME)).findFirst(); general.map(ParameterGroupDeclaration::getLayoutModel).flatMap(LayoutModel::getOrder).filter(order -> order > minGroupOrder) .ifPresent(order -> general.get() .setLayoutModel(builderFrom(general.get().getLayoutModel()).order(minGroupOrder - 1).build())); }
private void assertNoMimeTypeParams(ParameterizedDeclaration<?> withParams) { List<ParameterDeclaration> parameters = withParams.getParameterGroup(DEFAULT_GROUP_NAME).getParameters(); assertThat(parameters, hasSize(0)); }
/** * Describes parameters that are defined as Method parameters. */ void document(ParameterizedDeclaration<?> parameterized, Element method, MethodDocumentation documentation) { parameterized.getAllParameters().forEach(p -> { String description = documentation.getParameters().get(p.getName()); if (description != null) { p.setDescription(description); } }); if (method instanceof ExecutableElement) { ((ExecutableElement) method).getParameters().stream() .filter(e -> e.getAnnotation(ParameterGroup.class) != null) .forEach(group -> { TypeElement typeElement = (TypeElement) processingEnv.getTypeUtils().asElement(group.asType()); document(parameterized, typeElement); }); } }
protected Pair<ParameterGroupDeclaration, ParameterDeclaration> findParameterInGroup(ParameterizedDeclaration<?> declaration, String name) { return declaration.getParameterGroups().stream() .map(group -> { ParameterDeclaration parameter = findParameter(group.getParameters(), name); return parameter != null ? new Pair<>(group, parameter) : null; }) .filter(pair -> pair != null) .findFirst().orElse(null); }
private void assertStringMimeTypeParams(ParameterizedDeclaration<?> withParams) { List<ParameterDeclaration> parameters = withParams.getParameterGroup(DEFAULT_GROUP_NAME).getParameters(); assertThat(parameters, hasSize(1)); assertParameter(parameters.get(0), MIME_TYPE_PARAMETER_NAME); }
/** * The method will look for parameters of the given {@link ParameterizedDeclaration declaration} and is a parameter or * parameter group annotated with {@link OfValues} if found, a {@link ValueProviderModel} will be added to this element * to communicate that values can be provided. * <p> * Also the {@link ParameterDeclaration parameters} of the {@link ParameterizedDeclaration declaration} will be * enriched. * * @param containerDeclaration declaration to introspect their parameters */ private void enrichContainerModel(ParameterizedDeclaration<?> containerDeclaration) { List<ParameterDeclaration> allParameters = containerDeclaration.getAllParameters(); Map<String, String> parameterNames = getContainerParameterNames(allParameters); Map<ParameterGroupDeclaration, OfValues> dynamicGroupOptions = introspectParameterGroups(containerDeclaration.getParameterGroups()); Map<ParameterDeclaration, OfValues> dynamicOptions = introspectParameters(allParameters); dynamicOptions.forEach((paramDeclaration, resolverClass) -> enrichParameter(resolverClass, paramDeclaration, paramDeclaration::setValueProviderModel, 1, parameterNames, paramDeclaration.getName())); dynamicGroupOptions .forEach((paramGroupDeclaration, resolverClass) -> getParts(paramGroupDeclaration) .forEach((paramDeclaration, order) -> enrichParameter(resolverClass, paramDeclaration, paramDeclaration::setValueProviderModel, order, parameterNames, paramGroupDeclaration.getName()))); }
void document(ParameterizedDeclaration<?> parameterized, final TypeElement element) { TypeElement traversingElement = element; while (traversingElement != null && !Object.class.getName().equals(traversingElement.getQualifiedName().toString())) { final Map<String, VariableElement> variableElements = processor.getFieldsAnnotatedWith(traversingElement, Parameter.class) .entrySet() .stream() .collect(Collectors.toMap(entry -> getNameOrAlias(entry.getValue()), Map.Entry::getValue)); parameterized.getAllParameters() .stream().filter(param -> variableElements.containsKey(param.getName())) .forEach(param -> { String summary = processor.getJavaDocSummary(processingEnv, variableElements.get(param.getName())); param.setDescription(summary); }); traversingElement = (TypeElement) processingEnv.getTypeUtils().asElement(traversingElement.getSuperclass()); } for (VariableElement variableElement : processor.getFieldsAnnotatedWith(element, ParameterGroup.class) .values()) { TypeElement typeElement = (TypeElement) processingEnv.getTypeUtils().asElement(variableElement.asType()); document(parameterized, typeElement); } } }
private void document(ParameterizedDeclaration<?> declaration, List<XmlExtensionElementDocumentation> elements) { elements.stream().filter(e -> e.getName().equals(declaration.getName())).findAny() .ifPresent(e -> { declaration.setDescription(e.getDescription()); declaration.getAllParameters() .forEach(param -> e.getParameters().stream().filter(p -> p.getName().equals(param.getName())).findAny() .ifPresent(p -> param.setDescription(p.getDescription()))); }); } }.walk(declaration);
private void updateGeneralGroupOrder(ParameterizedDeclaration declaration, int minGroupOrder) { Optional<ParameterGroupDeclaration> general = declaration.getParameterGroups().stream() .filter(pg -> ((ParameterGroupDeclaration) pg).getName().equals(DEFAULT_GROUP_NAME)).findFirst(); general.map(ParameterGroupDeclaration::getLayoutModel).flatMap(LayoutModel::getOrder).filter(order -> order > minGroupOrder) .ifPresent(order -> general.get() .setLayoutModel(builderFrom(general.get().getLayoutModel()).order(minGroupOrder - 1).build())); }
private void assertMimeTypeParams(ParameterizedDeclaration<?> withParams) { List<ParameterDeclaration> parameters = withParams.getParameterGroup(DEFAULT_GROUP_NAME).getParameters(); assertThat(parameters, hasSize(2)); assertParameter(parameters.get(0), MIME_TYPE_PARAMETER_NAME); assertParameter(parameters.get(1), ENCODING_PARAMETER_NAME); }
private void establishOrder(ParameterizedDeclaration declaration) { addMissingParameterOrders(declaration.getAllParameters()); int minGroupOrder = addMissingParameterOrders(declaration.getParameterGroups()); updateGeneralGroupOrder(declaration, minGroupOrder); }
private void enrichDeclaration(ParameterizedDeclaration declaration, boolean requiredParameter) { when(extensionParameter.isAnnotatedWith(RequiredForMetadata.class)).thenReturn(requiredParameter); ArrayList<ParameterDeclaration> params = new ArrayList<>(); params.add(parameterDeclaration); when(declaration.getAllParameters()).thenReturn(params); ENRICHER.enrich(loadingContext); } }
private void assertParametersSinceMuleVersionModelProperty(ParameterizedDeclaration<?> withParams, boolean shouldAddSinceMuleVersionModelProperty) { List<ParameterDeclaration> parameters = withParams.getParameterGroup(DEFAULT_GROUP_NAME).getParameters(); parameters.stream() .forEach(parameter -> { assertThat(parameter.getModelProperty(SinceMuleVersionModelProperty.class).isPresent(), is(shouldAddSinceMuleVersionModelProperty)); if (shouldAddSinceMuleVersionModelProperty) { assertThat(parameter.getModelProperty(SinceMuleVersionModelProperty.class).get().getVersion(), is(SINCE_MULE_VERSION_MODEL_PROPERTY.getVersion())); } }); }
/** * The method will look for parameters of the given {@link ParameterizedDeclaration declaration} and is a parameter or * parameter group annotated with {@link OfValues} if found, a {@link ValueProviderModel} will be added to this element * to communicate that values can be provided. * <p> * Also the {@link ParameterDeclaration parameters} of the {@link ParameterizedDeclaration declaration} will be * enriched. * * @param containerDeclaration declaration to introspect their parameters */ private void enrichContainerModel(ParameterizedDeclaration<?> containerDeclaration) { List<ParameterDeclaration> allParameters = containerDeclaration.getAllParameters(); Map<String, String> parameterNames = getContainerParameterNames(allParameters); Map<ParameterGroupDeclaration, OfValues> dynamicGroupOptions = introspectParameterGroups(containerDeclaration.getParameterGroups()); Map<ParameterDeclaration, OfValues> dynamicOptions = introspectParameters(allParameters); dynamicOptions.forEach((paramDeclaration, resolverClass) -> enrichParameter(resolverClass, paramDeclaration, paramDeclaration::setValueProviderModel, 1, parameterNames, paramDeclaration.getName())); dynamicGroupOptions .forEach((paramGroupDeclaration, resolverClass) -> getParts(paramGroupDeclaration) .forEach((paramDeclaration, order) -> enrichParameter(resolverClass, paramDeclaration, paramDeclaration::setValueProviderModel, order, parameterNames, paramGroupDeclaration.getName()))); }
private void enrichMetadataKeyParameters(ParameterizedDeclaration<?> declaration, TypeKeysResolver typeKeysResolver) { declaration.getAllParameters() .forEach(paramDeclaration -> paramDeclaration.getModelProperty(ExtensionParameterDescriptorModelProperty.class) .ifPresent(modelProperty -> parseMetadataKeyAnnotations(modelProperty.getExtensionParameter(), paramDeclaration, typeKeysResolver))); }
/** * Describes parameters that are defined as Method parameters. */ void document(ParameterizedDeclaration<?> parameterized, Element method, MethodDocumentation documentation) { parameterized.getAllParameters().forEach(p -> { String description = documentation.getParameters().get(p.getName()); if (description != null) { p.setDescription(description); } }); if (method instanceof ExecutableElement) { ((ExecutableElement) method).getParameters().stream() .filter(e -> e.getAnnotation(ParameterGroup.class) != null) .forEach(group -> { TypeElement typeElement = (TypeElement) processingEnv.getTypeUtils().asElement(group.asType()); document(parameterized, typeElement); }); } }