use of org.eclipse.xtext.xbase.lib.Functions.Function1 in project mechanoid by robotoworks.
the class ContentProviderContractGenerator method generate.
public CharSequence generate(final Model model, final SqliteDatabaseSnapshot snapshot) {
StringConcatenation _builder = new StringConcatenation();
_builder.append("/*");
_builder.newLine();
_builder.append(" ");
_builder.append("* Generated by Robotoworks Mechanoid");
_builder.newLine();
_builder.append(" ");
_builder.append("*/");
_builder.newLine();
_builder.append("package ");
String _packageName = model.getPackageName();
_builder.append(_packageName, "");
_builder.append(";");
_builder.newLineIfNotEmpty();
_builder.newLine();
_builder.append("import android.net.Uri;");
_builder.newLine();
_builder.append("import android.provider.BaseColumns;");
_builder.newLine();
_builder.append("import com.robotoworks.mechanoid.Mechanoid;");
_builder.newLine();
_builder.append("import com.robotoworks.mechanoid.db.AbstractValuesBuilder;");
_builder.newLine();
_builder.append("import java.lang.reflect.Field;\t\t\t");
_builder.newLine();
_builder.append("import java.util.Collections;");
_builder.newLine();
_builder.append("import java.util.HashSet;");
_builder.newLine();
_builder.append("import java.util.HashMap;");
_builder.newLine();
_builder.append("import java.util.Set;");
_builder.newLine();
_builder.append("import java.util.Map;");
_builder.newLine();
_builder.newLine();
_builder.append("public class ");
DatabaseBlock _database = model.getDatabase();
String _name = _database.getName();
String _pascalize = Strings.pascalize(_name);
_builder.append(_pascalize, "");
_builder.append("Contract {");
_builder.newLineIfNotEmpty();
_builder.append(" ");
_builder.append("public static final String CONTENT_AUTHORITY = initAuthority();");
_builder.newLine();
_builder.newLine();
_builder.append("\t");
_builder.append("private static String initAuthority() {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("String authority = \"");
String _packageName_1 = model.getPackageName();
_builder.append(_packageName_1, "\t\t");
_builder.append(".");
DatabaseBlock _database_1 = model.getDatabase();
String _name_1 = _database_1.getName();
String _lowerCase = _name_1.toLowerCase();
_builder.append(_lowerCase, "\t\t");
_builder.append("\";");
_builder.newLineIfNotEmpty();
_builder.newLine();
_builder.append("\t\t");
_builder.append("try {");
_builder.newLine();
_builder.append(" \t\t");
_builder.newLine();
_builder.append(" \t\t");
_builder.append("ClassLoader loader = ");
DatabaseBlock _database_2 = model.getDatabase();
String _name_2 = _database_2.getName();
String _pascalize_1 = Strings.pascalize(_name_2);
_builder.append(_pascalize_1, " \t\t");
_builder.append("Contract.class.getClassLoader();");
_builder.newLineIfNotEmpty();
_builder.append(" \t\t");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("Class<?> clz = loader.loadClass(\"");
String _packageName_2 = model.getPackageName();
_builder.append(_packageName_2, "\t\t\t");
_builder.append(".");
DatabaseBlock _database_3 = model.getDatabase();
String _name_3 = _database_3.getName();
String _pascalize_2 = Strings.pascalize(_name_3);
_builder.append(_pascalize_2, "\t\t\t");
_builder.append("ContentProviderAuthority\");");
_builder.newLineIfNotEmpty();
_builder.append("\t\t\t");
_builder.append("Field declaredField = clz.getDeclaredField(\"CONTENT_AUTHORITY\");");
_builder.newLine();
_builder.append("\t\t\t");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("authority = declaredField.get(null).toString();");
_builder.newLine();
_builder.append("\t\t");
_builder.append("} catch (ClassNotFoundException e) {} ");
_builder.newLine();
_builder.append(" \t");
_builder.append("catch (NoSuchFieldException e) {} ");
_builder.newLine();
_builder.append(" \t");
_builder.append("catch (IllegalArgumentException e) {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("} catch (IllegalAccessException e) {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t\t");
_builder.newLine();
_builder.append("\t\t");
_builder.append("return authority;");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
_builder.append(" ");
_builder.append("private static final Uri BASE_CONTENT_URI = Uri.parse(\"content://\" + CONTENT_AUTHORITY);");
_builder.newLine();
_builder.newLine();
{
Collection<CreateTableStatement> _tables = snapshot.getTables();
final Function1<CreateTableStatement, String> _function = new Function1<CreateTableStatement, String>() {
public String apply(final CreateTableStatement x) {
return x.getName();
}
};
List<CreateTableStatement> _sortBy = IterableExtensions.<CreateTableStatement, String>sortBy(_tables, _function);
for (final CreateTableStatement tbl : _sortBy) {
_builder.append("\t");
_builder.append("interface ");
String _name_4 = tbl.getName();
String _pascalize_3 = Strings.pascalize(_name_4);
_builder.append(_pascalize_3, "\t");
_builder.append("Columns {");
_builder.newLineIfNotEmpty();
{
EList<ColumnSource> _columnDefs = tbl.getColumnDefs();
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 = IterableExtensions.<ColumnSource>filter(_columnDefs, _function_1);
for (final ColumnSource col : _filter) {
_builder.append("\t");
_builder.append("\t");
_builder.append("String ");
String _name_5 = col.getName();
String _underscore = Strings.underscore(_name_5);
String _upperCase = _underscore.toUpperCase();
_builder.append(_upperCase, "\t\t");
_builder.append(" = \"");
String _name_6 = col.getName();
_builder.append(_name_6, "\t\t");
_builder.append("\";");
_builder.newLineIfNotEmpty();
}
}
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
}
}
{
Collection<CreateViewStatement> _views = snapshot.getViews();
final Function1<CreateViewStatement, String> _function_2 = new Function1<CreateViewStatement, String>() {
public String apply(final CreateViewStatement x) {
return x.getName();
}
};
List<CreateViewStatement> _sortBy_1 = IterableExtensions.<CreateViewStatement, String>sortBy(_views, _function_2);
for (final CreateViewStatement vw : _sortBy_1) {
_builder.append("\t");
_builder.append("interface ");
String _name_7 = vw.getName();
String _pascalize_4 = Strings.pascalize(_name_7);
_builder.append(_pascalize_4, "\t");
_builder.append("Columns {");
_builder.newLineIfNotEmpty();
{
ArrayList<ColumnSource> _viewResultColumns = ModelUtil.getViewResultColumns(vw);
final Function1<ColumnSource, Boolean> _function_3 = 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(_viewResultColumns, _function_3);
for (final ColumnSource col_1 : _filter_1) {
_builder.append("\t");
_builder.append("\t");
CharSequence _generateInterfaceMemberForResultColumn = this.generateInterfaceMemberForResultColumn(col_1);
_builder.append(_generateInterfaceMemberForResultColumn, "\t\t");
_builder.newLineIfNotEmpty();
}
}
_builder.append("\t");
_builder.append("}");
_builder.newLine();
}
}
{
Collection<CreateTableStatement> _configInitTables = ModelUtil.getConfigInitTables(model);
final Function1<CreateTableStatement, String> _function_4 = new Function1<CreateTableStatement, String>() {
public String apply(final CreateTableStatement x) {
return x.getName();
}
};
List<CreateTableStatement> _sortBy_2 = IterableExtensions.<CreateTableStatement, String>sortBy(_configInitTables, _function_4);
for (final CreateTableStatement tbl_1 : _sortBy_2) {
_builder.append("\t");
_builder.append("interface ");
String _name_8 = tbl_1.getName();
String _pascalize_5 = Strings.pascalize(_name_8);
_builder.append(_pascalize_5, "\t");
_builder.append("Columns {");
_builder.newLineIfNotEmpty();
{
EList<ColumnSource> _columnDefs_1 = tbl_1.getColumnDefs();
final Function1<ColumnSource, Boolean> _function_5 = 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_2 = IterableExtensions.<ColumnSource>filter(_columnDefs_1, _function_5);
for (final ColumnSource col_2 : _filter_2) {
_builder.append("\t");
_builder.append("\t");
_builder.append("String ");
String _name_9 = col_2.getName();
String _underscore_1 = Strings.underscore(_name_9);
String _upperCase_1 = _underscore_1.toUpperCase();
_builder.append(_upperCase_1, "\t\t");
_builder.append(" = \"");
String _name_10 = col_2.getName();
_builder.append(_name_10, "\t\t");
_builder.append("\";");
_builder.newLineIfNotEmpty();
}
}
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
}
}
{
Collection<CreateViewStatement> _configInitViews = ModelUtil.getConfigInitViews(model);
final Function1<CreateViewStatement, String> _function_6 = new Function1<CreateViewStatement, String>() {
public String apply(final CreateViewStatement x) {
return x.getName();
}
};
List<CreateViewStatement> _sortBy_3 = IterableExtensions.<CreateViewStatement, String>sortBy(_configInitViews, _function_6);
for (final CreateViewStatement vw_1 : _sortBy_3) {
_builder.append("\t");
_builder.append("interface ");
String _name_11 = vw_1.getName();
String _pascalize_6 = Strings.pascalize(_name_11);
_builder.append(_pascalize_6, "\t");
_builder.append("Columns {");
_builder.newLineIfNotEmpty();
{
ArrayList<ColumnSource> _viewResultColumns_1 = ModelUtil.getViewResultColumns(vw_1);
final Function1<ColumnSource, Boolean> _function_7 = 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_3 = IterableExtensions.<ColumnSource>filter(_viewResultColumns_1, _function_7);
for (final ColumnSource col_3 : _filter_3) {
_builder.append("\t");
_builder.append("\t");
CharSequence _generateInterfaceMemberForResultColumn_1 = this.generateInterfaceMemberForResultColumn(col_3);
_builder.append(_generateInterfaceMemberForResultColumn_1, "\t\t");
_builder.newLineIfNotEmpty();
}
}
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
}
}
_builder.append("\t\t\t");
_builder.newLine();
{
Collection<CreateTableStatement> _tables_1 = snapshot.getTables();
final Function1<CreateTableStatement, String> _function_8 = new Function1<CreateTableStatement, String>() {
public String apply(final CreateTableStatement x) {
return x.getName();
}
};
List<CreateTableStatement> _sortBy_4 = IterableExtensions.<CreateTableStatement, String>sortBy(_tables_1, _function_8);
for (final CreateTableStatement tbl_2 : _sortBy_4) {
_builder.append("\t");
CharSequence _generateContractItem = this.generateContractItem(model, snapshot, tbl_2);
_builder.append(_generateContractItem, "\t");
_builder.newLineIfNotEmpty();
}
}
_builder.newLine();
{
Collection<CreateViewStatement> _views_1 = snapshot.getViews();
final Function1<CreateViewStatement, String> _function_9 = new Function1<CreateViewStatement, String>() {
public String apply(final CreateViewStatement x) {
return x.getName();
}
};
List<CreateViewStatement> _sortBy_5 = IterableExtensions.<CreateViewStatement, String>sortBy(_views_1, _function_9);
for (final CreateViewStatement vw_2 : _sortBy_5) {
_builder.append("\t");
CharSequence _generateContractItem_1 = this.generateContractItem(model, snapshot, vw_2);
_builder.append(_generateContractItem_1, "\t");
_builder.newLineIfNotEmpty();
}
}
_builder.append("\t");
_builder.newLine();
{
Collection<CreateTableStatement> _configInitTables_1 = ModelUtil.getConfigInitTables(model);
final Function1<CreateTableStatement, String> _function_10 = new Function1<CreateTableStatement, String>() {
public String apply(final CreateTableStatement x) {
return x.getName();
}
};
List<CreateTableStatement> _sortBy_6 = IterableExtensions.<CreateTableStatement, String>sortBy(_configInitTables_1, _function_10);
for (final CreateTableStatement tbl_3 : _sortBy_6) {
_builder.append("\t");
CharSequence _generateContractItem_2 = this.generateContractItem(model, snapshot, tbl_3);
_builder.append(_generateContractItem_2, "\t");
_builder.newLineIfNotEmpty();
}
}
_builder.newLine();
{
Collection<CreateViewStatement> _configInitViews_1 = ModelUtil.getConfigInitViews(model);
final Function1<CreateViewStatement, String> _function_11 = new Function1<CreateViewStatement, String>() {
public String apply(final CreateViewStatement x) {
return x.getName();
}
};
List<CreateViewStatement> _sortBy_7 = IterableExtensions.<CreateViewStatement, String>sortBy(_configInitViews_1, _function_11);
for (final CreateViewStatement vw_3 : _sortBy_7) {
_builder.append("\t");
CharSequence _generateContractItem_3 = this.generateContractItem(model, snapshot, vw_3);
_builder.append(_generateContractItem_3, "\t");
_builder.newLineIfNotEmpty();
}
}
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("static Map<Uri, Set<Uri>> REFERENCING_VIEWS;");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("static {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("Map<Uri, Set<Uri>> map = new HashMap<Uri, Set<Uri>>();");
_builder.newLine();
_builder.append("\t\t");
_builder.newLine();
{
Collection<CreateTableStatement> _tables_2 = snapshot.getTables();
final Function1<CreateTableStatement, String> _function_12 = new Function1<CreateTableStatement, String>() {
public String apply(final CreateTableStatement x) {
return x.getName();
}
};
List<CreateTableStatement> _sortBy_8 = IterableExtensions.<CreateTableStatement, String>sortBy(_tables_2, _function_12);
for (final CreateTableStatement tbl_4 : _sortBy_8) {
_builder.append("\t\t");
_builder.append("map.put(");
String _name_12 = tbl_4.getName();
String _pascalize_7 = Strings.pascalize(_name_12);
_builder.append(_pascalize_7, "\t\t");
_builder.append(".CONTENT_URI, ");
String _name_13 = tbl_4.getName();
String _pascalize_8 = Strings.pascalize(_name_13);
_builder.append(_pascalize_8, "\t\t");
_builder.append(".VIEW_URIS);");
_builder.newLineIfNotEmpty();
}
}
{
Collection<CreateViewStatement> _views_2 = snapshot.getViews();
final Function1<CreateViewStatement, String> _function_13 = new Function1<CreateViewStatement, String>() {
public String apply(final CreateViewStatement x) {
return x.getName();
}
};
List<CreateViewStatement> _sortBy_9 = IterableExtensions.<CreateViewStatement, String>sortBy(_views_2, _function_13);
for (final CreateViewStatement vw_4 : _sortBy_9) {
_builder.append("\t\t");
_builder.append("map.put(");
String _name_14 = vw_4.getName();
String _pascalize_9 = Strings.pascalize(_name_14);
_builder.append(_pascalize_9, "\t\t");
_builder.append(".CONTENT_URI, ");
String _name_15 = vw_4.getName();
String _pascalize_10 = Strings.pascalize(_name_15);
_builder.append(_pascalize_10, "\t\t");
_builder.append(".VIEW_URIS);");
_builder.newLineIfNotEmpty();
}
}
{
Collection<CreateTableStatement> _configInitTables_2 = ModelUtil.getConfigInitTables(model);
final Function1<CreateTableStatement, String> _function_14 = new Function1<CreateTableStatement, String>() {
public String apply(final CreateTableStatement x) {
return x.getName();
}
};
List<CreateTableStatement> _sortBy_10 = IterableExtensions.<CreateTableStatement, String>sortBy(_configInitTables_2, _function_14);
for (final CreateTableStatement tbl_5 : _sortBy_10) {
_builder.append("\t\t");
_builder.append("map.put(");
String _name_16 = tbl_5.getName();
String _pascalize_11 = Strings.pascalize(_name_16);
_builder.append(_pascalize_11, "\t\t");
_builder.append(".CONTENT_URI, ");
String _name_17 = tbl_5.getName();
String _pascalize_12 = Strings.pascalize(_name_17);
_builder.append(_pascalize_12, "\t\t");
_builder.append(".VIEW_URIS);");
_builder.newLineIfNotEmpty();
}
}
{
Collection<CreateViewStatement> _configInitViews_2 = ModelUtil.getConfigInitViews(model);
final Function1<CreateViewStatement, String> _function_15 = new Function1<CreateViewStatement, String>() {
public String apply(final CreateViewStatement x) {
return x.getName();
}
};
List<CreateViewStatement> _sortBy_11 = IterableExtensions.<CreateViewStatement, String>sortBy(_configInitViews_2, _function_15);
for (final CreateViewStatement vw_5 : _sortBy_11) {
_builder.append("\t\t");
_builder.append("map.put(");
String _name_18 = vw_5.getName();
String _pascalize_13 = Strings.pascalize(_name_18);
_builder.append(_pascalize_13, "\t\t");
_builder.append(".CONTENT_URI, ");
String _name_19 = vw_5.getName();
String _pascalize_14 = Strings.pascalize(_name_19);
_builder.append(_pascalize_14, "\t\t");
_builder.append(".VIEW_URIS);");
_builder.newLineIfNotEmpty();
}
}
_builder.append("\t\t");
_builder.newLine();
_builder.append("\t\t");
_builder.append("REFERENCING_VIEWS = Collections.unmodifiableMap(map);");
_builder.newLine();
_builder.append("\t\t");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
CharSequence _generateContractItemsForActions = this.generateContractItemsForActions(model, snapshot);
_builder.append(_generateContractItemsForActions, "\t");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("private ");
DatabaseBlock _database_4 = model.getDatabase();
String _name_20 = _database_4.getName();
String _pascalize_15 = Strings.pascalize(_name_20);
_builder.append(_pascalize_15, "\t");
_builder.append("Contract(){}");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("/**");
_builder.newLine();
_builder.append("\t ");
_builder.append("* <p>Delete all rows from all tables</p>");
_builder.newLine();
_builder.append("\t ");
_builder.append("*/\t\t\t\t\t\t");
_builder.newLine();
_builder.append("\t");
_builder.append("public static void deleteAll() {");
_builder.newLine();
{
Collection<CreateTableStatement> _tables_3 = snapshot.getTables();
final Function1<CreateTableStatement, String> _function_16 = new Function1<CreateTableStatement, String>() {
public String apply(final CreateTableStatement x) {
return x.getName();
}
};
List<CreateTableStatement> _sortBy_12 = IterableExtensions.<CreateTableStatement, String>sortBy(_tables_3, _function_16);
for (final CreateTableStatement tbl_6 : _sortBy_12) {
_builder.append("\t\t");
String _name_21 = tbl_6.getName();
String _pascalize_16 = Strings.pascalize(_name_21);
_builder.append(_pascalize_16, "\t\t");
_builder.append(".delete();");
_builder.newLineIfNotEmpty();
}
}
{
Collection<CreateTableStatement> _configInitTables_3 = ModelUtil.getConfigInitTables(model);
final Function1<CreateTableStatement, String> _function_17 = new Function1<CreateTableStatement, String>() {
public String apply(final CreateTableStatement x) {
return x.getName();
}
};
List<CreateTableStatement> _sortBy_13 = IterableExtensions.<CreateTableStatement, String>sortBy(_configInitTables_3, _function_17);
for (final CreateTableStatement tbl_7 : _sortBy_13) {
_builder.append("\t\t");
String _name_22 = tbl_7.getName();
String _pascalize_17 = Strings.pascalize(_name_22);
_builder.append(_pascalize_17, "\t\t");
_builder.append(".delete();");
_builder.newLineIfNotEmpty();
}
}
_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 ModelUtil method getViewResultColumns.
public static ArrayList<ColumnSource> getViewResultColumns(final CreateViewStatement stmt) {
ArrayList<ColumnSource> result = new ArrayList<ColumnSource>();
SelectStatement _selectStatement = stmt.getSelectStatement();
SelectCoreExpression coreExpr = _selectStatement.getCore();
if ((coreExpr instanceof SelectCore)) {
SelectCore core = ((SelectCore) coreExpr);
SelectCoreExpression _right = core.getRight();
SelectList selectList = ((SelectExpression) _right).getSelectList();
boolean _notEquals = (!Objects.equal(selectList, null));
if (_notEquals) {
EList<ColumnSource> _resultColumns = selectList.getResultColumns();
final Function1<ColumnSource, Boolean> _function = new Function1<ColumnSource, Boolean>() {
public Boolean apply(final ColumnSource it) {
boolean _and = false;
String _name = it.getName();
boolean _notEquals = (!Objects.equal(_name, null));
if (!_notEquals) {
_and = false;
} else {
String _name_1 = it.getName();
boolean _equals = _name_1.equals("");
boolean _not = (!_equals);
_and = _not;
}
return Boolean.valueOf(_and);
}
};
Iterable<ColumnSource> _filter = IterableExtensions.<ColumnSource>filter(_resultColumns, _function);
Iterables.<ColumnSource>addAll(result, _filter);
}
} else {
SelectList selectList_1 = ((SelectExpression) coreExpr).getSelectList();
boolean _notEquals_1 = (!Objects.equal(selectList_1, null));
if (_notEquals_1) {
EList<ColumnSource> _resultColumns_1 = selectList_1.getResultColumns();
final Function1<ColumnSource, Boolean> _function_1 = new Function1<ColumnSource, Boolean>() {
public Boolean apply(final ColumnSource it) {
boolean _and = false;
String _name = it.getName();
boolean _notEquals = (!Objects.equal(_name, null));
if (!_notEquals) {
_and = false;
} else {
String _name_1 = it.getName();
boolean _equals = _name_1.equals("");
boolean _not = (!_equals);
_and = _not;
}
return Boolean.valueOf(_and);
}
};
Iterable<ColumnSource> _filter_1 = IterableExtensions.<ColumnSource>filter(_resultColumns_1, _function_1);
Iterables.<ColumnSource>addAll(result, _filter_1);
}
}
return result;
}
use of org.eclipse.xtext.xbase.lib.Functions.Function1 in project mechanoid by robotoworks.
the class ModelUtil method findColumnDefs.
/**
* Find column definitions from caller going back to the definition
*/
public static ArrayList<EObject> findColumnDefs(final DDLStatement caller, final TableDefinition definition) {
final ArrayList<EObject> columns = new ArrayList<EObject>();
LinkedList<TableDefinition> tableHistory = ModelUtil.getHistory(definition);
TableDefinition last = tableHistory.peekLast();
if ((last instanceof CreateViewStatement)) {
CreateViewStatement view = ((CreateViewStatement) last);
ArrayList<ColumnSource> _viewResultColumns = ModelUtil.getViewResultColumns(view);
columns.addAll(_viewResultColumns);
return columns;
}
EList<ColumnSource> _columnDefs = ((CreateTableStatement) last).getColumnDefs();
columns.addAll(_columnDefs);
while ((!tableHistory.isEmpty())) {
{
final TableDefinition stmt = tableHistory.removeLast();
ArrayList<AlterTableAddColumnStatement> _findStatementsOfTypeBetween = ModelUtil.<AlterTableAddColumnStatement>findStatementsOfTypeBetween(AlterTableAddColumnStatement.class, stmt, caller);
final Function1<AlterTableAddColumnStatement, Boolean> _function = new Function1<AlterTableAddColumnStatement, Boolean>() {
public Boolean apply(final AlterTableAddColumnStatement it) {
TableDefinition _table = it.getTable();
return Boolean.valueOf(Objects.equal(_table, stmt));
}
};
Iterable<AlterTableAddColumnStatement> _filter = IterableExtensions.<AlterTableAddColumnStatement>filter(_findStatementsOfTypeBetween, _function);
final Consumer<AlterTableAddColumnStatement> _function_1 = new Consumer<AlterTableAddColumnStatement>() {
public void accept(final AlterTableAddColumnStatement it) {
ColumnSource _columnDef = it.getColumnDef();
columns.add(_columnDef);
}
};
_filter.forEach(_function_1);
}
}
return columns;
}
use of org.eclipse.xtext.xbase.lib.Functions.Function1 in project mechanoid by robotoworks.
the class ModelUtil method getAllReferenceableColumns.
public static ArrayList<EObject> getAllReferenceableColumns(final SelectExpression expr, final boolean includeAliases) {
final ArrayList<EObject> items = Lists.<EObject>newArrayList();
boolean _and = false;
SelectList _selectList = expr.getSelectList();
boolean _notEquals = (!Objects.equal(_selectList, null));
if (!_notEquals) {
_and = false;
} else {
_and = includeAliases;
}
if (_and) {
SelectList _selectList_1 = expr.getSelectList();
EList<ColumnSource> _resultColumns = _selectList_1.getResultColumns();
final Function1<ColumnSource, Boolean> _function = new Function1<ColumnSource, Boolean>() {
public Boolean apply(final ColumnSource it) {
String _name = it.getName();
return Boolean.valueOf((!Objects.equal(_name, null)));
}
};
Iterable<ColumnSource> _filter = IterableExtensions.<ColumnSource>filter(_resultColumns, _function);
Iterables.<EObject>addAll(items, _filter);
}
ArrayList<SingleSource> _findAllSingleSources = ModelUtil.findAllSingleSources(expr);
final Function1<SingleSource, Boolean> _function_1 = new Function1<SingleSource, Boolean>() {
public Boolean apply(final SingleSource item) {
if ((item instanceof SingleSourceTable)) {
String _name = ((SingleSourceTable) item).getName();
return Boolean.valueOf(Objects.equal(_name, null));
}
return Boolean.valueOf(false);
}
};
Iterable<SingleSource> _filter_1 = IterableExtensions.<SingleSource>filter(_findAllSingleSources, _function_1);
final Consumer<SingleSource> _function_2 = new Consumer<SingleSource>() {
public void accept(final SingleSource item) {
SingleSourceTable source = ((SingleSourceTable) item);
DDLStatement _ancestorOfType = ModelUtil.<DDLStatement>getAncestorOfType(item, DDLStatement.class);
TableDefinition _tableReference = source.getTableReference();
ArrayList<EObject> _findColumnDefs = ModelUtil.findColumnDefs(_ancestorOfType, _tableReference);
items.addAll(_findColumnDefs);
}
};
_filter_1.forEach(_function_2);
return items;
}
use of org.eclipse.xtext.xbase.lib.Functions.Function1 in project applause by applause.
the class EntitiesValidationTestHelper method isValidEntityWithAttributes.
public void isValidEntityWithAttributes(final CharSequence sequence) {
try {
final Model model = this._parseHelper.parse(sequence);
EList<NamedElement> _elements = model.getElements();
Iterable<Entity> _filter = Iterables.<Entity>filter(_elements, Entity.class);
final Entity entity = IterableExtensions.<Entity>head(_filter);
final EList<Attribute> attributes = entity.getAttributes();
int _size = attributes.size();
Matcher<Integer> _is = CoreMatchers.<Integer>is(Integer.valueOf(2));
Assert.<Integer>assertThat(Integer.valueOf(_size), _is);
EList<NamedElement> _elements_1 = model.getElements();
final Function1<NamedElement, Boolean> _function = new Function1<NamedElement, Boolean>() {
public Boolean apply(final NamedElement it) {
String _name = it.getName();
boolean _equals = Objects.equal(_name, "Date");
return Boolean.valueOf(_equals);
}
};
final NamedElement dateType = IterableExtensions.<NamedElement>findFirst(_elements_1, _function);
EList<NamedElement> _elements_2 = model.getElements();
final Function1<NamedElement, Boolean> _function_1 = new Function1<NamedElement, Boolean>() {
public Boolean apply(final NamedElement it) {
String _name = it.getName();
boolean _equals = Objects.equal(_name, "String");
return Boolean.valueOf(_equals);
}
};
final NamedElement stringType = IterableExtensions.<NamedElement>findFirst(_elements_2, _function_1);
final Attribute firstAttribute = IterableExtensions.<Attribute>head(attributes);
String _name = firstAttribute.getName();
Matcher<String> _is_1 = CoreMatchers.<String>is("name");
Assert.<String>assertThat(_name, _is_1);
Type _type = firstAttribute.getType();
Matcher<NamedElement> _is_2 = CoreMatchers.<NamedElement>is(stringType);
Assert.<Type>assertThat(_type, _is_2);
final Attribute secondAttribute = IterableExtensions.<Attribute>last(attributes);
String _name_1 = secondAttribute.getName();
Matcher<String> _is_3 = CoreMatchers.<String>is("birthdate");
Assert.<String>assertThat(_name_1, _is_3);
Type _type_1 = secondAttribute.getType();
Matcher<NamedElement> _is_4 = CoreMatchers.<NamedElement>is(dateType);
Assert.<Type>assertThat(_type_1, _is_4);
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
Aggregations