use of com.yahoo.aptutils.writer.expressions.Expression 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());
}
use of com.yahoo.aptutils.writer.expressions.Expression in project squidb by yahoo.
the class ViewModelFileWriter method emitUnaliasedPropertyArray.
private void emitUnaliasedPropertyArray() throws IOException {
writer.writeComment("--- unaliased property references");
Expression basePropertiesInit = Expressions.block(new Expression() {
@Override
public boolean writeExpression(JavaFileWriter writer) throws IOException {
return emitPropertyReferenceArrayBody(false);
}
}, false, false, false, false);
writer.writeFieldDeclaration(TypeConstants.PROPERTY_ARRAY, BASE_PROPERTY_ARRAY_NAME, basePropertiesInit, TypeConstants.PRIVATE_STATIC_FINAL).writeNewline();
}
use of com.yahoo.aptutils.writer.expressions.Expression in project squidb by yahoo.
the class ViewModelFileWriter method emitAliasedPropertyArray.
private void emitAliasedPropertyArray() throws IOException {
writer.writeComment("--- aliased property references");
Expression aliasedPropertiesInit = Expressions.block(new Expression() {
@Override
public boolean writeExpression(JavaFileWriter writer) throws IOException {
return emitPropertyReferenceArrayBody(true);
}
}, false, false, false, false);
writer.writeFieldDeclaration(TypeConstants.PROPERTY_ARRAY, ALIASED_PROPERTY_ARRAY_NAME, aliasedPropertiesInit, TypeConstants.PUBLIC_STATIC_FINAL).writeNewline();
writer.beginInitializerBlock(true, true);
writer.writeStatement(Expressions.callMethod("validateAliasedProperties", ALIASED_PROPERTY_ARRAY_NAME));
writer.finishInitializerBlock(false, true);
writer.writeNewline();
}
use of com.yahoo.aptutils.writer.expressions.Expression in project squidb by yahoo.
the class ViewModelFileWriter method emitSinglePropertyDeclaration.
private void emitSinglePropertyDeclaration(PropertyGenerator generator, int index) throws IOException {
modelSpec.getPluginBundle().beforeEmitPropertyDeclaration(writer, generator);
DeclaredTypeName type = generator.getPropertyType();
String fieldToQualify = ALIASED_PROPERTY_ARRAY_NAME + "[" + index + "]";
Expression expressionToCast;
if (modelSpec.getQueryElement() != null) {
String callOn = modelSpec.getSpecAnnotation().isSubquery() ? SUBQUERY_NAME : VIEW_NAME;
expressionToCast = Expressions.callMethodOn(callOn, "qualifyField", fieldToQualify);
} else {
expressionToCast = Expressions.reference(fieldToQualify);
}
writer.writeFieldDeclaration(type, generator.getPropertyName(), expressionToCast.cast(type), TypeConstants.PUBLIC_STATIC_FINAL).writeNewline();
modelSpec.getPluginBundle().afterEmitPropertyDeclaration(writer, generator);
}
use of com.yahoo.aptutils.writer.expressions.Expression in project squidb by yahoo.
the class EnumPropertyGenerator method writeGetterBody.
@Override
protected void writeGetterBody(JavaFileWriter writer, MethodDeclarationParameters params) throws IOException {
final String value = "value";
writer.writeFieldDeclaration(CoreTypes.JAVA_STRING, value, Expressions.callMethod("get", propertyName));
Expression condition = Expressions.fromString(value + " == null");
Expression ifTrue = Expressions.fromString("null");
Expression ifFalse = Expressions.staticMethod(enumType, "valueOf", value);
TernaryExpression ternary = new TernaryExpression(condition, ifTrue, ifFalse);
writer.writeStatement(ternary.returnExpr());
}
Aggregations