Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Importing implicit global scope
Importing implicit global scope [message #1276706] Mon, 24 March 2014 23:36 Go to next message
Miles Parker is currently offline Miles ParkerFriend
Messages: 1340
Registered: July 2009
Senior Member
Hi,

I'm wondering if there is a simple pattern to follow when you want to provide an implicit set of referenced files for all editor instances? IOTW, this would act just as if you had the import uris, except that the list wouldn't have to be defined or maintained by the tool user. It seems like this should be pretty simple but I'm getting lost in the sea of IResourceDescriptors and the like when trying to implement it and I'm thinking that I might be making a simple thing too complex...

thanks and cheers,

Miles
Re: Importing implicit global scope [message #1287149 is a reply to message #1276706] Mon, 07 April 2014 13:07 Go to previous message
Pawel Pogorzelski is currently offline Pawel PogorzelskiFriend
Messages: 26
Registered: July 2009
Junior Member
Miles,
working example for supporting both - explicit and implicit imports:

public class LocalScopeProvider extends ImportedNamespaceAwareLocalScopeProvider {

	protected List<ImportNormalizer> internalGetImportedNamespaceResolvers(final EObject context, boolean ignoreCase) {
		List<ImportNormalizer> resolvers = Lists.newArrayList();

		if (context instanceof Algorithm) {
			Algorithm algorithm = (Algorithm) context;

			// treat namespace declaration as implicit import
			Namespace namespace = algorithm.getNamespace();
			if (namespace != null) {
				String namespaceName = namespace.getName();
				if (namespaceName != null) {
					namespaceName += ".*";
					ImportNormalizer resolver = createImportedNamespaceResolver(namespaceName, ignoreCase);
					if (resolver != null)
						resolvers.add(resolver);
				}
			}

			// add explicit imports
			SimpleAttributeResolver<EObject, String> importResolver = SimpleAttributeResolver.newResolver(String.class,
					"importedNamespace");
			EList<EObject> eContents = algorithm.eContents();
			for (EObject child : eContents) {
				String value = importResolver.getValue(child);
				ImportNormalizer resolver = createImportedNamespaceResolver(value, ignoreCase);
				if (resolver != null)
					resolvers.add(resolver);
			}
		}

		return resolvers;
	}

}


Corresponding snippet from the grammar file (for the part with explicit imports):
Import:
"import" comments+=Comment* importedNamespace=WildCardName;


This might be needed in you Workflow file as well:
fragment = scoping.ImportNamespacesScopingFragment {}


Cheers,
PaweĊ‚
Previous Topic:Cross References to "surrounding" resource
Next Topic:Serialization Issue with Mathematical Expression
Goto Forum:
  


Current Time: Sat Nov 29 06:33:08 GMT 2014

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

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