Cross referencing - Fake Resource Set [message #1011027] |
Mon, 18 February 2013 12:34  |
Eclipse User |
|
|
|
Hi,
I am trying to get global scope for cross-referencing working using StyledTextXtextAdapter as per "TMF_meets_GMF_FINAL.pdf".
I have a simple grammar as follows:
Model:
('planets' planets+=Planet+ 'end')?
(equals='=' planet=[Planet])? ;
Planet:
name=ID description=STRING ;
If I run the default editor, all is well and I can create a list of planets and cross-reference as follows:
---------------------------------------------------------------------------------
planets
mars "Mars is the fourth planet from the Sun and the second smallest planet in the Solar System"
saturn "Saturn is the sixth planet from the Sun and the second largest planet in the Solar System"
end
= mars
---------------------------------------------------------------------------------
Following the example in "TMF_meets_GMF_FINAL.pdf", I have created the following code:
---------------------------------------------------------------------------------
/*
* create a "fake" resource and add planets
*/
IXtextFakeContextResourcesProvider provider = new IXtextFakeContextResourcesProvider()
{
public void populateFakeResourceSet( ResourceSet fakeResourceSet, XtextResource fakeResource )
{
// create context fake resources via given resource set
Model model = DataMappingFactoryImpl.eINSTANCE.createModel();
Planet mars = DataMappingFactoryImpl.eINSTANCE.createPlanet();
mars.setName( "mars" );
mars.setDescription( "description of mars" );
Planet pluto = DataMappingFactoryImpl.eINSTANCE.createPlanet();
pluto.setName( "pluto" );
pluto.setDescription( "description of pluto" );
model.getPlanets().add( mars );
model.getPlanets().add( pluto );
URI uri = fakeResource.getURI();
uri = uri.trimSegments( 1 );
uri = uri.appendSegment( "planets.dmapp" );
XtextResource newResource = (XtextResource) fakeResourceSet.createResource(uri);
newResource.getContents().add( model );
fakeResourceSet.getResources().add( newResource );
}
};
/*
* create the input widget
*/
final StyledText inputWidget = new StyledText( composite, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.WRAP );
StyledTextXtextAdapter xtextAdapter = new StyledTextXtextAdapter( injector, provider );
xtextAdapter.adapt( inputWidget );
---------------------------------------------------------------------------------
If I launch my editor and hit ctrl-space, content assist offers '=' and 'planets'. I hit '=' and then invoke content assist again. At this point I do not get further content assist which seems to indicate that the planets that I loaded in via populateFakeResourceSet are not within scope.
I would appreciate any assistance in understanding where I have gone wrong.
Many thanks,
Dan
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04357 seconds