Search in sources :

Example 1 with ParameterizedDeclaration

use of org.mule.runtime.api.meta.model.declaration.fluent.ParameterizedDeclaration in project mule by mulesoft.

the class ParameterDescriptionDocumenter method document.

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);
    }
}
Also used : MethodDocumentation(org.mule.runtime.module.extension.internal.capability.xml.schema.MethodDocumentation) Map(java.util.Map) ExecutableElement(javax.lang.model.element.ExecutableElement) ParameterizedDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.ParameterizedDeclaration) ProcessingEnvironment(javax.annotation.processing.ProcessingEnvironment) VariableElement(javax.lang.model.element.VariableElement) Element(javax.lang.model.element.Element) TypeElement(javax.lang.model.element.TypeElement) Parameter(org.mule.runtime.extension.api.annotation.param.Parameter) ParameterGroup(org.mule.runtime.extension.api.annotation.param.ParameterGroup) Collectors(java.util.stream.Collectors) TypeElement(javax.lang.model.element.TypeElement) ParameterGroup(org.mule.runtime.extension.api.annotation.param.ParameterGroup) Parameter(org.mule.runtime.extension.api.annotation.param.Parameter) VariableElement(javax.lang.model.element.VariableElement) Map(java.util.Map)

Example 2 with ParameterizedDeclaration

use of org.mule.runtime.api.meta.model.declaration.fluent.ParameterizedDeclaration in project mule by mulesoft.

the class ParameterDescriptionDocumenter method document.

/**
 * 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);
        });
    }
}
Also used : MethodDocumentation(org.mule.runtime.module.extension.internal.capability.xml.schema.MethodDocumentation) Map(java.util.Map) ExecutableElement(javax.lang.model.element.ExecutableElement) ParameterizedDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.ParameterizedDeclaration) ProcessingEnvironment(javax.annotation.processing.ProcessingEnvironment) VariableElement(javax.lang.model.element.VariableElement) Element(javax.lang.model.element.Element) TypeElement(javax.lang.model.element.TypeElement) Parameter(org.mule.runtime.extension.api.annotation.param.Parameter) ParameterGroup(org.mule.runtime.extension.api.annotation.param.ParameterGroup) Collectors(java.util.stream.Collectors) TypeElement(javax.lang.model.element.TypeElement) ExecutableElement(javax.lang.model.element.ExecutableElement) ParameterGroup(org.mule.runtime.extension.api.annotation.param.ParameterGroup)

Example 3 with ParameterizedDeclaration

use of org.mule.runtime.api.meta.model.declaration.fluent.ParameterizedDeclaration in project mule by mulesoft.

the class BooleanParameterDeclarationEnricher method enrich.

@Override
public void enrich(ExtensionLoadingContext extensionLoadingContext) {
    ExtensionDeclaration extensionDeclaration = extensionLoadingContext.getExtensionDeclarer().getDeclaration();
    new DeclarationWalker() {

        @Override
        protected void onParameter(ParameterizedDeclaration owner, ParameterGroupDeclaration parameterGroup, ParameterDeclaration declaration) {
            declaration.getType().accept(new MetadataTypeVisitor() {

                @Override
                public void visitBoolean(BooleanType booleanType) {
                    declaration.setRequired(false);
                    if (declaration.getDefaultValue() == null && !declaration.isConfigOverride()) {
                        declaration.setDefaultValue(valueOf(FALSE));
                    }
                }
            });
        }
    }.walk(extensionDeclaration);
}
Also used : ParameterGroupDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.ParameterGroupDeclaration) DeclarationWalker(org.mule.runtime.api.meta.model.declaration.fluent.util.DeclarationWalker) ParameterizedDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.ParameterizedDeclaration) BooleanType(org.mule.metadata.api.model.BooleanType) ExtensionDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclaration) ConfigOverride(org.mule.runtime.extension.api.annotation.param.ConfigOverride) ParameterDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.ParameterDeclaration) MetadataTypeVisitor(org.mule.metadata.api.visitor.MetadataTypeVisitor) ConfigOverride(org.mule.runtime.extension.api.annotation.param.ConfigOverride)

Example 4 with ParameterizedDeclaration

use of org.mule.runtime.api.meta.model.declaration.fluent.ParameterizedDeclaration in project mule by mulesoft.

the class ExtensionDescriptionsEnricher method document.

/**
 * Fills all the descriptions in the provided {@link ExtensionDeclaration} based on the
 * <strong>extensions-descriptions.xml</strong> file.
 *
 * @param declaration   the declaration to describe.
 * @param documentation the extension documentation with its corresponding description.
 */
private void document(ExtensionDeclaration declaration, XmlExtensionDocumentation documentation) {
    declaration.setDescription(documentation.getExtension().getDescription());
    new DeclarationWalker() {

        @Override
        protected void onConfiguration(ConfigurationDeclaration declaration) {
            document(declaration, documentation.getConfigs());
        }

        @Override
        protected void onOperation(WithOperationsDeclaration owner, OperationDeclaration declaration) {
            document(declaration, documentation.getOperations());
        }

        @Override
        protected void onConnectionProvider(ConnectedDeclaration owner, ConnectionProviderDeclaration declaration) {
            document(declaration, documentation.getConnections());
        }

        @Override
        protected void onSource(WithSourcesDeclaration owner, SourceDeclaration declaration) {
            document(declaration, documentation.getSources());
        }

        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);
}
Also used : XmlExtensionDocumentation(org.mule.runtime.module.extension.internal.resources.documentation.XmlExtensionDocumentation) WithSourcesDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.WithSourcesDeclaration) URL(java.net.URL) OperationDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.OperationDeclaration) ParameterizedDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.ParameterizedDeclaration) ExtensionDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclaration) ExtensionLoadingContext(org.mule.runtime.extension.api.loader.ExtensionLoadingContext) IOException(java.io.IOException) XmlExtensionElementDocumentation(org.mule.runtime.module.extension.internal.resources.documentation.XmlExtensionElementDocumentation) ConfigurationDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.ConfigurationDeclaration) ConnectedDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.ConnectedDeclaration) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) WithOperationsDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.WithOperationsDeclaration) DeclarationWalker(org.mule.runtime.api.meta.model.declaration.fluent.util.DeclarationWalker) DeclarationEnricher(org.mule.runtime.extension.api.loader.DeclarationEnricher) SourceDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.SourceDeclaration) ExtensionDescriptionsSerializer(org.mule.runtime.module.extension.internal.resources.documentation.ExtensionDescriptionsSerializer) ConnectionProviderDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.ConnectionProviderDeclaration) ConfigurationDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.ConfigurationDeclaration) ConnectionProviderDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.ConnectionProviderDeclaration) WithOperationsDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.WithOperationsDeclaration) OperationDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.OperationDeclaration) ConnectedDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.ConnectedDeclaration) DeclarationWalker(org.mule.runtime.api.meta.model.declaration.fluent.util.DeclarationWalker) XmlExtensionElementDocumentation(org.mule.runtime.module.extension.internal.resources.documentation.XmlExtensionElementDocumentation) WithSourcesDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.WithSourcesDeclaration) SourceDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.SourceDeclaration)

Aggregations

ParameterizedDeclaration (org.mule.runtime.api.meta.model.declaration.fluent.ParameterizedDeclaration)4 Map (java.util.Map)2 Collectors (java.util.stream.Collectors)2 ProcessingEnvironment (javax.annotation.processing.ProcessingEnvironment)2 Element (javax.lang.model.element.Element)2 ExecutableElement (javax.lang.model.element.ExecutableElement)2 TypeElement (javax.lang.model.element.TypeElement)2 VariableElement (javax.lang.model.element.VariableElement)2 ExtensionDeclaration (org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclaration)2 DeclarationWalker (org.mule.runtime.api.meta.model.declaration.fluent.util.DeclarationWalker)2 Parameter (org.mule.runtime.extension.api.annotation.param.Parameter)2 ParameterGroup (org.mule.runtime.extension.api.annotation.param.ParameterGroup)2 MethodDocumentation (org.mule.runtime.module.extension.internal.capability.xml.schema.MethodDocumentation)2 IOException (java.io.IOException)1 URL (java.net.URL)1 List (java.util.List)1 IOUtils (org.apache.commons.io.IOUtils)1 BooleanType (org.mule.metadata.api.model.BooleanType)1 MetadataTypeVisitor (org.mule.metadata.api.visitor.MetadataTypeVisitor)1 ConfigurationDeclaration (org.mule.runtime.api.meta.model.declaration.fluent.ConfigurationDeclaration)1