Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » How to support implicit imports?
How to support implicit imports? [message #882935] Thu, 07 June 2012 13:52 Go to next message
Scott Finnie is currently offline Scott FinnieFriend
Messages: 94
Registered: October 2011
Member
Would appreciate pointers on how to provide implicit imports. For example, I can currently write:

Domain Banking {
	Datatype Identifier {}
	Datatype Integer {}
}

Subsystem Portfolio of domain Banking {

	import Banking.*
	
	Class Account {
		number: Identifier {I}
		balance: Integer
	}
        //..etc.
}


I'd like to remove the need for the explicit 'import' statement and have it inferred automatically from the Subsystem declaration.

I'm thinking the answer might be a custom scope provider - possibly subtyping ImportedNamespaceAwareLocalScopeProvider? However that doesn't look trivial on the face of it so would appreciate any pointers before I disappear down a dead end.

Thanks.

Re: How to support implicit imports? [message #882946 is a reply to message #882935] Thu, 07 June 2012 14:04 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13628
Registered: July 2009
Senior Member
Hi,

have a look at org.eclipse.xtext.scoping.impl.ImportedNamespaceAwareLocalScopeProvider.getImportedNamespaceResolvers(EObject, boolean)

~Christian


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Thu, 07 June 2012 14:05]

Report message to a moderator

Re: How to support implicit imports? [message #883072 is a reply to message #882935] Thu, 07 June 2012 19:45 Go to previous message
Jan Koehnlein is currently offline Jan KoehnleinFriend
Messages: 760
Registered: July 2009
Location: Hamburg
Senior Member
If your imports depend on a context object, you have to override
ImportedNamespaceScopeProvider.internalGetImportedNamespaceResolvers(EObject,
boolean)
and add your imports as an ImportNormalizer. The method
createImportedNamespaceResolver(String, boolean) helps you create such
an object. The XtendImportedNamespaceScopeProvider does something similar.

If they are fixed (such as java.lang.* in Java), the hook is
ImportedNamespaceScopeProvider.getImplicitImports(boolean). For an
example, have a look at the XbaseImportedNamespaceScopeProvider.

Don't forget to bind your subclass of the
ImportedNamespaceAwareScopeProviderin the runtime module of your language.

Am 07.06.12 15:52, schrieb Scott Finnie:
> Would appreciate pointers on how to provide implicit imports. For
> example, I can currently write:
>
> Domain Banking {
> Datatype Identifier {}
> Datatype Integer {}
> }
>
> Subsystem Portfolio of domain Banking {
>
> import Banking.*
>
> Class Account {
> number: Identifier {I}
> balance: Integer
> }
> //..etc.
> }
>
> I'd like to remove the need for the explicit 'import' statement and have
> it inferred automatically from the Subsystem declaration.
>
> I'm thinking the answer might be a custom scope provider - possibly
> subtyping ImportedNamespaceAwareLocalScopeProvider? However that doesn't
> look trivial on the face of it so would appreciate any pointers before I
> disappear down a dead end.
>
> Thanks.
>
>


--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com


---
Get professional support from the Xtext committers at www.typefox.io
Previous Topic:Problem with XtextLinkingDiagnostic
Next Topic:Scoping docs
Goto Forum:
  


Current Time: Tue Oct 20 17:41:19 GMT 2020

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

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

Back to the top