Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Default import(Default import of scope)
Default import [message #733775] Wed, 05 October 2011 15:37 Go to next message
Andrew Gacek is currently offline Andrew GacekFriend
Messages: 32
Registered: October 2011
Member
I have a language which reads variable declarations from a separate fixed file. So A.mydsl, B.mydsl, and C.mydsl all look at a file called Types.mydsl. The problem is that they don't explicit reference that file. If I add an explicit reference using

'import' importURI=STRING

and add the corresponding 'import' declaration to each file then everything works fine. Is there a way to get this behavior without requiring an explicit import? The file is always called Types.mydsl and is always located in the same directory as the mydsl file which uses the types.

Thanks,
Andrew

[Updated on: Wed, 05 October 2011 15:37]

Report message to a moderator

Re: Default import [message #733778 is a reply to message #733775] Wed, 05 October 2011 15:41 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14670
Registered: July 2009
Senior Member
Hi,

what about a implicit explicit import? have a look at ImportUriGlobalScopeProvider / ImportUriResolver

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Default import [message #733783 is a reply to message #733778] Wed, 05 October 2011 15:56 Go to previous message
Andrew Gacek is currently offline Andrew GacekFriend
Messages: 32
Registered: October 2011
Member
Hi Christian,

Thank you for the quick reply. I created a subclass of ImportUriGlobalScopeProvider which tries to insert the Types.mydsl file automatically:

public class MydslImportUriGlobalScopeProvider extends
		ImportUriGlobalScopeProvider {
	
	@Override
	protected LinkedHashSet<URI> getImportedUris(final Resource resource) {
		LinkedHashSet<URI> temp = super.getImportedUris(resource);
		temp.add(URI.createURI("Types.mydsl"));
		return temp;
	}
	
}

and in my MydslRuntimeModule I now have:

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

Everything seems to work. I didn't see a correspond bind method to override the resolver, but it appears that I don't need to create my own anyway.

Thanks,
Andrew
Previous Topic:[xtext2] howto include (xtend) class as a static extension
Next Topic:[xtend2] Null-safe-operator not working
Goto Forum:
  


Current Time: Sat Apr 27 04:44:34 GMT 2024

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

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

Back to the top