use of com.yahoo.aptutils.writer.expressions.Expression in project squidb by yahoo.
the class ConstructorPlugin method emitConstructors.
@Override
public void emitConstructors(JavaFileWriter writer) throws IOException {
writer.writeComment("--- default constructors");
MethodDeclarationParameters params = new MethodDeclarationParameters().setModifiers(Modifier.PUBLIC).setConstructorName(modelSpec.getGeneratedClassName());
writer.beginConstructorDeclaration(params).writeStringStatement("super()").finishMethodDefinition();
DeclaredTypeName squidCursorType = TypeConstants.SQUID_CURSOR.clone();
squidCursorType.setTypeArgs(Collections.singletonList(modelSpec.getGeneratedClassName()));
params.setArgumentTypes(squidCursorType).setArgumentNames("cursor");
writer.beginConstructorDeclaration(params).writeStringStatement("this()").writeStringStatement("readPropertiesFromCursor(cursor)").finishMethodDefinition();
String valuesName = "values";
DeclaredTypeName valuesType = TypeConstants.MAP_VALUES;
params.setArgumentTypes(Collections.singletonList(valuesType)).setArgumentNames(valuesName);
writer.beginConstructorDeclaration(params).writeStatement(Expressions.callMethod("this", valuesName, ModelFileWriter.PROPERTIES_ARRAY_NAME)).finishMethodDefinition();
String methodName = "readPropertiesFromMap";
params.setArgumentTypes(Arrays.asList(valuesType, TypeConstants.PROPERTY_VARARGS)).setArgumentNames(valuesName, "withProperties");
writer.beginConstructorDeclaration(params).writeStringStatement("this()").writeStringStatement(methodName + "(" + valuesName + ", withProperties)").finishMethodDefinition();
MethodDeclarationParameters cloneParams = new MethodDeclarationParameters().setModifiers(Modifier.PUBLIC).setMethodName("clone").setReturnType(modelSpec.getGeneratedClassName());
Expression cloneBody = Expressions.callMethodOn("super", "clone").cast(modelSpec.getGeneratedClassName()).returnExpr();
writer.writeAnnotation(CoreTypes.OVERRIDE);
writer.beginMethodDefinition(cloneParams).writeStatement(cloneBody).finishMethodDefinition();
}
use of com.yahoo.aptutils.writer.expressions.Expression in project squidb by yahoo.
the class JSONPropertyGenerator method getTypeExpression.
private Expression getTypeExpression(DeclaredTypeName fieldType) {
List<? extends TypeName> typeArgs = fieldType.getTypeArgs();
if (AptUtils.isEmpty(typeArgs)) {
return Expressions.classObject(fieldType);
} else {
List<Expression> parameterizedTypeBuilderArgs = new ArrayList<>();
parameterizedTypeBuilderArgs.add(Expressions.classObject(fieldType));
for (TypeName typeArg : typeArgs) {
// The cast to DeclaredTypeName is safe because we recursively check all type args before constructing
// an instance of this property generator
parameterizedTypeBuilderArgs.add(getTypeExpression((DeclaredTypeName) typeArg));
}
return Expressions.staticMethod(JSONTypes.PARAMETERIZED_TYPE_BUILDER, "build", parameterizedTypeBuilderArgs);
}
}
use of com.yahoo.aptutils.writer.expressions.Expression in project squidb by yahoo.
the class JSONPropertyGenerator method writeSetterBody.
@Override
protected void writeSetterBody(JavaFileWriter writer, MethodDeclarationParameters params) throws IOException {
Expression typeExpression = getTypeExpression(fieldType);
writer.writeStatement(Expressions.staticMethod(JSONTypes.JSON_PROPERTY_SUPPORT, "setValueAsJSON", "this", propertyName, params.getArgumentNames().get(0), typeExpression));
writer.writeStringStatement("return this");
}
use of com.yahoo.aptutils.writer.expressions.Expression in project squidb by yahoo.
the class JSONPropertyGenerator method writeGetterBody.
@Override
protected void writeGetterBody(JavaFileWriter writer, MethodDeclarationParameters params) throws IOException {
Expression typeExpression = getTypeExpression(fieldType);
writer.writeStatement(Expressions.staticMethod(JSONTypes.JSON_PROPERTY_SUPPORT, "getValueFromJSON", "this", propertyName, typeExpression).returnExpr());
}
use of com.yahoo.aptutils.writer.expressions.Expression in project squidb by yahoo.
the class ViewModelFileWriter method emitSqlTableDeclaration.
private void emitSqlTableDeclaration(boolean view) throws IOException {
writer.writeComment("--- " + (view ? "view" : "subquery") + " declaration");
String name = "\"" + modelSpec.getSpecAnnotation().viewName().trim() + "\"";
if (modelSpec.getQueryElement() != null) {
Expression queryReference = Expressions.staticReference(modelSpec.getModelSpecName(), modelSpec.getQueryElement().getSimpleName().toString()).callMethod("selectMore", ALIASED_PROPERTY_ARRAY_NAME);
if (modelSpec.getViewQueryAnnotation().freeze()) {
queryReference = queryReference.callMethod("freeze");
}
writer.writeFieldDeclaration(TypeConstants.QUERY, QUERY_NAME, queryReference, TypeConstants.PUBLIC_STATIC_FINAL);
Expression initializer = constructInitializer(name, view);
writer.writeFieldDeclaration(view ? TypeConstants.VIEW : TypeConstants.SUBQUERY_TABLE, view ? VIEW_NAME : SUBQUERY_NAME, initializer, TypeConstants.PUBLIC_STATIC_FINAL);
} else {
writer.writeFieldDeclaration(CoreTypes.JAVA_STRING, view ? "VIEW_NAME" : "SUBQUERY_NAME", Expressions.fromString(name), TypeConstants.PUBLIC_STATIC_FINAL);
}
writer.writeNewline();
}
Aggregations