Crossreference to member of aliased container [message #757576] |
Sat, 19 November 2011 14:12  |
Eclipse User |
|
|
|
Hello,
I recently started trying out Xtext and I'm now trying to implement a (small) subset of SQLite for a project. I ran into the following problem for SELECT queries (simplified example):
Quote:
Table:
'CREATE' 'TABLE' name=ID '(' columns+=ColumnDef (',' columns+=ColumnDef)* ')';
Select:
'SELECT' resultColumns+=ResultColumn (',' resultColumns+=ResultColumn)* 'FROM' source=TableSource;
TableSource:
table=[Table | ID] ('AS' alias=ID)?;
And now I am unsure how to implement "ResultColumn".
Quote:
ResultColumn:
tableSource=[TableSource|ID] '.' column=[ColumnDef|ID]
would work, with a ScopeProvider that assigns the TableSource elements with either the referenced table's name or the given alias. But it would break the code completion a bit, because I cannot put a combination like "tableName.columnName" into the scope. I guess I'd have to look into writing a custom ContentAssist then?
The alternative would be
Quote:
ResultColumn:
column=[Column | QualifiedName]
and then create Column-EObjects that have references to the referenced TableSource AND the referenced Column. But I don't really know how this would be done. I guess this problem arises in lots of situations, like referencing a member of a Java-like-instance where the actual Member-EObject would be defined within the class, not the instance. So I'm wondering how this is normally handled, haven't really understood that from reading the documentation so far.
Thanks in advance for any help!
Regards,
Tobias
|
|
|
Re: Crossreference to member of aliased container [message #757581 is a reply to message #757576] |
Sat, 19 November 2011 16:14   |
Eclipse User |
|
|
|
Hi,
i dont get your problem
you have 2 possibilities
(1) you do ResultColumn: tableSource=[TableSource|ID] '.' column=[ColumnDef|ID]
(2) ResultColumn: column=[ColumnDef|QualifiedName]
in (1) you have of course to write first the tablename, then the '.' and then the column name, but i do not see this as a "break of code completion"
in (2) have a look at
Model:
tables+=Table*
selects+=Select*;
Table:
{Table}'CREATE' 'TABLE' name=ID '(' columns+=ColumnDef (',' columns+=ColumnDef)* ')';
Select:
{Select}'SELECT' resultColumns+=ResultColumn (',' resultColumns+=ResultColumn)* 'FROM' source=TableSource;
ColumnDef:
name=ID "varchar32"
;
ResultColumn:
column=[ColumnDef | QualifiedName];
QualifiedName: ID "." ID;
TableSource:
table=[Table | ID] ('AS' alias=ID)?;
public class MyDslScopeProvider extends AbstractDeclarativeScopeProvider {
IScope scope_ResultColumn_column(Select select, EReference ref) {
if (select.getSource() != null && select.getSource().getTable() != null) {
List<IEObjectDescription> scope = new ArrayList<IEObjectDescription>();
Table table = select.getSource().getTable();
String alias = select.getSource().getAlias();
for (ColumnDef col : table.getColumns()) {
scope.add(EObjectDescription.create(QualifiedName.create(table.getName(), col.getName()), col));
if (alias != null) {
scope.add(EObjectDescription.create(QualifiedName.create(alias, col.getName()), col));
}
}
return new SimpleScope(scope);
} else {
return IScope.NULLSCOPE;
}
}
}
~Christian
[Updated on: Sat, 19 November 2011 16:18] by Moderator
|
|
|
|
Re: Crossreference to member of aliased container [message #758284 is a reply to message #757584] |
Tue, 22 November 2011 09:52  |
Eclipse User |
|
|
|
Thank you for your answer. I guess using two references is the way to go then for me, because I need to know which alias/table was used to reference a specific column. In your (2), I would get a reference to the same column EObject, regardless of the actual table name/alias that was used. I now did it like you suggested in the last post, and it works so far.
It does not really "break" ContentAssist, but I'd rather present full "tableName.columnName" combinations in the ContentAssist, because usually there are just one or two tables involved. But I guess I'll try solving that using a customized ContentAssist.
Thanks for the help!
Regards,
Tobias
|
|
|
Powered by
FUDForum. Page generated in 0.03567 seconds