Search in sources :

Example 11 with Metadata

use of org.apache.camel.spi.Metadata in project camel by apache.

the class SpringAnnotationProcessor method processAttribute.

private boolean processAttribute(ProcessingEnvironment processingEnv, RoundEnvironment roundEnv, TypeElement originalClassType, TypeElement classElement, VariableElement fieldElement, String fieldName, XmlAttribute attribute, Set<EipOption> eipOptions, String prefix, String modelName) {
    Elements elementUtils = processingEnv.getElementUtils();
    String name = attribute.name();
    if (isNullOrEmpty(name) || "##default".equals(name)) {
        name = fieldName;
    }
    name = prefix + name;
    TypeMirror fieldType = fieldElement.asType();
    String fieldTypeName = fieldType.toString();
    TypeElement fieldTypeElement = findTypeElement(processingEnv, roundEnv, fieldTypeName);
    String defaultValue = findDefaultValue(fieldElement, fieldTypeName);
    String docComment = findJavaDoc(elementUtils, fieldElement, fieldName, name, classElement, true);
    if (isNullOrEmpty(docComment)) {
        Metadata metadata = fieldElement.getAnnotation(Metadata.class);
        docComment = metadata != null ? metadata.description() : null;
    }
    boolean required = attribute.required();
    // metadata may overrule element required
    required = findRequired(fieldElement, required);
    // gather enums
    Set<String> enums = new TreeSet<String>();
    boolean isEnum = fieldTypeElement != null && fieldTypeElement.getKind() == ElementKind.ENUM;
    if (isEnum) {
        TypeElement enumClass = findTypeElement(processingEnv, roundEnv, fieldTypeElement.asType().toString());
        // find all the enum constants which has the possible enum value that can be used
        List<VariableElement> fields = ElementFilter.fieldsIn(enumClass.getEnclosedElements());
        for (VariableElement var : fields) {
            if (var.getKind() == ElementKind.ENUM_CONSTANT) {
                String val = var.toString();
                enums.add(val);
            }
        }
    }
    boolean deprecated = fieldElement.getAnnotation(Deprecated.class) != null;
    String displayName = null;
    Metadata metadata = fieldElement.getAnnotation(Metadata.class);
    if (metadata != null) {
        displayName = metadata.displayName();
    }
    // special for id as its inherited from camel-core
    if ("id".equals(name) && isNullOrEmpty(docComment)) {
        if ("CamelContextFactoryBean".equals(originalClassType.getSimpleName().toString())) {
            docComment = "Sets the id (name) of this CamelContext";
        } else {
            docComment = "Sets the id of this node";
        }
    }
    EipOption ep = new EipOption(name, displayName, "attribute", fieldTypeName, required, defaultValue, docComment, deprecated, isEnum, enums, false, null, false);
    eipOptions.add(ep);
    return false;
}
Also used : TypeMirror(javax.lang.model.type.TypeMirror) TypeElement(javax.lang.model.element.TypeElement) AnnotationProcessorHelper.findTypeElement(org.apache.camel.tools.apt.AnnotationProcessorHelper.findTypeElement) TreeSet(java.util.TreeSet) Metadata(org.apache.camel.spi.Metadata) VariableElement(javax.lang.model.element.VariableElement) Elements(javax.lang.model.util.Elements) XmlElements(javax.xml.bind.annotation.XmlElements)

Example 12 with Metadata

use of org.apache.camel.spi.Metadata in project camel by apache.

the class CoreEipAnnotationProcessor method findEipModelProperties.

protected EipModel findEipModelProperties(ProcessingEnvironment processingEnv, RoundEnvironment roundEnv, TypeElement classElement, String javaTypeName, String name) {
    EipModel model = new EipModel();
    model.setJavaType(javaTypeName);
    model.setName(name);
    boolean deprecated = classElement.getAnnotation(Deprecated.class) != null;
    model.setDeprecated(deprecated);
    Metadata metadata = classElement.getAnnotation(Metadata.class);
    if (metadata != null) {
        if (!Strings.isNullOrEmpty(metadata.label())) {
            model.setLabel(metadata.label());
        }
        if (!Strings.isNullOrEmpty(metadata.title())) {
            model.setTitle(metadata.title());
        }
        if (!Strings.isNullOrEmpty(metadata.firstVersion())) {
            model.setFirstVersion(metadata.firstVersion());
        }
    }
    // favor to use class javadoc of component as description
    if (model.getJavaType() != null) {
        Elements elementUtils = processingEnv.getElementUtils();
        TypeElement typeElement = findTypeElement(processingEnv, roundEnv, model.getJavaType());
        if (typeElement != null) {
            String doc = elementUtils.getDocComment(typeElement);
            if (doc != null) {
                // need to sanitize the description first (we only want a summary)
                doc = sanitizeDescription(doc, true);
                // the javadoc may actually be empty, so only change the doc if we got something
                if (!Strings.isNullOrEmpty(doc)) {
                    model.setDescription(doc);
                }
            }
        }
    }
    return model;
}
Also used : TypeElement(javax.lang.model.element.TypeElement) AnnotationProcessorHelper.findTypeElement(org.apache.camel.tools.apt.AnnotationProcessorHelper.findTypeElement) Metadata(org.apache.camel.spi.Metadata) Elements(javax.lang.model.util.Elements) XmlElements(javax.xml.bind.annotation.XmlElements)

Example 13 with Metadata

use of org.apache.camel.spi.Metadata in project camel by apache.

the class CoreEipAnnotationProcessor method processVerbs.

/**
     * Special for processing an @XmlElementRef verbs field (rest-dsl)
     */
private void processVerbs(ProcessingEnvironment processingEnv, RoundEnvironment roundEnv, TypeElement originalClassType, XmlElementRef elementRef, VariableElement fieldElement, String fieldName, Set<EipOption> eipOptions, String prefix) {
    Elements elementUtils = processingEnv.getElementUtils();
    if ("verbs".equals(fieldName) && supportOutputs(originalClassType)) {
        String kind = "element";
        String name = elementRef.name();
        if (isNullOrEmpty(name) || "##default".equals(name)) {
            name = fieldName;
        }
        name = prefix + name;
        TypeMirror fieldType = fieldElement.asType();
        String fieldTypeName = fieldType.toString();
        String docComment = findJavaDoc(elementUtils, fieldElement, fieldName, name, originalClassType, true);
        // gather oneOf which extends any of the output base classes
        Set<String> oneOfTypes = new TreeSet<String>();
        // find all classes that has that superClassName
        Set<TypeElement> children = new LinkedHashSet<TypeElement>();
        for (String superclass : ONE_OF_VERBS) {
            findTypeElementChildren(processingEnv, roundEnv, children, superclass);
        }
        for (TypeElement child : children) {
            XmlRootElement rootElement = child.getAnnotation(XmlRootElement.class);
            if (rootElement != null) {
                String childName = rootElement.name();
                if (childName != null) {
                    oneOfTypes.add(childName);
                }
            }
        }
        String displayName = null;
        Metadata metadata = fieldElement.getAnnotation(Metadata.class);
        if (metadata != null) {
            displayName = metadata.displayName();
        }
        EipOption ep = new EipOption(name, displayName, kind, fieldTypeName, true, "", docComment, false, false, null, true, oneOfTypes, false);
        eipOptions.add(ep);
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) XmlRootElement(javax.xml.bind.annotation.XmlRootElement) TypeMirror(javax.lang.model.type.TypeMirror) TreeSet(java.util.TreeSet) TypeElement(javax.lang.model.element.TypeElement) AnnotationProcessorHelper.findTypeElement(org.apache.camel.tools.apt.AnnotationProcessorHelper.findTypeElement) Metadata(org.apache.camel.spi.Metadata) Elements(javax.lang.model.util.Elements) XmlElements(javax.xml.bind.annotation.XmlElements)

Example 14 with Metadata

use of org.apache.camel.spi.Metadata in project camel by apache.

the class CoreEipAnnotationProcessor method findDefaultValue.

private String findDefaultValue(VariableElement fieldElement, String fieldTypeName) {
    String defaultValue = null;
    Metadata metadata = fieldElement.getAnnotation(Metadata.class);
    if (metadata != null) {
        if (!Strings.isNullOrEmpty(metadata.defaultValue())) {
            defaultValue = metadata.defaultValue();
        }
    }
    if (defaultValue == null) {
        // if its a boolean type, then we use false as the default
        if ("boolean".equals(fieldTypeName) || "java.lang.Boolean".equals(fieldTypeName)) {
            defaultValue = "false";
        }
    }
    return defaultValue;
}
Also used : Metadata(org.apache.camel.spi.Metadata)

Example 15 with Metadata

use of org.apache.camel.spi.Metadata in project camel by apache.

the class CoreEipAnnotationProcessor method processValue.

private void processValue(ProcessingEnvironment processingEnv, RoundEnvironment roundEnv, TypeElement originalClassType, TypeElement classElement, VariableElement fieldElement, String fieldName, XmlValue value, Set<EipOption> eipOptions, String prefix, String modelName) {
    Elements elementUtils = processingEnv.getElementUtils();
    // XmlValue has no name attribute
    String name = fieldName;
    if ("method".equals(modelName) || "tokenize".equals(modelName) || "xtokenize".equals(modelName)) {
        // skip expression attribute on these three languages as they are solely configured using attributes
        if ("expression".equals(name)) {
            return;
        }
    }
    name = prefix + name;
    TypeMirror fieldType = fieldElement.asType();
    String fieldTypeName = fieldType.toString();
    String defaultValue = findDefaultValue(fieldElement, fieldTypeName);
    String docComment = findJavaDoc(elementUtils, fieldElement, fieldName, name, classElement, true);
    boolean required = true;
    // metadata may overrule element required
    required = findRequired(fieldElement, required);
    boolean deprecated = fieldElement.getAnnotation(Deprecated.class) != null;
    String displayName = null;
    Metadata metadata = fieldElement.getAnnotation(Metadata.class);
    if (metadata != null) {
        displayName = metadata.displayName();
    }
    EipOption ep = new EipOption(name, displayName, "value", fieldTypeName, required, defaultValue, docComment, deprecated, false, null, false, null, false);
    eipOptions.add(ep);
}
Also used : TypeMirror(javax.lang.model.type.TypeMirror) Metadata(org.apache.camel.spi.Metadata) Elements(javax.lang.model.util.Elements) XmlElements(javax.xml.bind.annotation.XmlElements)

Aggregations

Metadata (org.apache.camel.spi.Metadata)17 Elements (javax.lang.model.util.Elements)14 TypeMirror (javax.lang.model.type.TypeMirror)13 XmlElements (javax.xml.bind.annotation.XmlElements)12 TypeElement (javax.lang.model.element.TypeElement)11 AnnotationProcessorHelper.findTypeElement (org.apache.camel.tools.apt.AnnotationProcessorHelper.findTypeElement)11 TreeSet (java.util.TreeSet)9 LinkedHashSet (java.util.LinkedHashSet)8 VariableElement (javax.lang.model.element.VariableElement)6 XmlRootElement (javax.xml.bind.annotation.XmlRootElement)5 XmlElement (javax.xml.bind.annotation.XmlElement)2 AsPredicate (org.apache.camel.spi.AsPredicate)2 HashSet (java.util.HashSet)1 ExecutableElement (javax.lang.model.element.ExecutableElement)1 UriParam (org.apache.camel.spi.UriParam)1 UriParams (org.apache.camel.spi.UriParams)1 UriPath (org.apache.camel.spi.UriPath)1 ComponentOption (org.apache.camel.tools.apt.model.ComponentOption)1 EndpointOption (org.apache.camel.tools.apt.model.EndpointOption)1 EndpointPath (org.apache.camel.tools.apt.model.EndpointPath)1