Importing implicit global scope [message #1276706] |
Mon, 24 March 2014 19:36  |
Eclipse User |
|
|
|
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 09:07  |
Eclipse User |
|
|
|
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ł
|
|
|
Powered by
FUDForum. Page generated in 0.03837 seconds