use of org.eclipse.xtend2.lib.StringConcatenation in project mechanoid by robotoworks.
the class ActiveRecordGenerator method _generateProjectionIndicesMembers.
protected CharSequence _generateProjectionIndicesMembers(final CreateTableStatement stmt) {
StringConcatenation _builder = new StringConcatenation();
int counter = (-1);
_builder.newLineIfNotEmpty();
{
EList<ColumnSource> _columnDefs = stmt.getColumnDefs();
for (final ColumnSource col : _columnDefs) {
_builder.append("int ");
String _name = col.getName();
String _underscore = Strings.underscore(_name);
String _upperCase = _underscore.toUpperCase();
_builder.append(_upperCase, "");
_builder.append(" = ");
_builder.append(counter = (counter + 1), "");
_builder.append(";");
_builder.newLineIfNotEmpty();
}
}
return _builder;
}
use of org.eclipse.xtend2.lib.StringConcatenation in project mechanoid by robotoworks.
the class ActiveRecordGenerator method _generateParcelDeserializationStatements.
protected CharSequence _generateParcelDeserializationStatements(final CreateViewStatement stmt) {
StringConcatenation _builder = new StringConcatenation();
int counter = (-1);
_builder.newLineIfNotEmpty();
ArrayList<ColumnSource> cols = ModelUtil.getViewResultColumns(stmt);
_builder.newLineIfNotEmpty();
{
final Function1<ColumnSource, Boolean> _function = new Function1<ColumnSource, Boolean>() {
public Boolean apply(final ColumnSource it) {
String _name = it.getName();
boolean _equals = _name.equals("_id");
return Boolean.valueOf((!_equals));
}
};
Iterable<ColumnSource> _filter = IterableExtensions.<ColumnSource>filter(cols, _function);
for (final ColumnSource item : _filter) {
ResultColumn col = ((ResultColumn) item);
_builder.newLineIfNotEmpty();
ColumnType type = ModelUtil.getInferredColumnType(col);
_builder.newLineIfNotEmpty();
{
boolean _equals = Objects.equal(type, ColumnType.BOOLEAN);
if (_equals) {
_builder.append("m");
String _name = col.getName();
String _pascalize = Strings.pascalize(_name);
_builder.append(_pascalize, "");
_builder.append(" = (in.readInt() > 0);");
_builder.newLineIfNotEmpty();
} else {
boolean _equals_1 = Objects.equal(type, ColumnType.BLOB);
if (_equals_1) {
_builder.append("m");
String _name_1 = col.getName();
String _pascalize_1 = Strings.pascalize(_name_1);
_builder.append(_pascalize_1, "");
_builder.append(" = in.createByteArray();");
_builder.newLineIfNotEmpty();
} else {
_builder.append("m");
String _name_2 = col.getName();
String _pascalize_2 = Strings.pascalize(_name_2);
_builder.append(_pascalize_2, "");
_builder.append(" = in.read");
String _javaTypeName = ModelUtil.toJavaTypeName(type);
String _pascalize_3 = Strings.pascalize(_javaTypeName);
_builder.append(_pascalize_3, "");
_builder.append("();");
_builder.newLineIfNotEmpty();
}
}
}
}
}
_builder.newLine();
_builder.append("boolean[] dirtyFlags = new boolean[");
int _size = cols.size();
int _minus = (_size - 1);
_builder.append(_minus, "");
_builder.append("];");
_builder.newLineIfNotEmpty();
_builder.append("in.readBooleanArray(dirtyFlags);");
_builder.newLine();
{
final Function1<ColumnSource, Boolean> _function_1 = new Function1<ColumnSource, Boolean>() {
public Boolean apply(final ColumnSource it) {
String _name = it.getName();
boolean _equals = _name.equals("_id");
return Boolean.valueOf((!_equals));
}
};
Iterable<ColumnSource> _filter_1 = IterableExtensions.<ColumnSource>filter(cols, _function_1);
for (final ColumnSource col_1 : _filter_1) {
_builder.append("m");
String _name_3 = col_1.getName();
String _pascalize_4 = Strings.pascalize(_name_3);
_builder.append(_pascalize_4, "");
_builder.append("Dirty = dirtyFlags[");
_builder.append(counter = (counter + 1), "");
_builder.append("];");
_builder.newLineIfNotEmpty();
}
}
return _builder;
}
use of org.eclipse.xtend2.lib.StringConcatenation in project mechanoid by robotoworks.
the class ActiveRecordGenerator method _generateSetFromCursorStatements.
protected CharSequence _generateSetFromCursorStatements(final CreateViewStatement stmt) {
StringConcatenation _builder = new StringConcatenation();
ArrayList<ColumnSource> cols = ModelUtil.getViewResultColumns(stmt);
_builder.newLineIfNotEmpty();
{
final Function1<ColumnSource, Boolean> _function = new Function1<ColumnSource, Boolean>() {
public Boolean apply(final ColumnSource it) {
String _name = it.getName();
boolean _equals = _name.equals("_id");
return Boolean.valueOf((!_equals));
}
};
Iterable<ColumnSource> _filter = IterableExtensions.<ColumnSource>filter(cols, _function);
for (final ColumnSource item : _filter) {
ResultColumn col = ((ResultColumn) item);
_builder.newLineIfNotEmpty();
ColumnType type = ModelUtil.getInferredColumnType(col);
_builder.newLineIfNotEmpty();
{
boolean _equals = Objects.equal(type, ColumnType.BOOLEAN);
if (_equals) {
_builder.append("set");
String _name = col.getName();
String _pascalize = Strings.pascalize(_name);
_builder.append(_pascalize, "");
_builder.append("(c.getInt(Indices.");
String _name_1 = col.getName();
String _underscore = Strings.underscore(_name_1);
String _upperCase = _underscore.toUpperCase();
_builder.append(_upperCase, "");
_builder.append(") > 0);");
_builder.newLineIfNotEmpty();
} else {
boolean _equals_1 = Objects.equal(type, ColumnType.BLOB);
if (_equals_1) {
_builder.append("set");
String _name_2 = col.getName();
String _pascalize_1 = Strings.pascalize(_name_2);
_builder.append(_pascalize_1, "");
_builder.append("(c.getBlob(Indices.");
String _name_3 = col.getName();
String _underscore_1 = Strings.underscore(_name_3);
String _upperCase_1 = _underscore_1.toUpperCase();
_builder.append(_upperCase_1, "");
_builder.append("));");
_builder.newLineIfNotEmpty();
} else {
_builder.append("set");
String _name_4 = col.getName();
String _pascalize_2 = Strings.pascalize(_name_4);
_builder.append(_pascalize_2, "");
_builder.append("(c.get");
String _javaTypeName = ModelUtil.toJavaTypeName(type);
String _pascalize_3 = Strings.pascalize(_javaTypeName);
_builder.append(_pascalize_3, "");
_builder.append("(Indices.");
String _name_5 = col.getName();
String _underscore_2 = Strings.underscore(_name_5);
String _upperCase_2 = _underscore_2.toUpperCase();
_builder.append(_upperCase_2, "");
_builder.append("));");
_builder.newLineIfNotEmpty();
}
}
}
}
}
return _builder;
}
use of org.eclipse.xtend2.lib.StringConcatenation in project mechanoid by robotoworks.
the class ActiveRecordGenerator method _generateBuilderStatements.
protected CharSequence _generateBuilderStatements(final CreateViewStatement stmt) {
StringConcatenation _builder = new StringConcatenation();
ArrayList<ColumnSource> cols = ModelUtil.getViewResultColumns(stmt);
_builder.newLineIfNotEmpty();
{
final Function1<ColumnSource, Boolean> _function = new Function1<ColumnSource, Boolean>() {
public Boolean apply(final ColumnSource it) {
String _name = it.getName();
boolean _equals = _name.equals("_id");
return Boolean.valueOf((!_equals));
}
};
Iterable<ColumnSource> _filter = IterableExtensions.<ColumnSource>filter(cols, _function);
for (final ColumnSource col : _filter) {
_builder.append("if(m");
String _name = col.getName();
String _pascalize = Strings.pascalize(_name);
_builder.append(_pascalize, "");
_builder.append("Dirty) {");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("builder.set");
String _name_1 = col.getName();
String _pascalize_1 = Strings.pascalize(_name_1);
_builder.append(_pascalize_1, "\t");
_builder.append("(m");
String _name_2 = col.getName();
String _pascalize_2 = Strings.pascalize(_name_2);
_builder.append(_pascalize_2, "\t");
_builder.append(");");
_builder.newLineIfNotEmpty();
_builder.append("}");
_builder.newLine();
}
}
return _builder;
}
use of org.eclipse.xtend2.lib.StringConcatenation in project mechanoid by robotoworks.
the class ContentProviderContractGenerator method generateContractItem.
public CharSequence generateContractItem(final Model model, final SqliteDatabaseSnapshot snapshot, final TableDefinition stmt) {
StringConcatenation _builder = new StringConcatenation();
_builder.append("/**");
_builder.newLine();
_builder.append(" ");
_builder.append("* <p>Column definitions and helper methods to work with the ");
String _name = stmt.getName();
String _pascalize = Strings.pascalize(_name);
_builder.append(_pascalize, " ");
_builder.append(".</p>");
_builder.newLineIfNotEmpty();
_builder.append(" ");
_builder.append("*/");
_builder.newLine();
_builder.append("public static class ");
String _name_1 = stmt.getName();
String _pascalize_1 = Strings.pascalize(_name_1);
_builder.append(_pascalize_1, "");
_builder.append(" implements ");
String _name_2 = stmt.getName();
String _pascalize_2 = Strings.pascalize(_name_2);
_builder.append(_pascalize_2, "");
_builder.append("Columns");
{
boolean _hasAndroidPrimaryKey = this.hasAndroidPrimaryKey(stmt);
if (_hasAndroidPrimaryKey) {
_builder.append(", BaseColumns");
}
}
_builder.append(" {");
_builder.newLineIfNotEmpty();
_builder.append(" ");
_builder.append("public static final Uri CONTENT_URI = ");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("BASE_CONTENT_URI.buildUpon().appendPath(\"");
String _name_3 = stmt.getName();
_builder.append(_name_3, "\t\t\t");
_builder.append("\").build();");
_builder.newLineIfNotEmpty();
_builder.newLine();
_builder.append("\t");
_builder.append("/**");
_builder.newLine();
_builder.append("\t ");
_builder.append("* <p>The content type for a cursor that contains many ");
String _name_4 = stmt.getName();
String _pascalize_3 = Strings.pascalize(_name_4);
_builder.append(_pascalize_3, "\t ");
_builder.append(" rows.</p>");
_builder.newLineIfNotEmpty();
_builder.append("\t ");
_builder.append("*/");
_builder.newLine();
_builder.append(" ");
_builder.append("public static final String CONTENT_TYPE =");
_builder.newLine();
_builder.append(" ");
_builder.append("\"vnd.android.cursor.dir/vnd.");
DatabaseBlock _database = model.getDatabase();
String _name_5 = _database.getName();
String _lowerCase = _name_5.toLowerCase();
_builder.append(_lowerCase, " ");
_builder.append(".");
String _name_6 = stmt.getName();
_builder.append(_name_6, " ");
_builder.append("\";");
_builder.newLineIfNotEmpty();
_builder.newLine();
{
boolean _hasAndroidPrimaryKey_1 = this.hasAndroidPrimaryKey(stmt);
if (_hasAndroidPrimaryKey_1) {
_builder.append("\t");
_builder.append("/**");
_builder.newLine();
_builder.append("\t");
_builder.append(" ");
_builder.append("* <p>The content type for a cursor that contains a single ");
String _name_7 = stmt.getName();
String _pascalize_4 = Strings.pascalize(_name_7);
_builder.append(_pascalize_4, "\t ");
_builder.append(" row.</p>");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append(" ");
_builder.append("*/");
_builder.newLine();
_builder.append("\t");
_builder.append("public static final String ITEM_CONTENT_TYPE =");
_builder.newLine();
_builder.append("\t");
_builder.append("\t");
_builder.append("\"vnd.android.cursor.item/vnd.");
DatabaseBlock _database_1 = model.getDatabase();
String _name_8 = _database_1.getName();
String _lowerCase_1 = _name_8.toLowerCase();
_builder.append(_lowerCase_1, "\t\t");
_builder.append(".");
String _name_9 = stmt.getName();
_builder.append(_name_9, "\t\t");
_builder.append("\";");
_builder.newLineIfNotEmpty();
}
}
_builder.newLine();
_builder.append("\t");
_builder.append("/**");
_builder.newLine();
_builder.append("\t ");
_builder.append("* <p>Builds a Uri with appended id for a row in ");
String _name_10 = stmt.getName();
String _pascalize_5 = Strings.pascalize(_name_10);
_builder.append(_pascalize_5, "\t ");
_builder.append(", ");
_builder.newLineIfNotEmpty();
_builder.append("\t ");
_builder.append("* eg:- content://");
String _packageName = model.getPackageName();
_builder.append(_packageName, "\t ");
_builder.append(".");
DatabaseBlock _database_2 = model.getDatabase();
String _name_11 = _database_2.getName();
String _lowerCase_2 = _name_11.toLowerCase();
_builder.append(_lowerCase_2, "\t ");
_builder.append("/");
String _name_12 = stmt.getName();
String _lowerCase_3 = _name_12.toLowerCase();
_builder.append(_lowerCase_3, "\t ");
_builder.append("/123.</p>");
_builder.newLineIfNotEmpty();
_builder.append("\t ");
_builder.append("*/");
_builder.newLine();
_builder.append(" ");
_builder.append("public static Uri buildUriWithId(long id) {");
_builder.newLine();
_builder.append(" ");
_builder.append("return CONTENT_URI.buildUpon().appendPath(String.valueOf(id)).build();");
_builder.newLine();
_builder.append(" ");
_builder.append("}");
_builder.newLine();
_builder.append(" ");
String _name_13 = stmt.getName();
Iterable<ActionStatement> actions = this.findActionsForDefinition(model, _name_13);
_builder.newLineIfNotEmpty();
{
boolean _notEquals = (!Objects.equal(actions, null));
if (_notEquals) {
{
for (final ActionStatement action : actions) {
_builder.append("\t");
CharSequence _createActionUriBuilderMethod = this.createActionUriBuilderMethod(action);
_builder.append(_createActionUriBuilderMethod, "\t");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.newLine();
}
}
}
}
_builder.append("\t");
_builder.append("public static int delete() {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("return Mechanoid.getContentResolver().delete(");
String _name_14 = stmt.getName();
String _pascalize_6 = Strings.pascalize(_name_14);
_builder.append(_pascalize_6, "\t\t");
_builder.append(".CONTENT_URI, null, null);");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("public static int delete(String where, String[] selectionArgs) {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("return Mechanoid.getContentResolver().delete(");
String _name_15 = stmt.getName();
String _pascalize_7 = Strings.pascalize(_name_15);
_builder.append(_pascalize_7, "\t\t");
_builder.append(".CONTENT_URI, where, selectionArgs);");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("/**");
_builder.newLine();
_builder.append("\t ");
_builder.append("* <p>Create a new Builder for ");
String _name_16 = stmt.getName();
String _pascalize_8 = Strings.pascalize(_name_16);
_builder.append(_pascalize_8, "\t ");
_builder.append("</p>");
_builder.newLineIfNotEmpty();
_builder.append("\t ");
_builder.append("*/");
_builder.newLine();
_builder.append("\t");
_builder.append("public static Builder newBuilder() {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("return new Builder();");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("/**");
_builder.newLine();
_builder.append("\t ");
_builder.append("* <p>Build and execute insert or update statements for ");
String _name_17 = stmt.getName();
String _pascalize_9 = Strings.pascalize(_name_17);
_builder.append(_pascalize_9, "\t ");
_builder.append(".</p>");
_builder.newLineIfNotEmpty();
_builder.append("\t ");
_builder.append("*");
_builder.newLine();
_builder.append("\t ");
_builder.append("* <p>Use {@link ");
String _name_18 = stmt.getName();
String _pascalize_10 = Strings.pascalize(_name_18);
_builder.append(_pascalize_10, "\t ");
_builder.append("#newBuilder()} to create new builder</p>");
_builder.newLineIfNotEmpty();
_builder.append("\t ");
_builder.append("*/");
_builder.newLine();
_builder.append("\t");
_builder.append("public static class Builder extends AbstractValuesBuilder {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("private Builder() {");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("super(Mechanoid.getApplicationContext(), ");
String _name_19 = stmt.getName();
String _pascalize_11 = Strings.pascalize(_name_19);
_builder.append(_pascalize_11, "\t\t\t");
_builder.append(".CONTENT_URI);");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t\t");
_builder.newLine();
_builder.append("\t\t");
CharSequence _generateBuilderSetters = this.generateBuilderSetters(stmt);
_builder.append(_generateBuilderSetters, "\t\t");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("static final Set<Uri> VIEW_URIS;");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("static {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("HashSet<Uri> viewUris = new HashSet<Uri>();");
_builder.newLine();
_builder.newLine();
{
HashSet<CreateViewStatement> _allViewsReferencingTable = ModelUtil.getAllViewsReferencingTable(snapshot, stmt);
final Function1<CreateViewStatement, String> _function = new Function1<CreateViewStatement, String>() {
public String apply(final CreateViewStatement x) {
return x.getName();
}
};
List<CreateViewStatement> _sortBy = IterableExtensions.<CreateViewStatement, String>sortBy(_allViewsReferencingTable, _function);
for (final CreateViewStatement ref : _sortBy) {
_builder.append("\t\t");
_builder.append("viewUris.add(");
String _name_20 = ref.getName();
String _pascalize_12 = Strings.pascalize(_name_20);
_builder.append(_pascalize_12, "\t\t");
_builder.append(".CONTENT_URI);");
_builder.newLineIfNotEmpty();
}
}
{
HashSet<CreateViewStatement> _allViewsInConfigInitReferencingTable = ModelUtil.getAllViewsInConfigInitReferencingTable(model, stmt);
final Function1<CreateViewStatement, String> _function_1 = new Function1<CreateViewStatement, String>() {
public String apply(final CreateViewStatement x) {
return x.getName();
}
};
List<CreateViewStatement> _sortBy_1 = IterableExtensions.<CreateViewStatement, String>sortBy(_allViewsInConfigInitReferencingTable, _function_1);
for (final CreateViewStatement ref_1 : _sortBy_1) {
_builder.append("\t\t");
_builder.append("viewUris.add(");
String _name_21 = ref_1.getName();
String _pascalize_13 = Strings.pascalize(_name_21);
_builder.append(_pascalize_13, "\t\t");
_builder.append(".CONTENT_URI);");
_builder.newLineIfNotEmpty();
}
}
_builder.append("\t\t");
_builder.newLine();
_builder.append("\t\t");
_builder.append("VIEW_URIS = Collections.unmodifiableSet(viewUris);");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
return _builder;
}
Aggregations