Migrating Name Provider Function to Xtext 2.0 [message #683480] |
Mon, 13 June 2011 20:37 |
Rafael Angarita Messages: 94 Registered: November 2010 |
Member |
|
|
Hello,
I have this method that works very well for Xtext 1.0:
private IScope getColumnsQualifiedName(EList<Column> list) {
com.google.common.base.Function<Column, String> nameProvider = new com.google.common.base.Function<Column, String>() {
@Override
public String apply(Column from) {
CompositeNode cNode = NodeUtil.getNode(from);
EList<AbstractNode> anList = cNode.getChildren();
if (anList.size() > 1){
AbstractNode aNode = anList.get(1);
LeafNode lNode = (LeafNode) aNode;
return lNode.getText();
}
return null;
}
};
return Scopes.scopeFor(list, nameProvider, IScope.NULLSCOPE);
}
I use it to make columns of my table referencable inside the current table (i.e: as table indexes).
Those columns doesn't have a qualified name because they are cross-references to other type of object of my language.
Now, I'm migrating to Xtext 2.0 and I can't find (debugging) the value I should return here: "return lNode.getText()".
I'm following the migration guide, so I node I have to use the org.eclipse.xtext.nodemodel interfaces. Here is what I have:
private IScope getColumnsQualifiedName(Iterable<Column> list) {
com.google.common.base.Function<Column, QualifiedName> nameProvider = new com.google.common.base.Function<Column, QualifiedName>() {
@Override
public QualifiedName apply(Column from) {
ICompositeNode cNode = NodeModelUtils.getNode(from);
BidiIterable<INode> anList = cNode.getChildren();
Iterator<INode> i = anList.iterator();
if(i.hasNext()){
INode node = i.next();
ILeafNode lNode = (ILeafNode)node;
QualifiedName qn = QualifiedName.create(lNode.getText());
return qn;
}
return null;
}
};
return Scopes.scopeFor(list, nameProvider, IScope.NULLSCOPE);
//return null;
}
, but the QualifiedName qn is always "null". Sincerely, I don't understand much about how this tree model is supposed to be created, so my way of discovering where was the "lNode.getText()" i had to return was debugging, but this time, it seems I can't find it!
Maybe I missing some methods or utilities I should use.
How can I traverse correcty this tree?
Here is my table grammar:
TableDefinition:
table=Table;
Table:
'Name:' name=ID
table=TableStructure
;
TableStructure:
'Columns:' '{' columns+=Column (',' columns+=Column)* '}'
'Indexes:' '{' indexes+=Index+ '}'
('References:' '{'
references+=Reference (',' references+=Reference)* '}')?
;
Reference:
reference=[Table] ('as' name=ID '{' keymaps+=KeyMap (',' keymaps+=KeyMap)*'}')?
;
KeyMap:
fromAttribute=[Column] toAttribute=[attributeAG::Attribute]
;
Column:
attribute=[attributeAG::Attribute] (nullableColumn=NullableColumn)?
;
NullableColumn:
('null' | 'not null')
;
Index: {Index}
'Index:' indexName=IndexName (indextype = 'PrimaryKey' | indextype = 'Duplicate' | indextype = 'Unique')?
'Columns:' '{' indexcolumns+=IndexColumn (',' indexcolumns+=IndexColumn)* '}'
;
IndexName:
ID
;
IndexColumn:
indexColumn=[Column] (order=('Ascending'|'Descending'))?
;
Thank you very much for your help and great work!
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03393 seconds