/** * Subclasses can override this hook to generate a custom method body for the property setter. This version of the * hook is deprecated, users should use {@link #writeGetterBody(JavaFileWriter, MethodDeclarationParameters)} * instead. */ @Deprecated protected void writeSetterBody(JavaFileWriter writer, String argName) throws IOException { writer.writeStatement(Expressions.callMethod("set", propertyName, argName)); writer.writeStringStatement("return this"); }
@Override protected void writeSetterBody(JavaFileWriter writer, MethodDeclarationParameters params) throws IOException { String argName = params.getArgumentNames().get(0); final String argAsString = argName + "AsString"; Expression condition = Expressions.fromString(argName + " == null"); Expression ifTrue = Expressions.fromString("null"); Expression ifFalse = Expressions.callMethodOn(argName, "name"); writer.writeFieldDeclaration(CoreTypes.JAVA_STRING, argAsString, new TernaryExpression(condition, ifTrue, ifFalse)); writer.writeStatement(Expressions.callMethod("set", propertyName, argAsString)); writer.writeStringStatement("return this"); }
.setArgumentNames(valuesName); writer.beginConstructorDeclaration(params) .writeStatement(Expressions.callMethod("this", valuesName, ModelFileWriter.PROPERTIES_ARRAY_NAME)) .finishMethodDefinition();
/** * Subclasses can override this hook to generate a custom method body for the property getter. This version of the * hook is deprecated, users should use {@link #writeGetterBody(JavaFileWriter, MethodDeclarationParameters)} * instead. */ @Deprecated protected void writeGetterBody(JavaFileWriter writer) throws IOException { writer.writeStatement(Expressions.callMethod("get", propertyName).returnExpr()); }
@Override protected void writeSetterBody(JavaFileWriter writer, MethodDeclarationParameters params) throws IOException { String argName = params.getArgumentNames().get(0); final String argAsString = argName + "AsString"; Expression condition = Expressions.fromString(argName + " == null"); Expression ifTrue = Expressions.fromString("null"); Expression ifFalse = Expressions.callMethodOn(argName, "name"); writer.writeFieldDeclaration(CoreTypes.JAVA_STRING, argAsString, new TernaryExpression(condition, ifTrue, ifFalse)); writer.writeStatement(Expressions.callMethod("set", propertyName, argAsString)); writer.writeStringStatement("return this"); }
private void emitTableModelMapper() throws IOException { writer.writeComment("--- mappers"); writer.writeFieldDeclaration(TypeConstants.TABLE_MAPPING_VISITORS, "tableMappingInfo", Expressions.callMethod("generateTableMappingVisitors", PROPERTIES_ARRAY_NAME, ALIASED_PROPERTY_ARRAY_NAME, BASE_PROPERTY_ARRAY_NAME), TypeConstants.PRIVATE_STATIC_FINAL) .writeNewline(); writer.writeAnnotation(CoreTypes.OVERRIDE) .beginMethodDefinition(GET_TABLE_MAPPING_VISITORS) .writeStringStatement("return tableMappingInfo") .finishMethodDefinition(); }
.setArgumentNames(valuesName); writer.beginConstructorDeclaration(params) .writeStatement(Expressions.callMethod("this", valuesName, ModelFileWriter.PROPERTIES_ARRAY_NAME)) .finishMethodDefinition();
@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()); }
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(); }
@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(); } }
/** * Subclasses can override this hook to generate a custom method body for the property setter. This version of the * hook is deprecated, users should use {@link #writeGetterBody(JavaFileWriter, MethodDeclarationParameters)} * instead. */ @Deprecated protected void writeSetterBody(JavaFileWriter writer, String argName) throws IOException { writer.writeStatement(Expressions.callMethod("set", propertyName, argName)); writer.writeStringStatement("return this"); }
/** * Subclasses can override this hook to generate a custom method body for the property getter. This version of the * hook is deprecated, users should use {@link #writeGetterBody(JavaFileWriter, MethodDeclarationParameters)} * instead. */ @Deprecated protected void writeGetterBody(JavaFileWriter writer) throws IOException { writer.writeStatement(Expressions.callMethod("get", propertyName).returnExpr()); }
@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()); }
private void emitTableModelMapper() throws IOException { writer.writeComment("--- mappers"); writer.writeFieldDeclaration(TypeConstants.TABLE_MAPPING_VISITORS, "tableMappingInfo", Expressions.callMethod("generateTableMappingVisitors", PROPERTIES_ARRAY_NAME, ALIASED_PROPERTY_ARRAY_NAME, BASE_PROPERTY_ARRAY_NAME), TypeConstants.PRIVATE_STATIC_FINAL) .writeNewline(); writer.writeAnnotation(CoreTypes.OVERRIDE) .beginMethodDefinition(GET_TABLE_MAPPING_VISITORS) .writeStringStatement("return tableMappingInfo") .finishMethodDefinition(); }
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(); }
@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(); } }