Search in sources :

Example 1 with DefaultValue

use of org.jboss.forge.roaster.model.source.AnnotationElementSource.DefaultValue in project morphia by mongodb.

the class AnnotationBuilders method setDefaults.

private void setDefaults(MethodSource<JavaClassSource> constructor, JavaAnnotationSource source) {
    String body = "";
    List<AnnotationElementSource> elements = source.getAnnotationElements();
    for (AnnotationElementSource element : elements) {
        DefaultValue defaultValue = element.getDefaultValue();
        if (defaultValue != null) {
            String literal = defaultValue.getLiteral();
            var annot = defaultValue.getAnnotation();
            if (annot != null) {
                literal = format("%sBuilder.%s().build()", annot.getQualifiedName().replace(annot.getName(), "") + "builders." + annot.getName(), builderMethodName(annot.getName()));
            } else if (literal != null && element.getType().isArray()) {
                literal = format("new %s%s", element.getType().getName(), literal);
            }
            if (literal != null) {
                body += format("annotation.%s = %s;%n", element.getName(), literal);
            }
        }
    }
    constructor.setBody(body);
}
Also used : DefaultValue(org.jboss.forge.roaster.model.source.AnnotationElementSource.DefaultValue) AnnotationElementSource(org.jboss.forge.roaster.model.source.AnnotationElementSource)

Aggregations

AnnotationElementSource (org.jboss.forge.roaster.model.source.AnnotationElementSource)1 DefaultValue (org.jboss.forge.roaster.model.source.AnnotationElementSource.DefaultValue)1