Search in sources :

Example 1 with MethodDeclarationParameters

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();
    }
}
Also used : DeclaredTypeName(com.yahoo.aptutils.model.DeclaredTypeName) MethodDeclarationParameters(com.yahoo.aptutils.writer.parameters.MethodDeclarationParameters)

Example 2 with MethodDeclarationParameters

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();
}
Also used : DeclaredTypeName(com.yahoo.aptutils.model.DeclaredTypeName) Expression(com.yahoo.aptutils.writer.expressions.Expression) MethodDeclarationParameters(com.yahoo.aptutils.writer.parameters.MethodDeclarationParameters)

Example 3 with MethodDeclarationParameters

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);
}
Also used : MethodDeclarationParameters(com.yahoo.aptutils.writer.parameters.MethodDeclarationParameters)

Example 4 with MethodDeclarationParameters

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();
        }
    }
}
Also used : RowidPropertyGenerator(com.yahoo.squidb.processor.plugins.defaults.properties.generators.RowidPropertyGenerator) MethodDeclarationParameters(com.yahoo.aptutils.writer.parameters.MethodDeclarationParameters)

Example 5 with MethodDeclarationParameters

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();
}
Also used : MethodDeclarationParameters(com.yahoo.aptutils.writer.parameters.MethodDeclarationParameters)

Aggregations

MethodDeclarationParameters (com.yahoo.aptutils.writer.parameters.MethodDeclarationParameters)7 DeclaredTypeName (com.yahoo.aptutils.model.DeclaredTypeName)2 Expression (com.yahoo.aptutils.writer.expressions.Expression)2 ModelMethod (com.yahoo.squidb.annotations.ModelMethod)1 RowidPropertyGenerator (com.yahoo.squidb.processor.plugins.defaults.properties.generators.RowidPropertyGenerator)1 ArrayList (java.util.ArrayList)1