Skip to main content



      Home
Home » Modeling » TMF (Xtext) » How to support implicit imports?
How to support implicit imports? [message #882935] Thu, 07 June 2012 09:52 Go to next message
Eclipse UserFriend
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 10:04 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

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

~Christian

[Updated on: Thu, 07 June 2012 10:05] by Moderator

Re: How to support implicit imports? [message #883072 is a reply to message #882935] Thu, 07 June 2012 15:45 Go to previous message
Eclipse UserFriend
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
Previous Topic:Problem with XtextLinkingDiagnostic
Next Topic:Scoping docs
Goto Forum:
  


Current Time: Wed Jul 23 19:19:29 EDT 2025

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

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

Back to the top