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);
/** * 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); }); } }
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 addBackPressureParameter(ExtensionDeclaration extensionDeclaration, SourceDeclaration sourceDeclaration, BackPressureStrategyModelProperty property) { ParameterDeclaration parameter = new ParameterDeclaration(BACK_PRESSURE_STRATEGY_PARAMETER_NAME); parameter.setDescription(BACK_PRESSURE_STRATEGY_PARAMETER_DESCRIPTION); parameter.setRequired(false); parameter.setDefaultValue(property.getDefaultMode()); parameter.setExpressionSupport(NOT_SUPPORTED); parameter.setLayoutModel(LayoutModel.builder().tabName(ADVANCED_TAB).build()); MetadataType type = BaseTypeBuilder.create(JAVA).stringType() .id(format("%s-%s-backPressureStrategy", extensionDeclaration.getName(), sourceDeclaration.getName())) .with(new EnumAnnotation<>(property.getSupportedModes().stream().map(BackPressureMode::name).toArray(String[]::new))) .build(); parameter.setType(type, false); sourceDeclaration.getParameterGroup(DEFAULT_GROUP_NAME).addParameter(parameter); }
private ParameterDeclaration newParameter(String name, String description, boolean shouldAddSinceMuleVersionModelProperty) { ParameterDeclaration parameter = new ParameterDeclaration(name); parameter.setRequired(false); parameter.setExpressionSupport(SUPPORTED); parameter.setType(typeLoader.load(String.class), false); parameter.setDescription(description); parameter.setLayoutModel(LayoutModel.builder().tabName(ADVANCED_TAB_NAME).build()); if (shouldAddSinceMuleVersionModelProperty) { parameter.addModelProperty(SINCE_MULE_VERSION_MODEL_PROPERTY); } return parameter; } }
@Override protected void onSource(SourceDeclaration source) { extractType(source).ifPresent(type -> { if (type.isAssignableTo(PollingSource.class)) { source.setRunsOnPrimaryNodeOnly(true); ParameterDeclaration parameter = new ParameterDeclaration(SCHEDULING_STRATEGY_PARAMETER_NAME); parameter.setDescription(SCHEDULING_STRATEGY_PARAMETER_DESCRIPTION); parameter.setRequired(true); parameter.setType(loader.load(Scheduler.class), false); parameter.setExpressionSupport(NOT_SUPPORTED); parameter.addModelProperty(new InfrastructureParameterModelProperty(10)); parameter.addModelProperty(new QNameModelProperty(new QName(CORE_NAMESPACE, SCHEDULING_STRATEGY_ELEMENT_IDENTIFIER, CORE_PREFIX))); parameter.setDslConfiguration(ParameterDslConfiguration.builder() .allowsInlineDefinition(true) .allowsReferences(false) .allowTopLevelDefinition(false) .build()); thereArePollingSources.set(true); source.getParameterGroup(DEFAULT_GROUP_NAME).addParameter(parameter); } }); } }.walk(extensionDeclarer.getDeclaration());
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 OperationDeclaration buildUnauthorizeOperation() { OperationDeclaration operation = new OperationDeclaration(UNAUTHORIZE_OPERATION_NAME); operation.setDescription("Deletes all the access token information of a given resource owner id so that it's impossible to " + "execute any operation for that user without doing the authorization dance again"); operation.setBlocking(true); operation.setExecutionType(BLOCKING); operation.setOutput(toDeclaration(voidType)); operation.setOutputAttributes(toDeclaration(voidType)); operation.setRequiresConnection(false); operation.setSupportsStreaming(false); operation.setTransactional(false); operation.addModelProperty(new ComponentExecutorModelProperty((model, params) -> new UnauthorizeOperationExecutor())); ParameterGroupDeclaration group = operation.getParameterGroup(DEFAULT_GROUP_NAME); group.showInDsl(false); ParameterDeclaration parameter = new ParameterDeclaration(RESOURCE_OWNER_ID_PARAMETER_NAME); parameter.setDescription("The id of the resource owner which access should be invalidated"); parameter.setExpressionSupport(SUPPORTED); parameter.setLayoutModel(LayoutModel.builder().build()); parameter.setRequired(false); parameter.setParameterRole(BEHAVIOUR); parameter.setType(stringType, false); group.addParameter(parameter); return operation; }
/** * 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); }); } }
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 addBackPressureParameter(ExtensionDeclaration extensionDeclaration, SourceDeclaration sourceDeclaration, BackPressureStrategyModelProperty property) { ParameterDeclaration parameter = new ParameterDeclaration(BACK_PRESSURE_STRATEGY_PARAMETER_NAME); parameter.setDescription(BACK_PRESSURE_STRATEGY_PARAMETER_DESCRIPTION); parameter.setRequired(false); parameter.setDefaultValue(property.getDefaultMode()); parameter.setExpressionSupport(NOT_SUPPORTED); parameter.setLayoutModel(LayoutModel.builder().tabName(ADVANCED_TAB).build()); MetadataType type = BaseTypeBuilder.create(JAVA).stringType() .id(format("%s-%s-backPressureStrategy", extensionDeclaration.getName(), sourceDeclaration.getName())) .with(new EnumAnnotation<>(property.getSupportedModes().stream().map(BackPressureMode::name).toArray(String[]::new))) .build(); parameter.setType(type, false); sourceDeclaration.getParameterGroup(DEFAULT_GROUP_NAME).addParameter(parameter); }
private ParameterDeclaration newParameter(String name, String description) { ParameterDeclaration parameter = new ParameterDeclaration(name); parameter.setRequired(false); parameter.setExpressionSupport(SUPPORTED); parameter.setType(typeLoader.load(String.class), false); parameter.setDescription(description); parameter.setLayoutModel(LayoutModel.builder().tabName(ADVANCED_TAB_NAME).build()); return parameter; } }
@Override protected void onSource(SourceDeclaration source) { extractType(source).ifPresent(type -> { if (type.isAssignableTo(PollingSource.class)) { source.setRunsOnPrimaryNodeOnly(true); ParameterDeclaration parameter = new ParameterDeclaration(SCHEDULING_STRATEGY_PARAMETER_NAME); parameter.setDescription(SCHEDULING_STRATEGY_PARAMETER_DESCRIPTION); parameter.setRequired(true); parameter.setType(loader.load(Scheduler.class), false); parameter.setExpressionSupport(NOT_SUPPORTED); parameter.addModelProperty(new InfrastructureParameterModelProperty(10)); parameter.addModelProperty(new QNameModelProperty(new QName(CORE_NAMESPACE, SCHEDULING_STRATEGY_ELEMENT_IDENTIFIER, CORE_PREFIX))); parameter.setDslConfiguration(ParameterDslConfiguration.builder() .allowsInlineDefinition(true) .allowsReferences(false) .allowTopLevelDefinition(false) .build()); thereArePollingSources.set(true); source.getParameterGroup(DEFAULT_GROUP_NAME).addParameter(parameter); } }); } }.walk(extensionDeclarer.getDeclaration());
private OperationDeclaration buildUnauthorizeOperation() { OperationDeclaration operation = new OperationDeclaration(UNAUTHORIZE_OPERATION_NAME); operation.setDescription("Deletes all the access token information of a given resource owner id so that it's impossible to " + "execute any operation for that user without doing the authorization dance again"); operation.setBlocking(true); operation.setExecutionType(BLOCKING); operation.setOutput(toDeclaration(voidType)); operation.setOutputAttributes(toDeclaration(voidType)); operation.setRequiresConnection(false); operation.setSupportsStreaming(false); operation.setTransactional(false); operation.addModelProperty(new ComponentExecutorModelProperty((model, params) -> new UnauthorizeOperationExecutor())); ParameterGroupDeclaration group = operation.getParameterGroup(DEFAULT_GROUP_NAME); group.showInDsl(false); ParameterDeclaration parameter = new ParameterDeclaration(RESOURCE_OWNER_ID_PARAMETER_NAME); parameter.setDescription("The id of the resource owner which access should be invalidated"); parameter.setExpressionSupport(SUPPORTED); parameter.setLayoutModel(LayoutModel.builder().build()); parameter.setRequired(false); parameter.setParameterRole(BEHAVIOUR); parameter.setType(stringType, false); group.addParameter(parameter); return operation; }