use of com.yahoo.aptutils.writer.parameters.MethodDeclarationParameters in project squidb by yahoo.
the class AndroidModelPlugin method emitConstructors.
@Override
public void emitConstructors(JavaFileWriter writer) throws IOException {
if (generateConstructors) {
String valuesName = "contentValues";
DeclaredTypeName valuesType = TypeConstants.CONTENT_VALUES;
MethodDeclarationParameters params = new MethodDeclarationParameters().setModifiers(Modifier.PUBLIC).setConstructorName(modelSpec.getGeneratedClassName());
params.setArgumentTypes(Collections.singletonList(valuesType)).setArgumentNames(valuesName);
writer.beginConstructorDeclaration(params).writeStatement(Expressions.callMethod("this", valuesName, ModelFileWriter.PROPERTIES_ARRAY_NAME)).finishMethodDefinition();
String methodName = "readPropertiesFromContentValues";
params.setArgumentTypes(Arrays.asList(valuesType, TypeConstants.PROPERTY_VARARGS)).setArgumentNames(valuesName, "withProperties");
writer.beginConstructorDeclaration(params).writeStringStatement("this()").writeStringStatement(methodName + "(" + valuesName + ", withProperties)").finishMethodDefinition();
}
}
use of com.yahoo.aptutils.writer.parameters.MethodDeclarationParameters 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.parameters.MethodDeclarationParameters in project squidb by yahoo.
the class BasicPropertyGenerator method emitGetter.
@Override
public final void emitGetter(JavaFileWriter writer) throws IOException {
if (isDeprecated) {
return;
}
MethodDeclarationParameters params = getterMethodParams();
modelSpec.getPluginBundle().beforeEmitGetter(writer, this, params);
writer.beginMethodDefinition(params);
writeGetterBody(writer, params);
writer.finishMethodDefinition();
modelSpec.getPluginBundle().afterEmitGetter(writer, this, params);
}
use of com.yahoo.aptutils.writer.parameters.MethodDeclarationParameters in project squidb by yahoo.
the class TableModelSpecFieldPlugin method emitMethods.
@Override
public void emitMethods(JavaFileWriter writer) throws IOException {
// overridden setRowId with appropriate return type
if (!pluginEnv.hasSquidbOption(PluginEnvironment.OPTIONS_DISABLE_DEFAULT_GETTERS_AND_SETTERS)) {
RowidPropertyGenerator rowidPropertyGenerator = modelSpec.getMetadata(METADATA_KEY_ROWID_ALIAS_PROPERTY_GENERATOR);
if (rowidPropertyGenerator != null && !"setRowId".equals(rowidPropertyGenerator.setterMethodName())) {
MethodDeclarationParameters params = new MethodDeclarationParameters().setModifiers(Modifier.PUBLIC).setMethodName("setRowId").setArgumentTypes(CoreTypes.PRIMITIVE_LONG).setArgumentNames("rowid").setReturnType(modelSpec.getGeneratedClassName());
writer.writeAnnotation(CoreTypes.OVERRIDE).beginMethodDefinition(params).writeStringStatement("super.setRowId(rowid)").writeStringStatement("return this").finishMethodDefinition();
}
}
}
use of com.yahoo.aptutils.writer.parameters.MethodDeclarationParameters in project squidb by yahoo.
the class TableModelSpecFieldPlugin method writeRowidSupportMethods.
private void writeRowidSupportMethods(JavaFileWriter writer, String propertyName) throws IOException {
// Write TABLE.setRowIdProperty call
writer.beginInitializerBlock(true, true);
writer.writeStatement(Expressions.callMethodOn(TableModelFileWriter.TABLE_NAME, "setRowIdProperty", propertyName));
writer.finishInitializerBlock(true, true);
writer.writeNewline();
// Write getRowIdProperty() method
writer.writeAnnotation(CoreTypes.OVERRIDE);
MethodDeclarationParameters params = new MethodDeclarationParameters().setModifiers(Modifier.PUBLIC).setReturnType(TypeConstants.LONG_PROPERTY).setMethodName("getRowIdProperty");
writer.beginMethodDefinition(params);
writer.writeStringStatement("return " + propertyName);
writer.finishMethodDefinition();
}
Aggregations