Search in sources :

Example 1 with Alias

use of com.yahoo.squidb.annotations.Alias in project squidb by yahoo.

the class ViewModelFileWriter method emitPropertyReferenceArrayBody.

private boolean emitPropertyReferenceArrayBody(boolean alias) throws IOException {
    for (PropertyGenerator propertyGenerator : modelSpec.getPropertyGenerators()) {
        Expression reference = Expressions.staticReference(modelSpec.getModelSpecName(), propertyGenerator.getPropertyName());
        if (alias) {
            VariableElement field = propertyGenerator.getField();
            if (field != null) {
                Alias aliasAnnotation = field.getAnnotation(Alias.class);
                if (aliasAnnotation != null && !AptUtils.isEmpty(aliasAnnotation.value().trim())) {
                    reference = reference.callMethod("as", "\"" + aliasAnnotation.value().trim() + "\"");
                }
            }
        }
        writer.writeExpression(reference);
        writer.appendString(",\n");
    }
    return !AptUtils.isEmpty(modelSpec.getPropertyGenerators());
}
Also used : Expression(com.yahoo.aptutils.writer.expressions.Expression) Alias(com.yahoo.squidb.annotations.Alias) PropertyGenerator(com.yahoo.squidb.processor.plugins.defaults.properties.generators.PropertyGenerator) VariableElement(javax.lang.model.element.VariableElement)

Aggregations

Expression (com.yahoo.aptutils.writer.expressions.Expression)1 Alias (com.yahoo.squidb.annotations.Alias)1 PropertyGenerator (com.yahoo.squidb.processor.plugins.defaults.properties.generators.PropertyGenerator)1 VariableElement (javax.lang.model.element.VariableElement)1