use of org.eclipse.xtext.xbase.lib.Functions.Function1 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.xtext.xbase.lib.Functions.Function1 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.xtext.xbase.lib.Functions.Function1 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;
}
use of org.eclipse.xtext.xbase.lib.Functions.Function1 in project mechanoid by robotoworks.
the class ContentProviderContractGenerator method findActionsForDefinition.
/**
* Find all actions associated to the given definition,
* actions are associated to the definition via the first
* part of an action uri, for instance /recipes/a/b/c is
* associated to recipes
*/
public Iterable<ActionStatement> findActionsForDefinition(final Model model, final String defName) {
DatabaseBlock _database = model.getDatabase();
ConfigBlock _config = _database.getConfig();
boolean _equals = Objects.equal(_config, null);
if (_equals) {
return new ArrayList<ActionStatement>();
}
DatabaseBlock _database_1 = model.getDatabase();
ConfigBlock _config_1 = _database_1.getConfig();
EList<ConfigurationStatement> _statements = _config_1.getStatements();
Iterable<ActionStatement> _filter = Iterables.<ActionStatement>filter(_statements, ActionStatement.class);
final Function1<ActionStatement, Boolean> _function = new Function1<ActionStatement, Boolean>() {
public Boolean apply(final ActionStatement action) {
ContentUri _uri = action.getUri();
String _type = _uri.getType();
return Boolean.valueOf(_type.equals(defName));
}
};
return IterableExtensions.<ActionStatement>filter(_filter, _function);
}
use of org.eclipse.xtext.xbase.lib.Functions.Function1 in project mechanoid by robotoworks.
the class ContentProviderContractGenerator method _generateBuilderSetters.
protected CharSequence _generateBuilderSetters(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();
_builder.append("public Builder set");
String _name = col.getName();
String _pascalize = Strings.pascalize(_name);
_builder.append(_pascalize, "");
_builder.append("(");
String _javaTypeName = ModelUtil.toJavaTypeName(type);
_builder.append(_javaTypeName, "");
_builder.append(" value) {");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("mValues.put(");
String _name_1 = stmt.getName();
String _pascalize_1 = Strings.pascalize(_name_1);
_builder.append(_pascalize_1, "\t");
_builder.append(".");
String _name_2 = col.getName();
String _underscore = Strings.underscore(_name_2);
String _upperCase = _underscore.toUpperCase();
_builder.append(_upperCase, "\t");
_builder.append(", value);");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("return this;");
_builder.newLine();
_builder.append("}");
_builder.newLine();
}
}
return _builder;
}
Aggregations