Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Cross referencing - Fake Resource Set
Cross referencing - Fake Resource Set [message #1011027] Mon, 18 February 2013 17:34 Go to next message
Dan Simkins is currently offline Dan SimkinsFriend
Messages: 38
Registered: December 2012
Member
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
Re: Cross referencing - Fake Resource Set [message #1011318 is a reply to message #1011027] Tue, 19 February 2013 10:00 Go to previous messageGo to next message
Andreas Muelder is currently offline Andreas MuelderFriend
Messages: 73
Registered: July 2011
Member
Dan,

maybe it does not work because pluto is no longer a planet? Wink

Try to bind a ResourceSetGlobalScopeProvider in the runtime module of your xtext language.It will put all elements from the resource set onto the scope.

@Override
	public Class<? extends IGlobalScopeProvider> bindIGlobalScopeProvider() {
		return ResourceSetGlobalScopeProvider.class;
	}


Best regards,

Andreas
Re: Cross referencing - Fake Resource Set [message #1011330 is a reply to message #1011318] Tue, 19 February 2013 10:39 Go to previous message
Dan Simkins is currently offline Dan SimkinsFriend
Messages: 38
Registered: December 2012
Member
Hi Andreas,

Ah, I should have prefixed pluto with "dwarf" Very Happy

I really appreciate your response and suggestion - it now works perfectly!!

Many thanks,

Dan

Previous Topic:xTextEditor to xmi serialization
Next Topic:Customizing Outline View
Goto Forum:
  


Current Time: Thu Apr 25 01:14:35 GMT 2024

Powered by FUDForum. Page generated in 0.02779 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top